From 7c556ae4447ee929bd1bae1ba436f9ad5121f162 Mon Sep 17 00:00:00 2001 From: str-mv Date: Thu, 09 Jul 2020 10:29:48 +0000 Subject: [PATCH] Smart contract module added --- --- a/Cargo.lock +++ b/Cargo.lock @@ -1982,7 +1982,7 @@ "sha2", "smallvec 1.3.0", "thiserror", - "unsigned-varint", + "unsigned-varint 0.3.3", "void", "zeroize", ] @@ -2046,7 +2046,7 @@ "sha2", "smallvec 1.3.0", "uint", - "unsigned-varint", + "unsigned-varint 0.3.3", "void", "wasm-timer", ] @@ -2086,7 +2086,7 @@ "libp2p-core", "log", "parking_lot 0.10.2", - "unsigned-varint", + "unsigned-varint 0.3.3", ] [[package]] @@ -2437,7 +2437,7 @@ "sha-1", "sha2", "sha3", - "unsigned-varint", + "unsigned-varint 0.3.3", ] [[package]] @@ -2448,16 +2448,16 @@ [[package]] name = "multistream-select" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74cdcf7cfb3402881e15a1f95116cb033d69b33c83d481e1234777f5ef0c3d2c" +checksum = "c9157e87afbc2ef0d84cc0345423d715f445edde00141c93721c162de35a05e5" dependencies = [ "bytes 0.5.4", "futures 0.3.4", "log", "pin-project", "smallvec 1.3.0", - "unsigned-varint", + "unsigned-varint 0.4.0", ] [[package]] @@ -2516,8 +2516,10 @@ version = "2.0.0-alpha.6" dependencies = [ "futures 0.3.4", + "jsonrpc-core", "log", "nft-runtime", + "pallet-contracts-rpc", "sc-basic-authorship", "sc-cli", "sc-client", @@ -2526,6 +2528,7 @@ "sc-executor", "sc-finality-grandpa", "sc-network", + "sc-rpc", "sc-service", "sc-transaction-pool", "sp-consensus", @@ -2548,6 +2551,8 @@ "frame-system", "pallet-aura", "pallet-balances", + "pallet-contracts", + "pallet-contracts-primitives", "pallet-grandpa", "pallet-nft", "pallet-randomness-collective-flip", @@ -2766,6 +2771,71 @@ ] [[package]] +name = "pallet-contracts" +version = "2.0.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2bc13b765baa08a15815c0d836fee239fde73252a6c7babc437796eda561f5" +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-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5216edfd33a69a45bdd79f088563479dfdd6ecfb3c477b0f83955b844251c665" +dependencies = [ + "parity-scale-codec", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-contracts-rpc" +version = "0.8.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c575d839564073fa5757f9dfe5863b48eb07108ecda63521740b8bd8ed6f05c3" +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-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747f66dc20367de627c701675c66af0a53b4309df16c9929c0d23d2e27e436ee" +dependencies = [ + "pallet-contracts-primitives", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] name = "pallet-finality-tracker" version = "2.0.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2922,7 +2992,7 @@ "percent-encoding 2.1.0", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.3.3", "url 2.1.1", ] @@ -2940,7 +3010,7 @@ "percent-encoding 2.1.0", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.3.3", "url 2.1.1", ] @@ -2956,7 +3026,7 @@ "sha-1", "sha2", "sha3", - "unsigned-varint", + "unsigned-varint 0.3.3", ] [[package]] @@ -3137,18 +3207,18 @@ [[package]] name = "pin-project" -version = "0.4.9" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f6a7f5eee6292c559c793430c55c00aea9d3b3d1905e855806ca4d7253426a2" +checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.9" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8988430ce790d8682672117bc06dda364c0be32d3abd738234f19f3240bad99a" +checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" dependencies = [ "proc-macro2", "quote 1.0.3", @@ -3341,6 +3411,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" @@ -4205,7 +4286,7 @@ "sp-utils", "substrate-prometheus-endpoint", "thiserror", - "unsigned-varint", + "unsigned-varint 0.3.3", "void", "wasm-timer", "zeroize", @@ -5180,6 +5261,20 @@ ] [[package]] +name = "sp-sandbox" +version = "0.8.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2441d2ed3b141b74a6eaca28b469420bcd438c3ac43d25eadfe494d905135f" +dependencies = [ + "parity-scale-codec", + "sp-core", + "sp-io", + "sp-std", + "sp-wasm-interface", + "wasmi", +] + +[[package]] name = "sp-serializer" version = "2.0.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -6082,6 +6177,12 @@ ] [[package]] +name = "unsigned-varint" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "669d776983b692a906c881fcd0cfb34271a48e197e4d6cb8df32b05bfc3d3fa5" + +[[package]] name = "untrusted" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -16,6 +16,13 @@ futures = '0.3.4' log = '0.4.8' structopt = '0.3.8' +jsonrpc-core = '14.0.5' + +[dependencies.pallet-contracts-rpc] +version = '0.8.0-alpha.6' + +[dependencies.sc-rpc] +version = '2.0.0-alpha.6' [dependencies.nft-runtime] path = '../runtime' --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -7,6 +7,7 @@ use sp_finality_grandpa::AuthorityId as GrandpaId; 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/"; @@ -120,5 +121,12 @@ sudo: Some(SudoConfig { key: root_key, }), + contracts: Some(ContractsConfig { + gas_price: 1_000_000_000, + current_schedule: ContractsSchedule { + // enable_println, + ..Default::default() + }, + }), } } --- a/pallets/nft/Cargo.toml +++ b/pallets/nft/Cargo.toml @@ -40,8 +40,6 @@ default-features = false version = '2.0.0-alpha.6' - - [features] default = ['std'] std = [ --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -14,6 +14,16 @@ package = 'parity-scale-codec' version = '1.3.0' +[dependencies.contracts] +default-features = false +package = 'pallet-contracts' +version = '2.0.0-alpha.6' + +[dependencies.contracts-primitives] +default-features = false +package = 'pallet-contracts-primitives' +version = '2.0.0-alpha.6' + [dependencies.frame-executive] default-features = false version = '2.0.0-alpha.6' @@ -133,6 +143,8 @@ 'aura/std', 'balances/std', 'codec/std', + 'contracts/std', + 'contracts-primitives/std', 'frame-executive/std', 'frame-support/std', 'grandpa/std', --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -35,6 +35,7 @@ pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; pub use timestamp::Call as TimestampCall; +pub use contracts::Schedule as ContractsSchedule; /// Importing a template pallet pub use nft; @@ -201,6 +202,48 @@ type AccountStore = System; } +// Contracts price units. +pub const MILLICENTS: Balance = 1_000_000_000; +pub const CENTS: Balance = 1_000 * MILLICENTS; +pub const DOLLARS: Balance = 100 * CENTS; + +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; + pub const ContractTransactionBaseFee: Balance = 1 * CENTS; + pub const ContractTransactionByteFee: Balance = 10 * MILLICENTS; + pub const ContractFee: Balance = 1 * CENTS; +} + +impl contracts::Trait for Runtime { + type Currency = Balances; + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Call = Call; + type Event = Event; + type DetermineContractAddress = contracts::SimpleAddressDeterminer; + type ComputeDispatchFee = contracts::DefaultDispatchFeeComputor; + type TrieIdGenerator = contracts::TrieIdFromParentCounter; + type GasPayment = (); + type RentPayment = (); + type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap; + type TombstoneDeposit = TombstoneDeposit; + type StorageSizeOffset = contracts::DefaultStorageSizeOffset; + type RentByteFee = RentByteFee; + type RentDepositOffset = RentDepositOffset; + type SurchargeReward = SurchargeReward; + type TransactionBaseFee = ContractTransactionBaseFee; + type TransactionByteFee = ContractTransactionByteFee; + type ContractFee = ContractFee; + type CallBaseFee = contracts::DefaultCallBaseFee; + type InstantiateBaseFee = contracts::DefaultInstantiateBaseFee; + type MaxDepth = contracts::DefaultMaxDepth; + type MaxValueSize = contracts::DefaultMaxValueSize; + type BlockGasLimit = contracts::DefaultBlockGasLimit; +} + parameter_types! { pub const TransactionBaseFee: Balance = 0; pub const TransactionByteFee: Balance = 1; @@ -229,7 +272,7 @@ pub enum Runtime where Block = Block, NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic + UncheckedExtrinsic = UncheckedExtrinsic, { System: system::{Module, Call, Config, Storage, Event}, RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage}, @@ -238,7 +281,8 @@ Grandpa: grandpa::{Module, Call, Storage, Config, Event}, Balances: balances::{Module, Call, Storage, Config, Event}, TransactionPayment: transaction_payment::{Module, Storage}, - Sudo: sudo::{Module, Call, Config, Storage, Event}, + Sudo: sudo::{Module, Call, Config, Storage, Event}, + Contracts: contracts::{Module, Call, Config, Storage, Event}, // Used for the module template in `./template.rs` Nft: nft::{Module, Call, Storage, Event}, } --- a/smart_contract/nft/Cargo.toml +++ b/smart_contract/nft/Cargo.toml @@ -10,7 +10,7 @@ ink_primitives = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_primitives", default-features = false } ink_core = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_core", default-features = false } ink_lang = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_lang", default-features = false } -scale = { package = "parity-scale-codec", version = "1.2", default-features = false, features = ["derive"] } +scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] } sp-core = { git = "https://github.com/paritytech/substrate/", package = "sp-core", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate/", package = "sp-runtime", default-features = false } -- gitstuff