Skip to content

Commit

Permalink
MESH-1824: Empty perms default + MESH-1825: Contracts RPC (#1239)
Browse files Browse the repository at this point in the history
* mesh-1824: make empty perms the default

* mesh-1825: enable rpc for contracts

* mesh-1825: address review comments

* Fix comment.

Co-authored-by: Robert Gabriel Jakabosky <rjakabosky+neopallium@neoawareness.com>

Co-authored-by: Robert Gabriel Jakabosky <rjakabosky+neopallium@neoawareness.com>
  • Loading branch information
Centril and Neopallium authored May 16, 2022
1 parent 661f84a commit 0ec8819
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 56 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pallet-babe = { git = "https://github.com/PolymathNetwork/substrate", branch = "
pallet-balances = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-contracts = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-contracts-primitives = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
#pallet-contracts-rpc = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
#pallet-contracts-rpc-runtime-api = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-contracts-rpc = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-contracts-rpc-runtime-api = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-grandpa = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-im-online = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
pallet-indices = { git = "https://github.com/PolymathNetwork/substrate", branch = "polymesh-develop" }
Expand Down Expand Up @@ -122,7 +122,7 @@ members = [
"pallets/committee",
"pallets/common",
"pallets/compliance-manager",
#"pallets/contracts",
"pallets/contracts",
"pallets/corporate-actions",
"pallets/external-agents",
"pallets/group",
Expand Down Expand Up @@ -212,8 +212,7 @@ frame-support = "4.0.0-dev"
frame-system = "4.0.0-dev"
frame-system-rpc-runtime-api = "4.0.0-dev"
grandpa = { package = "sc-finality-grandpa", version = "0.10.0-dev" }
#pallet-contracts = "4.0.0-dev"
#pallet-contracts-rpc-runtime-api = "4.0.0-dev"
pallet-contracts-rpc-runtime-api = "4.0.0-dev"
pallet-babe = "4.0.0-dev"
pallet-im-online = "4.0.0-dev"
pallet-indices = "4.0.0-dev"
Expand Down
2 changes: 1 addition & 1 deletion node-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
polymesh-primitives = { path = "../primitives", default-features = false }
#pallet-contracts-rpc = { version = "4.0.0-dev" }
pallet-contracts-rpc = { version = "4.0.0-dev" }
pallet-group-rpc = { path = "../pallets/group/rpc" }
pallet-staking-rpc = { path = "../pallets/staking/rpc" }
pallet-protocol-fee-rpc = { path = "../pallets/protocol-fee/rpc" }
Expand Down
10 changes: 6 additions & 4 deletions node-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#![warn(missing_docs)]

use polymesh_primitives::{AccountId, Block, BlockNumber, Hash, IdentityId, Index, Moment, Ticker};
use polymesh_primitives::{
AccountId, Balance, Block, BlockNumber, Hash, IdentityId, Index, Moment, Ticker,
};
use sc_client_api::AuxStore;
use sc_consensus_babe::{Config, Epoch};
use sc_consensus_epochs::SharedEpochChanges;
Expand Down Expand Up @@ -117,7 +119,7 @@ where
+ Send
+ 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
//C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,
C::Api: node_rpc::transaction_payment::TransactionPaymentRuntimeApi<Block, UE>,
C::Api: pallet_staking_rpc::StakingRuntimeApi<Block>,
C::Api: node_rpc::pips::PipsRuntimeApi<Block, AccountId>,
Expand All @@ -141,7 +143,7 @@ where
pips::{Pips, PipsApi},
transaction_payment::{TransactionPayment, TransactionPaymentApi},
};
//use pallet_contracts_rpc::{Contracts, ContractsApi};
use pallet_contracts_rpc::{Contracts, ContractsApi};
use pallet_group_rpc::{Group, GroupApi};
use pallet_protocol_fee_rpc::{ProtocolFee, ProtocolFeeApi};
use pallet_staking_rpc::{Staking, StakingApi};
Expand Down Expand Up @@ -181,7 +183,7 @@ where
// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/PolymathNetwork/substrate/pull/3480
// These RPCs should use an asynchronous caller instead.
//io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
client.clone(),
)));
Expand Down
6 changes: 3 additions & 3 deletions pallets/contracts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn free_balance<T: Config>(acc: &T::AccountId) -> Balance {
/// Returns the address of the new contract.
fn instantiate<T: Config>(user: &User<T>, wasm: WasmModule<T>, salt: Vec<u8>) -> T::AccountId {
let callee = Base::<T>::contract_address(&user.account(), &wasm.hash, &salt);
Pallet::<T>::instantiate_with_code(
Pallet::<T>::instantiate_with_code_perms(
user.origin().into(),
Base::<T>::subsistence_threshold(), // endowment
Weight::MAX, // gas limit
Expand Down Expand Up @@ -201,7 +201,7 @@ benchmarks! {

// Pre-instantiate a contract so that one with the hash exists.
let _ = instantiate::<T>(&user, wasm, salt());
}: _(user.origin(), ENDOWMENT, Weight::MAX, hash, vec![], other_salt, Permissions::empty())
}: instantiate(user.origin(), ENDOWMENT, Weight::MAX, hash, vec![], other_salt)
verify {
// Ensure contract has the full value.
assert_eq!(free_balance::<T>(&addr), ENDOWMENT);
Expand Down Expand Up @@ -232,7 +232,7 @@ benchmarks! {
// Construct the contract code + get addr.
let wasm = WasmModule::<T>::sized(c);
let addr = Base::<T>::contract_address(&user.account(), &wasm.hash, &salt);
}: _(user.origin(), ENDOWMENT, Weight::MAX, wasm.code, vec![], salt, Permissions::empty())
}: _(user.origin(), ENDOWMENT, Weight::MAX, wasm.code, vec![], salt)
verify {
// Ensure contract has the full value.
assert_eq!(free_balance::<T>(&addr), ENDOWMENT);
Expand Down
Loading

0 comments on commit 0ec8819

Please sign in to comment.