diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index 413ce7e7f..fad044866 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -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; @@ -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(error: T) -> Error { Error { code: ErrorCode::ServerError(codes::ENCRYPTION_ERROR), diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index dbb27037c..52aecb465 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -353,4 +353,8 @@ impl Ethcore for EthcoreClient where Mode::Active => "active", }.into()) } + + fn enode(&self) -> Result { + take_weak!(self.sync).enode().ok_or_else(errors::network_disabled) + } } diff --git a/rpc/src/v1/tests/helpers/sync_provider.rs b/rpc/src/v1/tests/helpers/sync_provider.rs index c85fddea5..531b9bd2d 100644 --- a/rpc/src/v1/tests/helpers/sync_provider.rs +++ b/rpc/src/v1/tests/helpers/sync_provider.rs @@ -93,5 +93,9 @@ impl SyncProvider for TestSyncProvider { } ] } + + fn enode(&self) -> Option { + None + } } diff --git a/rpc/src/v1/traits/ethcore.rs b/rpc/src/v1/traits/ethcore.rs index 18279d364..8e9f58fb3 100644 --- a/rpc/src/v1/traits/ethcore.rs +++ b/rpc/src/v1/traits/ethcore.rs @@ -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; + + /// Get the enode of this node. + #[rpc(name = "ethcore_enode")] + fn enode(&self) -> Result; } } diff --git a/sync/src/api.rs b/sync/src/api.rs index abe18c3cd..2e18fd5cc 100644 --- a/sync/src/api.rs +++ b/sync/src/api.rs @@ -73,6 +73,9 @@ pub trait SyncProvider: Send + Sync { /// Get peers information fn peers(&self) -> Vec; + + /// Get the enode if available. + fn enode(&self) -> Option; } /// Peer connection information @@ -143,6 +146,10 @@ impl SyncProvider for EthSync { self.handler.sync.write().peers(&sync_io) }).unwrap_or(Vec::new()) } + + fn enode(&self) -> Option { + self.network.external_url() + } } struct SyncProtocolHandler {