use crate::{
api, connections::TxInfo, frame_system::pallet::Call::set_code, AccountId, Balance, BlockHash,
Call::System, ConnectionApi, RootConnection, SudoCall, TxStatus,
};
#[async_trait::async_trait]
pub trait SystemApi {
async fn get_free_balance(&self, account: AccountId, at: Option<BlockHash>) -> Balance;
}
#[async_trait::async_trait]
pub trait SystemSudoApi {
async fn set_code(&self, code: Vec<u8>, status: TxStatus) -> anyhow::Result<TxInfo>;
}
#[async_trait::async_trait]
impl SystemSudoApi for RootConnection {
async fn set_code(&self, code: Vec<u8>, status: TxStatus) -> anyhow::Result<TxInfo> {
let call = System(set_code { code });
self.sudo_unchecked(call, status).await
}
}
#[async_trait::async_trait]
impl<C: ConnectionApi> SystemApi for C {
async fn get_free_balance(&self, account: AccountId, at: Option<BlockHash>) -> Balance {
let addrs = api::storage().system().account(&account);
match self.get_storage_entry_maybe(&addrs, at).await {
None => 0,
Some(account) => account.data.free,
}
}
}