From 42e23a963300bd101a172b54c23d3c2bdee54432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 23 Oct 2017 16:45:06 +0200 Subject: [PATCH] Return proper SignedTransactions representation. --- rpc/src/v1/helpers/dispatch.rs | 27 ++++++++++++++++++++------- rpc/src/v1/impls/signer.rs | 7 ++++--- rpc/src/v1/tests/mocked/signing.rs | 6 ++++-- rpc/src/v1/types/transaction.rs | 9 ++++----- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 0da257035..d84bd6cad 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -71,6 +71,9 @@ pub trait Dispatcher: Send + Sync + Clone { fn sign(&self, accounts: Arc, filled: FilledTransactionRequest, password: SignWith) -> BoxFuture, Error>; + /// Converts a `SignedTransaction` into `RichRawTransaction` + fn enrich(&self, SignedTransaction) -> RpcRichRawTransaction; + /// "Dispatch" a local transaction. fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result; } @@ -163,6 +166,11 @@ impl Dispatcher for FullDispatcher RpcRichRawTransaction { + let block_number = self.client.best_block_header().number(); + RpcRichRawTransaction::from_signed(signed_transaction, block_number, self.client.eip86_transition()) + } + fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { let hash = signed_transaction.transaction.hash(); @@ -261,11 +269,11 @@ impl LightDispatcher { transaction_queue: Arc>, ) -> Self { LightDispatcher { - sync: sync, - client: client, - on_demand: on_demand, - cache: cache, - transaction_queue: transaction_queue, + sync, + client, + on_demand, + cache, + transaction_queue, } } @@ -399,6 +407,11 @@ impl Dispatcher for LightDispatcher { .and_then(move |nonce| with_nonce(filled, nonce))) } + fn enrich(&self, signed_transaction: SignedTransaction) -> RpcRichRawTransaction { + let block_number = self.client.best_block_header().number(); + RpcRichRawTransaction::from_signed(signed_transaction, block_number, self.client.eip86_transition()) + } + fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { let hash = signed_transaction.transaction.hash(); @@ -510,8 +523,8 @@ pub fn execute( }, ConfirmationPayload::SignTransaction(request) => { Box::new(dispatcher.sign(accounts, request, pass) - .map(|result| result - .map(RpcRichRawTransaction::from) + .map(move |result| result + .map(move |tx| dispatcher.enrich(tx)) .map(ConfirmationResponse::SignTransaction) )) }, diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index c864134fb..cecd1f2db 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -73,8 +73,8 @@ impl SignerClient { SignerClient { signer: signer.clone(), accounts: store.clone(), - dispatcher: dispatcher, - subscribers: subscribers, + dispatcher, + subscribers, } } @@ -205,7 +205,8 @@ impl Signer for SignerClient { }, ConfirmationPayload::SignTransaction(request) => { Self::verify_transaction(bytes, request, |pending_transaction| { - Ok(ConfirmationResponse::SignTransaction(pending_transaction.transaction.into())) + let rich = self.dispatcher.enrich(pending_transaction.transaction); + Ok(ConfirmationResponse::SignTransaction(rich)) }) }, ConfirmationPayload::EthSignMessage(address, data) => { diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index 05199e696..dbe5534ca 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -26,7 +26,7 @@ use v1::impls::SigningQueueClient; use v1::metadata::Metadata; use v1::traits::{EthSigning, ParitySigning, Parity}; use v1::helpers::{SignerService, SigningQueue, FullDispatcher}; -use v1::types::ConfirmationResponse; +use v1::types::{ConfirmationResponse, RichRawTransaction}; use v1::tests::helpers::TestMinerService; use v1::tests::mocked::parity; @@ -334,7 +334,9 @@ fn should_add_sign_transaction_to_the_queue() { ::std::thread::spawn(move || loop { if signer.requests().len() == 1 { // respond - signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SignTransaction(t.into()))); + signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SignTransaction( + RichRawTransaction::from_signed(t.into(), 0x0, u64::max_value()) + ))); break } ::std::thread::sleep(Duration::from_millis(100)) diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 90d512c86..dbd326488 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -158,11 +158,10 @@ pub struct RichRawTransaction { pub transaction: Transaction } - -impl From for RichRawTransaction { - fn from(t: SignedTransaction) -> Self { - // TODO: change transition to 0 when EIP-86 is commonly used. - let tx: Transaction = Transaction::from_signed(t, 0, u64::max_value()); +impl RichRawTransaction { + /// Creates new `RichRawTransaction` from `SignedTransaction`. + pub fn from_signed(tx: SignedTransaction, block_number: u64, eip86_transition: u64) -> Self { + let tx = Transaction::from_signed(tx, block_number, eip86_transition); RichRawTransaction { raw: tx.raw.clone(), transaction: tx,