Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query asset fee details #244

Merged
merged 11 commits into from
Aug 14, 2022
Merged
57 changes: 40 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ members = [
]

#only while debugging
#[patch."https://github.com/encointer/pallets"]
#encointer-balances-tx-payment = { path = "../encointer-pallets/balances-tx-payment" }
#encointer-ceremonies-assignment = { path = "../encointer-pallets/ceremonies/assignment" }
#encointer-primitives = { path = "../encointer-pallets/primitives" }
#pallet-encointer-ceremonies = { path = "../encointer-pallets/ceremonies" }
#pallet-encointer-ceremonies-rpc = { path = "../encointer-pallets/ceremonies/rpc" }
#pallet-encointer-ceremonies-rpc-runtime-api = { path = "../encointer-pallets/ceremonies/rpc/runtime-api" }
#pallet-encointer-communities = { path = "../encointer-pallets/communities" }
#pallet-encointer-communities-rpc = { path = "../encointer-pallets/communities/rpc" }
#pallet-encointer-communities-rpc-runtime-api = { path = "../encointer-pallets/communities/rpc/runtime-api" }
#pallet-encointer-balances = { path = "../encointer-pallets/balances" }
#pallet-encointer-scheduler = { path = "../encointer-pallets/scheduler" }
#pallet-encointer-bazaar = { path = "../encointer-pallets/bazaar" }
#pallet-encointer-bazaar-rpc = { path = "../encointer-pallets/bazaar/rpc" }
#pallet-encointer-bazaar-rpc-runtime-api = { path = "../encointer-pallets/bazaar/rpc/runtime-api" }
[patch."https://github.com/encointer/pallets"]
encointer-balances-tx-payment = { path = "../pallets/balances-tx-payment" }
#encointer-balances-tx-payment-rpc-runtime-api = { path = "../pallets/balances-tx-payment/rpc/runtime-api" }
encointer-ceremonies-assignment = { path = "../pallets/ceremonies/assignment" }
encointer-primitives = { path = "../pallets/primitives" }
pallet-encointer-ceremonies = { path = "../pallets/ceremonies" }
pallet-encointer-ceremonies-rpc = { path = "../pallets/ceremonies/rpc" }
pallet-encointer-ceremonies-rpc-runtime-api = { path = "../pallets/ceremonies/rpc/runtime-api" }
pallet-encointer-communities = { path = "../pallets/communities" }
pallet-encointer-communities-rpc = { path = "../pallets/communities/rpc" }
pallet-encointer-communities-rpc-runtime-api = { path = "../pallets/communities/rpc/runtime-api" }
pallet-encointer-balances = { path = "../pallets/balances" }
pallet-encointer-scheduler = { path = "../pallets/scheduler" }
pallet-encointer-bazaar = { path = "../pallets/bazaar" }
pallet-encointer-bazaar-rpc = { path = "../pallets/bazaar/rpc" }
pallet-encointer-bazaar-rpc-runtime-api = { path = "../pallets/bazaar/rpc/runtime-api" }

#[patch."https://github.com/scs/substrate-api-client"]
#substrate-api-client = { path = "../substrate-api-client" }
Expand Down
3 changes: 3 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client

# substrate deps
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-transaction-payment = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git",branch = "master" }
sp-application-crypto = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-rpc = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand Down
51 changes: 43 additions & 8 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ use substrate_api_client::{
};
use substrate_client_keystore::{KeystoreExt, LocalKeystore};

use pallet_transaction_payment::FeeDetails;
use sp_rpc::number::NumberOrHex;

type AccountPublic = <Signature as Verify>::Signer;
const KEYSTORE_PATH: &str = "my_keystore";
const PREFUNDING_NR_OF_TRANSFER_EXTRINSICS: u128 = 1000;
Expand Down Expand Up @@ -227,14 +230,8 @@ fn main() {
let accountid = get_accountid_from_str(account);
match matches.cid_arg() {
Some(cid_str) => {
let cid = verify_cid(&api, cid_str, maybe_at);
let bn = get_block_number(&api);
let dr = get_demurrage_per_block(&api, cid);
let balance = if let Some(entry) = api
.get_storage_double_map("EncointerBalances", "Balance", cid, accountid, maybe_at).unwrap() {
apply_demurrage(entry, bn, dr)
} else { BalanceType::from_num(0) };
println!("{}", balance);
let balance = get_community_balance(&api, &cid_str, &accountid, maybe_at);
println!{"{:?}", balance};
}
None => {
if matches.all_flag() {
Expand Down Expand Up @@ -1449,6 +1446,26 @@ fn get_block_number(api: &Api) -> BlockNumber {
hdr.number
}

pub fn get_community_balance(
api: &Api,
cid_str: &str,
account_id: &AccountId,
maybe_at: Option<Hash>,
) -> BalanceType {
let cid = verify_cid(&api, cid_str, maybe_at);
let bn = get_block_number(&api);
let dr = get_demurrage_per_block(&api, cid);
let balance = if let Some(entry) = api
.get_storage_double_map("EncointerBalances", "Balance", cid, account_id, maybe_at)
.unwrap()
{
apply_demurrage(entry, bn, dr)
} else {
BalanceType::from_num(0)
};
balance
}

fn get_demurrage_per_block(api: &Api, cid: CommunityIdentifier) -> Demurrage {
let d: Option<Demurrage> = api
.get_storage_map("EncointerBalances", "DemurragePerBlock", cid, None)
Expand Down Expand Up @@ -1642,6 +1659,24 @@ fn get_all_balances(
serde_json::from_str(&n).ok()
}

fn get_asset_fee_details(
api: &Api,
cid_str: &str,
encoded_xt: &str,
) -> Option<FeeDetails<NumberOrHex>> {
let cid = verify_cid(&api, cid_str, None);
let req = json!({
"method": "encointer_queryAssetFeeDetails",
"params": vec![to_value(cid).unwrap(), to_value(encoded_xt).unwrap()],
"jsonrpc": "2.0",
"id": "1",
});

let n = api.get_request(req.into()).unwrap().expect("Could not query asset fee details");

Some(serde_json::from_str(&n).unwrap())
}

fn prove_attendance(
prover: AccountId,
cid: CommunityIdentifier,
Expand Down
Loading