Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add RPC enode lookup #3096

Merged
merged 2 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod codes {
pub const ACCOUNT_ERROR: i64 = -32023;
pub const SIGNER_DISABLED: i64 = -32030;
pub const DAPPS_DISABLED: i64 = -32031;
pub const NETWORK_DISABLED: i64 = -32035;
pub const REQUEST_REJECTED: i64 = -32040;
pub const REQUEST_REJECTED_LIMIT: i64 = -32041;
pub const REQUEST_NOT_FOUND: i64 = -32042;
Expand Down Expand Up @@ -185,6 +186,14 @@ pub fn dapps_disabled() -> Error {
}
}

pub fn network_disabled() -> Error {
Error {
code: ErrorCode::ServerError(codes::NETWORK_DISABLED),
message: "Network is disabled or not yet up.".into(),
data: None
}
}

pub fn encryption_error<T: fmt::Debug>(error: T) -> Error {
Error {
code: ErrorCode::ServerError(codes::ENCRYPTION_ERROR),
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/v1/impls/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,8 @@ impl<C, M, S: ?Sized, F> Ethcore for EthcoreClient<C, M, S, F> where
Mode::Active => "active",
}.into())
}

fn enode(&self) -> Result<String, Error> {
take_weak!(self.sync).enode().ok_or_else(errors::network_disabled)
}
}
4 changes: 4 additions & 0 deletions rpc/src/v1/tests/helpers/sync_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ impl SyncProvider for TestSyncProvider {
}
]
}

fn enode(&self) -> Option<String> {
None
}
}

4 changes: 4 additions & 0 deletions rpc/src/v1/traits/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,9 @@ build_rpc_trait! {
/// Get the mode. Results one of: "active", "passive", "dark", "off".
#[rpc(name = "ethcore_mode")]
fn mode(&self) -> Result<String, Error>;

/// Get the enode of this node.
#[rpc(name = "ethcore_enode")]
fn enode(&self) -> Result<String, Error>;
}
}
7 changes: 7 additions & 0 deletions sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub trait SyncProvider: Send + Sync {

/// Get peers information
fn peers(&self) -> Vec<PeerInfo>;

/// Get the enode if available.
fn enode(&self) -> Option<String>;
}

/// Peer connection information
Expand Down Expand Up @@ -143,6 +146,10 @@ impl SyncProvider for EthSync {
self.handler.sync.write().peers(&sync_io)
}).unwrap_or(Vec::new())
}

fn enode(&self) -> Option<String> {
self.network.external_url()
}
}

struct SyncProtocolHandler {
Expand Down