Skip to content

Commit

Permalink
Fix key resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Oct 3, 2023
1 parent 0afbdde commit a4e8e9e
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions crates/extrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,21 +436,6 @@ pub async fn fetch_wasm_code(
Ok(pristine_bytes)
}

/// Parse a contract account address from a storage key. Returns error if a key is
/// malformated.
fn parse_contract_account_address(
storage_contract_account_key: &[u8],
storage_contract_root_key_len: usize,
) -> Result<AccountId32> {
// storage_contract_account_key is a concatenation of contract_info_of root key and
// Twox64Concat(AccountId)
let mut account = storage_contract_account_key
.get(storage_contract_root_key_len + 8..)
.ok_or(anyhow!("Unexpected storage key size"))?;
AccountId32::decode(&mut account)
.map_err(|err| anyhow!("AccountId deserialization error: {}", err))
}

/// Fetch all contract addresses from the storage using the provided client and count of
/// requested elements starting from an optional address
pub async fn fetch_all_contracts(
Expand All @@ -471,7 +456,8 @@ pub async fn fetch_all_contracts(
// at the moment we are ignoring the contract info itself, this could be improved
// by returning this information.
let (key, _contract_info) = result?;
let contract_account = parse_contract_account_address(&key, key.len())?;
let contract_account = AccountId32::decode(&mut &key[..])
.map_err(|err| anyhow!("AccountId deserialization error: {}", err))?;
contract_accounts.push(contract_account);
}

Expand Down

0 comments on commit a4e8e9e

Please sign in to comment.