RPCs for mode change (#3002)

* Allow warnings.

* Add RPCs to allow ad-hoc mode changes.

* Add the JSAPI interfaces

* Add missing file.
This commit is contained in:
Gav Wood
2016-10-31 16:58:35 +01:00
committed by GitHub
parent 54a408fd88
commit 547871f933
12 changed files with 153 additions and 4 deletions

View File

@@ -30,6 +30,7 @@ use ethsync::{SyncProvider, ManageNetwork};
use ethcore::miner::MinerService;
use ethcore::client::{MiningBlockChainClient};
use ethcore::ids::BlockID;
use ethcore::mode::Mode;
use jsonrpc_core::Error;
use v1::traits::Ethcore;
@@ -343,4 +344,13 @@ impl<C, M, S: ?Sized, F> Ethcore for EthcoreClient<C, M, S, F> where
.into()
)
}
fn mode(&self) -> Result<String, Error> {
Ok(match take_weak!(self.client).mode() {
Mode::Off => "off",
Mode::Dark(..) => "dark",
Mode::Passive(..) => "passive",
Mode::Active => "active",
}.into())
}
}

View File

@@ -19,6 +19,7 @@ use std::sync::{Arc, Weak};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient;
use ethcore::mode::Mode;
use ethsync::ManageNetwork;
use v1::helpers::errors;
use v1::traits::EthcoreSet;
@@ -147,4 +148,15 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
take_weak!(self.net).stop_network();
Ok(true)
}
fn set_mode(&self, mode: String) -> Result<bool, Error> {
take_weak!(self.client).set_mode(match mode.as_str() {
"off" => Mode::Off,
"dark" => Mode::Dark(300),
"passive" => Mode::Passive(300, 3600),
"active" => Mode::Active,
e => { return Err(errors::invalid_params("mode", e.to_owned())); },
});
Ok(true)
}
}

View File

@@ -129,5 +129,9 @@ build_rpc_trait! {
/// Returns next nonce for particular sender. Should include all transactions in the queue.
#[rpc(name = "ethcore_nextNonce")]
fn next_nonce(&self, H160) -> Result<U256, Error>;
/// Get the mode. Results one of: "active", "passive", "dark", "off".
#[rpc(name = "ethcore_mode")]
fn mode(&self) -> Result<String, Error>;
}
}

View File

@@ -69,11 +69,19 @@ build_rpc_trait! {
fn accept_non_reserved_peers(&self) -> Result<bool, Error>;
/// Start the network.
///
/// Deprecated. Use `set_mode("active")` instead.
#[rpc(name = "ethcore_startNetwork")]
fn start_network(&self) -> Result<bool, Error>;
/// Stop the network.
///
/// Deprecated. Use `set_mode("off")` instead.
#[rpc(name = "ethcore_stopNetwork")]
fn stop_network(&self) -> Result<bool, Error>;
/// Set the mode. Argument must be one of: "active", "passive", "dark", "off".
#[rpc(name = "ethcore_setMode")]
fn set_mode(&self, String) -> Result<bool, Error>;
}
}