@@ -17,6 +17,10 @@ use partner_chains_demo_runtime::{
1717 opaque:: { Block , SessionKeys } ,
1818} ;
1919use partner_chains_demo_runtime:: { BlockNumber , BlockProducerMetadataType , CrossChainPublic , Hash } ;
20+ use sc_consensus_beefy:: communication:: notification:: {
21+ BeefyBestBlockStream , BeefyVersionedFinalityProofStream ,
22+ } ;
23+ use sc_consensus_beefy_rpc:: Beefy ;
2024use sc_consensus_grandpa:: {
2125 FinalityProofProvider , GrandpaJustificationStream , SharedAuthoritySet , SharedVoterState ,
2226} ;
@@ -28,6 +32,7 @@ use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
2832use sp_api:: { CallApiAt , ProvideRuntimeApi } ;
2933use sp_block_builder:: BlockBuilder ;
3034use sp_blockchain:: { Error as BlockChainError , HeaderBackend , HeaderMetadata } ;
35+ use sp_consensus_beefy:: AuthorityIdBound ;
3136use sp_session_validator_management_query:: SessionValidatorManagementQuery ;
3237use sp_sidechain:: GetEpochDurationApi ;
3338use std:: sync:: Arc ;
@@ -47,23 +52,35 @@ pub struct GrandpaDeps<B> {
4752 pub finality_provider : Arc < FinalityProofProvider < B , Block > > ,
4853}
4954
55+ /// Dependencies for BEEFY
56+ pub struct BeefyDeps < AuthorityId : AuthorityIdBound > {
57+ /// Receives notifications about finality proof events from BEEFY.
58+ pub beefy_finality_proof_stream : BeefyVersionedFinalityProofStream < Block , AuthorityId > ,
59+ /// Receives notifications about best block events from BEEFY.
60+ pub beefy_best_block_stream : BeefyBestBlockStream < Block > ,
61+ /// Executor to drive the subscription manager in the BEEFY RPC handler.
62+ pub subscription_executor : sc_rpc:: SubscriptionTaskExecutor ,
63+ }
64+
5065/// Full client dependencies.
51- pub struct FullDeps < C , P , B , T > {
66+ pub struct FullDeps < C , P , B , T , AuthorityId : AuthorityIdBound > {
5267 /// The client instance to use.
5368 pub client : Arc < C > ,
5469 /// Transaction pool instance.
5570 pub pool : Arc < P > ,
5671 /// GRANDPA specific dependencies.
5772 pub grandpa : GrandpaDeps < B > ,
73+ /// BEEFY specific dependencies.
74+ pub beefy : BeefyDeps < AuthorityId > ,
5875 /// Data sources.
5976 pub data_sources : DataSources ,
6077 /// Source of system time
6178 pub time_source : Arc < T > ,
6279}
6380
6481/// Instantiate all full RPC extensions.
65- pub fn create_full < C , P , B , T > (
66- deps : FullDeps < C , P , B , T > ,
82+ pub fn create_full < C , P , B , T , AuthorityId : AuthorityIdBound > (
83+ deps : FullDeps < C , P , B , T , AuthorityId > ,
6784) -> Result < RpcModule < ( ) > , Box < dyn std:: error:: Error + Send + Sync > >
6885where
6986 C : ProvideRuntimeApi < Block > ,
@@ -93,10 +110,11 @@ where
93110 T : TimeSource + Send + Sync + ' static ,
94111{
95112 use pallet_transaction_payment_rpc:: { TransactionPayment , TransactionPaymentApiServer } ;
113+ use sc_consensus_beefy_rpc:: BeefyApiServer ;
96114 use substrate_frame_rpc_system:: { System , SystemApiServer } ;
97115
98116 let mut module = RpcModule :: new ( ( ) ) ;
99- let FullDeps { client, pool, grandpa, data_sources, time_source } = deps;
117+ let FullDeps { client, pool, grandpa, beefy , data_sources, time_source } = deps;
100118
101119 module. merge ( System :: new ( client. clone ( ) , pool. clone ( ) ) . into_rpc ( ) ) ?;
102120 module. merge ( TransactionPayment :: new ( client. clone ( ) ) . into_rpc ( ) ) ?;
@@ -137,6 +155,15 @@ where
137155 . into_rpc ( ) ,
138156 ) ?;
139157
158+ module. merge (
159+ Beefy :: < Block , AuthorityId > :: new (
160+ beefy. beefy_finality_proof_stream ,
161+ beefy. beefy_best_block_stream ,
162+ beefy. subscription_executor ,
163+ ) ?
164+ . into_rpc ( ) ,
165+ ) ?;
166+
140167 // Extend this RPC with a custom API by using the following syntax.
141168 // `YourRpcStruct` should have a reference to a client, which is needed
142169 // to call into the runtime.
0 commit comments