From 641fbf28d6c82191a3b1b4fb45fb743e267e1d01 Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 2 Nov 2016 16:13:16 +0000 Subject: [PATCH 1/2] add enode rpc --- rpc/src/v1/helpers/errors.rs | 9 +++++++++ rpc/src/v1/impls/ethcore.rs | 4 ++++ rpc/src/v1/tests/helpers/sync_provider.rs | 4 ++++ rpc/src/v1/traits/ethcore.rs | 4 ++++ sync/src/api.rs | 7 +++++++ 5 files changed, 28 insertions(+) diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index 413ce7e7fdf..f74fb4618bc 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 dbb27037c47..2fd33ebe267 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 c85fddea5af..753b7d6b542 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 18279d364f2..fbbbf5815dc 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 abe18c3cd21..b8b5c1883d2 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 { From 72f34389b0965567a4257e5e25f5a66f0dee08be Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 2 Nov 2016 16:30:57 +0000 Subject: [PATCH 2/2] spaces -> tabs --- rpc/src/v1/helpers/errors.rs | 2 +- rpc/src/v1/impls/ethcore.rs | 6 +++--- rpc/src/v1/tests/helpers/sync_provider.rs | 6 +++--- rpc/src/v1/traits/ethcore.rs | 6 +++--- sync/src/api.rs | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index f74fb4618bc..fad0448664c 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -41,7 +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 NETWORK_DISABLED: i64 = -32035; pub const REQUEST_REJECTED: i64 = -32040; pub const REQUEST_REJECTED_LIMIT: i64 = -32041; pub const REQUEST_NOT_FOUND: i64 = -32042; diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index 2fd33ebe267..52aecb465b7 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -354,7 +354,7 @@ impl Ethcore for EthcoreClient where }.into()) } - fn enode(&self) -> Result { - take_weak!(self.sync).enode().ok_or_else(errors::network_disabled) - } + 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 753b7d6b542..531b9bd2d3f 100644 --- a/rpc/src/v1/tests/helpers/sync_provider.rs +++ b/rpc/src/v1/tests/helpers/sync_provider.rs @@ -94,8 +94,8 @@ impl SyncProvider for TestSyncProvider { ] } - fn enode(&self) -> Option { - None - } + fn enode(&self) -> Option { + None + } } diff --git a/rpc/src/v1/traits/ethcore.rs b/rpc/src/v1/traits/ethcore.rs index fbbbf5815dc..8e9f58fb314 100644 --- a/rpc/src/v1/traits/ethcore.rs +++ b/rpc/src/v1/traits/ethcore.rs @@ -134,8 +134,8 @@ build_rpc_trait! { #[rpc(name = "ethcore_mode")] fn mode(&self) -> Result; - /// Get the enode of this node. - #[rpc(name = "ethcore_enode")] - fn enode(&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 b8b5c1883d2..2e18fd5cc4c 100644 --- a/sync/src/api.rs +++ b/sync/src/api.rs @@ -74,8 +74,8 @@ pub trait SyncProvider: Send + Sync { /// Get peers information fn peers(&self) -> Vec; - /// Get the enode if available. - fn enode(&self) -> Option; + /// Get the enode if available. + fn enode(&self) -> Option; } /// Peer connection information @@ -147,9 +147,9 @@ impl SyncProvider for EthSync { }).unwrap_or(Vec::new()) } - fn enode(&self) -> Option { - self.network.external_url() - } + fn enode(&self) -> Option { + self.network.external_url() + } } struct SyncProtocolHandler {