mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 08:21:05 +00:00
Make parameter types implementation more flexible (#3112)
* Make parameter types implementation more flexible * Bump `impl_version`
This commit is contained in:
committed by
Gavin Wood
parent
9ee79d5c5e
commit
c42d73d302
@@ -70,7 +70,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 110,
|
||||
impl_version: 110,
|
||||
impl_version: 111,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
@@ -341,21 +341,11 @@ impl treasury::Trait for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const SignedClaimHandicap: BlockNumber = 2;
|
||||
pub const TombstoneDeposit: Balance = 16;
|
||||
pub const StorageSizeOffset: u32 = 8;
|
||||
pub const RentByteFee: Balance = 4;
|
||||
pub const RentDepositOffset: Balance = 1000;
|
||||
pub const SurchargeReward: Balance = 150;
|
||||
pub const ContractTransferFee: Balance = 1 * CENTS;
|
||||
pub const ContractCreationFee: Balance = 1 * CENTS;
|
||||
pub const ContractTransactionBaseFee: Balance = 1 * CENTS;
|
||||
pub const ContractTransactionByteFee: Balance = 10 * MILLICENTS;
|
||||
pub const ContractFee: Balance = 1 * CENTS;
|
||||
pub const CallBaseFee: Gas = 1000;
|
||||
pub const CreateBaseFee: Gas = 1000;
|
||||
pub const MaxDepth: u32 = 1024;
|
||||
pub const BlockGasLimit: Gas = 10_000_000;
|
||||
}
|
||||
|
||||
impl contracts::Trait for Runtime {
|
||||
@@ -366,21 +356,21 @@ impl contracts::Trait for Runtime {
|
||||
type ComputeDispatchFee = contracts::DefaultDispatchFeeComputor<Runtime>;
|
||||
type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;
|
||||
type GasPayment = ();
|
||||
type SignedClaimHandicap = SignedClaimHandicap;
|
||||
type TombstoneDeposit = TombstoneDeposit;
|
||||
type StorageSizeOffset = StorageSizeOffset;
|
||||
type RentByteFee = RentByteFee;
|
||||
type RentDepositOffset = RentDepositOffset;
|
||||
type SurchargeReward = SurchargeReward;
|
||||
type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;
|
||||
type TombstoneDeposit = contracts::DefaultTombstoneDeposit;
|
||||
type StorageSizeOffset = contracts::DefaultStorageSizeOffset;
|
||||
type RentByteFee = contracts::DefaultRentByteFee;
|
||||
type RentDepositOffset = contracts::DefaultRentDepositOffset;
|
||||
type SurchargeReward = contracts::DefaultSurchargeReward;
|
||||
type TransferFee = ContractTransferFee;
|
||||
type CreationFee = ContractCreationFee;
|
||||
type TransactionBaseFee = ContractTransactionBaseFee;
|
||||
type TransactionByteFee = ContractTransactionByteFee;
|
||||
type ContractFee = ContractFee;
|
||||
type CallBaseFee = CallBaseFee;
|
||||
type CreateBaseFee = CreateBaseFee;
|
||||
type MaxDepth = MaxDepth;
|
||||
type BlockGasLimit = BlockGasLimit;
|
||||
type CallBaseFee = contracts::DefaultCallBaseFee;
|
||||
type CreateBaseFee = contracts::DefaultCreateBaseFee;
|
||||
type MaxDepth = contracts::DefaultMaxDepth;
|
||||
type BlockGasLimit = contracts::DefaultBlockGasLimit;
|
||||
}
|
||||
|
||||
impl sudo::Trait for Runtime {
|
||||
|
||||
@@ -543,7 +543,6 @@ mod tests {
|
||||
// old uncles can't get in.
|
||||
{
|
||||
assert_eq!(System::block_number(), 8);
|
||||
assert_eq!(<Test as Trait>::UncleGenerations::get(), 5);
|
||||
|
||||
let gen_2 = seal_header(
|
||||
create_header(2, canon_chain.canon_hash(1), [3; 32].into()),
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
//! The Contract module is a work in progress. The following examples show how this Contract module can be
|
||||
//! used to create and call contracts.
|
||||
//!
|
||||
//! * [`ink`](https://github.com/paritytech/ink) is
|
||||
//! * [`ink`](https://github.com/paritytech/ink) is
|
||||
//! an [`eDSL`](https://wiki.haskell.org/Embedded_domain_specific_language) that enables writing
|
||||
//! WebAssembly based smart contracts in the Rust programming language. This is a work in progress.
|
||||
//!
|
||||
@@ -104,7 +104,8 @@ use runtime_primitives::traits::{
|
||||
};
|
||||
use srml_support::dispatch::{Result, Dispatchable};
|
||||
use srml_support::{
|
||||
Parameter, StorageMap, StorageValue, decl_module, decl_event, decl_storage, storage::child
|
||||
Parameter, StorageMap, StorageValue, decl_module, decl_event, decl_storage, storage::child,
|
||||
parameter_types,
|
||||
};
|
||||
use srml_support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get};
|
||||
use system::{ensure_signed, RawOrigin, ensure_root};
|
||||
@@ -280,21 +281,38 @@ pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as system::Trait>
|
||||
pub type NegativeImbalanceOf<T> =
|
||||
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
|
||||
|
||||
pub const DEFAULT_SIGNED_CLAIM_HANDICAP: u32 = 0;
|
||||
pub const DEFAULT_TOMBSTONE_DEPOSIT: u32 = 0;
|
||||
pub const DEFAULT_STORAGE_SIZE_OFFSET: u32 = 0;
|
||||
pub const DEFAULT_RENT_BYTE_FEE: u32 = 0;
|
||||
pub const DEFAULT_RENT_DEPOSIT_OFFSET: u32 = 0;
|
||||
pub const DEFAULT_SURCHARGE_REWARD: u32 = 0;
|
||||
pub const DEFAULT_TRANSFER_FEE: u32 = 0;
|
||||
pub const DEFAULT_CREATION_FEE: u32 = 0;
|
||||
pub const DEFAULT_TRANSACTION_BASE_FEE: u32 = 0;
|
||||
pub const DEFAULT_TRANSACTION_BYTE_FEE: u32 = 0;
|
||||
pub const DEFAULT_CONTRACT_FEE: u32 = 21;
|
||||
pub const DEFAULT_CALL_BASE_FEE: u32 = 135;
|
||||
pub const DEFAULT_CREATE_BASE_FEE: u32 = 175;
|
||||
pub const DEFAULT_MAX_DEPTH: u32 = 100;
|
||||
pub const DEFAULT_BLOCK_GAS_LIMIT: u32 = 10_000_000;
|
||||
parameter_types! {
|
||||
/// A resonable default value for [`Trait::SignedClaimedHandicap`].
|
||||
pub const DefaultSignedClaimHandicap: u32 = 2;
|
||||
/// A resonable default value for [`Trait::TombstoneDeposit`].
|
||||
pub const DefaultTombstoneDeposit: u32 = 16;
|
||||
/// A resonable default value for [`Trait::StorageSizeOffset`].
|
||||
pub const DefaultStorageSizeOffset: u32 = 8;
|
||||
/// A resonable default value for [`Trait::RentByteFee`].
|
||||
pub const DefaultRentByteFee: u32 = 4;
|
||||
/// A resonable default value for [`Trait::RentDepositOffset`].
|
||||
pub const DefaultRentDepositOffset: u32 = 1000;
|
||||
/// A resonable default value for [`Trait::SurchargeReward`].
|
||||
pub const DefaultSurchargeReward: u32 = 150;
|
||||
/// A resonable default value for [`Trait::TransferFee`].
|
||||
pub const DefaultTransferFee: u32 = 0;
|
||||
/// A resonable default value for [`Trait::CreationFee`].
|
||||
pub const DefaultCreationFee: u32 = 0;
|
||||
/// A resonable default value for [`Trait::TransactionBaseFee`].
|
||||
pub const DefaultTransactionBaseFee: u32 = 0;
|
||||
/// A resonable default value for [`Trait::TransactionByteFee`].
|
||||
pub const DefaultTransactionByteFee: u32 = 0;
|
||||
/// A resonable default value for [`Trait::ContractFee`].
|
||||
pub const DefaultContractFee: u32 = 21;
|
||||
/// A resonable default value for [`Trait::CallBaseFee`].
|
||||
pub const DefaultCallBaseFee: u32 = 1000;
|
||||
/// A resonable default value for [`Trait::CreateBaseFee`].
|
||||
pub const DefaultCreateBaseFee: u32 = 1000;
|
||||
/// A resonable default value for [`Trait::MaxDepth`].
|
||||
pub const DefaultMaxDepth: u32 = 1024;
|
||||
/// A resonable default value for [`Trait::BlockGasLimit`].
|
||||
pub const DefaultBlockGasLimit: u32 = 10_000_000;
|
||||
}
|
||||
|
||||
pub trait Trait: timestamp::Trait {
|
||||
type Currency: Currency<Self::AccountId>;
|
||||
@@ -361,24 +379,19 @@ pub trait Trait: timestamp::Trait {
|
||||
/// The fee to be paid for making a transaction; the per-byte portion.
|
||||
type TransactionByteFee: Get<BalanceOf<Self>>;
|
||||
|
||||
/// The fee required to create a contract instance. A reasonable default value
|
||||
/// is 21.
|
||||
/// The fee required to create a contract instance.
|
||||
type ContractFee: Get<BalanceOf<Self>>;
|
||||
|
||||
/// The base fee charged for calling into a contract. A reasonable default
|
||||
/// value is 135.
|
||||
/// The base fee charged for calling into a contract.
|
||||
type CallBaseFee: Get<Gas>;
|
||||
|
||||
/// The base fee charged for creating a contract. A reasonable default value
|
||||
/// is 175.
|
||||
/// The base fee charged for creating a contract.
|
||||
type CreateBaseFee: Get<Gas>;
|
||||
|
||||
/// The maximum nesting level of a call/create stack. A reasonable default
|
||||
/// value is 100.
|
||||
/// The maximum nesting level of a call/create stack.
|
||||
type MaxDepth: Get<u32>;
|
||||
|
||||
/// The maximum amount of gas that could be expended per block. A reasonable
|
||||
/// default value is 10_000_000.
|
||||
/// The maximum amount of gas that could be expended per block.
|
||||
type BlockGasLimit: Get<Gas>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1369,16 +1369,9 @@ mod tests {
|
||||
assert_eq!(Elections::next_vote_from(4), 4);
|
||||
assert_eq!(Elections::next_vote_from(5), 8);
|
||||
assert_eq!(Elections::vote_index(), 0);
|
||||
assert_eq!(<Test as Trait>::CandidacyBond::get(), 3);
|
||||
assert_eq!(<Test as Trait>::VotingBond::get(), 0);
|
||||
assert_eq!(<Test as Trait>::VotingFee::get(), 0);
|
||||
assert_eq!(<Test as Trait>::PresentSlashPerVoter::get(), 1);
|
||||
assert_eq!(Elections::presentation_duration(), 2);
|
||||
assert_eq!(<Test as Trait>::InactiveGracePeriod::get(), 1);
|
||||
assert_eq!(<Test as Trait>::VotingPeriod::get(), 4);
|
||||
assert_eq!(Elections::term_duration(), 5);
|
||||
assert_eq!(Elections::desired_seats(), 2);
|
||||
assert_eq!(<Test as Trait>::CarryCount::get(), 2);
|
||||
|
||||
assert_eq!(Elections::members(), vec![]);
|
||||
assert_eq!(Elections::next_tally(), Some(4));
|
||||
|
||||
@@ -85,19 +85,28 @@ pub use runtime_primitives::ConsensusEngineId;
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! parameter_types {
|
||||
(pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
|
||||
pub struct $name;
|
||||
$crate::parameter_types!{IMPL $name , $type , $value}
|
||||
$crate::parameter_types!{ $( $rest )* }
|
||||
);
|
||||
(const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
|
||||
struct $name;
|
||||
(
|
||||
$( #[ $attr:meta ] )*
|
||||
$vis:vis const $name:ident: $type:ty = $value:expr;
|
||||
$( $rest:tt )*
|
||||
) => (
|
||||
$( #[ $attr ] )*
|
||||
$vis struct $name;
|
||||
$crate::parameter_types!{IMPL $name , $type , $value}
|
||||
$crate::parameter_types!{ $( $rest )* }
|
||||
);
|
||||
() => ();
|
||||
(IMPL $name:ident , $type:ty , $value:expr) => {
|
||||
impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } }
|
||||
impl $name {
|
||||
fn get() -> $type {
|
||||
$value
|
||||
}
|
||||
}
|
||||
impl<I: From<$type>> $crate::traits::Get<I> for $name {
|
||||
fn get() -> I {
|
||||
I::from($value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user