From 98b3962412b9375d7b8db7505fd67d429f15001e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 18 Apr 2016 23:13:38 +0200 Subject: [PATCH] RPC methods to set the limits --- rpc/src/v1/impls/ethcore.rs | 11 +++++++++ rpc/src/v1/tests/ethcore.rs | 28 +++++++++++++++++++++++ rpc/src/v1/tests/helpers/miner_service.rs | 10 ++++++++ rpc/src/v1/traits/ethcore.rs | 8 +++++++ 4 files changed, 57 insertions(+) diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index d9764842c..2d1267a02 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -67,6 +67,17 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static { }) } + fn set_transactions_limit(&self, params: Params) -> Result { + from_params::<(usize,)>(params).and_then(|(limit,)| { + take_weak!(self.miner).set_transactions_limit(limit); + to_value(&true) + }) + } + + fn transactions_limit(&self, _: Params) -> Result { + to_value(&take_weak!(self.miner).transactions_limit()) + } + fn min_gas_price(&self, _: Params) -> Result { to_value(&take_weak!(self.miner).minimal_gas_price()) } diff --git a/rpc/src/v1/tests/ethcore.rs b/rpc/src/v1/tests/ethcore.rs index 06d4ffc1c..bef3180cf 100644 --- a/rpc/src/v1/tests/ethcore.rs +++ b/rpc/src/v1/tests/ethcore.rs @@ -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())); +} diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 927b8ed50..7b323b198 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -39,6 +39,7 @@ pub struct TestMinerService { gas_floor_target: RwLock, author: RwLock
, extra_data: RwLock, + limit: RwLock, } 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() } diff --git a/rpc/src/v1/traits/ethcore.rs b/rpc/src/v1/traits/ethcore.rs index fb96ef035..90bb112e0 100644 --- a/rpc/src/v1/traits/ethcore.rs +++ b/rpc/src/v1/traits/ethcore.rs @@ -33,6 +33,12 @@ pub trait Ethcore: Sized + Send + Sync + 'static { /// Sets new author for mined block. fn set_author(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Sets the limits for transaction queue. + fn set_transactions_limit(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns current transactions limit. + fn transactions_limit(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Returns mining extra data. fn extra_data(&self, _: Params) -> Result { 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 } }