mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Child trie api changes BREAKING (#4857)
Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -125,12 +125,11 @@ use sp_runtime::{
|
||||
use frame_support::dispatch::{DispatchResult, Dispatchable};
|
||||
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
|
||||
use frame_support::{
|
||||
Parameter, decl_module, decl_event, decl_storage, decl_error, storage::child,
|
||||
parameter_types, IsSubType,
|
||||
Parameter, decl_module, decl_event, decl_storage, decl_error,
|
||||
parameter_types, IsSubType, storage::child::{self, ChildInfo},
|
||||
};
|
||||
use frame_support::traits::{OnUnbalanced, Currency, Get, Time, Randomness};
|
||||
use frame_system::{self as system, ensure_signed, RawOrigin, ensure_root};
|
||||
use sp_core::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
|
||||
use pallet_contracts_primitives::{RentProjection, ContractAccessError};
|
||||
|
||||
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
|
||||
@@ -229,15 +228,14 @@ pub struct RawAliveContractInfo<CodeHash, Balance, BlockNumber> {
|
||||
|
||||
impl<CodeHash, Balance, BlockNumber> RawAliveContractInfo<CodeHash, Balance, BlockNumber> {
|
||||
/// Associated child trie unique id is built from the hash part of the trie id.
|
||||
pub fn child_trie_unique_id(&self) -> child::ChildInfo {
|
||||
trie_unique_id(&self.trie_id[..])
|
||||
pub fn child_trie_info(&self) -> ChildInfo {
|
||||
child_trie_info(&self.trie_id[..])
|
||||
}
|
||||
}
|
||||
|
||||
/// Associated child trie unique id is built from the hash part of the trie id.
|
||||
pub(crate) fn trie_unique_id(trie_id: &[u8]) -> child::ChildInfo {
|
||||
let start = CHILD_STORAGE_KEY_PREFIX.len() + b"default:".len();
|
||||
child::ChildInfo::new_default(&trie_id[start ..])
|
||||
pub(crate) fn child_trie_info(trie_id: &[u8]) -> ChildInfo {
|
||||
ChildInfo::new_default(trie_id)
|
||||
}
|
||||
|
||||
pub type TombstoneContractInfo<T> =
|
||||
@@ -270,10 +268,6 @@ pub trait TrieIdGenerator<AccountId> {
|
||||
///
|
||||
/// The implementation must ensure every new trie id is unique: two consecutive calls with the
|
||||
/// same parameter needs to return different trie id values.
|
||||
///
|
||||
/// Also, the implementation is responsible for ensuring that `TrieId` starts with
|
||||
/// `:child_storage:`.
|
||||
/// TODO: We want to change this, see https://github.com/paritytech/substrate/issues/2325
|
||||
fn trie_id(account_id: &AccountId) -> TrieId;
|
||||
}
|
||||
|
||||
@@ -297,13 +291,7 @@ where
|
||||
let mut buf = Vec::new();
|
||||
buf.extend_from_slice(account_id.as_ref());
|
||||
buf.extend_from_slice(&new_seed.to_le_bytes()[..]);
|
||||
|
||||
// TODO: see https://github.com/paritytech/substrate/issues/2325
|
||||
CHILD_STORAGE_KEY_PREFIX.iter()
|
||||
.chain(b"default:")
|
||||
.chain(T::Hashing::hash(&buf[..]).as_ref().iter())
|
||||
.cloned()
|
||||
.collect()
|
||||
T::Hashing::hash(&buf[..]).as_ref().into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,13 +812,11 @@ impl<T: Trait> Module<T> {
|
||||
let key_values_taken = delta.iter()
|
||||
.filter_map(|key| {
|
||||
child::get_raw(
|
||||
&origin_contract.trie_id,
|
||||
origin_contract.child_trie_unique_id(),
|
||||
&origin_contract.child_trie_info(),
|
||||
&blake2_256(key),
|
||||
).map(|value| {
|
||||
child::kill(
|
||||
&origin_contract.trie_id,
|
||||
origin_contract.child_trie_unique_id(),
|
||||
&origin_contract.child_trie_info(),
|
||||
&blake2_256(key),
|
||||
);
|
||||
|
||||
@@ -842,8 +828,8 @@ impl<T: Trait> Module<T> {
|
||||
let tombstone = <TombstoneContractInfo<T>>::new(
|
||||
// This operation is cheap enough because last_write (delta not included)
|
||||
// is not this block as it has been checked earlier.
|
||||
&child::child_root(
|
||||
&origin_contract.trie_id,
|
||||
&child::root(
|
||||
&origin_contract.child_trie_info(),
|
||||
)[..],
|
||||
code_hash,
|
||||
);
|
||||
@@ -851,8 +837,7 @@ impl<T: Trait> Module<T> {
|
||||
if tombstone != dest_tombstone {
|
||||
for (key, value) in key_values_taken {
|
||||
child::put_raw(
|
||||
&origin_contract.trie_id,
|
||||
origin_contract.child_trie_unique_id(),
|
||||
&origin_contract.child_trie_info(),
|
||||
&blake2_256(key),
|
||||
&value,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user