Skip to content

Commit

Permalink
fixbug
Browse files Browse the repository at this point in the history
Offline new client
  • Loading branch information
tuminfei committed Aug 3, 2021
1 parent 45e65c8 commit 48a7dae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 243 deletions.
117 changes: 13 additions & 104 deletions bin/rpc/src/fuxi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,14 @@ use sp_block_builder::BlockBuilder;
pub use sc_rpc_api::DenyUnsafe;
use sp_transaction_pool::TransactionPool;

use sc_client_api::{
backend::{StorageProvider, Backend, StateBackend, AuxStore},
client::BlockchainEvents
};
use sc_transaction_graph::{ChainApi, Pool};
use sc_rpc::SubscriptionTaskExecutor;
use sp_runtime::traits::BlakeTwo256;
use sc_network::NetworkService;
use jsonrpc_pubsub::manager::SubscriptionManager;
use fc_rpc_core::types::{PendingTransactions, FilterPool};

/// Full client dependencies.
pub struct FullDeps<C, P, A: ChainApi> {
pub struct FullDeps<C, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Graph pool instance.
pub graph: Arc<Pool<A>>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// The Node authority flag
pub is_authority: bool,
/// Whether to enable dev signer
pub enable_dev_signer: bool,
/// Network service
pub network: Arc<NetworkService<Block, Hash>>,
/// Ethereum pending transactions.
pub pending_transactions: PendingTransactions,
/// EthFilterApi pool.
pub filter_pool: Option<FilterPool>,
/// Manual seal command sink
pub command_sink: Option<futures::channel::mpsc::Sender<sc_consensus_manual_seal::rpc::EngineCommand<Hash>>>,
}

/// Light client extra dependencies.
Expand All @@ -62,109 +37,39 @@ pub struct LightDeps<C, F, P> {
}

/// Instantiate all full RPC extensions.
pub fn create_full<C, P, BE, A>(
deps: FullDeps<C, P, A>,
subscription_task_executor: SubscriptionTaskExecutor
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> jsonrpc_core::IoHandler<sc_rpc::Metadata> where
BE: Backend<Block> + 'static,
BE::State: StateBackend<BlakeTwo256>,
C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,
C: BlockchainEvents<Block>,
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError> + 'static,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: pallet_staking_rpc::StakingRuntimeApi<Block, AccountId, Balance>,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: BlockBuilder<Block>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
P: TransactionPool<Block=Block> + 'static,
A: ChainApi<Block = Block> + 'static,
P: TransactionPool + 'static,
{
use substrate_frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use pallet_staking_rpc::{Staking, StakingApi};
use pallet_contracts_rpc::{Contracts, ContractsApi};
use fc_rpc::{
EthApi, EthApiServer, EthFilterApi, EthFilterApiServer, NetApi, NetApiServer,
EthPubSubApi, EthPubSubApiServer, Web3Api, Web3ApiServer, EthDevSigner, EthSigner,
HexEncodedIdProvider,
};

let mut io = jsonrpc_core::IoHandler::default();
let FullDeps {
client,
pool,
graph,
deny_unsafe,
is_authority,
network,
pending_transactions,
filter_pool,
command_sink,
enable_dev_signer,
} = deps;

io.extend_with(
SystemApi::to_delegate(FullSystem::new(client.clone(), pool.clone(), deny_unsafe))
SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe))
);

io.extend_with(
TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone()))
);

let mut signers = Vec::new();
if enable_dev_signer {
signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
}
io.extend_with(
EthApiServer::to_delegate(EthApi::new(
client.clone(),
pool.clone(),
graph,
fuxi_runtime::TransactionConverter,
network.clone(),
pending_transactions.clone(),
signers,
is_authority,
))
);

if let Some(filter_pool) = filter_pool {
io.extend_with(
EthFilterApiServer::to_delegate(EthFilterApi::new(
client.clone(),
filter_pool.clone(),
500 as usize, // max stored filters
))
);
}

io.extend_with(
NetApiServer::to_delegate(NetApi::new(
client.clone(),
network.clone(),
))
);

io.extend_with(
Web3ApiServer::to_delegate(Web3Api::new(
client.clone(),
))
);

io.extend_with(
EthPubSubApiServer::to_delegate(EthPubSubApi::new(
pool.clone(),
client.clone(),
network.clone(),
SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(
HexEncodedIdProvider::default(),
Arc::new(subscription_task_executor)
),
))
);

io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));

io.extend_with(
Expand All @@ -175,16 +80,20 @@ pub fn create_full<C, P, BE, A>(
// `YourRpcStruct` should have a reference to a client, which is needed
// to call into the runtime.
// `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`

io
}

/// Instantiate all RPC extensions for light node.
pub fn create_light<C, P, F>(deps: LightDeps<C, F, P>) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
where
C: Send + Sync + 'static,
C: 'static + Send + Sync,
C: ProvideRuntimeApi<Block>,
C: sp_blockchain::HeaderBackend<Block>,
F: sc_client_api::light::Fetcher<Block> + 'static,
P: sp_transaction_pool::TransactionPool + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
P: 'static + sp_transaction_pool::TransactionPool,
F: 'static + sc_client_api::Fetcher<Block>,
{
// --- substrate ---
use substrate_frame_rpc_system::{LightSystem, SystemApi};
Expand Down
Loading

0 comments on commit 48a7dae

Please sign in to comment.