Skip to content

Commit

Permalink
Query the account balance success
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Aug 4, 2023
1 parent 12cd849 commit 570718b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ shell-words = { version = "1.1.0" }
async-trait = { version = "0.1.69" }
serde_json = { version = "1.0.100" }
serde = { version = "1.0.166" }
array-bytes = "6.1.0"
clap_complete_command = { version = "0.5.1" }
frame-metadata = { version = "16.0.0", features = ["decode"] }
# substrate
Expand All @@ -29,4 +30,5 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
fp-account = { git = "https://github.com/boundless-forest/frontier", branch = "bear-polkadot-v1.0.0" }
4 changes: 2 additions & 2 deletions src/app/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub enum StateCommand {
#[command(name = "account")]
pub enum AccountCommand {
Balances {
#[arg(long)]
#[arg(name = "account-id", long)]
account_id: String,
#[arg(long)]
#[arg(name = "at-block", long)]
at_block: Option<String>,
},
}
9 changes: 7 additions & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// std
use std::str::FromStr;
// crates.io
use frame_system::AccountInfo;
use pallet_balances::AccountData;
// this crate
use crate::{
Expand Down Expand Up @@ -108,7 +109,7 @@ pub async fn handle_commands<CI: ChainInfo>(
let storage_key = map_storage_key(&metadata, "System", "Account", key)
.map_err(|_| RpcError::StorageKeyFailed)?;

let account: Option<AccountData<CI::Balance>> =
let account: Option<AccountInfo<CI::Nonce, AccountData<CI::Balance>>> =
client.get_storage(storage_key, hash).await?;
if let Some(a) = account {
use serde::{Deserialize, Serialize};
Expand All @@ -118,7 +119,11 @@ pub async fn handle_commands<CI: ChainInfo>(
pub reserved: Balance,
pub frozen: Balance,
}
let res = AccountData { free: a.free, reserved: a.reserved, frozen: a.frozen };
let res = AccountData {
free: a.data.free,
reserved: a.data.reserved,
frozen: a.data.frozen,
};

print_format_json(res);
}
Expand Down
4 changes: 4 additions & 0 deletions src/networks/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl ChainInfo for PangolinChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Pangolin;
const WS_PORT: &'static str = "wss://pangolin-rpc.darwinia.network:443";
Expand All @@ -37,6 +38,7 @@ impl ChainInfo for PangoroChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Pangoro;
const WS_PORT: &'static str = "wss://pangoro-rpc.darwinia.network:443";
Expand All @@ -52,6 +54,7 @@ impl ChainInfo for CrabChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Crab;
const WS_PORT: &'static str = "wss://crab-rpc.darwinia.network:443";
Expand All @@ -67,6 +70,7 @@ impl ChainInfo for DarwiniaChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Darwinia;
const WS_PORT: &'static str = "wss://rpc.darwinia.network:443";
Expand Down
8 changes: 5 additions & 3 deletions src/networks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use node_template::NoteTemplate;
pub use polkadot::{KusamaChain, PolkadotChain};

// std
use std::{marker::Sync, str::FromStr};
use std::{fmt::Debug, marker::Sync, str::FromStr};
// crates.io
use clap::Subcommand;
use serde::{Deserialize, Serialize};
Expand All @@ -21,10 +21,12 @@ pub trait ChainInfo: Sync + Send {
/// The network name of this chain
const NET_WORK: Network;

// The account id type of the chain
/// The account id type of the chain
type AccountId: Serialize + DeserializeOwned + Encode + FromStr + AsRef<[u8]>;
/// The balance type of the chain
type Balance: Serialize + DeserializeOwned + Decode;
type Balance: Serialize + DeserializeOwned + Decode + Debug;
/// The nonce type of the chain
type Nonce: Serialize + DeserializeOwned + Decode + Debug;
/// The block type of the chain
type Block: Serialize + DeserializeOwned;
/// The block number type of the chain
Expand Down
1 change: 1 addition & 0 deletions src/networks/node_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl ChainInfo for NoteTemplate {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Local;
const WS_PORT: &'static str = "ws://127.0.0.1:9944";
Expand Down
2 changes: 2 additions & 0 deletions src/networks/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl ChainInfo for PolkadotChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Polkadot;
const WS_PORT: &'static str = "wss://rpc.polkadot.io:443";
Expand All @@ -37,6 +38,7 @@ impl ChainInfo for KusamaChain {
type BlockNumber = u32;
type Hash = H256;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Nonce = u32;

const NET_WORK: Network = Network::Kusama;
const WS_PORT: &'static str = "wss://kusama-rpc.polkadot.io:443";
Expand Down

0 comments on commit 570718b

Please sign in to comment.