Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 94 additions & 7 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ members = [
"bin/node/executor",
"bin/node/primitives",
"bin/node/rpc",
# TODO(niklasad1): bring back once rpsee macros is a thing.
# "bin/node/rpc-client",
"bin/node/rpc-client",
"bin/node/runtime",
"bin/node/testing",
"bin/utils/chain-spec-builder",
Expand Down Expand Up @@ -198,8 +197,7 @@ members = [
"utils/frame/remote-externalities",
"utils/frame/frame-utilities-cli",
"utils/frame/try-runtime/cli",
# TODO(niklasad1): port this to jsonrpsee
# "utils/frame/rpc/support",
"utils/frame/rpc/support",
"utils/frame/rpc/system",
"utils/prometheus",
"utils/wasm-builder",
Expand Down
38 changes: 14 additions & 24 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;

use jsonrpsee::RpcModule;
use pallet_contracts_rpc::ContractsRpc;
use pallet_mmr_rpc::MmrRpc;
use pallet_transaction_payment_rpc::TransactionPaymentRpc;
use sc_consensus_babe_rpc::BabeRpc;
use sc_finality_grandpa_rpc::GrandpaRpc;
use sc_sync_state_rpc::SyncStateRpc;
use substrate_frame_rpc_system::{SystemRpc, SystemRpcBackendFull};
use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc};
use pallet_mmr_rpc::{MmrApiServer, MmrRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use sc_consensus_babe_rpc::{BabeApiServer, BabeRpc};
use sc_finality_grandpa_rpc::{GrandpaApiServer, GrandpaRpc};
use sc_sync_state_rpc::{SyncStateRpc, SyncStateRpcApiServer};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc, SystemRpcBackendFull};

type FullClient =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
Expand Down Expand Up @@ -180,8 +180,7 @@ pub fn new_partial(
Some(shared_authority_set.clone()),
),
)
.into_rpc_module()
.expect("TODO: error handling");
.into_rpc();

let babe_rpc = BabeRpc::new(
client2.clone(),
Expand All @@ -191,8 +190,7 @@ pub fn new_partial(
select_chain2,
deny_unsafe,
)
.into_rpc_module()
.expect("TODO: error handling");
.into_rpc();
let sync_state_rpc = SyncStateRpc::new(
chain_spec,
client2.clone(),
Expand All @@ -201,21 +199,13 @@ pub fn new_partial(
deny_unsafe,
)
.expect("TODO: error handling")
.into_rpc_module()
.expect("TODO: error handling");
let transaction_payment_rpc = TransactionPaymentRpc::new(client2.clone())
.into_rpc_module()
.expect("TODO: error handling");
.into_rpc();
let transaction_payment_rpc = TransactionPaymentRpc::new(client2.clone()).into_rpc();
let system_rpc_backend =
SystemRpcBackendFull::new(client2.clone(), transaction_pool2.clone(), deny_unsafe);
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");
let contracts_rpc = ContractsRpc::new(client2.clone())
.into_rpc_module()
.expect("TODO: error handling");

let system_rpc = SystemRpc::new(Box::new(system_rpc_backend)).into_rpc();
let mmr_rpc = MmrRpc::new(client2.clone()).into_rpc();
let contracts_rpc = ContractsRpc::new(client2.clone()).into_rpc();
let mut module = RpcModule::new(());
module.merge(grandpa_rpc).expect("TODO: error handling");
module.merge(babe_rpc).expect("TODO: error handling");
Expand Down
5 changes: 2 additions & 3 deletions bin/node/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
futures = "0.3.16"
jsonrpc-core-client = { version = "18.0.0", default-features = false, features = [
"http",
] }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "master", features = ["client", "macros"] }
tokio = { version = "1.10", features = ["full"] }
node-primitives = { version = "2.0.0", path = "../primitives" }
sp-tracing = { version = "4.0.0-dev", path = "../../../primitives/tracing" }
sc-rpc = { version = "4.0.0-dev", path = "../../../client/rpc" }
50 changes: 26 additions & 24 deletions bin/node/rpc-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
//! This module shows how you can write a Rust RPC client that connects to a running
//! substrate node and use statically typed RPC wrappers.

use futures::{Future, TryFutureExt};
use jsonrpc_core_client::{transports::http, RpcError};
use futures::TryFutureExt;
use jsonrpsee::{types::Error, ws_client::WsClientBuilder};
use node_primitives::Hash;
use sc_rpc::author::{hash::ExtrinsicOrHash, AuthorClient};
use sc_rpc::author::{hash::ExtrinsicOrHash, AuthorApiClient};

fn main() -> Result<(), RpcError> {
#[tokio::main]
async fn main() -> Result<(), Error> {
sp_tracing::try_init_simple();

futures::executor::block_on(async {
let uri = "http://localhost:9933";

http::connect(uri)
.and_then(|client: AuthorClient<Hash, Hash>| remove_all_extrinsics(client))
.await
})
// NOTE(niklasad1): changed this to the WS client because the jsonrpsee proc macros
// requires the trait bound `SubscriptionClient` that is not implemented is not implemented for HTTP client.
WsClientBuilder::default()
.build("ws://localhost:9944")
.and_then(|client| remove_all_extrinsics(client))
.await
}

/// Remove all pending extrinsics from the node.
Expand All @@ -47,17 +47,19 @@ fn main() -> Result<(), RpcError> {
///
/// As the result of running the code the entire content of the transaction pool is going
/// to be removed and the extrinsics are going to be temporarily banned.
fn remove_all_extrinsics(
client: AuthorClient<Hash, Hash>,
) -> impl Future<Output = Result<(), RpcError>> {
client
.pending_extrinsics()
.and_then(move |pending| {
client.remove_extrinsic(
pending.into_iter().map(|tx| ExtrinsicOrHash::Extrinsic(tx.into())).collect(),
)
})
.map_ok(|removed| {
println!("Removed extrinsics: {:?}", removed);
})
async fn remove_all_extrinsics<C>(client: C) -> Result<(), Error>
where
C: AuthorApiClient<Hash, Hash> + Sync,
{
let pending_exts = client.pending_extrinsics().await?;
let removed = client
.remove_extrinsic(
pending_exts
.into_iter()
.map(|tx| ExtrinsicOrHash::Extrinsic(tx.into()))
.collect(),
)
.await?;
println!("Removed extrinsics: {:?}", removed);
Ok(())
}
Loading