Filling-in optional fields of TransactionRequest... (#1305)

* More meaningful errors when sending transaction

* Fixing returned value

* Consolidating all RPC error codes

* Fixed loosing peers on incoming connections. (#1293)

* Deactivate peer if it has no new data

* Fixed node table timer registration

* Fixed handshake timeout expiration

* Extra trace

* Fixed session count calculation

* Only deactivate incapable peers in ChainHead state

* Timer registration is not needed

* x64 path

* firewall rules

* Fix read-ahead bug.

Re-ahead 8 bytes rather than 3 to ensure large blocks import fine.

* Refactor to use a const.

* Update README.md

* Gas price statistics. (#1291)

* Gas price statistics.

Affects eth_gasPrice.
Added ethcore_gasPriceStatistics.

Closes #1265

* Fix a bug in eth_gasPrice

* Fix tests.

* Revert minor alteration.

* Tests for gas_price_statistics.

- Tests;
- Additional infrastructure for generating test blocks with
transactions.

* Key load avoid warning (#1303)

* avoid warning with key

* fix intendations

* more intendation fix

* ok() instead of expect()

* Filling-in optional fields of TransactionRequest.

* Adding reference to miner
This commit is contained in:
Tomasz Drwięga 2016-06-18 14:55:46 +02:00 committed by Gav Wood
parent 91dc31fd70
commit 5e1e3ce857
3 changed files with 28 additions and 7 deletions

View File

@ -147,7 +147,7 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
if deps.signer_port.is_some() {
server.add_delegate(EthSigningQueueClient::new(&deps.signer_queue).to_delegate());
server.add_delegate(EthSigningQueueClient::new(&deps.signer_queue, &deps.miner).to_delegate());
} else {
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
}

View File

@ -24,25 +24,40 @@ use util::numbers::*;
use util::keys::store::AccountProvider;
use v1::helpers::{SigningQueue, ConfirmationsQueue};
use v1::traits::EthSigning;
use v1::types::TransactionRequest;
use v1::types::{TransactionRequest, Bytes};
use v1::impls::{sign_and_dispatch, error_codes};
/// Implementation of functions that require signing when no trusted signer is used.
pub struct EthSigningQueueClient {
pub struct EthSigningQueueClient<M: MinerService> {
queue: Weak<ConfirmationsQueue>,
miner: Weak<M>,
}
impl EthSigningQueueClient {
impl<M: MinerService> EthSigningQueueClient<M> {
/// Creates a new signing queue client given shared signing queue.
pub fn new(queue: &Arc<ConfirmationsQueue>) -> Self {
pub fn new(queue: &Arc<ConfirmationsQueue>, miner: &Arc<M>) -> Self {
EthSigningQueueClient {
queue: Arc::downgrade(queue),
miner: Arc::downgrade(miner),
}
}
fn fill_optional_fields(&self, miner: Arc<M>, mut request: TransactionRequest) -> TransactionRequest {
if let None = request.gas {
request.gas = Some(miner.sensible_gas_limit());
}
if let None = request.gas_price {
request.gas_price = Some(miner.sensible_gas_price());
}
if let None = request.data {
request.data = Some(Bytes::new(Vec::new()));
}
request
}
}
impl EthSigning for EthSigningQueueClient {
impl<M: MinerService + 'static> EthSigning for EthSigningQueueClient<M> {
fn sign(&self, _params: Params) -> Result<Value, Error> {
warn!("Invoking eth_sign is not yet supported with signer enabled.");
@ -54,6 +69,8 @@ impl EthSigning for EthSigningQueueClient {
from_params::<(TransactionRequest, )>(params)
.and_then(|(request, )| {
let queue = take_weak!(self.queue);
let miner = take_weak!(self.miner);
let request = self.fill_optional_fields(miner, request);
let id = queue.add_request(request);
let result = id.wait_with_timeout();
result.unwrap_or_else(|| to_value(&H256::new()))

View File

@ -19,21 +19,25 @@ use jsonrpc_core::IoHandler;
use v1::impls::EthSigningQueueClient;
use v1::traits::EthSigning;
use v1::helpers::{ConfirmationsQueue, SigningQueue};
use v1::tests::helpers::TestMinerService;
use util::keys::TestAccount;
struct EthSigningTester {
pub queue: Arc<ConfirmationsQueue>,
pub miner: Arc<TestMinerService>,
pub io: IoHandler,
}
impl Default for EthSigningTester {
fn default() -> Self {
let queue = Arc::new(ConfirmationsQueue::default());
let miner = Arc::new(TestMinerService::default());
let io = IoHandler::new();
io.add_delegate(EthSigningQueueClient::new(&queue).to_delegate());
io.add_delegate(EthSigningQueueClient::new(&queue, &miner).to_delegate());
EthSigningTester {
queue: queue,
miner: miner,
io: io,
}
}