@@ -20,6 +20,10 @@ use partner_chains_demo_runtime::{
2020 opaque:: { Block , SessionKeys } ,
2121} ;
2222use partner_chains_demo_runtime:: { BlockNumber , BlockProducerMetadataType , CrossChainPublic , Hash } ;
23+ use sc_consensus_beefy:: communication:: notification:: {
24+ BeefyBestBlockStream , BeefyVersionedFinalityProofStream ,
25+ } ;
26+ use sc_consensus_beefy_rpc:: Beefy ;
2327use sc_consensus_grandpa:: {
2428 FinalityProofProvider , GrandpaJustificationStream , SharedAuthoritySet , SharedVoterState ,
2529} ;
@@ -31,6 +35,7 @@ use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
3135use sp_api:: ProvideRuntimeApi ;
3236use sp_block_builder:: BlockBuilder ;
3337use sp_blockchain:: { Error as BlockChainError , HeaderBackend , HeaderMetadata } ;
38+ use sp_consensus_beefy:: AuthorityIdBound ;
3439use sp_session_validator_management_query:: SessionValidatorManagementQuery ;
3540use std:: sync:: Arc ;
3641use time_source:: TimeSource ;
@@ -49,23 +54,35 @@ pub struct GrandpaDeps<B> {
4954 pub finality_provider : Arc < FinalityProofProvider < B , Block > > ,
5055}
5156
57+ /// Dependencies for BEEFY
58+ pub struct BeefyDeps < AuthorityId : AuthorityIdBound > {
59+ /// Receives notifications about finality proof events from BEEFY.
60+ pub beefy_finality_proof_stream : BeefyVersionedFinalityProofStream < Block , AuthorityId > ,
61+ /// Receives notifications about best block events from BEEFY.
62+ pub beefy_best_block_stream : BeefyBestBlockStream < Block > ,
63+ /// Executor to drive the subscription manager in the BEEFY RPC handler.
64+ pub subscription_executor : sc_rpc:: SubscriptionTaskExecutor ,
65+ }
66+
5267/// Full client dependencies.
53- pub struct FullDeps < C , P , B , T > {
68+ pub struct FullDeps < C , P , B , T , AuthorityId : AuthorityIdBound > {
5469 /// The client instance to use.
5570 pub client : Arc < C > ,
5671 /// Transaction pool instance.
5772 pub pool : Arc < P > ,
5873 /// GRANDPA specific dependencies.
5974 pub grandpa : GrandpaDeps < B > ,
75+ /// BEEFY specific dependencies.
76+ pub beefy : BeefyDeps < AuthorityId > ,
6077 /// Data sources.
6178 pub data_sources : DataSources ,
6279 /// Source of system time
6380 pub time_source : Arc < T > ,
6481}
6582
6683/// Instantiate all full RPC extensions.
67- pub fn create_full < C , P , B , T > (
68- deps : FullDeps < C , P , B , T > ,
84+ pub fn create_full < C , P , B , T , AuthorityId : AuthorityIdBound > (
85+ deps : FullDeps < C , P , B , T , AuthorityId > ,
6986) -> Result < RpcModule < ( ) > , Box < dyn std:: error:: Error + Send + Sync > >
7087where
7188 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