mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
[big refactor] Remove crate aliasing. (#4395)
* Rename: Phase 1. * Unify codec. * Fixing: Phase 2 * Fixing: Phase 3. * Fixing: Phase 4. * Fixing: Phase 5. * Fixing: Phase 6. * Fixing: Phase 7. * Fixing: Phase 8. Tests * Fixing: Phase 9. Tests!!! * Fixing: Phase 10. Moar tests! * Finally done! * More fixes. * Rename primitives:: to sp_core:: * Apply renames in finality-grandpa. * Fix benches. * Fix benches 2. * Revert node-template. * Fix frame-system in our modules.
This commit is contained in:
committed by
Gavin Wood
parent
f14d98a439
commit
8778ca7dc8
@@ -26,9 +26,9 @@ use sp_std::collections::btree_map::{BTreeMap, Entry};
|
||||
use sp_std::prelude::*;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use sp_runtime::traits::{Bounded, Zero};
|
||||
use support::traits::{Currency, Get, Imbalance, SignedImbalance, UpdateBalanceOutcome};
|
||||
use support::{storage::child, StorageMap};
|
||||
use system;
|
||||
use frame_support::traits::{Currency, Get, Imbalance, SignedImbalance, UpdateBalanceOutcome};
|
||||
use frame_support::{storage::child, StorageMap};
|
||||
use frame_system;
|
||||
|
||||
// Note: we don't provide Option<Contract> because we can't create
|
||||
// the trie_id in the overlay, thus we provide an overlay on the fields
|
||||
@@ -100,7 +100,7 @@ impl<T: Trait> Default for ChangeEntry<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub type ChangeSet<T> = BTreeMap<<T as system::Trait>::AccountId, ChangeEntry<T>>;
|
||||
pub type ChangeSet<T> = BTreeMap<<T as frame_system::Trait>::AccountId, ChangeEntry<T>>;
|
||||
|
||||
pub trait AccountDb<T: Trait> {
|
||||
/// Account is used when overlayed otherwise trie_id must be provided.
|
||||
@@ -184,7 +184,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
|
||||
code_hash,
|
||||
storage_size: T::StorageSizeOffset::get(),
|
||||
trie_id: <T as Trait>::TrieIdGenerator::trie_id(&address),
|
||||
deduct_block: <system::Module<T>>::block_number(),
|
||||
deduct_block: <frame_system::Module<T>>::block_number(),
|
||||
rent_allowance: <BalanceOf<T>>::max_value(),
|
||||
last_write: None,
|
||||
}
|
||||
@@ -195,7 +195,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
|
||||
code_hash,
|
||||
storage_size: T::StorageSizeOffset::get(),
|
||||
trie_id: <T as Trait>::TrieIdGenerator::trie_id(&address),
|
||||
deduct_block: <system::Module<T>>::block_number(),
|
||||
deduct_block: <frame_system::Module<T>>::block_number(),
|
||||
rent_allowance: <BalanceOf<T>>::max_value(),
|
||||
last_write: None,
|
||||
}
|
||||
@@ -213,7 +213,7 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {
|
||||
}
|
||||
|
||||
if !changed.storage.is_empty() {
|
||||
new_info.last_write = Some(<system::Module<T>>::block_number());
|
||||
new_info.last_write = Some(<frame_system::Module<T>>::block_number());
|
||||
}
|
||||
|
||||
for (k, v) in changed.storage.into_iter() {
|
||||
|
||||
@@ -22,20 +22,20 @@ use crate::rent;
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::traits::{Bounded, CheckedAdd, CheckedSub, Zero};
|
||||
use support::{
|
||||
use frame_support::{
|
||||
storage::unhashed,
|
||||
traits::{WithdrawReason, Currency, Time, Randomness},
|
||||
};
|
||||
|
||||
pub type AccountIdOf<T> = <T as system::Trait>::AccountId;
|
||||
pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
|
||||
pub type CallOf<T> = <T as Trait>::Call;
|
||||
pub type MomentOf<T> = <<T as Trait>::Time as Time>::Moment;
|
||||
pub type SeedOf<T> = <T as system::Trait>::Hash;
|
||||
pub type BlockNumberOf<T> = <T as system::Trait>::BlockNumber;
|
||||
pub type SeedOf<T> = <T as frame_system::Trait>::Hash;
|
||||
pub type BlockNumberOf<T> = <T as frame_system::Trait>::BlockNumber;
|
||||
pub type StorageKey = [u8; 32];
|
||||
|
||||
/// A type that represents a topic of an event. At the moment a hash is used.
|
||||
pub type TopicOf<T> = <T as system::Trait>::Hash;
|
||||
pub type TopicOf<T> = <T as frame_system::Trait>::Hash;
|
||||
|
||||
/// A status code return to the source of a contract call or instantiation indicating success or
|
||||
/// failure. A code of 0 indicates success and that changes are applied. All other codes indicate
|
||||
@@ -304,7 +304,7 @@ where
|
||||
vm: &vm,
|
||||
loader: &loader,
|
||||
timestamp: T::Time::now(),
|
||||
block_number: <system::Module<T>>::block_number(),
|
||||
block_number: <frame_system::Module<T>>::block_number(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -871,7 +871,7 @@ mod tests {
|
||||
|
||||
fn insert(&mut self, f: impl Fn(MockCtx) -> ExecResult + 'a) -> CodeHash<Test> {
|
||||
// Generate code hashes as monotonically increasing values.
|
||||
let code_hash = <Test as system::Trait>::Hash::from_low_u64_be(self.counter);
|
||||
let code_hash = <Test as frame_system::Trait>::Hash::from_low_u64_be(self.counter);
|
||||
|
||||
self.counter += 1;
|
||||
self.map.insert(code_hash, MockExecutable::new(f));
|
||||
|
||||
@@ -19,7 +19,7 @@ use sp_std::convert::TryFrom;
|
||||
use sp_runtime::traits::{
|
||||
CheckedMul, Zero, SaturatedConversion, SimpleArithmetic, UniqueSaturatedInto,
|
||||
};
|
||||
use support::{
|
||||
use frame_support::{
|
||||
traits::{Currency, ExistenceRequirement, Imbalance, OnUnbalanced, WithdrawReason}, StorageValue,
|
||||
};
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ pub use crate::exec::{ExecResult, ExecReturnValue, ExecError, StatusCode};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use primitives::crypto::UncheckedFrom;
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_std::{prelude::*, marker::PhantomData, fmt::Debug};
|
||||
use codec::{Codec, Encode, Decode};
|
||||
use sp_io::hashing::blake2_256;
|
||||
@@ -119,17 +119,17 @@ use sp_runtime::{
|
||||
},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use support::dispatch::{Result, Dispatchable};
|
||||
use support::{
|
||||
use frame_support::dispatch::{Result, Dispatchable};
|
||||
use frame_support::{
|
||||
Parameter, decl_module, decl_event, decl_storage, storage::child,
|
||||
parameter_types, IsSubType,
|
||||
weights::DispatchInfo,
|
||||
};
|
||||
use support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness};
|
||||
use system::{ensure_signed, RawOrigin, ensure_root};
|
||||
use primitives::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
|
||||
use frame_support::traits::{OnFreeBalanceZero, 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;
|
||||
|
||||
pub type CodeHash<T> = <T as system::Trait>::Hash;
|
||||
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
|
||||
pub type TrieId = Vec<u8>;
|
||||
|
||||
/// A function that generates an `AccountId` for a contract upon instantiation.
|
||||
@@ -203,7 +203,7 @@ impl<T: Trait> ContractInfo<T> {
|
||||
}
|
||||
|
||||
pub type AliveContractInfo<T> =
|
||||
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as system::Trait>::BlockNumber>;
|
||||
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as frame_system::Trait>::BlockNumber>;
|
||||
|
||||
/// Information for managing an account and its sub trie abstraction.
|
||||
/// This is the required info to cache for an account.
|
||||
@@ -237,7 +237,7 @@ pub(crate) fn trie_unique_id(trie_id: &[u8]) -> child::ChildInfo {
|
||||
}
|
||||
|
||||
pub type TombstoneContractInfo<T> =
|
||||
RawTombstoneContractInfo<<T as system::Trait>::Hash, <T as system::Trait>::Hashing>;
|
||||
RawTombstoneContractInfo<<T as frame_system::Trait>::Hash, <T as frame_system::Trait>::Hashing>;
|
||||
|
||||
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct RawTombstoneContractInfo<H, Hasher>(H, PhantomData<Hasher>);
|
||||
@@ -303,9 +303,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
|
||||
pub type NegativeImbalanceOf<T> =
|
||||
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
|
||||
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
|
||||
|
||||
parameter_types! {
|
||||
/// A reasonable default value for [`Trait::SignedClaimedHandicap`].
|
||||
@@ -342,16 +342,16 @@ parameter_types! {
|
||||
pub const DefaultBlockGasLimit: u32 = 10_000_000;
|
||||
}
|
||||
|
||||
pub trait Trait: system::Trait {
|
||||
pub trait Trait: frame_system::Trait {
|
||||
type Currency: Currency<Self::AccountId>;
|
||||
type Time: Time;
|
||||
type Randomness: Randomness<Self::Hash>;
|
||||
|
||||
/// The outer call dispatch type.
|
||||
type Call: Parameter + Dispatchable<Origin=<Self as system::Trait>::Origin> + IsSubType<Module<Self>, Self>;
|
||||
type Call: Parameter + Dispatchable<Origin=<Self as frame_system::Trait>::Origin> + IsSubType<Module<Self>, Self>;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
|
||||
|
||||
/// A function type to get the contract address given the instantiator.
|
||||
type DetermineContractAddress: ContractAddressFor<CodeHash<Self>, Self::AccountId>;
|
||||
@@ -469,7 +469,7 @@ impl<T: Trait> ComputeDispatchFee<<T as Trait>::Call, BalanceOf<T>> for DefaultD
|
||||
|
||||
decl_module! {
|
||||
/// Contracts module.
|
||||
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin {
|
||||
pub struct Module<T: Trait> for enum Call where origin: <T as frame_system::Trait>::Origin {
|
||||
/// Number of block delay an extrinsic claim surcharge has.
|
||||
///
|
||||
/// When claim surcharge is called by an extrinsic the rent is checked
|
||||
@@ -630,10 +630,10 @@ decl_module! {
|
||||
fn claim_surcharge(origin, dest: T::AccountId, aux_sender: Option<T::AccountId>) {
|
||||
let origin = origin.into();
|
||||
let (signed, rewarded) = match (origin, aux_sender) {
|
||||
(Ok(system::RawOrigin::Signed(account)), None) => {
|
||||
(Ok(frame_system::RawOrigin::Signed(account)), None) => {
|
||||
(true, account)
|
||||
},
|
||||
(Ok(system::RawOrigin::None), Some(aux_sender)) => {
|
||||
(Ok(frame_system::RawOrigin::None), Some(aux_sender)) => {
|
||||
(false, aux_sender)
|
||||
},
|
||||
_ => return Err(
|
||||
@@ -751,7 +751,7 @@ impl<T: Trait> Module<T> {
|
||||
DepositEvent {
|
||||
topics,
|
||||
event,
|
||||
} => <system::Module<T>>::deposit_event_indexed(
|
||||
} => <frame_system::Module<T>>::deposit_event_indexed(
|
||||
&*topics,
|
||||
<T as Trait>::Event::from(event).into(),
|
||||
),
|
||||
@@ -788,7 +788,7 @@ impl<T: Trait> Module<T> {
|
||||
.and_then(|c| c.get_alive())
|
||||
.ok_or("Cannot restore from inexisting or tombstone contract")?;
|
||||
|
||||
let current_block = <system::Module<T>>::block_number();
|
||||
let current_block = <frame_system::Module<T>>::block_number();
|
||||
|
||||
if origin_contract.last_write == Some(current_block) {
|
||||
return Err("Origin TrieId written in the current block");
|
||||
@@ -870,8 +870,8 @@ decl_event! {
|
||||
pub enum Event<T>
|
||||
where
|
||||
Balance = BalanceOf<T>,
|
||||
<T as system::Trait>::AccountId,
|
||||
<T as system::Trait>::Hash
|
||||
<T as frame_system::Trait>::AccountId,
|
||||
<T as frame_system::Trait>::Hash
|
||||
{
|
||||
/// Transfer happened `from` to `to` with given `value` as part of a `call` or `instantiate`.
|
||||
Transfer(AccountId, AccountId, Balance),
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
use crate::{BalanceOf, ContractInfo, ContractInfoOf, TombstoneContractInfo, Trait, AliveContractInfo};
|
||||
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul, Saturating, Zero,
|
||||
SaturatedConversion};
|
||||
use support::traits::{Currency, ExistenceRequirement, Get, WithdrawReason, OnUnbalanced};
|
||||
use support::StorageMap;
|
||||
use support::storage::child;
|
||||
use frame_support::traits::{Currency, ExistenceRequirement, Get, WithdrawReason, OnUnbalanced};
|
||||
use frame_support::StorageMap;
|
||||
use frame_support::storage::child;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
#[must_use]
|
||||
@@ -58,7 +58,7 @@ fn try_evict_or_and_pay_rent<T: Trait>(
|
||||
Some(ContractInfo::Alive(contract)) => contract,
|
||||
};
|
||||
|
||||
let current_block_number = <system::Module<T>>::block_number();
|
||||
let current_block_number = <frame_system::Module<T>>::block_number();
|
||||
|
||||
// How much block has passed since the last deduction for the contract.
|
||||
let blocks_passed = {
|
||||
|
||||
@@ -32,29 +32,32 @@ use sp_runtime::{
|
||||
traits::{BlakeTwo256, Hash, IdentityLookup, SignedExtension},
|
||||
testing::{Digest, DigestItem, Header, UintAuthorityId, H256},
|
||||
};
|
||||
use support::{
|
||||
use frame_support::{
|
||||
assert_ok, assert_err, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types,
|
||||
storage::child, StorageMap, StorageValue, traits::{Currency, Get},
|
||||
weights::{DispatchInfo, DispatchClass, Weight},
|
||||
};
|
||||
use std::{cell::RefCell, sync::atomic::{AtomicUsize, Ordering}};
|
||||
use primitives::storage::well_known_keys;
|
||||
use system::{self, EventRecord, Phase};
|
||||
use sp_core::storage::well_known_keys;
|
||||
use frame_system::{self as system, EventRecord, Phase};
|
||||
|
||||
mod contract {
|
||||
// Re-export contents of the root. This basically
|
||||
// needs to give a name for the current crate.
|
||||
// This hack is required for `impl_outer_event!`.
|
||||
pub use super::super::*;
|
||||
use support::impl_outer_event;
|
||||
use frame_support::impl_outer_event;
|
||||
}
|
||||
|
||||
use pallet_balances as balances;
|
||||
|
||||
impl_outer_event! {
|
||||
pub enum MetaEvent for Test {
|
||||
balances<T>, contract<T>,
|
||||
}
|
||||
}
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test { }
|
||||
pub enum Origin for Test where system = frame_system { }
|
||||
}
|
||||
impl_outer_dispatch! {
|
||||
pub enum Call for Test where origin: Origin {
|
||||
@@ -98,7 +101,7 @@ parameter_types! {
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
impl frame_system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
@@ -115,7 +118,7 @@ impl system::Trait for Test {
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type Version = ();
|
||||
}
|
||||
impl balances::Trait for Test {
|
||||
impl pallet_balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type OnFreeBalanceZero = Contract;
|
||||
type OnNewAccount = ();
|
||||
@@ -129,7 +132,7 @@ impl balances::Trait for Test {
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = 1;
|
||||
}
|
||||
impl timestamp::Trait for Test {
|
||||
impl pallet_timestamp::Trait for Test {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
@@ -178,11 +181,11 @@ impl Trait for Test {
|
||||
type BlockGasLimit = BlockGasLimit;
|
||||
}
|
||||
|
||||
type Balances = balances::Module<Test>;
|
||||
type Timestamp = timestamp::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Timestamp = pallet_timestamp::Module<Test>;
|
||||
type Contract = Module<Test>;
|
||||
type System = system::Module<Test>;
|
||||
type Randomness = randomness_collective_flip::Module<Test>;
|
||||
type System = frame_system::Module<Test>;
|
||||
type Randomness = pallet_randomness_collective_flip::Module<Test>;
|
||||
|
||||
pub struct DummyContractAddressFor;
|
||||
impl ContractAddressFor<H256, u64> for DummyContractAddressFor {
|
||||
@@ -194,7 +197,7 @@ impl ContractAddressFor<H256, u64> for DummyContractAddressFor {
|
||||
pub struct DummyTrieIdGenerator;
|
||||
impl TrieIdGenerator<u64> for DummyTrieIdGenerator {
|
||||
fn trie_id(account_id: &u64) -> TrieId {
|
||||
use primitives::storage::well_known_keys;
|
||||
use sp_core::storage::well_known_keys;
|
||||
|
||||
let new_seed = super::AccountCounter::mutate(|v| {
|
||||
*v = v.wrapping_add(1);
|
||||
@@ -270,8 +273,8 @@ impl ExtBuilder {
|
||||
}
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
self.set_associated_consts();
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
balances::GenesisConfig::<Test> {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![],
|
||||
vesting: vec![],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
@@ -289,7 +292,7 @@ impl ExtBuilder {
|
||||
/// Generate Wasm binary and code hash from wabt source.
|
||||
fn compile_module<T>(wabt_module: &str)
|
||||
-> Result<(Vec<u8>, <T::Hashing as Hash>::Output), wabt::Error>
|
||||
where T: system::Trait
|
||||
where T: frame_system::Trait
|
||||
{
|
||||
let wasm = wabt::wat2wasm(wabt_module)?;
|
||||
let code_hash = T::Hashing::hash(&wasm);
|
||||
@@ -426,7 +429,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -437,7 +440,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(
|
||||
balances::RawEvent::NewAccount(BOB, 100)
|
||||
pallet_balances::RawEvent::NewAccount(BOB, 100)
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
@@ -484,7 +487,7 @@ const CODE_DISPATCH_CALL: &str = r#"
|
||||
fn dispatch_call() {
|
||||
// This test can fail due to the encoding changes. In case it becomes too annoying
|
||||
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
|
||||
let encoded = Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50)));
|
||||
let encoded = Encode::encode(&Call::Balances(pallet_balances::Call::transfer(CHARLIE, 50)));
|
||||
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
|
||||
|
||||
let (wasm, code_hash) = compile_module::<Test>(CODE_DISPATCH_CALL).unwrap();
|
||||
@@ -499,7 +502,7 @@ fn dispatch_call() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -528,7 +531,7 @@ fn dispatch_call() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -539,7 +542,7 @@ fn dispatch_call() {
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(
|
||||
balances::RawEvent::NewAccount(BOB, 100)
|
||||
pallet_balances::RawEvent::NewAccount(BOB, 100)
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
@@ -558,14 +561,14 @@ fn dispatch_call() {
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(
|
||||
balances::RawEvent::NewAccount(CHARLIE, 50)
|
||||
pallet_balances::RawEvent::NewAccount(CHARLIE, 50)
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(
|
||||
balances::RawEvent::Transfer(BOB, CHARLIE, 50, 0)
|
||||
pallet_balances::RawEvent::Transfer(BOB, CHARLIE, 50, 0)
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
@@ -602,7 +605,7 @@ const CODE_DISPATCH_CALL_THEN_TRAP: &str = r#"
|
||||
fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
|
||||
// This test can fail due to the encoding changes. In case it becomes too annoying
|
||||
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
|
||||
let encoded = Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50)));
|
||||
let encoded = Encode::encode(&Call::Balances(pallet_balances::Call::transfer(CHARLIE, 50)));
|
||||
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
|
||||
|
||||
let (wasm, code_hash) = compile_module::<Test>(CODE_DISPATCH_CALL_THEN_TRAP).unwrap();
|
||||
@@ -617,7 +620,7 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -650,7 +653,7 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -661,7 +664,7 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(
|
||||
balances::RawEvent::NewAccount(BOB, 100)
|
||||
pallet_balances::RawEvent::NewAccount(BOB, 100)
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
@@ -802,7 +805,7 @@ mod call {
|
||||
fn test_set_rent_code_and_hash() {
|
||||
// This test can fail due to the encoding changes. In case it becomes too annoying
|
||||
// let's rewrite so as we use this module controlled call or we serialize it in runtime.
|
||||
let encoded = Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50)));
|
||||
let encoded = Encode::encode(&Call::Balances(pallet_balances::Call::transfer(CHARLIE, 50)));
|
||||
assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]);
|
||||
|
||||
let (wasm, code_hash) = compile_module::<Test>(CODE_SET_RENT).unwrap();
|
||||
@@ -816,7 +819,7 @@ fn test_set_rent_code_and_hash() {
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -841,7 +844,7 @@ fn storage_size() {
|
||||
Origin::signed(ALICE),
|
||||
30_000,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
let bob_contract = ContractInfoOf::<Test>::get(BOB).unwrap().get_alive().unwrap();
|
||||
assert_eq!(bob_contract.storage_size, <Test as Trait>::StorageSizeOffset::get() + 4);
|
||||
@@ -868,7 +871,7 @@ fn deduct_blocks() {
|
||||
Origin::signed(ALICE),
|
||||
30_000,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
// Check creation
|
||||
@@ -962,7 +965,7 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn() -> bool, removes: bool)
|
||||
Origin::signed(ALICE),
|
||||
100,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
// Advance blocks
|
||||
@@ -995,7 +998,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
Origin::signed(ALICE),
|
||||
100,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
let subsistence_threshold = 50 /*existential_deposit*/ + 16 /*tombstone_deposit*/;
|
||||
@@ -1031,7 +1034,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
Origin::signed(ALICE),
|
||||
1_000,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(100u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(100u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
// Trigger rent must have no effect
|
||||
@@ -1066,7 +1069,7 @@ fn removals(trigger_call: impl Fn() -> bool) {
|
||||
Origin::signed(ALICE),
|
||||
50+Balances::minimum_balance(),
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
// Trigger rent must have no effect
|
||||
@@ -1110,7 +1113,7 @@ fn call_removed_contract() {
|
||||
Origin::signed(ALICE),
|
||||
100,
|
||||
100_000, code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode() // rent allowance
|
||||
));
|
||||
|
||||
// Calling contract should succeed.
|
||||
@@ -1311,7 +1314,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
|
||||
assert_eq!(System::events(), vec![
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(0),
|
||||
event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
event: MetaEvent::balances(pallet_balances::RawEvent::NewAccount(1, 1_000_000)),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
@@ -1333,7 +1336,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
|
||||
30_000,
|
||||
100_000,
|
||||
set_rent_code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(0u32).encode()
|
||||
<Test as pallet_balances::Trait>::Balance::from(0u32).encode()
|
||||
));
|
||||
|
||||
// Check if `BOB` was created successfully and that the rent allowance is
|
||||
@@ -1370,7 +1373,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
|
||||
30_000,
|
||||
100_000,
|
||||
restoration_code_hash.into(),
|
||||
<Test as balances::Trait>::Balance::from(0u32).encode()
|
||||
<Test as pallet_balances::Trait>::Balance::from(0u32).encode()
|
||||
));
|
||||
|
||||
// Before performing a call to `DJANGO` save its original trie id.
|
||||
@@ -2425,7 +2428,7 @@ fn get_runtime_storage() {
|
||||
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
|
||||
Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
|
||||
support::storage::unhashed::put_raw(
|
||||
frame_support::storage::unhashed::put_raw(
|
||||
&[1, 2, 3, 4],
|
||||
0x14144020u32.to_le_bytes().to_vec().as_ref()
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ use crate::wasm::{prepare, runtime::Env, PrefabWasmModule};
|
||||
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Trait};
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::traits::{Hash, Bounded};
|
||||
use support::StorageMap;
|
||||
use frame_support::StorageMap;
|
||||
|
||||
/// Gas metering token that used for charging storing code into the code storage.
|
||||
///
|
||||
|
||||
@@ -96,7 +96,7 @@ macro_rules! unmarshall_then_body {
|
||||
#[inline(always)]
|
||||
pub fn constrain_closure<R, F>(f: F) -> F
|
||||
where
|
||||
F: FnOnce() -> Result<R, sandbox::HostError>,
|
||||
F: FnOnce() -> Result<R, sp_sandbox::HostError>,
|
||||
{
|
||||
f
|
||||
}
|
||||
@@ -110,14 +110,14 @@ macro_rules! unmarshall_then_body_then_marshall {
|
||||
unmarshall_then_body!($body, $ctx, $args_iter, $( $names : $params ),*)
|
||||
});
|
||||
let r = body()?;
|
||||
return Ok(sandbox::ReturnValue::Value({ use $crate::wasm::env_def::ConvertibleToWasm; r.to_typed_value() }))
|
||||
return Ok(sp_sandbox::ReturnValue::Value({ use $crate::wasm::env_def::ConvertibleToWasm; r.to_typed_value() }))
|
||||
});
|
||||
( $args_iter:ident, $ctx:ident, ( $( $names:ident : $params:ty ),* ) => $body:tt ) => ({
|
||||
let body = $crate::wasm::env_def::macros::constrain_closure::<(), _>(|| {
|
||||
unmarshall_then_body!($body, $ctx, $args_iter, $( $names : $params ),*)
|
||||
});
|
||||
body()?;
|
||||
return Ok(sandbox::ReturnValue::Unit)
|
||||
return Ok(sp_sandbox::ReturnValue::Unit)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ macro_rules! define_func {
|
||||
( < E: $ext_ty:tt > $name:ident ( $ctx: ident $(, $names:ident : $params:ty)*) $(-> $returns:ty)* => $body:tt ) => {
|
||||
fn $name< E: $ext_ty >(
|
||||
$ctx: &mut $crate::wasm::Runtime<E>,
|
||||
args: &[sandbox::TypedValue],
|
||||
) -> Result<sandbox::ReturnValue, sandbox::HostError> {
|
||||
args: &[sp_sandbox::TypedValue],
|
||||
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError> {
|
||||
#[allow(unused)]
|
||||
let mut args = args.iter();
|
||||
|
||||
@@ -196,7 +196,7 @@ mod tests {
|
||||
use parity_wasm::elements::FunctionType;
|
||||
use parity_wasm::elements::ValueType;
|
||||
use sp_runtime::traits::Zero;
|
||||
use sandbox::{self, ReturnValue, TypedValue};
|
||||
use sp_sandbox::{self, ReturnValue, TypedValue};
|
||||
use crate::wasm::tests::MockExt;
|
||||
use crate::wasm::Runtime;
|
||||
use crate::exec::Ext;
|
||||
@@ -206,15 +206,15 @@ mod tests {
|
||||
fn macro_unmarshall_then_body_then_marshall_value_or_trap() {
|
||||
fn test_value(
|
||||
_ctx: &mut u32,
|
||||
args: &[sandbox::TypedValue],
|
||||
) -> Result<ReturnValue, sandbox::HostError> {
|
||||
args: &[sp_sandbox::TypedValue],
|
||||
) -> Result<ReturnValue, sp_sandbox::HostError> {
|
||||
let mut args = args.iter();
|
||||
unmarshall_then_body_then_marshall!(
|
||||
args,
|
||||
_ctx,
|
||||
(a: u32, b: u32) -> u32 => {
|
||||
if b == 0 {
|
||||
Err(sandbox::HostError)
|
||||
Err(sp_sandbox::HostError)
|
||||
} else {
|
||||
Ok(a / b)
|
||||
}
|
||||
@@ -234,8 +234,8 @@ mod tests {
|
||||
fn macro_unmarshall_then_body_then_marshall_unit() {
|
||||
fn test_unit(
|
||||
ctx: &mut u32,
|
||||
args: &[sandbox::TypedValue],
|
||||
) -> Result<ReturnValue, sandbox::HostError> {
|
||||
args: &[sp_sandbox::TypedValue],
|
||||
) -> Result<ReturnValue, sp_sandbox::HostError> {
|
||||
let mut args = args.iter();
|
||||
unmarshall_then_body_then_marshall!(
|
||||
args,
|
||||
@@ -260,11 +260,11 @@ mod tests {
|
||||
if !amount.is_zero() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(sandbox::HostError)
|
||||
Err(sp_sandbox::HostError)
|
||||
}
|
||||
});
|
||||
let _f: fn(&mut Runtime<MockExt>, &[sandbox::TypedValue])
|
||||
-> Result<sandbox::ReturnValue, sandbox::HostError> = ext_gas::<MockExt>;
|
||||
let _f: fn(&mut Runtime<MockExt>, &[sp_sandbox::TypedValue])
|
||||
-> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError> = ext_gas::<MockExt>;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -312,7 +312,7 @@ mod tests {
|
||||
if !amount.is_zero() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(sandbox::HostError)
|
||||
Err(sp_sandbox::HostError)
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use super::Runtime;
|
||||
use crate::exec::Ext;
|
||||
|
||||
use sandbox::{self, TypedValue};
|
||||
use sp_sandbox::{self, TypedValue};
|
||||
use parity_wasm::elements::{FunctionType, ValueType};
|
||||
|
||||
#[macro_use]
|
||||
@@ -69,8 +69,8 @@ impl ConvertibleToWasm for u64 {
|
||||
pub(crate) type HostFunc<E> =
|
||||
fn(
|
||||
&mut Runtime<E>,
|
||||
&[sandbox::TypedValue]
|
||||
) -> Result<sandbox::ReturnValue, sandbox::HostError>;
|
||||
&[sp_sandbox::TypedValue]
|
||||
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError>;
|
||||
|
||||
pub(crate) trait FunctionImplProvider<E: Ext> {
|
||||
fn impls<F: FnMut(&[u8], HostFunc<E>)>(f: &mut F);
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::gas::GasMeter;
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use codec::{Encode, Decode};
|
||||
use sandbox;
|
||||
use sp_sandbox;
|
||||
|
||||
#[macro_use]
|
||||
mod env_def;
|
||||
@@ -114,7 +114,7 @@ impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a> {
|
||||
gas_meter: &mut GasMeter<E::T>,
|
||||
) -> ExecResult {
|
||||
let memory =
|
||||
sandbox::Memory::new(exec.prefab_module.initial, Some(exec.prefab_module.maximum))
|
||||
sp_sandbox::Memory::new(exec.prefab_module.initial, Some(exec.prefab_module.maximum))
|
||||
.unwrap_or_else(|_| {
|
||||
// unlike `.expect`, explicit panic preserves the source location.
|
||||
// Needed as we can't use `RUST_BACKTRACE` in here.
|
||||
@@ -125,7 +125,7 @@ impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a> {
|
||||
)
|
||||
});
|
||||
|
||||
let mut imports = sandbox::EnvironmentDefinitionBuilder::new();
|
||||
let mut imports = sp_sandbox::EnvironmentDefinitionBuilder::new();
|
||||
imports.add_memory("env", "memory", memory.clone());
|
||||
runtime::Env::impls(&mut |name, func_ptr| {
|
||||
imports.add_host_func("env", name, func_ptr);
|
||||
@@ -141,7 +141,7 @@ impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a> {
|
||||
|
||||
// Instantiate the instance from the instrumented module code and invoke the contract
|
||||
// entrypoint.
|
||||
let result = sandbox::Instance::new(&exec.prefab_module.code, &imports, &mut runtime)
|
||||
let result = sp_sandbox::Instance::new(&exec.prefab_module.code, &imports, &mut runtime)
|
||||
.and_then(|mut instance| instance.invoke(exec.entrypoint_name, &[], &mut runtime));
|
||||
to_execution_result(runtime, result)
|
||||
}
|
||||
@@ -152,7 +152,7 @@ mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
use primitives::H256;
|
||||
use sp_core::H256;
|
||||
use crate::exec::{Ext, StorageKey, ExecError, ExecReturnValue, STATUS_SUCCESS};
|
||||
use crate::gas::{Gas, GasMeter};
|
||||
use crate::tests::{Test, Call};
|
||||
@@ -1111,7 +1111,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
&mock_ext.dispatches,
|
||||
&[DispatchEntry(
|
||||
Call::Balances(balances::Call::set_balance(42, 1337, 0)),
|
||||
Call::Balances(pallet_balances::Call::set_balance(42, 1337, 0)),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ use crate::exec::{
|
||||
Ext, ExecResult, ExecError, ExecReturnValue, StorageKey, TopicOf, STATUS_SUCCESS,
|
||||
};
|
||||
use crate::gas::{Gas, GasMeter, Token, GasMeterResult, approx_gas_for_balance};
|
||||
use sandbox;
|
||||
use system;
|
||||
use sp_sandbox;
|
||||
use frame_system;
|
||||
use sp_std::prelude::*;
|
||||
use sp_std::convert::TryInto;
|
||||
use sp_std::mem;
|
||||
@@ -48,7 +48,7 @@ pub(crate) struct Runtime<'a, E: Ext + 'a> {
|
||||
ext: &'a mut E,
|
||||
scratch_buf: Vec<u8>,
|
||||
schedule: &'a Schedule,
|
||||
memory: sandbox::Memory,
|
||||
memory: sp_sandbox::Memory,
|
||||
gas_meter: &'a mut GasMeter<E::T>,
|
||||
special_trap: Option<SpecialTrap>,
|
||||
}
|
||||
@@ -57,7 +57,7 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
|
||||
ext: &'a mut E,
|
||||
input_data: Vec<u8>,
|
||||
schedule: &'a Schedule,
|
||||
memory: sandbox::Memory,
|
||||
memory: sp_sandbox::Memory,
|
||||
gas_meter: &'a mut GasMeter<E::T>,
|
||||
) -> Self {
|
||||
Runtime {
|
||||
@@ -74,7 +74,7 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
|
||||
|
||||
pub(crate) fn to_execution_result<E: Ext>(
|
||||
runtime: Runtime<E>,
|
||||
sandbox_result: Result<sandbox::ReturnValue, sandbox::Error>,
|
||||
sandbox_result: Result<sp_sandbox::ReturnValue, sp_sandbox::Error>,
|
||||
) -> ExecResult {
|
||||
// Special case. The trap was the result of the execution `return` host function.
|
||||
if let Some(SpecialTrap::Return(data)) = runtime.special_trap {
|
||||
@@ -84,12 +84,12 @@ pub(crate) fn to_execution_result<E: Ext>(
|
||||
// Check the exact type of the error.
|
||||
match sandbox_result {
|
||||
// No traps were generated. Proceed normally.
|
||||
Ok(sandbox::ReturnValue::Unit) => {
|
||||
Ok(sp_sandbox::ReturnValue::Unit) => {
|
||||
let mut buffer = runtime.scratch_buf;
|
||||
buffer.clear();
|
||||
Ok(ExecReturnValue { status: STATUS_SUCCESS, data: buffer })
|
||||
}
|
||||
Ok(sandbox::ReturnValue::Value(sandbox::TypedValue::I32(exit_code))) => {
|
||||
Ok(sp_sandbox::ReturnValue::Value(sp_sandbox::TypedValue::I32(exit_code))) => {
|
||||
let status = (exit_code & 0xFF).try_into()
|
||||
.expect("exit_code is masked into the range of a u8; qed");
|
||||
Ok(ExecReturnValue { status, data: runtime.scratch_buf })
|
||||
@@ -105,10 +105,10 @@ pub(crate) fn to_execution_result<E: Ext>(
|
||||
//
|
||||
// Because panics are really undesirable in the runtime code, we treat this as
|
||||
// a trap for now. Eventually, we might want to revisit this.
|
||||
Err(sandbox::Error::Module) =>
|
||||
Err(sp_sandbox::Error::Module) =>
|
||||
Err(ExecError { reason: "validation error", buffer: runtime.scratch_buf }),
|
||||
// Any other kind of a trap should result in a failure.
|
||||
Err(sandbox::Error::Execution) | Err(sandbox::Error::OutOfBounds) =>
|
||||
Err(sp_sandbox::Error::Execution) | Err(sp_sandbox::Error::OutOfBounds) =>
|
||||
Err(ExecError { reason: "during execution", buffer: runtime.scratch_buf }),
|
||||
}
|
||||
}
|
||||
@@ -182,10 +182,10 @@ fn charge_gas<T: Trait, Tok: Token<T>>(
|
||||
gas_meter: &mut GasMeter<T>,
|
||||
metadata: &Tok::Metadata,
|
||||
token: Tok,
|
||||
) -> Result<(), sandbox::HostError> {
|
||||
) -> Result<(), sp_sandbox::HostError> {
|
||||
match gas_meter.charge(metadata, token) {
|
||||
GasMeterResult::Proceed => Ok(()),
|
||||
GasMeterResult::OutOfGas => Err(sandbox::HostError),
|
||||
GasMeterResult::OutOfGas => Err(sp_sandbox::HostError),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,11 +201,11 @@ fn read_sandbox_memory<E: Ext>(
|
||||
ctx: &mut Runtime<E>,
|
||||
ptr: u32,
|
||||
len: u32,
|
||||
) -> Result<Vec<u8>, sandbox::HostError> {
|
||||
) -> Result<Vec<u8>, sp_sandbox::HostError> {
|
||||
charge_gas(ctx.gas_meter, ctx.schedule, RuntimeToken::ReadMemory(len))?;
|
||||
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
ctx.memory.get(ptr, buf.as_mut_slice()).map_err(|_| sandbox::HostError)?;
|
||||
ctx.memory.get(ptr, buf.as_mut_slice()).map_err(|_| sp_sandbox::HostError)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
@@ -221,11 +221,11 @@ fn read_sandbox_memory_into_scratch<E: Ext>(
|
||||
ctx: &mut Runtime<E>,
|
||||
ptr: u32,
|
||||
len: u32,
|
||||
) -> Result<(), sandbox::HostError> {
|
||||
) -> Result<(), sp_sandbox::HostError> {
|
||||
charge_gas(ctx.gas_meter, ctx.schedule, RuntimeToken::ReadMemory(len))?;
|
||||
|
||||
ctx.scratch_buf.resize(len as usize, 0);
|
||||
ctx.memory.get(ptr, ctx.scratch_buf.as_mut_slice()).map_err(|_| sandbox::HostError)?;
|
||||
ctx.memory.get(ptr, ctx.scratch_buf.as_mut_slice()).map_err(|_| sp_sandbox::HostError)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ fn read_sandbox_memory_into_buf<E: Ext>(
|
||||
ctx: &mut Runtime<E>,
|
||||
ptr: u32,
|
||||
buf: &mut [u8],
|
||||
) -> Result<(), sandbox::HostError> {
|
||||
) -> Result<(), sp_sandbox::HostError> {
|
||||
charge_gas(ctx.gas_meter, ctx.schedule, RuntimeToken::ReadMemory(buf.len() as u32))?;
|
||||
|
||||
ctx.memory.get(ptr, buf).map_err(Into::into)
|
||||
@@ -260,9 +260,9 @@ fn read_sandbox_memory_as<E: Ext, D: Decode>(
|
||||
ctx: &mut Runtime<E>,
|
||||
ptr: u32,
|
||||
len: u32,
|
||||
) -> Result<D, sandbox::HostError> {
|
||||
) -> Result<D, sp_sandbox::HostError> {
|
||||
let buf = read_sandbox_memory(ctx, ptr, len)?;
|
||||
D::decode(&mut &buf[..]).map_err(|_| sandbox::HostError)
|
||||
D::decode(&mut &buf[..]).map_err(|_| sp_sandbox::HostError)
|
||||
}
|
||||
|
||||
/// Write the given buffer to the designated location in the sandbox memory, consuming
|
||||
@@ -276,10 +276,10 @@ fn read_sandbox_memory_as<E: Ext, D: Decode>(
|
||||
fn write_sandbox_memory<T: Trait>(
|
||||
schedule: &Schedule,
|
||||
gas_meter: &mut GasMeter<T>,
|
||||
memory: &sandbox::Memory,
|
||||
memory: &sp_sandbox::Memory,
|
||||
ptr: u32,
|
||||
buf: &[u8],
|
||||
) -> Result<(), sandbox::HostError> {
|
||||
) -> Result<(), sp_sandbox::HostError> {
|
||||
charge_gas(gas_meter, schedule, RuntimeToken::WriteMemory(buf.len() as u32))?;
|
||||
|
||||
memory.set(ptr, buf)?;
|
||||
@@ -318,7 +318,7 @@ define_env!(Env, <E: Ext>,
|
||||
// - value_len: the length of the value. If `value_non_null` is set to 0, then this parameter is ignored.
|
||||
ext_set_storage(ctx, key_ptr: u32, value_non_null: u32, value_ptr: u32, value_len: u32) => {
|
||||
if value_non_null != 0 && ctx.ext.max_value_size() < value_len {
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
let mut key: StorageKey = [0; 32];
|
||||
read_sandbox_memory_into_buf(ctx, key_ptr, &mut key)?;
|
||||
@@ -328,7 +328,7 @@ define_env!(Env, <E: Ext>,
|
||||
} else {
|
||||
None
|
||||
};
|
||||
ctx.ext.set_storage(key, value).map_err(|_| sandbox::HostError)?;
|
||||
ctx.ext.set_storage(key, value).map_err(|_| sp_sandbox::HostError)?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
@@ -382,7 +382,7 @@ define_env!(Env, <E: Ext>,
|
||||
input_data_ptr: u32,
|
||||
input_data_len: u32
|
||||
) -> u32 => {
|
||||
let callee: <<E as Ext>::T as system::Trait>::AccountId =
|
||||
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
|
||||
read_sandbox_memory_as(ctx, callee_ptr, callee_len)?;
|
||||
let value: BalanceOf<<E as Ext>::T> =
|
||||
read_sandbox_memory_as(ctx, value_ptr, value_len)?;
|
||||
@@ -532,7 +532,7 @@ define_env!(Env, <E: Ext>,
|
||||
// The trap mechanism is used to immediately terminate the execution.
|
||||
// This trap should be handled appropriately before returning the result
|
||||
// to the user of this crate.
|
||||
Err(sandbox::HostError)
|
||||
Err(sp_sandbox::HostError)
|
||||
},
|
||||
|
||||
// Stores the address of the caller into the scratch buffer.
|
||||
@@ -597,7 +597,7 @@ define_env!(Env, <E: Ext>,
|
||||
ext_random(ctx, subject_ptr: u32, subject_len: u32) => {
|
||||
// The length of a subject can't exceed `max_subject_len`.
|
||||
if subject_len > ctx.schedule.max_subject_len {
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
|
||||
let subject_buf = read_sandbox_memory(ctx, subject_ptr, subject_len)?;
|
||||
@@ -675,7 +675,7 @@ define_env!(Env, <E: Ext>,
|
||||
delta_ptr: u32,
|
||||
delta_count: u32
|
||||
) => {
|
||||
let dest: <<E as Ext>::T as system::Trait>::AccountId =
|
||||
let dest: <<E as Ext>::T as frame_system::Trait>::AccountId =
|
||||
read_sandbox_memory_as(ctx, dest_ptr, dest_len)?;
|
||||
let code_hash: CodeHash<<E as Ext>::T> =
|
||||
read_sandbox_memory_as(ctx, code_hash_ptr, code_hash_len)?;
|
||||
@@ -696,7 +696,7 @@ define_env!(Env, <E: Ext>,
|
||||
delta.push(delta_key);
|
||||
|
||||
// Offset key_ptr to the next element.
|
||||
key_ptr = key_ptr.checked_add(KEY_SIZE as u32).ok_or_else(|| sandbox::HostError)?;
|
||||
key_ptr = key_ptr.checked_add(KEY_SIZE as u32).ok_or_else(|| sp_sandbox::HostError)?;
|
||||
}
|
||||
|
||||
delta
|
||||
@@ -729,13 +729,13 @@ define_env!(Env, <E: Ext>,
|
||||
let offset = offset as usize;
|
||||
if offset > ctx.scratch_buf.len() {
|
||||
// Offset can't be larger than scratch buffer length.
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
|
||||
// This can't panic since `offset <= ctx.scratch_buf.len()`.
|
||||
let src = &ctx.scratch_buf[offset..];
|
||||
if src.len() != len as usize {
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
|
||||
// Finally, perform the write.
|
||||
@@ -775,12 +775,12 @@ define_env!(Env, <E: Ext>,
|
||||
|
||||
// If there are more than `max_event_topics`, then trap.
|
||||
if topics.len() > ctx.schedule.max_event_topics as usize {
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
|
||||
// Check for duplicate topics. If there are any, then trap.
|
||||
if has_duplicates(&mut topics) {
|
||||
return Err(sandbox::HostError);
|
||||
return Err(sp_sandbox::HostError);
|
||||
}
|
||||
|
||||
let event_data = read_sandbox_memory(ctx, data_ptr, data_len)?;
|
||||
|
||||
Reference in New Issue
Block a user