Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add contracts RPC (#9261)
Browse files Browse the repository at this point in the history
* Add contracts RPC

* cleanup

* Make pretty
  • Loading branch information
dvdplm authored Jul 3, 2021
1 parent 0e29c4b commit 18afbb5
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 248 deletions.
10 changes: 3 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pallet-grandpa = { version = "3.1.0", path = "../../../frame/grandpa" }
pallet-transaction-payment-rpc = { version = "3.0.0", path = "../../../frame/transaction-payment/rpc/" }
substrate-frame-rpc-system = { version = "3.0.0", path = "../../../utils/frame/rpc/system/" }
pallet-mmr-rpc = { version = "3.0.0", path = "../../../frame/merkle-mountain-range/rpc/" }
pallet-contracts-rpc = { version = "3.0.0", path = "../../../frame/contracts/rpc/" }

# node-specific dependencies
node-runtime = { version = "2.0.0", path = "../runtime" }
Expand Down
9 changes: 5 additions & 4 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use sc_sync_state_rpc::SyncStateRpc;
use pallet_transaction_payment_rpc::TransactionPaymentRpc;
use substrate_frame_rpc_system::{SystemRpc, SystemRpcBackendFull};
use pallet_mmr_rpc::MmrRpc;
use pallet_contracts_rpc::ContractsRpc;

type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
type FullBackend = sc_service::TFullBackend<Block>;
Expand Down Expand Up @@ -195,14 +196,16 @@ pub fn new_partial(
let system_rpc = SystemRpc::new(Box::new(system_rpc_backend)).into_rpc_module().expect("TODO: error handling");

let mmr_rpc = MmrRpc::new(client2.clone()).into_rpc_module().expect("TODO: error handling");
// TODO: add other rpc modules here
let contracts_rpc = ContractsRpc::new(client2.clone()).into_rpc_module().expect("TODO: error handling");

let mut module = RpcModule::new(());
module.merge(grandpa_rpc).expect("TODO: error handling");
module.merge(babe_rpc).expect("TODO: error handling");
module.merge(sync_state_rpc).expect("TODO: error handling");
module.merge(transaction_payment_rpc).expect("TODO: error handling");
module.merge(system_rpc).expect("TODO: error handling");
module.merge(mmr_rpc).expect("TODO: error handling");
module.merge(contracts_rpc).expect("TODO: error handling");
module
};

Expand All @@ -211,10 +214,8 @@ pub fn new_partial(
// TODO: (dp) remove this when all APIs are ported.
let (rpc_extensions_builder, rpc_setup) = {
let rpc_setup = grandpa::SharedVoterState::empty();
let client = client.clone();
let rpc_extensions_builder = move |_deny_unsafe, _subscription_executor| {
let deps = node_rpc::FullDeps { client: client.clone() };
node_rpc::create_full(deps)
node_rpc::create_full()
};

(rpc_extensions_builder, rpc_setup)
Expand Down
4 changes: 0 additions & 4 deletions bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
jsonrpc-core = "15.1.0"
node-primitives = { version = "2.0.0", path = "../primitives" }
pallet-contracts-rpc = { version = "3.0.0", path = "../../../frame/contracts/rpc/" }
sc-client-api = { version = "3.0.0", path = "../../../client/api" }
sc-consensus-babe = { version = "0.9.0", path = "../../../client/consensus/babe" }
sc-consensus-epochs = { version = "0.9.0", path = "../../../client/consensus/epochs" }
sc-finality-grandpa = { version = "0.9.0", path = "../../../client/finality-grandpa" }
sc-rpc-api = { version = "0.9.0", path = "../../../client/rpc-api" }
sc-rpc = { version = "3.0.0", path = "../../../client/rpc" }
sp-api = { version = "3.0.0", path = "../../../primitives/api" }
sp-block-builder = { version = "3.0.0", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" }
sp-keystore = { version = "0.9.0", path = "../../../primitives/keystore" }
33 changes: 3 additions & 30 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@
use std::sync::Arc;

use sp_keystore::SyncCryptoStorePtr;
use node_primitives::{Block, BlockNumber, AccountId, Balance, Hash};
use node_primitives::{Block, BlockNumber, Hash};
use sc_consensus_babe::{Config, Epoch};
use sc_consensus_epochs::SharedEpochChanges;
use sc_finality_grandpa::{
SharedVoterState, SharedAuthoritySet, FinalityProofProvider, GrandpaJustificationStream
};
pub use sc_rpc_api::DenyUnsafe;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};
use sc_rpc::SubscriptionTaskExecutor;
use sc_client_api::AuxStore;

/// Light client extra dependencies.
pub struct LightDeps<C, F, P> {
Expand Down Expand Up @@ -83,35 +79,12 @@ pub struct GrandpaDeps<B> {
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
}

/// Full client dependencies.
pub struct FullDeps<C> {
/// The client instance to use.
pub client: Arc<C>,
}

/// A IO handler that uses all Full RPC extensions.
pub type IoHandler = jsonrpc_core::IoHandler<()>;

/// Instantiate all Full RPC extensions.
// TODO(niklasad1): replace these.
pub fn create_full<C>(
deps: FullDeps<C>,
) -> jsonrpc_core::IoHandler<()> where
C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + AuxStore +
HeaderMetadata<Block, Error=BlockChainError> + Sync + Send + 'static,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,
C::Api: BlockBuilder<Block>,
pub fn create_full() -> jsonrpc_core::IoHandler<()>
{
use pallet_contracts_rpc::{Contracts, ContractsApi};

let mut io = jsonrpc_core::IoHandler::default();
let FullDeps { client } = deps;

// Making synchronous calls in light client freezes the browser currently,
// more context: https://github.com/paritytech/substrate/pull/3480
// These RPCs should use an asynchronous caller instead.
io.extend_with(
ContractsApi::to_delegate(Contracts::new(client.clone()))
);
io
jsonrpc_core::IoHandler::default()
}
9 changes: 3 additions & 6 deletions frame/contracts/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "2" }
jsonrpc-core = "15"
jsonrpc-core-client = "15"
jsonrpc-derive = "15"
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "master", features = ["server"] }
jsonrpsee-types = { git = "https://github.com/paritytech/jsonrpsee", branch = "master" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

# Substrate Dependencies
pallet-contracts-primitives = { version = "3.0.0", path = "../common" }
Expand All @@ -27,6 +27,3 @@ sp-blockchain = { version = "3.0.0", path = "../../../primitives/blockchain" }
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-rpc = { version = "3.0.0", path = "../../../primitives/rpc" }
sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" }

[dev-dependencies]
serde_json = "1"
Loading

0 comments on commit 18afbb5

Please sign in to comment.