@@ -20,6 +20,10 @@ use partner_chains_demo_runtime::{
20
20
opaque:: { Block , SessionKeys } ,
21
21
} ;
22
22
use 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 ;
23
27
use sc_consensus_grandpa:: {
24
28
FinalityProofProvider , GrandpaJustificationStream , SharedAuthoritySet , SharedVoterState ,
25
29
} ;
@@ -31,6 +35,7 @@ use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
31
35
use sp_api:: ProvideRuntimeApi ;
32
36
use sp_block_builder:: BlockBuilder ;
33
37
use sp_blockchain:: { Error as BlockChainError , HeaderBackend , HeaderMetadata } ;
38
+ use sp_consensus_beefy:: AuthorityIdBound ;
34
39
use sp_session_validator_management_query:: SessionValidatorManagementQuery ;
35
40
use std:: sync:: Arc ;
36
41
use time_source:: TimeSource ;
@@ -49,23 +54,35 @@ pub struct GrandpaDeps<B> {
49
54
pub finality_provider : Arc < FinalityProofProvider < B , Block > > ,
50
55
}
51
56
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
+
52
67
/// Full client dependencies.
53
- pub struct FullDeps < C , P , B , T > {
68
+ pub struct FullDeps < C , P , B , T , AuthorityId : AuthorityIdBound > {
54
69
/// The client instance to use.
55
70
pub client : Arc < C > ,
56
71
/// Transaction pool instance.
57
72
pub pool : Arc < P > ,
58
73
/// GRANDPA specific dependencies.
59
74
pub grandpa : GrandpaDeps < B > ,
75
+ /// BEEFY specific dependencies.
76
+ pub beefy : BeefyDeps < AuthorityId > ,
60
77
/// Data sources.
61
78
pub data_sources : DataSources ,
62
79
/// Source of system time
63
80
pub time_source : Arc < T > ,
64
81
}
65
82
66
83
/// 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 > ,
69
86
) -> Result < RpcModule < ( ) > , Box < dyn std:: error:: Error + Send + Sync > >
70
87
where
71
88
C : ProvideRuntimeApi < Block > ,
@@ -93,10 +110,11 @@ where
93
110
T : TimeSource + Send + Sync + ' static ,
94
111
{
95
112
use pallet_transaction_payment_rpc:: { TransactionPayment , TransactionPaymentApiServer } ;
113
+ use sc_consensus_beefy_rpc:: BeefyApiServer ;
96
114
use substrate_frame_rpc_system:: { System , SystemApiServer } ;
97
115
98
116
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;
100
118
101
119
module. merge ( System :: new ( client. clone ( ) , pool. clone ( ) ) . into_rpc ( ) ) ?;
102
120
module. merge ( TransactionPayment :: new ( client. clone ( ) ) . into_rpc ( ) ) ?;
@@ -137,6 +155,15 @@ where
137
155
. into_rpc ( ) ,
138
156
) ?;
139
157
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
+
140
167
// Extend this RPC with a custom API by using the following syntax.
141
168
// `YourRpcStruct` should have a reference to a client, which is needed
142
169
// to call into the runtime.
0 commit comments