Rename: srml-contract → srml-contracts (#2905)

* srml-contract → srml-contracts

* Trim.

* Bump version
This commit is contained in:
Sergei Pepyakin
2019-06-19 15:26:33 +02:00
committed by Bastian Köcher
parent 37acb90847
commit 828485ec08
23 changed files with 102 additions and 50 deletions
+3 -3
View File
@@ -2178,7 +2178,7 @@ dependencies = [
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"srml-balances 2.0.0",
"srml-contract 2.0.0",
"srml-contracts 2.0.0",
"srml-grandpa 2.0.0",
"srml-indices 2.0.0",
"srml-session 2.0.0",
@@ -2238,7 +2238,7 @@ dependencies = [
"sr-version 2.0.0",
"srml-aura 2.0.0",
"srml-balances 2.0.0",
"srml-contract 2.0.0",
"srml-contracts 2.0.0",
"srml-council 2.0.0",
"srml-democracy 2.0.0",
"srml-executive 2.0.0",
@@ -3499,7 +3499,7 @@ dependencies = [
]
[[package]]
name = "srml-contract"
name = "srml-contracts"
version = "2.0.0"
dependencies = [
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+1 -1
View File
@@ -64,7 +64,7 @@ members = [
"srml/assets",
"srml/aura",
"srml/balances",
"srml/contract",
"srml/contracts",
"srml/council",
"srml/democracy",
"srml/example",
+1 -1
View File
@@ -388,7 +388,7 @@ substrate-trie
sr-api, sr-io, sr-primitives, sr-sandbox, sr-std, sr-version
* Substrate Runtime Module Library (SRML)
[source, shell]
srml-assets, srml-balances, srml-consensus, srml-contract, srml-council, srml-democracy, srml-example,
srml-assets, srml-balances, srml-consensus, srml-contracts, srml-council, srml-democracy, srml-example,
srml-executive, srml-metadata, srml-session, srml-staking, srml-support, srml-system, srml-timestamp,
srml-treasury
* Node
+5 -5
View File
@@ -20,7 +20,7 @@ use primitives::{ed25519, sr25519, Pair, crypto::UncheckedInto};
use node_primitives::{AccountId, AuraId};
use node_runtime::{CouncilSeatsConfig, AuraConfig, DemocracyConfig, SystemConfig,
SessionConfig, StakingConfig, StakerStatus, TimestampConfig, BalancesConfig, TreasuryConfig,
SudoConfig, ContractConfig, GrandpaConfig, IndicesConfig, Permill, Perbill, SessionKeys};
SudoConfig, ContractsConfig, GrandpaConfig, IndicesConfig, Permill, Perbill, SessionKeys};
pub use node_runtime::GenesisConfig;
use substrate_service;
use hex_literal::hex;
@@ -162,7 +162,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
spend_period: 1 * DAYS,
burn: Permill::from_percent(50),
}),
contract: Some(ContractConfig {
contracts: Some(ContractsConfig {
signed_claim_handicap: 2,
rent_byte_price: 4,
rent_deposit_offset: 1000,
@@ -268,7 +268,7 @@ pub fn testnet_genesis(
const ENDOWMENT: u128 = 1 << 20;
let council_desired_seats = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32;
let mut contract_config = ContractConfig {
let mut contracts_config = ContractsConfig {
signed_claim_handicap: 2,
rent_byte_price: 4,
rent_deposit_offset: 1000,
@@ -288,7 +288,7 @@ pub fn testnet_genesis(
current_schedule: Default::default(),
};
// this should only be enabled on development chains
contract_config.current_schedule.enable_println = enable_println;
contracts_config.current_schedule.enable_println = enable_println;
GenesisConfig {
system: Some(SystemConfig {
@@ -349,7 +349,7 @@ pub fn testnet_genesis(
spend_period: 12 * 60 * 24,
burn: Permill::from_percent(50),
}),
contract: Some(contract_config),
contracts: Some(contracts_config),
sudo: Some(SudoConfig {
key: root_key,
}),
+1 -1
View File
@@ -27,7 +27,7 @@ staking = { package = "srml-staking", path = "../../srml/staking" }
system = { package = "srml-system", path = "../../srml/system" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" }
treasury = { package = "srml-treasury", path = "../../srml/treasury" }
contract = { package = "srml-contract", path = "../../srml/contract" }
contracts = { package = "srml-contracts", path = "../../srml/contracts" }
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa" }
indices = { package = "srml-indices", path = "../../srml/indices" }
wabt = "~0.7.4"
+55 -20
View File
@@ -23,7 +23,17 @@
pub use substrate_executor::NativeExecutor;
use substrate_executor::native_executor_instance;
native_executor_instance!(pub Executor, node_runtime::api::dispatch, node_runtime::native_version, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm"));
// Declare an instance of the native executor named `Executor`. Include the wasm binary as the
// equivalent wasm code.
native_executor_instance!(
pub Executor,
node_runtime::api::dispatch,
node_runtime::native_version,
include_bytes!(
"../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm"
)
);
#[cfg(test)]
mod tests {
@@ -39,8 +49,8 @@ mod tests {
use node_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::{Header as HeaderT, Hash as HashT};
use runtime_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use {balances, indices, system, staking, timestamp, treasury, contract};
use contract::ContractAddressFor;
use {balances, indices, system, staking, timestamp, treasury, contracts};
use contracts::ContractAddressFor;
use system::{EventRecord, Phase};
use node_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System,
@@ -48,8 +58,23 @@ mod tests {
use wabt;
use primitives::map;
const BLOATY_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm");
const COMPACT_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm");
/// The wasm runtime code.
///
/// `compact` since it is after post-processing with wasm-gc which performs tree-shaking thus
/// making the binary slimmer. There is a convention to use compact version of the runtime
/// as canonical. This is why `native_executor_instance` also uses the compact version of the
/// runtime.
const COMPACT_CODE: &[u8] =
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm");
/// The wasm runtime binary which hasn't undergone the compacting process.
///
/// The idea here is to pass it as the current runtime code to the executor so the executor will
/// have to execute provided wasm code instead of the native equivalent. This trick is used to
/// test code paths that differ between native and wasm versions.
const BLOATY_CODE: &[u8] =
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm");
const GENESIS_HASH: [u8; 32] = [69u8; 32];
type TestExternalities<H> = CoreTestExternalities<H, u64>;
@@ -363,7 +388,7 @@ mod tests {
council_seats: Some(Default::default()),
timestamp: Some(Default::default()),
treasury: Some(Default::default()),
contract: Some(Default::default()),
contracts: Some(Default::default()),
sudo: Some(Default::default()),
grandpa: Some(GrandpaConfig {
_genesis_phantom_data: Default::default(),
@@ -751,10 +776,17 @@ mod tests {
)
;; Destination AccountId to transfer the funds.
;; Represented by H256 (32 bytes long) in little endian.
(data (i32.const 4) "\09\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 4)
"\09\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
"\00\00\00\00"
)
;; Amount of value to transfer.
;; Represented by u128 (16 bytes long) in little endian.
(data (i32.const 36) "\06\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 36)
"\06\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
"\00\00"
)
)
"#;
@@ -764,7 +796,7 @@ mod tests {
let transfer_code = wabt::wat2wasm(CODE_TRANSFER).unwrap();
let transfer_ch = <Runtime as system::Trait>::Hashing::hash(&transfer_code);
let addr = <Runtime as contract::Trait>::DetermineContractAddress::contract_address_for(
let addr = <Runtime as contracts::Trait>::DetermineContractAddress::contract_address_for(
&transfer_ch,
&[],
&charlie(),
@@ -781,20 +813,25 @@ mod tests {
},
CheckedExtrinsic {
signed: Some((charlie(), 0)),
function: Call::Contract(
contract::Call::put_code::<Runtime>(10_000, transfer_code)
function: Call::Contracts(
contracts::Call::put_code::<Runtime>(10_000, transfer_code)
),
},
CheckedExtrinsic {
signed: Some((charlie(), 1)),
function: Call::Contract(
contract::Call::create::<Runtime>(10, 10_000, transfer_ch, Vec::new())
function: Call::Contracts(
contracts::Call::create::<Runtime>(10, 10_000, transfer_ch, Vec::new())
),
},
CheckedExtrinsic {
signed: Some((charlie(), 2)),
function: Call::Contract(
contract::Call::call::<Runtime>(indices::address::Address::Id(addr.clone()), 10, 10_000, vec![0x00, 0x01, 0x02, 0x03])
function: Call::Contracts(
contracts::Call::call::<Runtime>(
indices::address::Address::Id(addr.clone()),
10,
10_000,
vec![0x00, 0x01, 0x02, 0x03]
)
),
},
]
@@ -807,7 +844,7 @@ mod tests {
runtime_io::with_externalities(&mut t, || {
// Verify that the contract constructor worked well and code of TRANSFER contract is actually deployed.
assert_eq!(
&contract::ContractInfoOf::<Runtime>::get(addr)
&contracts::ContractInfoOf::<Runtime>::get(addr)
.and_then(|c| c.get_alive())
.unwrap()
.code_hash,
@@ -861,8 +898,7 @@ mod tests {
#[test]
fn panic_execution_gives_error() {
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm");
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(foreign_code, map![
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
vec![69u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
@@ -889,8 +925,7 @@ mod tests {
#[test]
fn successful_execution_gives_ok() {
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm");
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(foreign_code, map![
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, map![
blake2_256(&<balances::FreeBalance<Runtime>>::key_for(alice())).to_vec() => {
vec![111u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
+3 -3
View File
@@ -17,7 +17,7 @@ version = { package = "sr-version", path = "../../core/sr-version", default-feat
support = { package = "srml-support", path = "../../srml/support", default-features = false }
aura = { package = "srml-aura", path = "../../srml/aura", default-features = false }
balances = { package = "srml-balances", path = "../../srml/balances", default-features = false }
contract = { package = "srml-contract", path = "../../srml/contract", default-features = false }
contracts = { package = "srml-contracts", path = "../../srml/contracts", default-features = false }
council = { package = "srml-council", path = "../../srml/council", default-features = false }
democracy = { package = "srml-democracy", path = "../../srml/democracy", default-features = false }
executive = { package = "srml-executive", path = "../../srml/executive", default-features = false }
@@ -39,7 +39,7 @@ substrate-keyring = { path = "../../core/keyring", optional = true }
[features]
default = ["std"]
core = [
"contract/core",
"contracts/core",
]
std = [
"parity-codec/std",
@@ -49,7 +49,7 @@ std = [
"support/std",
"aura/std",
"balances/std",
"contract/std",
"contracts/std",
"council/std",
"democracy/std",
"executive/std",
+8 -8
View File
@@ -58,8 +58,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 95,
impl_version: 95,
spec_version: 96,
impl_version: 96,
apis: RUNTIME_API_VERSIONS,
};
@@ -112,7 +112,7 @@ impl indices::Trait for Runtime {
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contract), Session);
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type Event = Event;
type TransactionPayment = ();
@@ -217,14 +217,14 @@ impl treasury::Trait for Runtime {
type ProposalRejection = ();
}
impl contract::Trait for Runtime {
impl contracts::Trait for Runtime {
type Currency = Balances;
type Call = Call;
type Event = Event;
type Gas = u64;
type DetermineContractAddress = contract::SimpleAddressDeterminator<Runtime>;
type ComputeDispatchFee = contract::DefaultDispatchFeeComputor<Runtime>;
type TrieIdGenerator = contract::TrieIdFromParentCounter<Runtime>;
type DetermineContractAddress = contracts::SimpleAddressDeterminator<Runtime>;
type ComputeDispatchFee = contracts::DefaultDispatchFeeComputor<Runtime>;
type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;
type GasPayment = ();
}
@@ -261,7 +261,7 @@ construct_runtime!(
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config<T>, Event},
Treasury: treasury,
Contract: contract,
Contracts: contracts,
Sudo: sudo,
}
);
+2 -2
View File
@@ -1484,7 +1484,7 @@ dependencies = [
"sr-version 2.0.0",
"srml-aura 2.0.0",
"srml-balances 2.0.0",
"srml-contract 2.0.0",
"srml-contracts 2.0.0",
"srml-council 2.0.0",
"srml-democracy 2.0.0",
"srml-executive 2.0.0",
@@ -2443,7 +2443,7 @@ dependencies = [
]
[[package]]
name = "srml-contract"
name = "srml-contracts"
version = "2.0.0"
dependencies = [
"parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1,5 +1,5 @@
[package]
name = "srml-contract"
name = "srml-contracts"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -75,7 +75,12 @@ pub trait AccountDb<T: Trait> {
pub struct DirectAccountDb;
impl<T: Trait> AccountDb<T> for DirectAccountDb {
fn get_storage(&self, _account: &T::AccountId, trie_id: Option<&TrieId>, location: &StorageKey) -> Option<Vec<u8>> {
fn get_storage(
&self,
_account: &T::AccountId,
trie_id: Option<&TrieId>,
location: &StorageKey
) -> Option<Vec<u8>> {
trie_id.and_then(|id| child::get_raw(id, &blake2_256(location)))
}
fn get_code_hash(&self, account: &T::AccountId) -> Option<CodeHash<T>> {
@@ -240,7 +245,12 @@ impl<'a, T: Trait> OverlayAccountDb<'a, T> {
}
impl<'a, T: Trait> AccountDb<T> for OverlayAccountDb<'a, T> {
fn get_storage(&self, account: &T::AccountId, trie_id: Option<&TrieId>, location: &StorageKey) -> Option<Vec<u8>> {
fn get_storage(
&self,
account: &T::AccountId,
trie_id: Option<&TrieId>,
location: &StorageKey
) -> Option<Vec<u8>> {
self.local
.borrow()
.get(account)
@@ -19,7 +19,8 @@
//! - In order to run contract code we need to instrument it with gas metering.
//! To do that we need to provide the schedule which will supply exact gas costs values.
//! We cache this code in the storage saving the schedule version.
//! - Before running contract code we check if the cached code has the schedule version that is equal to the current saved schedule.
//! - Before running contract code we check if the cached code has the schedule version that
//! is equal to the current saved schedule.
//! If it is equal then run the code, if it isn't reinstrument with the current schedule.
//! - When we update the schedule we want it to have strictly greater version than the current saved one:
//! this guarantees that every instrumented contract code in cache cannot have the version equal to the current one.
@@ -419,7 +419,10 @@ mod tests {
;; Input data to pass to the contract being created.
(data (i32.const 12) "\01\02\03\04")
;; Hash of code.
(data (i32.const 16) "\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11")
(data (i32.const 16)
"\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11"
"\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11"
)
)
"#;
@@ -569,7 +572,10 @@ mod tests {
(func (export "deploy"))
(data (i32.const 4) "\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11")
(data (i32.const 4)
"\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11"
"\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11"
)
)
"#;