difftreelog
Contracts rpc runtime added
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2553,6 +2553,7 @@
"pallet-balances",
"pallet-contracts",
"pallet-contracts-primitives",
+ "pallet-contracts-rpc-runtime-api",
"pallet-grandpa",
"pallet-nft",
"pallet-randomness-collective-flip",
node/src/chain_spec.rsdiffbeforeafterboth1use sp_core::{Pair, Public, sr25519};2use nft_runtime::{3 AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,4 SudoConfig, SystemConfig, WASM_BINARY, Signature5};6use sp_consensus_aura::sr25519::AuthorityId as AuraId;7use sp_finality_grandpa::AuthorityId as GrandpaId;8use sp_runtime::traits::{Verify, IdentifyAccount};9use sc_service::ChainType;10use nft_runtime::{ContractsConfig, ContractsSchedule};1112// Note this is the URL for the telemetry server13//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";1415/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.16pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;1718/// Helper function to generate a crypto pair from seed19pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {20 TPublic::Pair::from_string(&format!("//{}", seed), None)21 .expect("static values are valid; qed")22 .public()23}2425type AccountPublic = <Signature as Verify>::Signer;2627/// Helper function to generate an account ID from seed28pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where29 AccountPublic: From<<TPublic::Pair as Pair>::Public>30{31 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()32}3334/// Helper function to generate an authority key for Aura35pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {36 (37 get_from_seed::<AuraId>(s),38 get_from_seed::<GrandpaId>(s),39 )40}4142pub fn development_config() -> ChainSpec {43 ChainSpec::from_genesis(44 "Development",45 "dev",46 ChainType::Development,47 || testnet_genesis(48 vec![49 authority_keys_from_seed("Alice"),50 ],51 get_account_id_from_seed::<sr25519::Public>("Alice"),52 vec![53 get_account_id_from_seed::<sr25519::Public>("Alice"),54 get_account_id_from_seed::<sr25519::Public>("Bob"),55 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),56 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),57 ],58 true,59 ),60 vec![],61 None,62 None,63 None,64 None,65 )66}6768pub fn local_testnet_config() -> ChainSpec {69 ChainSpec::from_genesis(70 "Local Testnet",71 "local_testnet",72 ChainType::Local,73 || testnet_genesis(74 vec![75 authority_keys_from_seed("Alice"),76 authority_keys_from_seed("Bob"),77 ],78 get_account_id_from_seed::<sr25519::Public>("Alice"),79 vec![80 get_account_id_from_seed::<sr25519::Public>("Alice"),81 get_account_id_from_seed::<sr25519::Public>("Bob"),82 get_account_id_from_seed::<sr25519::Public>("Charlie"),83 get_account_id_from_seed::<sr25519::Public>("Dave"),84 get_account_id_from_seed::<sr25519::Public>("Eve"),85 get_account_id_from_seed::<sr25519::Public>("Ferdie"),86 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),87 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),88 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),89 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),90 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),91 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),92 ],93 true,94 ),95 vec![],96 None,97 None,98 None,99 None,100 )101}102103fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,104 root_key: AccountId,105 endowed_accounts: Vec<AccountId>,106 _enable_println: bool) -> GenesisConfig {107 GenesisConfig {108 system: Some(SystemConfig {109 code: WASM_BINARY.to_vec(),110 changes_trie_config: Default::default(),111 }),112 balances: Some(BalancesConfig {113 balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),114 }),115 aura: Some(AuraConfig {116 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),117 }),118 grandpa: Some(GrandpaConfig {119 authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),120 }),121 sudo: Some(SudoConfig {122 key: root_key,123 }),124 contracts: Some(ContractsConfig {125 gas_price: 1_000_000_000,126 current_schedule: ContractsSchedule {127 // enable_println,128 ..Default::default()129 },130 }),131 }132}1use sp_core::{Pair, Public, sr25519};2use nft_runtime::{3 AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,4 SudoConfig, SystemConfig, WASM_BINARY, Signature5};6use sp_consensus_aura::sr25519::AuthorityId as AuraId;7use sp_finality_grandpa::AuthorityId as GrandpaId;8use sp_runtime::traits::{Verify, IdentifyAccount};9use sc_service::ChainType;10use nft_runtime::{ContractsConfig, ContractsSchedule};1112// Note this is the URL for the telemetry server13//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";1415/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.16pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;1718/// Helper function to generate a crypto pair from seed19pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {20 TPublic::Pair::from_string(&format!("//{}", seed), None)21 .expect("static values are valid; qed")22 .public()23}2425type AccountPublic = <Signature as Verify>::Signer;2627/// Helper function to generate an account ID from seed28pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where29 AccountPublic: From<<TPublic::Pair as Pair>::Public>30{31 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()32}3334/// Helper function to generate an authority key for Aura35pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {36 (37 get_from_seed::<AuraId>(s),38 get_from_seed::<GrandpaId>(s),39 )40}4142pub fn development_config() -> ChainSpec {43 ChainSpec::from_genesis(44 "Development",45 "dev",46 ChainType::Development,47 || testnet_genesis(48 vec![49 authority_keys_from_seed("Alice"),50 ],51 get_account_id_from_seed::<sr25519::Public>("Alice"),52 vec![53 get_account_id_from_seed::<sr25519::Public>("Alice"),54 get_account_id_from_seed::<sr25519::Public>("Bob"),55 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),56 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),57 ],58 true,59 ),60 vec![],61 None,62 None,63 None,64 None,65 )66}6768pub fn local_testnet_config() -> ChainSpec {69 ChainSpec::from_genesis(70 "Local Testnet",71 "local_testnet",72 ChainType::Local,73 || testnet_genesis(74 vec![75 authority_keys_from_seed("Alice"),76 authority_keys_from_seed("Bob"),77 ],78 get_account_id_from_seed::<sr25519::Public>("Alice"),79 vec![80 get_account_id_from_seed::<sr25519::Public>("Alice"),81 get_account_id_from_seed::<sr25519::Public>("Bob"),82 get_account_id_from_seed::<sr25519::Public>("Charlie"),83 get_account_id_from_seed::<sr25519::Public>("Dave"),84 get_account_id_from_seed::<sr25519::Public>("Eve"),85 get_account_id_from_seed::<sr25519::Public>("Ferdie"),86 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),87 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),88 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),89 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),90 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),91 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),92 ],93 true,94 ),95 vec![],96 None,97 None,98 None,99 None,100 )101}102103fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,104 root_key: AccountId,105 endowed_accounts: Vec<AccountId>,106 _enable_println: bool) -> GenesisConfig {107 GenesisConfig {108 system: Some(SystemConfig {109 code: WASM_BINARY.to_vec(),110 changes_trie_config: Default::default(),111 }),112 balances: Some(BalancesConfig {113 balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),114 }),115 aura: Some(AuraConfig {116 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),117 }),118 grandpa: Some(GrandpaConfig {119 authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),120 }),121 sudo: Some(SudoConfig {122 key: root_key,123 }),124 contracts: Some(ContractsConfig {125 gas_price: 1_000,126 current_schedule: ContractsSchedule {127 // enable_println,128 ..Default::default()129 },130 }),131 }132}runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -24,6 +24,11 @@
package = 'pallet-contracts-primitives'
version = '2.0.0-alpha.6'
+[dependencies.contracts-rpc-runtime-api]
+default-features = false
+package = 'pallet-contracts-rpc-runtime-api'
+version = '0.8.0-alpha.6'
+
[dependencies.frame-executive]
default-features = false
version = '2.0.0-alpha.6'
@@ -143,8 +148,9 @@
'aura/std',
'balances/std',
'codec/std',
- 'contracts/std',
- 'contracts-primitives/std',
+ "contracts/std",
+ "contracts-primitives/std",
+ "contracts-rpc-runtime-api/std",
'frame-executive/std',
'frame-support/std',
'grandpa/std',
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -36,6 +36,9 @@
pub use sp_runtime::{Perbill, Permill};
pub use timestamp::Call as TimestampCall;
pub use contracts::Schedule as ContractsSchedule;
+pub use contracts_rpc_runtime_api::{
+ self as runtime_api, ContractExecResult
+};
/// Importing a template pallet
pub use nft;
@@ -403,4 +406,39 @@
Grandpa::grandpa_authorities()
}
}
+
+ 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)
+ }
+ }
}