Skip to content

Commit

Permalink
Uses a number as network ID (#123)
Browse files Browse the repository at this point in the history
* Merge master

* Uses a number as network ID

* Remove trailing space
  • Loading branch information
drewstone authored Sep 13, 2020
1 parent cbf5768 commit ac50956
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
34 changes: 31 additions & 3 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,34 @@ impl<B, C, SC, P, CT, BE> EthApiT for EthApi<B, C, SC, P, CT, BE> where
}
}

pub struct NetApi;
pub struct NetApi<B, BE, C, SC> {
select_chain: SC,
client: Arc<C>,
_marker: PhantomData<(B, BE)>,
}

impl<B, BE, C, SC> NetApi<B, BE, C, SC> {
pub fn new(
client: Arc<C>,
select_chain: SC,
) -> Self {
Self {
client: client,
select_chain: select_chain,
_marker: PhantomData,
}
}
}

impl NetApiT for NetApi {
impl<B, BE, C, SC> NetApiT for NetApi<B, BE, C, SC> where
C: ProvideRuntimeApi<B> + StorageProvider<B, BE> + AuxStore,
C::Api: EthereumRuntimeRPCApi<B>,
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
C: Send + Sync + 'static,
SC: SelectChain<B> + Clone + 'static,
B: BlockT<Hash=H256> + Send + Sync + 'static,
{
fn is_listening(&self) -> Result<bool> {
Ok(true)
}
Expand All @@ -873,6 +898,9 @@ impl NetApiT for NetApi {
}

fn version(&self) -> Result<String> {
Ok("Frontier/v0.1.0".to_string())
let header = self.select_chain.best_chain()
.map_err(|_| internal_err("fetch header failed"))?;
Ok(self.client.runtime_api().chain_id(&BlockId::Hash(header.hash()))
.map_err(|_| internal_err("fetch runtime chain id failed"))?.to_string())
}
}
10 changes: 7 additions & 3 deletions template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{sync::Arc, fmt};

use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApi};
use frontier_template_runtime::{Hash, AccountId, Index, opaque::Block, Balance};
use sp_api::ProvideRuntimeApi;
use sp_api::{ProvideRuntimeApi, Core};
use sp_transaction_pool::TransactionPool;
use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};
use sp_consensus::SelectChain;
Expand Down Expand Up @@ -99,14 +99,18 @@ pub fn create_full<C, P, M, SC, BE>(
io.extend_with(
EthApiServer::to_delegate(EthApi::new(
client.clone(),
select_chain,
select_chain.clone(),
pool.clone(),
frontier_template_runtime::TransactionConverter,
is_authority,
))
);

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

match command_sink {
Expand Down

0 comments on commit ac50956

Please sign in to comment.