difftreelog
NFTPAR-47 + contracts module
in: master
9 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2762,8 +2762,10 @@
version = "2.0.0-rc4"
dependencies = [
"futures 0.3.5",
+ "jsonrpc-core",
"log",
"nft-runtime",
+ "pallet-contracts-rpc",
"parking_lot 0.10.2",
"sc-basic-authorship",
"sc-cli",
@@ -2773,6 +2775,7 @@
"sc-executor",
"sc-finality-grandpa",
"sc-network",
+ "sc-rpc",
"sc-service",
"sc-transaction-pool",
"sp-consensus",
@@ -2795,6 +2798,9 @@
"frame-system",
"pallet-aura",
"pallet-balances",
+ "pallet-contracts",
+ "pallet-contracts-primitives",
+ "pallet-contracts-rpc-runtime-api",
"pallet-grandpa",
"pallet-nft",
"pallet-randomness-collective-flip",
@@ -3013,6 +3019,67 @@
]
[[package]]
+name = "pallet-contracts"
+version = "2.0.0-rc4"
+source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "pallet-contracts-primitives",
+ "parity-scale-codec",
+ "parity-wasm",
+ "pwasm-utils",
+ "serde",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-sandbox",
+ "sp-std",
+ "wasmi-validation",
+]
+
+[[package]]
+name = "pallet-contracts-primitives"
+version = "2.0.0-rc4"
+source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
+dependencies = [
+ "parity-scale-codec",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
+name = "pallet-contracts-rpc"
+version = "0.8.0-rc4"
+source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
+dependencies = [
+ "jsonrpc-core",
+ "jsonrpc-core-client",
+ "jsonrpc-derive",
+ "pallet-contracts-primitives",
+ "pallet-contracts-rpc-runtime-api",
+ "parity-scale-codec",
+ "serde",
+ "sp-api",
+ "sp-blockchain",
+ "sp-core",
+ "sp-rpc",
+ "sp-runtime",
+]
+
+[[package]]
+name = "pallet-contracts-rpc-runtime-api"
+version = "0.8.0-rc4"
+source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
+dependencies = [
+ "pallet-contracts-primitives",
+ "parity-scale-codec",
+ "sp-api",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
name = "pallet-finality-tracker"
version = "2.0.0-rc4"
source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
@@ -3620,6 +3687,17 @@
checksum = "8e86d370532557ae7573551a1ec8235a0f8d6cb276c7c9e6aa490b511c447485"
[[package]]
+name = "pwasm-utils"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192"
+dependencies = [
+ "byteorder",
+ "log",
+ "parity-wasm",
+]
+
+[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -5576,6 +5654,19 @@
]
[[package]]
+name = "sp-sandbox"
+version = "0.8.0-rc4"
+source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
+dependencies = [
+ "parity-scale-codec",
+ "sp-core",
+ "sp-io",
+ "sp-std",
+ "sp-wasm-interface",
+ "wasmi",
+]
+
+[[package]]
name = "sp-serializer"
version = "2.0.0-rc4"
source = "git+https://github.com/paritytech/substrate.git?tag=v2.0.0-rc4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
node/Cargo.tomldiffbeforeafterboth--- a/node/Cargo.toml
+++ b/node/Cargo.toml
@@ -20,6 +20,16 @@
log = '0.4.8'
parking_lot = '0.10.0'
structopt = '0.3.8'
+jsonrpc-core = '14.0.5'
+
+[dependencies.pallet-contracts-rpc]
+git = 'https://github.com/paritytech/substrate.git'
+version = '0.8.0-rc4'
+tag = 'v2.0.0-rc4'
+
+[dependencies.sc-rpc]
+git = 'https://github.com/paritytech/substrate.git'
+tag = 'v2.0.0-rc4'
[dependencies.nft-runtime]
path = '../runtime'
node/src/chain_spec.rsdiffbeforeafterboth--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -8,6 +8,8 @@
use sp_runtime::traits::{Verify, IdentifyAccount};
use sc_service::ChainType;
+use nft_runtime::{ContractsConfig, ContractsSchedule};
+
// Note this is the URL for the telemetry server
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
@@ -111,6 +113,12 @@
balances: Some(BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
}),
+ contracts: Some(ContractsConfig {
+ current_schedule: ContractsSchedule {
+ // enable_println,
+ ..Default::default()
+ },
+ }),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}),
node/src/service.rsdiffbeforeafterboth--- a/node/src/service.rs
+++ b/node/src/service.rs
@@ -27,6 +27,7 @@
/// be able to perform chain operations.
macro_rules! new_full_start {
($config:expr) => {{
+ use jsonrpc_core::IoHandler;
use std::sync::Arc;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
@@ -86,7 +87,15 @@
import_setup = Some((grandpa_block_import, grandpa_link));
Ok(import_queue)
- })?;
+ })?
+ .with_rpc_extensions(|builder| -> Result<IoHandler<sc_rpc::Metadata>, _> {
+ let handler = pallet_contracts_rpc::Contracts::new(builder.client().clone());
+ let delegate = pallet_contracts_rpc::ContractsApi::to_delegate(handler);
+
+ let mut io = IoHandler::default();
+ io.extend_with(delegate);
+ Ok(io)
+ })?;
(builder, import_setup, inherent_data_providers)
}}
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -58,10 +58,7 @@
/// Next available collection ID
pub NextCollectionID get(fn next_collection_id): u64;
-
pub Collection get(fn collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
- //pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
-
pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;
/// Balance owner per collection map
@@ -69,10 +66,10 @@
pub ApprovedList get(fn approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;
pub ItemList get(fn item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
- // pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
+ pub ItemListIndex get(fn item_index): map hasher(blake2_128_concat) u64 => u64;
+
+ pub AddressTokens get(fn address_tokens): map hasher(blake2_128_concat) (u64, T::AccountId) => Vec<u64>;
- pub ItemListIndex get(fn item_index): map hasher(blake2_128_concat) u64 => u64;
- // pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;
}
}
@@ -247,7 +244,11 @@
data: properties,
};
+
let current_index = <ItemListIndex>::get(collection_id);
+
+ Self::add_token_index(collection_id, current_index, new_item.owner.clone())?;
+
<ItemListIndex>::insert(collection_id, current_index);
<ItemList<T>>::insert((collection_id, current_index), new_item);
@@ -279,6 +280,8 @@
}
<ItemList<T>>::remove((collection_id, item_id));
+ Self::remove_token_index(collection_id, item_id, item.owner.clone())?;
+
// update balance
let new_balance = <Balance<T>>::get((collection_id, item.owner.clone())) - 1;
<Balance<T>>::insert((collection_id, item.owner.clone()), new_balance);
@@ -319,9 +322,13 @@
<Balance<T>>::insert((collection_id, new_owner.clone()), balance_new_owner);
// change owner
- item.owner = new_owner;
+ let old_owner = item.owner.clone();
+ item.owner = new_owner.clone();
<ItemList<T>>::insert((collection_id, item_id), item);
+ // update index collection
+ Self::move_token_index(collection_id, item_id, old_owner, new_owner.clone())?;
+
// reset approved list
let itm: Vec<T::AccountId> = Vec::new();
<ApprovedList<T>>::insert((collection_id, item_id), itm);
@@ -401,3 +408,55 @@
}
}
}
+
+
+impl<T: Trait> Module<T> {
+ fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {
+
+ let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));
+ if list_exists {
+
+ let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));
+ let item_contains = list.contains(&item_index.clone());
+
+ if !item_contains {
+ list.push(item_index.clone());
+ }
+
+ <AddressTokens<T>>::insert((collection_id, owner.clone()), list);
+
+ } else {
+
+ let mut itm = Vec::new();
+ itm.push(item_index.clone());
+ <AddressTokens<T>>::insert((collection_id, owner), itm);
+ }
+
+ Ok(())
+ }
+
+ fn remove_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {
+
+ let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));
+ if list_exists {
+
+ let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));
+ let item_contains = list.contains(&item_index.clone());
+
+ if item_contains {
+ list.retain(|&item| item != item_index);
+ <AddressTokens<T>>::insert((collection_id, owner), list);
+ }
+ }
+
+ Ok(())
+ }
+
+ fn move_token_index(collection_id: u64, item_index: u64, old_owner: T::AccountId, new_owner: T::AccountId) -> DispatchResult {
+
+ Self::remove_token_index(collection_id, item_index, old_owner)?;
+ Self::add_token_index(collection_id, item_index, new_owner)?;
+
+ Ok(())
+ }
+}
\ No newline at end of file
pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -1,7 +1,12 @@
// Creating mock runtime here
use crate::{Module, Trait};
-use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
+use frame_support::{
+ impl_outer_origin, parameter_types,
+ weights::{
+ Weight,
+ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND },
+ }};
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
@@ -11,7 +16,8 @@
};
impl_outer_origin! {
- pub enum Origin for Test {}
+ pub enum Origin for Test {
+ }
}
// For testing the pallet, we construct most of a mock runtime. This means
@@ -24,12 +30,17 @@
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
+ pub MaximumExtrinsicWeight: Weight = 10 * WEIGHT_PER_SECOND;
}
+
impl system::Trait for Test {
type Origin = Origin;
type Call = ();
type Index = u64;
type BlockNumber = u64;
+ type BaseCallFilter = ();
+ type DbWeight = RocksDbWeight;
+ type BlockExecutionWeight = BlockExecutionWeight;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
@@ -37,6 +48,8 @@
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
+ type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
+ type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type MaximumBlockWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
@@ -49,6 +62,7 @@
impl Trait for Test {
type Event = ();
}
+
pub type TemplateModule = Module<Test>;
// This function basically just builds a genesis storage key/value store according to
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -297,3 +297,50 @@
assert_ok!(TemplateModule::transfer_from(origin1.clone(), 1, 1, 2));
});
}
+
+#[test]
+fn index_list() {
+ new_test_ext().execute_with(|| {
+ let size = 1024;
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
+ let origin3 = Origin::signed(3);
+
+ assert_ok!(TemplateModule::create_collection(origin1.clone(), size));
+ assert_ok!(TemplateModule::create_collection(origin2.clone(), size));
+ assert_ok!(TemplateModule::create_collection(origin3.clone(), size));
+
+ assert_eq!(TemplateModule::collection(1).owner, 1);
+ assert_eq!(TemplateModule::collection(2).owner, 2);
+ assert_eq!(TemplateModule::collection(3).owner, 3);
+
+ // create items
+ assert_ok!(TemplateModule::create_item(
+ origin1.clone(),
+ 1,
+ [1, 1, 1].to_vec()
+ ));
+
+ assert_ok!(TemplateModule::create_item(
+ origin1.clone(),
+ 1,
+ [1, 1, 2].to_vec()
+ ));
+
+ assert_ok!(TemplateModule::create_item(
+ origin1.clone(),
+ 1,
+ [1, 2, 3].to_vec()
+ ));
+
+ assert_eq!(TemplateModule::address_tokens((1, 1)).len(), 3);
+
+ // burn one
+ assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 2));
+ assert_eq!(TemplateModule::address_tokens((1, 1)).len(), 2);
+
+ // burn another one
+ assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 3));
+ assert_eq!(TemplateModule::address_tokens((1, 1))[0], 1);
+ });
+}
\ No newline at end of file
runtime/Cargo.tomldiffbeforeafterboth1[features]2default = ['std']3std = [4 'aura/std',5 'balances/std',6 'codec/std',7 'frame-executive/std',8 'frame-support/std',9 'grandpa/std',10 'randomness-collective-flip/std',11 'serde',12 'sp-api/std',13 'sp-block-builder/std',14 'sp-consensus-aura/std',15 'sp-core/std',16 'sp-inherents/std',17 'sp-io/std',18 'sp-offchain/std',19 'sp-runtime/std',20 'sp-session/std',21 'sp-std/std',22 'sp-transaction-pool/std',23 'sp-version/std',24 'sudo/std',25 'system/std',26 'timestamp/std',27 'transaction-payment/std',28 'nft/std',29]30[dependencies.aura]31default-features = false32git = 'https://github.com/paritytech/substrate.git'33package = 'pallet-aura'34tag = 'v2.0.0-rc4'35version = '2.0.0-rc4'3637[dependencies.balances]38default-features = false39git = 'https://github.com/paritytech/substrate.git'40package = 'pallet-balances'41tag = 'v2.0.0-rc4'42version = '2.0.0-rc4'4344[dependencies.codec]45default-features = false46features = ['derive']47package = 'parity-scale-codec'48version = '1.3.1'4950[dependencies.frame-executive]51default-features = false52git = 'https://github.com/paritytech/substrate.git'53tag = 'v2.0.0-rc4'54version = '2.0.0-rc4'5556[dependencies.frame-support]57default-features = false58git = 'https://github.com/paritytech/substrate.git'59tag = 'v2.0.0-rc4'60version = '2.0.0-rc4'6162[dependencies.grandpa]63default-features = false64git = 'https://github.com/paritytech/substrate.git'65package = 'pallet-grandpa'66tag = 'v2.0.0-rc4'67version = '2.0.0-rc4'6869[dependencies.randomness-collective-flip]70default-features = false71git = 'https://github.com/paritytech/substrate.git'72package = 'pallet-randomness-collective-flip'73tag = 'v2.0.0-rc4'74version = '2.0.0-rc4'7576[dependencies.serde]77features = ['derive']78optional = true79version = '1.0.101'8081[dependencies.sp-api]82default-features = false83git = 'https://github.com/paritytech/substrate.git'84tag = 'v2.0.0-rc4'85version = '2.0.0-rc4'8687[dependencies.sp-block-builder]88default-features = false89git = 'https://github.com/paritytech/substrate.git'90tag = 'v2.0.0-rc4'91version = '2.0.0-rc4'9293[dependencies.sp-consensus-aura]94default-features = false95git = 'https://github.com/paritytech/substrate.git'96tag = 'v2.0.0-rc4'97version = '0.8.0-rc4'9899[dependencies.sp-core]100default-features = false101git = 'https://github.com/paritytech/substrate.git'102tag = 'v2.0.0-rc4'103version = '2.0.0-rc4'104105[dependencies.sp-inherents]106default-features = false107git = 'https://github.com/paritytech/substrate.git'108tag = 'v2.0.0-rc4'109version = '2.0.0-rc4'110111[dependencies.sp-io]112default-features = false113git = 'https://github.com/paritytech/substrate.git'114tag = 'v2.0.0-rc4'115version = '2.0.0-rc4'116117[dependencies.sp-offchain]118default-features = false119git = 'https://github.com/paritytech/substrate.git'120tag = 'v2.0.0-rc4'121version = '2.0.0-rc4'122123[dependencies.sp-runtime]124default-features = false125git = 'https://github.com/paritytech/substrate.git'126tag = 'v2.0.0-rc4'127version = '2.0.0-rc4'128129[dependencies.sp-session]130default-features = false131git = 'https://github.com/paritytech/substrate.git'132tag = 'v2.0.0-rc4'133version = '2.0.0-rc4'134135[dependencies.sp-std]136default-features = false137git = 'https://github.com/paritytech/substrate.git'138tag = 'v2.0.0-rc4'139version = '2.0.0-rc4'140141[dependencies.sp-transaction-pool]142default-features = false143git = 'https://github.com/paritytech/substrate.git'144tag = 'v2.0.0-rc4'145version = '2.0.0-rc4'146147[dependencies.sp-version]148default-features = false149git = 'https://github.com/paritytech/substrate.git'150tag = 'v2.0.0-rc4'151version = '2.0.0-rc4'152153[dependencies.sudo]154default-features = false155git = 'https://github.com/paritytech/substrate.git'156package = 'pallet-sudo'157tag = 'v2.0.0-rc4'158version = '2.0.0-rc4'159160[dependencies.system]161default-features = false162git = 'https://github.com/paritytech/substrate.git'163package = 'frame-system'164tag = 'v2.0.0-rc4'165version = '2.0.0-rc4'166167[dependencies.nft]168default-features = false169package = 'pallet-nft'170path = '../pallets/nft'171version = '2.0.0-rc4'172173[dependencies.timestamp]174default-features = false175git = 'https://github.com/paritytech/substrate.git'176package = 'pallet-timestamp'177tag = 'v2.0.0-rc4'178version = '2.0.0-rc4'179180[dependencies.transaction-payment]181default-features = false182git = 'https://github.com/paritytech/substrate.git'183package = 'pallet-transaction-payment'184tag = 'v2.0.0-rc4'185version = '2.0.0-rc4'186187[package]188authors = ['UseTech']189edition = '2018'190homepage = 'https://usetech.com/blockchain'191license = 'Unlicense'192name = 'nft-runtime'193repository = 'https://github.com/usetech-llc/nft_parachain/'194version = '2.0.0-rc4'195196[package.metadata.docs.rs]197targets = ['x86_64-unknown-linux-gnu']198199[build-dependencies.wasm-builder-runner]200git = 'https://github.com/paritytech/substrate.git'201package = 'substrate-wasm-builder-runner'202tag = 'v2.0.0-rc4'203version = '1.0.5'1[features]2default = ['std']3std = [4 'aura/std',5 'balances/std',6 'codec/std',7 'contracts/std',8 'contracts-primitives/std',9 'contracts-rpc-runtime-api/std',10 'frame-executive/std',11 'frame-support/std',12 'grandpa/std',13 'randomness-collective-flip/std',14 'serde',15 'sp-api/std',16 'sp-block-builder/std',17 'sp-consensus-aura/std',18 'sp-core/std',19 'sp-inherents/std',20 'sp-io/std',21 'sp-offchain/std',22 'sp-runtime/std',23 'sp-session/std',24 'sp-std/std',25 'sp-transaction-pool/std',26 'sp-version/std',27 'sudo/std',28 'system/std',29 'timestamp/std',30 'transaction-payment/std',31 'nft/std',32]33[dependencies.aura]34default-features = false35git = 'https://github.com/paritytech/substrate.git'36package = 'pallet-aura'37tag = 'v2.0.0-rc4'38version = '2.0.0-rc4'3940[dependencies.balances]41default-features = false42git = 'https://github.com/paritytech/substrate.git'43package = 'pallet-balances'44tag = 'v2.0.0-rc4'45version = '2.0.0-rc4'4647[dependencies.codec]48default-features = false49features = ['derive']50package = 'parity-scale-codec'51version = '1.3.1'5253[dependencies.contracts]54git = 'https://github.com/paritytech/substrate.git'55default-features = false56package = 'pallet-contracts'57tag = 'v2.0.0-rc4'58version = '2.0.0-rc4'5960[dependencies.contracts-primitives]61git = 'https://github.com/paritytech/substrate.git'62default-features = false63package = 'pallet-contracts-primitives'64tag = 'v2.0.0-rc4'65version = '2.0.0-rc4'6667[dependencies.contracts-rpc-runtime-api]68git = 'https://github.com/paritytech/substrate.git'69default-features = false70package = 'pallet-contracts-rpc-runtime-api'71version = '0.8.0-rc4'72tag = 'v2.0.0-rc4'7374[dependencies.frame-executive]75default-features = false76git = 'https://github.com/paritytech/substrate.git'77tag = 'v2.0.0-rc4'78version = '2.0.0-rc4'7980[dependencies.frame-support]81default-features = false82git = 'https://github.com/paritytech/substrate.git'83tag = 'v2.0.0-rc4'84version = '2.0.0-rc4'8586[dependencies.grandpa]87default-features = false88git = 'https://github.com/paritytech/substrate.git'89package = 'pallet-grandpa'90tag = 'v2.0.0-rc4'91version = '2.0.0-rc4'9293[dependencies.randomness-collective-flip]94default-features = false95git = 'https://github.com/paritytech/substrate.git'96package = 'pallet-randomness-collective-flip'97tag = 'v2.0.0-rc4'98version = '2.0.0-rc4'99100[dependencies.serde]101features = ['derive']102optional = true103version = '1.0.101'104105[dependencies.sp-api]106default-features = false107git = 'https://github.com/paritytech/substrate.git'108tag = 'v2.0.0-rc4'109version = '2.0.0-rc4'110111[dependencies.sp-block-builder]112default-features = false113git = 'https://github.com/paritytech/substrate.git'114tag = 'v2.0.0-rc4'115version = '2.0.0-rc4'116117[dependencies.sp-consensus-aura]118default-features = false119git = 'https://github.com/paritytech/substrate.git'120tag = 'v2.0.0-rc4'121version = '0.8.0-rc4'122123[dependencies.sp-core]124default-features = false125git = 'https://github.com/paritytech/substrate.git'126tag = 'v2.0.0-rc4'127version = '2.0.0-rc4'128129[dependencies.sp-inherents]130default-features = false131git = 'https://github.com/paritytech/substrate.git'132tag = 'v2.0.0-rc4'133version = '2.0.0-rc4'134135[dependencies.sp-io]136default-features = false137git = 'https://github.com/paritytech/substrate.git'138tag = 'v2.0.0-rc4'139version = '2.0.0-rc4'140141[dependencies.sp-offchain]142default-features = false143git = 'https://github.com/paritytech/substrate.git'144tag = 'v2.0.0-rc4'145version = '2.0.0-rc4'146147[dependencies.sp-runtime]148default-features = false149git = 'https://github.com/paritytech/substrate.git'150tag = 'v2.0.0-rc4'151version = '2.0.0-rc4'152153[dependencies.sp-session]154default-features = false155git = 'https://github.com/paritytech/substrate.git'156tag = 'v2.0.0-rc4'157version = '2.0.0-rc4'158159[dependencies.sp-std]160default-features = false161git = 'https://github.com/paritytech/substrate.git'162tag = 'v2.0.0-rc4'163version = '2.0.0-rc4'164165[dependencies.sp-transaction-pool]166default-features = false167git = 'https://github.com/paritytech/substrate.git'168tag = 'v2.0.0-rc4'169version = '2.0.0-rc4'170171[dependencies.sp-version]172default-features = false173git = 'https://github.com/paritytech/substrate.git'174tag = 'v2.0.0-rc4'175version = '2.0.0-rc4'176177[dependencies.sudo]178default-features = false179git = 'https://github.com/paritytech/substrate.git'180package = 'pallet-sudo'181tag = 'v2.0.0-rc4'182version = '2.0.0-rc4'183184[dependencies.system]185default-features = false186git = 'https://github.com/paritytech/substrate.git'187package = 'frame-system'188tag = 'v2.0.0-rc4'189version = '2.0.0-rc4'190191[dependencies.nft]192default-features = false193package = 'pallet-nft'194path = '../pallets/nft'195version = '2.0.0-rc4'196197[dependencies.timestamp]198default-features = false199git = 'https://github.com/paritytech/substrate.git'200package = 'pallet-timestamp'201tag = 'v2.0.0-rc4'202version = '2.0.0-rc4'203204[dependencies.transaction-payment]205default-features = false206git = 'https://github.com/paritytech/substrate.git'207package = 'pallet-transaction-payment'208tag = 'v2.0.0-rc4'209version = '2.0.0-rc4'210211[package]212authors = ['UseTech']213edition = '2018'214homepage = 'https://usetech.com/blockchain'215license = 'Unlicense'216name = 'nft-runtime'217repository = 'https://github.com/usetech-llc/nft_parachain/'218version = '2.0.0-rc4'219220[package.metadata.docs.rs]221targets = ['x86_64-unknown-linux-gnu']222223[build-dependencies.wasm-builder-runner]224git = 'https://github.com/paritytech/substrate.git'225package = 'substrate-wasm-builder-runner'226tag = 'v2.0.0-rc4'227version = '1.0.5'runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -24,6 +24,7 @@
use sp_version::RuntimeVersion;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
+use contracts_rpc_runtime_api::ContractExecResult;
// A few exports that help ease life for downstream crates.
#[cfg(any(feature = "std", test))]
@@ -31,6 +32,7 @@
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use sp_runtime::{Permill, Perbill};
+pub use contracts::Schedule as ContractsSchedule;
pub use frame_support::{
construct_runtime, parameter_types, StorageValue,
traits::{KeyOwnerProofSystem, Randomness},
@@ -69,6 +71,10 @@
/// Digest item type.
pub type DigestItem = generic::DigestItem<Hash>;
+pub const MILLICENTS: Balance = 1_000_000_000;
+pub const CENTS: Balance = 1_000 * MILLICENTS;
+pub const DOLLARS: Balance = 100 * CENTS;
+
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
@@ -254,6 +260,32 @@
type Call = Call;
}
+parameter_types! {
+ pub const TombstoneDeposit: Balance = 16 * MILLICENTS;
+ pub const RentByteFee: Balance = 4 * MILLICENTS;
+ pub const RentDepositOffset: Balance = 1000 * MILLICENTS;
+ pub const SurchargeReward: Balance = 150 * MILLICENTS;
+}
+
+impl contracts::Trait for Runtime {
+ type Time = Timestamp;
+ type Randomness = RandomnessCollectiveFlip;
+ type Currency = Balances;
+ type Event = Event;
+ type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;
+ type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;
+ type RentPayment = ();
+ type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;
+ type TombstoneDeposit = TombstoneDeposit;
+ type StorageSizeOffset = contracts::DefaultStorageSizeOffset;
+ type RentByteFee = RentByteFee;
+ type RentDepositOffset = RentDepositOffset;
+ type SurchargeReward = SurchargeReward;
+ type MaxDepth = contracts::DefaultMaxDepth;
+ type MaxValueSize = contracts::DefaultMaxValueSize;
+ type WeightPrice = transaction_payment::Module<Self>;
+}
+
/// Used for the module template in `./template.rs`
impl nft::Trait for Runtime {
type Event = Event;
@@ -267,6 +299,7 @@
{
System: system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
+ Contracts: contracts::{Module, Call, Config, Storage, Event<T>},
Timestamp: timestamp::{Module, Call, Storage, Inherent},
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
@@ -413,4 +446,40 @@
None
}
}
+
+ impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>
+ for Runtime
+ {
+ fn call(
+ origin: AccountId,
+ dest: AccountId,
+ value: Balance,
+ gas_limit: u64,
+ input_data: Vec<u8>,
+ ) -> ContractExecResult {
+ let exec_result =
+ Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);
+ match exec_result {
+ Ok(v) => ContractExecResult::Success {
+ status: v.status,
+ data: v.data,
+ },
+ Err(_) => ContractExecResult::Error,
+ }
+ }
+
+ fn get_storage(
+ address: AccountId,
+ key: [u8; 32],
+ ) -> contracts_primitives::GetStorageResult {
+ Contracts::get_storage(address, key)
+ }
+
+ fn rent_projection(
+ address: AccountId,
+ ) -> contracts_primitives::RentProjectionResult<BlockNumber> {
+ Contracts::rent_projection(address)
+ }
+ }
+
}