--- 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", --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -122,7 +122,7 @@ key: root_key, }), contracts: Some(ContractsConfig { - gas_price: 1_000_000_000, + gas_price: 1_000, current_schedule: ContractsSchedule { // enable_println, ..Default::default() --- 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', --- 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 + for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: u64, + input_data: Vec, + ) -> 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 { + Contracts::rent_projection(address) + } + } }