1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#![warn(missing_docs)]
use common::{ContentSource, Description, TradingPair};
use framenode_runtime::opaque::Block;
use framenode_runtime::{
eth_bridge, AccountId, AssetId, AssetName, AssetSymbol, Balance, BalancePrecision, DEXId,
FilterMode, Index, LiquiditySourceType, ResolveTime, Runtime, SwapVariant, Symbol,
};
use jsonrpsee::RpcModule;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_service::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use std::sync::Arc;
pub type RpcExtension = RpcModule<()>;
use beefy_gadget::communication::notification::{
BeefyBestBlockStream, BeefyVersionedFinalityProofStream,
};
pub struct BeefyDeps {
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block>,
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
pub subscription_executor: sc_rpc::SubscriptionTaskExecutor,
}
pub struct FullDeps<C, P, B> {
pub client: Arc<C>,
pub backend: Arc<B>,
pub pool: Arc<P>,
pub deny_unsafe: DenyUnsafe,
pub beefy: BeefyDeps,
}
#[cfg(feature = "wip")]
pub fn add_wip_rpc<C>(
mut rpc: RpcExtension,
client: Arc<C>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
C: Send + Sync + 'static,
C::Api: beefy_light_client_rpc::BeefyLightClientRuntimeAPI<Block, beefy_light_client::BitField>,
{
use beefy_light_client_rpc::{BeefyLightClientAPIServer, BeefyLightClientClient};
rpc.merge(BeefyLightClientClient::new(client).into_rpc())?;
Ok(rpc)
}
#[cfg(feature = "ready-to-test")]
pub fn add_ready_for_test_rpc(
rpc: RpcExtension,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>> {
Ok(rpc)
}
pub fn create_full<C, P, B>(
deps: FullDeps<C, P, B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
C: Send + Sync + 'static,
C::Api: mmr_rpc::MmrRuntimeApi<
Block,
<Block as sp_runtime::traits::Block>::Hash,
<<Block as sp_runtime::traits::Block>::Header as sp_runtime::traits::Header>::Number,
>,
C::Api: sp_beefy::BeefyApi<Block>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: dex_api_rpc::DEXRuntimeAPI<
Block,
AssetId,
DEXId,
Balance,
LiquiditySourceType,
SwapVariant,
>,
C::Api: oracle_proxy_rpc::OracleProxyRuntimeApi<Block, Symbol, ResolveTime>,
C::Api: dex_manager_rpc::DEXManagerRuntimeAPI<Block, DEXId>,
C::Api: trading_pair_rpc::TradingPairRuntimeAPI<
Block,
DEXId,
TradingPair<AssetId>,
AssetId,
LiquiditySourceType,
>,
C::Api: assets_rpc::AssetsRuntimeAPI<
Block,
AccountId,
AssetId,
Balance,
AssetSymbol,
AssetName,
BalancePrecision,
ContentSource,
Description,
>,
C::Api: liquidity_proxy_rpc::LiquidityProxyRuntimeAPI<
Block,
DEXId,
AssetId,
Balance,
SwapVariant,
LiquiditySourceType,
FilterMode,
>,
C::Api: eth_bridge_rpc::EthBridgeRuntimeApi<
Block,
sp_core::H256,
eth_bridge::offchain::SignatureParams,
AccountId,
eth_bridge::requests::AssetKind,
AssetId,
sp_core::H160,
eth_bridge::requests::OffchainRequest<Runtime>,
eth_bridge::requests::RequestStatus,
eth_bridge::requests::OutgoingRequestEncoded,
framenode_runtime::NetworkId,
framenode_runtime::BalancePrecision,
>,
C::Api: iroha_migration_rpc::IrohaMigrationRuntimeAPI<Block>,
C::Api: pswap_distribution_rpc::PswapDistributionRuntimeAPI<Block, AccountId, Balance>,
C::Api: rewards_rpc::RewardsRuntimeAPI<Block, sp_core::H160, Balance>,
C::Api: vested_rewards_rpc::VestedRewardsRuntimeApi<
Block,
AccountId,
AssetId,
Balance,
common::CrowdloanTag,
>,
C::Api: farming_rpc::FarmingRuntimeApi<Block, AssetId>,
C::Api: BlockBuilder<Block>,
C::Api: farming_rpc::FarmingRuntimeApi<Block, AssetId>,
C::Api: leaf_provider_rpc::LeafProviderRuntimeAPI<Block>,
C::Api: bridge_proxy_rpc::BridgeProxyRuntimeAPI<Block, AssetId>,
P: TransactionPool + Send + Sync + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use assets_rpc::{AssetsAPIServer, AssetsClient};
use beefy_gadget_rpc::{Beefy, BeefyApiServer};
use bridge_channel_rpc::{BridgeChannelAPIServer, BridgeChannelClient};
use bridge_proxy_rpc::{BridgeProxyAPIServer, BridgeProxyClient};
use dex_api_rpc::{DEXAPIServer, DEX};
use dex_manager_rpc::{DEXManager, DEXManagerAPIServer};
use eth_bridge_rpc::{EthBridgeApiServer, EthBridgeRpc};
use farming_rpc::{FarmingApiServer, FarmingClient};
use iroha_migration_rpc::{IrohaMigrationAPIServer, IrohaMigrationClient};
use leaf_provider_rpc::{LeafProviderAPIServer, LeafProviderClient};
use liquidity_proxy_rpc::{LiquidityProxyAPIServer, LiquidityProxyClient};
use mmr_rpc::{Mmr, MmrApiServer};
use oracle_proxy_rpc::{OracleProxyApiServer, OracleProxyClient};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use pswap_distribution_rpc::{PswapDistributionAPIServer, PswapDistributionClient};
use rewards_rpc::{RewardsAPIServer, RewardsClient};
use substrate_frame_rpc_system::{System, SystemApiServer};
use trading_pair_rpc::{TradingPairAPIServer, TradingPairClient};
use vested_rewards_rpc::{VestedRewardsApiServer, VestedRewardsClient};
let mut io = RpcModule::new(());
let FullDeps {
client,
pool,
deny_unsafe,
beefy,
backend,
} = deps;
io.merge(Mmr::new(client.clone()).into_rpc())?;
io.merge(
Beefy::<Block>::new(
beefy.beefy_finality_proof_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
)?
.into_rpc(),
)?;
io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
io.merge(DEX::new(client.clone()).into_rpc())?;
io.merge(DEXManager::new(client.clone()).into_rpc())?;
io.merge(TradingPairClient::new(client.clone()).into_rpc())?;
io.merge(AssetsClient::new(client.clone()).into_rpc())?;
io.merge(LiquidityProxyClient::new(client.clone()).into_rpc())?;
io.merge(OracleProxyClient::new(client.clone()).into_rpc())?;
io.merge(EthBridgeRpc::new(client.clone()).into_rpc())?;
io.merge(IrohaMigrationClient::new(client.clone()).into_rpc())?;
io.merge(PswapDistributionClient::new(client.clone()).into_rpc())?;
io.merge(RewardsClient::new(client.clone()).into_rpc())?;
io.merge(VestedRewardsClient::new(client.clone()).into_rpc())?;
io.merge(FarmingClient::new(client.clone()).into_rpc())?;
io.merge(LeafProviderClient::new(client.clone()).into_rpc())?;
io.merge(BridgeProxyClient::new(client.clone()).into_rpc())?;
if let Some(storage) = backend.offchain_storage() {
io.merge(<BridgeChannelClient<_, _> as BridgeChannelAPIServer<
bridge_types::types::BridgeOffchainData<
framenode_runtime::BlockNumber,
framenode_runtime::BridgeMaxMessagesPerCommit,
framenode_runtime::BridgeMaxMessagePayloadSize,
>,
>>::into_rpc(BridgeChannelClient::new(storage)))?;
}
Ok(io)
}