54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use color_eyre::Result;
|
|
use subxt::{
|
|
backend::BlockRef,
|
|
utils::{Yes, H256, AccountId32},
|
|
client::OnlineClient,
|
|
};
|
|
|
|
use crate::CasperConfig;
|
|
|
|
pub mod session;
|
|
pub mod staking;
|
|
pub mod system;
|
|
pub mod babe;
|
|
pub mod balances;
|
|
|
|
pub async fn do_storage_call<'address, Addr>(
|
|
online_client: &OnlineClient<CasperConfig>,
|
|
storage_key: &'address Addr,
|
|
maybe_at_hash: Option<&H256>,
|
|
) -> Result<Option<Addr::Target>, subxt::Error>
|
|
where
|
|
Addr: subxt::storage::Address<IsFetchable = Yes> + 'address,
|
|
{
|
|
let at_hash = match maybe_at_hash {
|
|
Some(at_hash) => BlockRef::from_hash(*at_hash),
|
|
None => online_client
|
|
.backend()
|
|
.latest_finalized_block_ref()
|
|
.await?,
|
|
};
|
|
|
|
online_client
|
|
.storage()
|
|
.at(at_hash)
|
|
.fetch(storage_key)
|
|
.await
|
|
}
|
|
|
|
pub fn do_constant_call<'address, Addr>(
|
|
online_client: &OnlineClient<CasperConfig>,
|
|
constant_query: &'address Addr,
|
|
) -> Result<Addr::Target, subxt::Error>
|
|
where
|
|
Addr: subxt::constants::Address + 'address
|
|
{
|
|
let constant_client = online_client.constants();
|
|
constant_client.validate(constant_query).expect("constant query should be correct; qed");
|
|
constant_client.at(constant_query)
|
|
}
|
|
|
|
pub fn convert_array_to_account_id(who: &[u8; 32]) -> AccountId32 {
|
|
AccountId32::from(*who)
|
|
}
|