From 08c51d904cb2ff768200de47d32818307b1d814a Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Sat, 18 May 2024 17:44:22 +0530 Subject: [PATCH] Adds transaction payment rpc in minimal template --- Cargo.lock | 1 + templates/minimal/node/Cargo.toml | 1 + templates/minimal/node/src/rpc.rs | 5 ++++- templates/minimal/runtime/src/lib.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 2a4b9b138bf8..2515c397d998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8421,6 +8421,7 @@ dependencies = [ "futures-timer", "jsonrpsee", "minimal-template-runtime", + "pallet-transaction-payment-rpc", "polkadot-sdk-frame", "sc-basic-authorship", "sc-cli", diff --git a/templates/minimal/node/Cargo.toml b/templates/minimal/node/Cargo.toml index 606fd0580356..c6c71c968da0 100644 --- a/templates/minimal/node/Cargo.toml +++ b/templates/minimal/node/Cargo.toml @@ -45,6 +45,7 @@ sp-block-builder = { path = "../../../substrate/primitives/block-builder" } sp-io = { path = "../../../substrate/primitives/io" } sp-runtime = { path = "../../../substrate/primitives/runtime" } +pallet-transaction-payment-rpc = { path = "../../../substrate/frame/transaction-payment/rpc" } substrate-frame-rpc-system = { path = "../../../substrate/utils/frame/rpc/system" } # Once the native runtime is gone, there should be little to no dependency on FRAME here, and diff --git a/templates/minimal/node/src/rpc.rs b/templates/minimal/node/src/rpc.rs index d0c417a93d7a..636fb03b44c4 100644 --- a/templates/minimal/node/src/rpc.rs +++ b/templates/minimal/node/src/rpc.rs @@ -23,7 +23,8 @@ #![warn(missing_docs)] use jsonrpsee::RpcModule; -use runtime::interface::{AccountId, Nonce, OpaqueBlock}; +use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; +use runtime::interface::{AccountId, Balance, Nonce, OpaqueBlock}; use sc_transaction_pool_api::TransactionPool; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use std::sync::Arc; @@ -55,12 +56,14 @@ where + 'static, C::Api: sp_block_builder::BlockBuilder, C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, P: TransactionPool + 'static, { let mut module = RpcModule::new(()); let FullDeps { client, pool, deny_unsafe } = deps; module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; + module.merge(TransactionPayment::new(client).into_rpc())?; Ok(module) } diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index d2debbf5689f..7a4cb262f767 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -271,6 +271,32 @@ impl_runtime_apis! { } } + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi< + Block, + interface::Balance, + RuntimeCall + > for Runtime + { + fn query_call_info( + call: RuntimeCall, + len: u32, + ) -> RuntimeDispatchInfo { + TransactionPayment::query_call_info(call, len) + } + fn query_call_fee_details( + call: RuntimeCall, + len: u32, + ) -> FeeDetails { + TransactionPayment::query_call_fee_details(call, len) + } + fn query_weight_to_fee(weight: Weight) -> interface::Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> interface::Balance { + TransactionPayment::length_to_fee(length) + } + } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config)