mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 15:21:08 +00:00
Add support for RPC state_getReadProof (#106)
* Add support for RPC `state_getReadProof` * Format code * Add test
This commit is contained in:
@@ -36,6 +36,7 @@ hex = "0.4.0"
|
||||
sp-rpc = { version = "2.0.0-alpha.7", package = "sp-rpc" }
|
||||
sp-core = { version = "2.0.0-alpha.7", package = "sp-core" }
|
||||
sp-transaction-pool = { version = "2.0.0-alpha.7", package = "sp-transaction-pool" }
|
||||
sc-rpc-api = { version = "0.8.0-alpha.7", package = "sc-rpc-api" }
|
||||
|
||||
[dev-dependencies]
|
||||
async-std = { version = "1.5.0", features = ["attributes"] }
|
||||
|
||||
+35
@@ -50,6 +50,7 @@ use codec::{
|
||||
};
|
||||
use futures::future;
|
||||
use jsonrpsee::client::Subscription;
|
||||
use sc_rpc_api::state::ReadProof;
|
||||
use sp_core::{
|
||||
storage::{
|
||||
StorageChangeSet,
|
||||
@@ -263,6 +264,19 @@ impl<T: System, S, E> Client<T, S, E> {
|
||||
Ok(block)
|
||||
}
|
||||
|
||||
/// Get proof of storage entries at a specific block's state.
|
||||
pub async fn read_proof<H>(
|
||||
&self,
|
||||
keys: Vec<StorageKey>,
|
||||
hash: Option<H>,
|
||||
) -> Result<ReadProof<T::Hash>, Error>
|
||||
where
|
||||
H: Into<T::Hash> + 'static,
|
||||
{
|
||||
let proof = self.rpc.read_proof(keys, hash.map(|h| h.into())).await?;
|
||||
Ok(proof)
|
||||
}
|
||||
|
||||
/// Create and submit an extrinsic and return corresponding Hash if successful
|
||||
pub async fn submit_extrinsic<X: Encode>(
|
||||
&self,
|
||||
@@ -519,6 +533,10 @@ impl codec::Encode for Encoded {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sp_core::storage::{
|
||||
well_known_keys,
|
||||
StorageKey,
|
||||
};
|
||||
use sp_keyring::{
|
||||
AccountKeyring,
|
||||
Ed25519Keyring,
|
||||
@@ -575,6 +593,23 @@ mod tests {
|
||||
client.block(block_hash).await.unwrap();
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[ignore] // requires locally running substrate node
|
||||
async fn test_getting_read_proof() {
|
||||
let client = test_client().await;
|
||||
let block_hash = client.block_hash(None).await.unwrap();
|
||||
client
|
||||
.read_proof(
|
||||
vec![
|
||||
StorageKey(well_known_keys::HEAP_PAGES.to_vec()),
|
||||
StorageKey(well_known_keys::EXTRINSIC_INDEX.to_vec()),
|
||||
],
|
||||
block_hash,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
#[ignore] // requires locally running substrate node
|
||||
async fn test_state_total_issuance() {
|
||||
|
||||
+12
@@ -38,6 +38,7 @@ use jsonrpsee::{
|
||||
use num_traits::bounds::Bounded;
|
||||
|
||||
use frame_metadata::RuntimeMetadataPrefixed;
|
||||
use sc_rpc_api::state::ReadProof;
|
||||
use serde::Serialize;
|
||||
use sp_core::{
|
||||
storage::{
|
||||
@@ -230,6 +231,17 @@ impl<T: System> Rpc<T> {
|
||||
Ok(block)
|
||||
}
|
||||
|
||||
/// Get proof of storage entries at a specific block's state.
|
||||
pub async fn read_proof(
|
||||
&self,
|
||||
keys: Vec<StorageKey>,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<ReadProof<T::Hash>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(keys)?, to_json_value(hash)?]);
|
||||
let proof = self.client.request("state_getReadProof", params).await?;
|
||||
Ok(proof)
|
||||
}
|
||||
|
||||
/// Fetch the runtime version
|
||||
pub async fn runtime_version(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user