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 1 commit
Commits
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
Prev Previous commit
Next Next commit
fix some unwraps
  • Loading branch information
niklasad1 committed Sep 17, 2021
commit fdd7aae8290aea04995e3ba0e5c1d7c6148b8cdc
19 changes: 11 additions & 8 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

use std::sync::Arc;

use jsonrpsee::RpcModule;
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

pub use sc_rpc_api::DenyUnsafe;

/// Full client dependencies.
pub struct FullDeps<C, P> {
/// The client instance to use.
Expand All @@ -25,7 +27,9 @@ pub struct FullDeps<C, P> {
}

/// Instantiate all full RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> jsonrpsee::RpcModule<()>
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
Expand All @@ -38,18 +42,17 @@ where
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc, SystemRpcBackendFull};

let mut module = jsonrpsee::RpcModule::new(());
let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

let system_rpc_backend = SystemRpcBackendFull::new(client.clone(), pool.clone(), deny_unsafe);
module.merge(SystemRpc::new(Box::new(system_rpc_backend)).into_rpc()).unwrap();

module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc()).unwrap();
module.merge(SystemRpc::new(Box::new(system_rpc_backend)).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;

// Extend this RPC with a custom API by using the following syntax.
// `YourRpcStruct` should have a reference to a client, which is needed
// to call into the runtime.
// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...))).unwrap();`
// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;`

module
Ok(module)
}
4 changes: 2 additions & 2 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
Box::new(move |deny_unsafe, _| {
let deps =
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };
Ok(crate::rpc::create_full(deps))
crate::rpc::create_full(deps).map_err(Into::into)
})
};

Expand Down Expand Up @@ -459,7 +459,7 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
Box::new(move |deny_unsafe, _| {
let deps =
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };
Ok(crate::rpc::create_full(deps))
crate::rpc::create_full(deps).map_err(Into::into)
})
};

Expand Down