2222#![ warn( missing_docs) ]
2323
2424use jsonrpsee:: RpcModule ;
25+ use mmr_rpc:: { Mmr , MmrApiServer } ;
2526use pallet_transaction_payment_rpc:: { TransactionPayment , TransactionPaymentApiServer } ;
2627use sc_client_api:: { AuxStore , BlockBackend } ;
2728use sc_consensus_subspace:: archiver:: { ArchivedSegmentNotification , SegmentHeadersStore } ;
@@ -42,13 +43,14 @@ use sp_consensus_subspace::{FarmerPublicKey, SubspaceApi};
4243use sp_objects:: ObjectsApi ;
4344use std:: sync:: Arc ;
4445use subspace_core_primitives:: crypto:: kzg:: Kzg ;
46+ use subspace_core_primitives:: BlockNumber ;
4547use subspace_networking:: libp2p:: Multiaddr ;
4648use subspace_runtime_primitives:: opaque:: Block ;
4749use subspace_runtime_primitives:: { AccountId , Balance , Nonce } ;
4850use substrate_frame_rpc_system:: { System , SystemApiServer } ;
4951
5052/// Full client dependencies.
51- pub struct FullDeps < C , P , SO , AS >
53+ pub struct FullDeps < C , P , SO , AS , B >
5254where
5355 SO : SyncOracle + Send + Sync + Clone ,
5456{
@@ -78,11 +80,13 @@ where
7880 pub sync_oracle : SubspaceSyncOracle < SO > ,
7981 /// Kzg instance.
8082 pub kzg : Kzg ,
83+ /// Backend used by the node.
84+ pub backend : Arc < B > ,
8185}
8286
8387/// Instantiate all full RPC extensions.
84- pub fn create_full < C , P , SO , AS > (
85- deps : FullDeps < C , P , SO , AS > ,
88+ pub fn create_full < C , P , SO , AS , B > (
89+ deps : FullDeps < C , P , SO , AS , B > ,
8690) -> Result < RpcModule < ( ) > , Box < dyn std:: error:: Error + Send + Sync > >
8791where
8892 C : ProvideRuntimeApi < Block >
@@ -96,10 +100,13 @@ where
96100 + pallet_transaction_payment_rpc:: TransactionPaymentRuntimeApi < Block , Balance >
97101 + BlockBuilder < Block >
98102 + SubspaceApi < Block , FarmerPublicKey >
103+ + mmr_rpc:: MmrRuntimeApi < Block , <Block as sp_runtime:: traits:: Block >:: Hash , BlockNumber >
99104 + ObjectsApi < Block > ,
100105 P : TransactionPool + ' static ,
101106 SO : SyncOracle + Send + Sync + Clone + ' static ,
102107 AS : AuxStore + Send + Sync + ' static ,
108+ B : sc_client_api:: Backend < Block > + Send + Sync + ' static ,
109+ B :: State : sc_client_api:: StateBackend < sp_runtime:: traits:: HashingFor < Block > > ,
103110{
104111 let mut module = RpcModule :: new ( ( ) ) ;
105112 let FullDeps {
@@ -115,6 +122,7 @@ where
115122 segment_headers_store,
116123 sync_oracle,
117124 kzg,
125+ backend,
118126 } = deps;
119127
120128 let chain_name = chain_spec. name ( ) . to_string ( ) ;
@@ -127,7 +135,7 @@ where
127135
128136 module. merge (
129137 SubspaceRpc :: new ( SubspaceRpcConfig {
130- client,
138+ client : client . clone ( ) ,
131139 subscription_executor,
132140 new_slot_notification_stream,
133141 reward_signing_notification_stream,
@@ -140,6 +148,15 @@ where
140148 } ) ?
141149 . into_rpc ( ) ,
142150 ) ?;
151+ module. merge (
152+ Mmr :: new (
153+ client,
154+ backend
155+ . offchain_storage ( )
156+ . ok_or ( "Backend doesn't provide the required offchain storage" ) ?,
157+ )
158+ . into_rpc ( ) ,
159+ ) ?;
143160
144161 Ok ( module)
145162}
0 commit comments