mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
Add block-centric Storage API (#774)
* blocks: Add storage method Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Add support for runtime API calls and expose it to the blocks API Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * storage: Add storage type for block centric API Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjust subxt to the new Storage interface Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Fix clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -32,8 +32,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// For storage requests, we can join futures together to
|
||||
// await multiple futures concurrently:
|
||||
let a_fut = api.storage().fetch(&staking_bonded, None);
|
||||
let b_fut = api.storage().fetch(&staking_ledger, None);
|
||||
let a_fut = api.storage().at(None).await?.fetch(&staking_bonded);
|
||||
let b_fut = api.storage().at(None).await?.fetch(&staking_ledger);
|
||||
let (a, b) = join!(a_fut, b_fut);
|
||||
|
||||
println!("{a:?}, {b:?}");
|
||||
|
||||
@@ -66,7 +66,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
let account = api
|
||||
.storage()
|
||||
.fetch_or_default(&storage_address, None)
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch_or_default(&storage_address)
|
||||
.await?
|
||||
.to_value()?;
|
||||
println!("Bob's account details: {account}");
|
||||
@@ -74,7 +76,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 4. Dynamic storage iteration (the dynamic equivalent to the fetch_all_accounts example).
|
||||
|
||||
let storage_address = subxt::dynamic::storage_root("System", "Account");
|
||||
let mut iter = api.storage().iter(storage_address, 10, None).await?;
|
||||
let mut iter = api
|
||||
.storage()
|
||||
.at(None)
|
||||
.await?
|
||||
.iter(storage_address, 10)
|
||||
.await?;
|
||||
while let Some((key, account)) = iter.next().await? {
|
||||
println!("{}: {}", hex::encode(key), account.to_value()?);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let address = polkadot::storage().system().account_root();
|
||||
|
||||
let mut iter = api.storage().iter(address, 10, None).await?;
|
||||
let mut iter = api.storage().at(None).await?.iter(address, 10).await?;
|
||||
|
||||
while let Some((key, account)) = iter.next().await? {
|
||||
println!("{}: {}", hex::encode(key), account.data.free);
|
||||
|
||||
@@ -32,7 +32,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let api = OnlineClient::<PolkadotConfig>::new().await?;
|
||||
|
||||
let active_era_addr = polkadot::storage().staking().active_era();
|
||||
let era = api.storage().fetch(&active_era_addr, None).await?.unwrap();
|
||||
let era = api
|
||||
.storage()
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch(&active_era_addr)
|
||||
.await?
|
||||
.unwrap();
|
||||
println!(
|
||||
"Staking active era: index: {:?}, start: {:?}",
|
||||
era.index, era.start
|
||||
@@ -52,13 +58,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let controller_acc_addr = polkadot::storage().staking().bonded(&alice_stash_id);
|
||||
let controller_acc = api
|
||||
.storage()
|
||||
.fetch(&controller_acc_addr, None)
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch(&controller_acc_addr)
|
||||
.await?
|
||||
.unwrap();
|
||||
println!(" account controlled by: {:?}", controller_acc);
|
||||
|
||||
let era_reward_addr = polkadot::storage().staking().eras_reward_points(era.index);
|
||||
let era_result = api.storage().fetch(&era_reward_addr, None).await?;
|
||||
let era_result = api
|
||||
.storage()
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch(&era_reward_addr)
|
||||
.await?;
|
||||
println!("Era reward points: {:?}", era_result);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
{
|
||||
let key_addr = polkadot::storage().xcm_pallet().version_notifiers_root();
|
||||
|
||||
let mut iter = api.storage().iter(key_addr, 10, None).await?;
|
||||
let mut iter = api.storage().at(None).await?.iter(key_addr, 10).await?;
|
||||
|
||||
println!("\nExample 1. Obtained keys:");
|
||||
while let Some((key, value)) = iter.next().await? {
|
||||
@@ -52,14 +52,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Fetch at most 10 keys from below the prefix XcmPallet' VersionNotifiers.
|
||||
let keys = api
|
||||
.storage()
|
||||
.fetch_keys(&key_addr.to_root_bytes(), 10, None, None)
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch_keys(&key_addr.to_root_bytes(), 10, None)
|
||||
.await?;
|
||||
|
||||
println!("Example 2. Obtained keys:");
|
||||
for key in keys.iter() {
|
||||
println!("Key: 0x{}", hex::encode(key));
|
||||
|
||||
if let Some(storage_data) = api.storage().fetch_raw(&key.0, None).await? {
|
||||
if let Some(storage_data) =
|
||||
api.storage().at(None).await?.fetch_raw(&key.0).await?
|
||||
{
|
||||
// We know the return value to be `QueryId` (`u64`) from inspecting either:
|
||||
// - polkadot code
|
||||
// - polkadot.rs generated file under `version_notifiers()` fn
|
||||
@@ -86,13 +90,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// `twox_128("XcmPallet") ++ twox_128("VersionNotifiers") ++ twox_64(2u32) ++ 2u32`
|
||||
println!("\nExample 3\nQuery key: 0x{}", hex::encode(&query_key));
|
||||
|
||||
let keys = api.storage().fetch_keys(&query_key, 10, None, None).await?;
|
||||
let keys = api
|
||||
.storage()
|
||||
.at(None)
|
||||
.await?
|
||||
.fetch_keys(&query_key, 10, None)
|
||||
.await?;
|
||||
|
||||
println!("Obtained keys:");
|
||||
for key in keys.iter() {
|
||||
println!("Key: 0x{}", hex::encode(key));
|
||||
|
||||
if let Some(storage_data) = api.storage().fetch_raw(&key.0, None).await? {
|
||||
if let Some(storage_data) =
|
||||
api.storage().at(None).await?.fetch_raw(&key.0).await?
|
||||
{
|
||||
// We know the return value to be `QueryId` (`u64`) from inspecting either:
|
||||
// - polkadot code
|
||||
// - polkadot.rs generated file under `version_notifiers()` fn
|
||||
|
||||
Reference in New Issue
Block a user