RPC methods to set the limits

This commit is contained in:
Tomasz Drwięga 2016-04-18 23:13:38 +02:00
parent 5df817c8e0
commit 98b3962412
4 changed files with 57 additions and 0 deletions

View File

@ -67,6 +67,17 @@ impl<M> Ethcore for EthcoreClient<M> where M: MinerService + 'static {
})
}
fn set_transactions_limit(&self, params: Params) -> Result<Value, Error> {
from_params::<(usize,)>(params).and_then(|(limit,)| {
take_weak!(self.miner).set_transactions_limit(limit);
to_value(&true)
})
}
fn transactions_limit(&self, _: Params) -> Result<Value, Error> {
to_value(&take_weak!(self.miner).transactions_limit())
}
fn min_gas_price(&self, _: Params) -> Result<Value, Error> {
to_value(&take_weak!(self.miner).minimal_gas_price())
}

View File

@ -123,3 +123,31 @@ fn rpc_ethcore_set_author() {
assert_eq!(io.handle_request(request), Some(response.to_owned()));
assert_eq!(miner.author(), Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap());
}
#[test]
fn rpc_ethcore_set_transactions_limit() {
let miner = miner_service();
let ethcore = EthcoreClient::new(&miner).to_delegate();
let io = IoHandler::new();
io.add_delegate(ethcore);
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setTransactionsLimit", "params":[10240240], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
assert_eq!(io.handle_request(request), Some(response.to_owned()));
assert_eq!(miner.transactions_limit(), 10_240_240);
}
#[test]
fn rpc_ethcore_transactions_limit() {
let miner = miner_service();
let ethcore = EthcoreClient::new(&miner).to_delegate();
let io = IoHandler::new();
io.add_delegate(ethcore);
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
assert_eq!(io.handle_request(request), Some(response.to_owned()));
}

View File

@ -39,6 +39,7 @@ pub struct TestMinerService {
gas_floor_target: RwLock<U256>,
author: RwLock<Address>,
extra_data: RwLock<Bytes>,
limit: RwLock<usize>,
}
impl Default for TestMinerService {
@ -52,6 +53,7 @@ impl Default for TestMinerService {
gas_floor_target: RwLock::new(U256::from(12345)),
author: RwLock::new(Address::zero()),
extra_data: RwLock::new(vec![1, 2, 3, 4]),
limit: RwLock::new(1024),
}
}
}
@ -84,6 +86,14 @@ impl MinerService for TestMinerService {
*self.min_gas_price.write().unwrap() = min_gas_price;
}
fn set_transactions_limit(&self, limit: usize) {
*self.limit.write().unwrap() = limit;
}
fn transactions_limit(&self) -> usize {
*self.limit.read().unwrap()
}
fn author(&self) -> Address {
*self.author.read().unwrap()
}

View File

@ -33,6 +33,12 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
/// Sets new author for mined block.
fn set_author(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Sets the limits for transaction queue.
fn set_transactions_limit(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns current transactions limit.
fn transactions_limit(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns mining extra data.
fn extra_data(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
@ -49,10 +55,12 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
delegate.add_method("ethcore_setGasFloorTarget", Ethcore::set_gas_floor_target);
delegate.add_method("ethcore_setExtraData", Ethcore::set_extra_data);
delegate.add_method("ethcore_setAuthor", Ethcore::set_author);
delegate.add_method("ethcore_setTransactionsLimit", Ethcore::set_transactions_limit);
delegate.add_method("ethcore_extraData", Ethcore::extra_data);
delegate.add_method("ethcore_gasFloorTarget", Ethcore::gas_floor_target);
delegate.add_method("ethcore_minGasPrice", Ethcore::min_gas_price);
delegate.add_method("ethcore_transactionsLimit", Ethcore::transactions_limit);
delegate
}
}