Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
@@ -27,7 +27,7 @@
//! Thus, before executing a contract it should be reinstrument with new schedule.
use crate::wasm::{prepare, runtime::Env, PrefabWasmModule};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Trait};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Config};
use sp_std::prelude::*;
use sp_runtime::traits::Hash;
use sp_core::crypto::UncheckedFrom;
@@ -37,7 +37,7 @@ use frame_support::StorageMap;
/// as a result of this function.
///
/// This function instruments the given code and caches it in the storage.
pub fn save<T: Trait>(
pub fn save<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -55,7 +55,7 @@ pub fn save<T: Trait>(
/// This version neither checks nor instruments the passed in code. This is useful
/// when code needs to be benchmarked without the injected instrumentation.
#[cfg(feature = "runtime-benchmarks")]
pub fn save_raw<T: Trait>(
pub fn save_raw<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -73,7 +73,7 @@ pub fn save_raw<T: Trait>(
/// If the module was instrumented with a lower version of schedule than
/// the current one given as an argument, then this function will perform
/// re-instrumentation and update the cache in the storage.
pub fn load<T: Trait>(
pub fn load<T: Config>(
code_hash: &CodeHash<T>,
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -129,8 +129,8 @@ macro_rules! define_func {
args: &[sp_sandbox::Value],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError>
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
#[allow(unused)]
@@ -190,8 +190,8 @@ macro_rules! define_env {
impl<E: Ext> $crate::wasm::env_def::FunctionImplProvider<E> for $init_name
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
fn impls<F: FnMut(&[u8], $crate::wasm::env_def::HostFunc<E>)>(f: &mut F) {
+9 -9
View File
@@ -17,7 +17,7 @@
//! This module provides a means for executing contracts
//! represented in wasm.
use crate::{CodeHash, Schedule, Trait};
use crate::{CodeHash, Schedule, Config};
use crate::wasm::env_def::FunctionImplProvider;
use crate::exec::Ext;
use crate::gas::GasMeter;
@@ -68,17 +68,17 @@ pub struct WasmExecutable {
}
/// Loader which fetches `WasmExecutable` from the code cache.
pub struct WasmLoader<'a, T: Trait> {
pub struct WasmLoader<'a, T: Config> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmLoader { schedule }
}
}
impl<'a, T: Trait> crate::exec::Loader<T> for WasmLoader<'a, T>
impl<'a, T: Config> crate::exec::Loader<T> for WasmLoader<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -101,17 +101,17 @@ where
}
/// Implementation of `Vm` that takes `WasmExecutable` and executes it.
pub struct WasmVm<'a, T: Trait> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub struct WasmVm<'a, T: Config> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmVm { schedule }
}
}
impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a, T>
impl<'a, T: Config> crate::exec::Vm<T> for WasmVm<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -462,8 +462,8 @@ mod tests {
gas_meter: &mut GasMeter<E::T>,
) -> ExecResult
where
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
use crate::exec::Vm;
@@ -20,7 +20,7 @@
use crate::wasm::env_def::ImportSatisfyCheck;
use crate::wasm::PrefabWasmModule;
use crate::{Schedule, Trait};
use crate::{Schedule, Config};
use parity_wasm::elements::{self, Internal, External, MemoryType, Type, ValueType};
use pwasm_utils;
@@ -34,13 +34,13 @@ pub const IMPORT_MODULE_FN: &str = "seal0";
/// compiler toolchains might not support specifying other modules than "env" for memory imports.
pub const IMPORT_MODULE_MEMORY: &str = "env";
struct ContractModule<'a, T: Trait> {
struct ContractModule<'a, T: Config> {
/// A deserialized module. The module is valid (this is Guaranteed by `new` method).
module: elements::Module,
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> ContractModule<'a, T> {
impl<'a, T: Config> ContractModule<'a, T> {
/// Creates a new instance of `ContractModule`.
///
/// Returns `Err` if the `original_code` couldn't be decoded or
@@ -369,7 +369,7 @@ impl<'a, T: Trait> ContractModule<'a, T> {
}
}
fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<T>)
fn get_memory_limits<T: Config>(module: Option<&MemoryType>, schedule: &Schedule<T>)
-> Result<(u32, u32), &'static str>
{
if let Some(memory_type) = module {
@@ -410,7 +410,7 @@ fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<
/// - all imported functions from the external environment matches defined by `env` module,
///
/// The preprocessing includes injecting code for gas metering and metering the height of stack.
pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
pub fn prepare_contract<C: ImportSatisfyCheck, T: Config>(
original_code: &[u8],
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> {
@@ -452,7 +452,7 @@ pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking {
use super::{
Trait, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
Config, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
};
use parity_wasm::elements::FunctionType;
@@ -463,7 +463,7 @@ pub mod benchmarking {
}
/// Prepare function that neither checks nor instruments the passed in code.
pub fn prepare_contract<T: Trait>(original_code: &[u8], schedule: &Schedule<T>)
pub fn prepare_contract<T: Config>(original_code: &[u8], schedule: &Schedule<T>)
-> Result<PrefabWasmModule, &'static str>
{
let contract_module = ContractModule::new(original_code, schedule)?;
@@ -17,7 +17,7 @@
//! Environment definition of the wasm smart-contract runtime.
use crate::{
HostFnWeights, Schedule, Trait, CodeHash, BalanceOf, Error,
HostFnWeights, Schedule, Config, CodeHash, BalanceOf, Error,
exec::{Ext, StorageKey, TopicOf},
gas::{Gas, GasMeter, Token, GasMeterResult},
wasm::env_def::ConvertibleToWasm,
@@ -193,7 +193,7 @@ pub enum RuntimeToken {
HashBlake128(u32),
}
impl<T: Trait> Token<T> for RuntimeToken
impl<T: Config> Token<T> for RuntimeToken
where
T::AccountId: UncheckedFrom<T::Hash>, T::AccountId: AsRef<[u8]>
{
@@ -291,8 +291,8 @@ pub struct Runtime<'a, E: Ext + 'a> {
impl<'a, E> Runtime<'a, E>
where
E: Ext + 'a,
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
pub fn new(
ext: &'a mut E,
@@ -709,7 +709,7 @@ define_env!(Env, <E: Ext>,
value_len: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::Transfer)?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(account_ptr, account_len)?;
let value: BalanceOf<<E as Ext>::T> =
ctx.read_sandbox_memory_as(value_ptr, value_len)?;
@@ -762,7 +762,7 @@ define_env!(Env, <E: Ext>,
output_len_ptr: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::CallBase(input_data_len))?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(callee_ptr, callee_len)?;
let value: BalanceOf<<E as Ext>::T> = ctx.read_sandbox_memory_as(value_ptr, value_len)?;
let input_data = ctx.read_sandbox_memory(input_data_ptr, input_data_len)?;
@@ -922,7 +922,7 @@ define_env!(Env, <E: Ext>,
beneficiary_len: u32
) => {
ctx.charge_gas(RuntimeToken::Terminate)?;
let beneficiary: <<E as Ext>::T as frame_system::Trait>::AccountId =
let beneficiary: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(beneficiary_ptr, beneficiary_len)?;
if let Ok(_) = ctx.ext.terminate(&beneficiary).map_err(|e| ctx.store_err(e)) {
@@ -1169,7 +1169,7 @@ define_env!(Env, <E: Ext>,
delta_count: u32
) => {
ctx.charge_gas(RuntimeToken::RestoreTo(delta_count))?;
let dest: <<E as Ext>::T as frame_system::Trait>::AccountId =
let dest: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(dest_ptr, dest_len)?;
let code_hash: CodeHash<<E as Ext>::T> =
ctx.read_sandbox_memory_as(code_hash_ptr, code_hash_len)?;