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
+13 -3
View File
@@ -21,7 +21,12 @@ async fn storage_plain_lookup() -> Result<(), subxt::Error> {
wait_for_blocks(&api).await;
let addr = node_runtime::storage().timestamp().now();
let entry = api.storage().fetch_or_default(&addr, None).await?;
let entry = api
.storage()
.at(None)
.await?
.fetch_or_default(&addr)
.await?;
assert!(entry > 0);
Ok(())
@@ -45,7 +50,12 @@ async fn storage_map_lookup() -> Result<(), subxt::Error> {
// Look up the nonce for the user (we expect it to be 1).
let nonce_addr = node_runtime::storage().system().account(alice);
let entry = api.storage().fetch_or_default(&nonce_addr, None).await?;
let entry = api
.storage()
.at(None)
.await?
.fetch_or_default(&nonce_addr)
.await?;
assert_eq!(entry.nonce, 1);
Ok(())
@@ -113,7 +123,7 @@ async fn storage_n_map_storage_lookup() -> Result<(), subxt::Error> {
// The actual test; look up this approval in storage:
let addr = node_runtime::storage().assets().approvals(99, alice, bob);
let entry = api.storage().fetch(&addr, None).await?;
let entry = api.storage().at(None).await?.fetch(&addr).await?;
assert_eq!(entry.map(|a| a.amount), Some(123));
Ok(())
}