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:
Alexandru Vasile
2023-01-20 12:49:19 +02:00
committed by GitHub
parent 4155850063
commit e4e9562b45
17 changed files with 608 additions and 388 deletions
+44 -12
View File
@@ -42,11 +42,15 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> {
let alice_pre = api
.storage()
.fetch_or_default(&alice_account_addr, None)
.at(None)
.await?
.fetch_or_default(&alice_account_addr)
.await?;
let bob_pre = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
let tx = node_runtime::tx().balances().transfer(bob_address, 10_000);
@@ -75,11 +79,15 @@ async fn tx_basic_transfer() -> Result<(), subxt::Error> {
let alice_post = api
.storage()
.fetch_or_default(&alice_account_addr, None)
.at(None)
.await?
.fetch_or_default(&alice_account_addr)
.await?;
let bob_post = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
assert!(alice_pre.data.free - 10_000 >= alice_post.data.free);
@@ -113,11 +121,15 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> {
let alice_pre = api
.storage()
.fetch_or_default(&alice_account_addr, None)
.at(None)
.await?
.fetch_or_default(&alice_account_addr)
.await?;
let bob_pre = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
let tx = subxt::dynamic::tx(
@@ -159,11 +171,15 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> {
let alice_post = api
.storage()
.fetch_or_default(&alice_account_addr, None)
.at(None)
.await?
.fetch_or_default(&alice_account_addr)
.await?;
let bob_post = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
let alice_pre_free = alice_pre
@@ -214,7 +230,9 @@ async fn multiple_transfers_work_nonce_incremented() -> Result<(), subxt::Error>
let bob_pre = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
let tx = node_runtime::tx()
@@ -233,7 +251,9 @@ async fn multiple_transfers_work_nonce_incremented() -> Result<(), subxt::Error>
let bob_post = api
.storage()
.fetch_or_default(&bob_account_addr, None)
.at(None)
.await?
.fetch_or_default(&bob_account_addr)
.await?;
assert_eq!(bob_pre.data.free + 30_000, bob_post.data.free);
@@ -246,7 +266,14 @@ async fn storage_total_issuance() {
let api = ctx.client();
let addr = node_runtime::storage().balances().total_issuance();
let total_issuance = api.storage().fetch_or_default(&addr, None).await.unwrap();
let total_issuance = api
.storage()
.at(None)
.await
.unwrap()
.fetch_or_default(&addr)
.await
.unwrap();
assert_ne!(total_issuance, 0);
}
@@ -274,7 +301,12 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> {
let locks_addr = node_runtime::storage().balances().locks(bob);
let locks = api.storage().fetch_or_default(&locks_addr, None).await?;
let locks = api
.storage()
.at(None)
.await?
.fetch_or_default(&locks_addr)
.await?;
assert_eq!(
locks.0,
@@ -222,13 +222,23 @@ async fn tx_call() {
.contracts()
.contract_info_of(&contract);
let contract_info = cxt.client().storage().fetch(&info_addr, None).await;
let contract_info = cxt
.client()
.storage()
.at(None)
.await
.unwrap()
.fetch(&info_addr)
.await;
assert!(contract_info.is_ok());
let keys = cxt
.client()
.storage()
.fetch_keys(&info_addr.to_bytes(), 10, None, None)
.at(None)
.await
.unwrap()
.fetch_keys(&info_addr.to_bytes(), 10, None)
.await
.unwrap()
.iter()
+16 -3
View File
@@ -150,7 +150,13 @@ async fn chill_works_for_controller_only() -> Result<(), Error> {
.await?;
let ledger_addr = node_runtime::storage().staking().ledger(alice.account_id());
let ledger = api.storage().fetch(&ledger_addr, None).await?.unwrap();
let ledger = api
.storage()
.at(None)
.await?
.fetch(&ledger_addr)
.await?
.unwrap();
assert_eq!(alice_stash.account_id(), &ledger.stash);
let chill_tx = node_runtime::tx().staking().chill();
@@ -232,7 +238,9 @@ async fn storage_current_era() -> Result<(), Error> {
let current_era_addr = node_runtime::storage().staking().current_era();
let _current_era = api
.storage()
.fetch(&current_era_addr, None)
.at(None)
.await?
.fetch(&current_era_addr)
.await?
.expect("current era always exists");
Ok(())
@@ -243,7 +251,12 @@ async fn storage_era_reward_points() -> Result<(), Error> {
let ctx = test_context().await;
let api = ctx.client();
let reward_points_addr = node_runtime::storage().staking().eras_reward_points(0);
let current_era_result = api.storage().fetch(&reward_points_addr, None).await;
let current_era_result = api
.storage()
.at(None)
.await?
.fetch(&reward_points_addr)
.await;
assert!(current_era_result.is_ok());
Ok(())
@@ -24,7 +24,9 @@ async fn storage_account() -> Result<(), subxt::Error> {
let account_info = api
.storage()
.fetch_or_default(&account_info_addr, None)
.at(None)
.await?
.fetch_or_default(&account_info_addr)
.await;
assert_matches!(account_info, Ok(_));
@@ -14,7 +14,10 @@ async fn storage_get_current_timestamp() {
let timestamp = api
.storage()
.fetch(&node_runtime::storage().timestamp().now(), None)
.at(None)
.await
.unwrap()
.fetch(&node_runtime::storage().timestamp().now())
.await;
assert!(timestamp.is_ok())