Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function renamings in state api interface + improved documentation #448

Merged
merged 10 commits into from
Feb 10, 2023
2 changes: 1 addition & 1 deletion examples/examples/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn main() {
println!("Retrieving value for key {:?}", storage_key);
// We're expecting account info as return value because we fetch added a prefix of "System" + "Account".
let storage_data: AccountInfo =
api.get_storage_by_key_hash(storage_key.clone(), None).unwrap().unwrap();
api.get_storage_by_storage_key(storage_key.clone(), None).unwrap().unwrap();
println!("Retrieved data {:?}", storage_data);
}
}
2 changes: 1 addition & 1 deletion examples/examples/staking_batch_payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn get_last_reward_received_for(
let ledger_storage_key = api.metadata().storage_map_key("Staking", "Ledger", account).unwrap();

let claimed_rewards: Vec<u32> =
match api.get_storage_by_key_hash::<StakingLedger>(ledger_storage_key, None) {
match api.get_storage_by_storage_key::<StakingLedger>(ledger_storage_key, None) {
Ok(Some(ledger)) => ledger.claimed_rewards,
_ => Vec::new(),
};
Expand Down
45 changes: 18 additions & 27 deletions node-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,50 +455,41 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
impl Metadata {
pub fn storage_value_key(
&self,
storage_prefix: &'static str,
storage_key_name: &'static str,
pallet: &'static str,
key: &'static str,
) -> Result<StorageKey, MetadataError> {
Ok(self
.pallet(storage_prefix)?
.storage(storage_key_name)?
.get_value(storage_prefix)?
.key())
Ok(self.pallet(pallet)?.storage(key)?.get_value(pallet)?.key())
}

pub fn storage_map_key<K: Encode>(
&self,
storage_prefix: &'static str,
storage_key_name: &'static str,
pallet: &'static str,
key: &'static str,
map_key: K,
) -> Result<StorageKey, MetadataError> {
Ok(self
.pallet(storage_prefix)?
.storage(storage_key_name)?
.get_map::<K>(storage_prefix)?
.key(map_key))
Ok(self.pallet(pallet)?.storage(key)?.get_map::<K>(pallet)?.key(map_key))
}

pub fn storage_map_key_prefix(
&self,
storage_prefix: &'static str,
storage_key_name: &'static str,
pallet: &'static str,
key: &'static str,
) -> Result<StorageKey, MetadataError> {
self.pallet(storage_prefix)?
.storage(storage_key_name)?
.get_map_prefix(storage_prefix)
self.pallet(pallet)?.storage(key)?.get_map_prefix(pallet)
}

/// `first` and `second` are the keys for the double map.
masapr marked this conversation as resolved.
Show resolved Hide resolved
pub fn storage_double_map_key<K: Encode, Q: Encode>(
&self,
storage_prefix: &'static str,
storage_key_name: &'static str,
first: K,
second: Q,
pallet: &'static str,
key: &'static str,
first_double_map_key: K,
second_double_map_key: Q,
) -> Result<StorageKey, MetadataError> {
Ok(self
.pallet(storage_prefix)?
.storage(storage_key_name)?
.get_double_map::<K, Q>(storage_prefix)?
.key(first, second))
.pallet(pallet)?
.storage(key)?
.get_double_map::<K, Q>(pallet)?
.key(first_double_map_key, second_double_map_key))
}
}
2 changes: 1 addition & 1 deletion src/api/rpc_api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
fn fetch_events_from_block(&self, block_hash: Runtime::Hash) -> Result<Events<Runtime::Hash>> {
let key = crate::storage_key("System", "Events");
let event_bytes = self
.get_opaque_storage_by_key_hash(key, Some(block_hash))?
.get_opaque_storage_by_storage_key(key, Some(block_hash))?
.ok_or(Error::BlockNotFound)?;
let events =
Events::<Runtime::Hash>::new(self.metadata().clone(), Default::default(), event_bytes);
Expand Down
2 changes: 1 addition & 1 deletion src/api/rpc_api/frame_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
)?;

info!("storage key is: 0x{}", hex::encode(&storagekey));
self.get_storage_by_key_hash(storagekey, None)
self.get_storage_by_storage_key(storagekey, None)
}

fn get_account_data(
Expand Down
Loading