Return proper SignedTransactions representation.

This commit is contained in:
Tomasz Drwięga 2017-10-23 16:45:06 +02:00
parent 4ba2587226
commit 42e23a9633
No known key found for this signature in database
GPG Key ID: D066F497E62CAF66
4 changed files with 32 additions and 17 deletions

View File

@ -71,6 +71,9 @@ pub trait Dispatcher: Send + Sync + Clone {
fn sign(&self, accounts: Arc<AccountProvider>, filled: FilledTransactionRequest, password: SignWith) fn sign(&self, accounts: Arc<AccountProvider>, filled: FilledTransactionRequest, password: SignWith)
-> BoxFuture<WithToken<SignedTransaction>, Error>; -> BoxFuture<WithToken<SignedTransaction>, Error>;
/// Converts a `SignedTransaction` into `RichRawTransaction`
fn enrich(&self, SignedTransaction) -> RpcRichRawTransaction;
/// "Dispatch" a local transaction. /// "Dispatch" a local transaction.
fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error>; fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error>;
} }
@ -163,6 +166,11 @@ impl<C: MiningBlockChainClient, M: MinerService> Dispatcher for FullDispatcher<C
})) }))
} }
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<H256, Error> { fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error> {
let hash = signed_transaction.transaction.hash(); let hash = signed_transaction.transaction.hash();
@ -261,11 +269,11 @@ impl LightDispatcher {
transaction_queue: Arc<RwLock<LightTransactionQueue>>, transaction_queue: Arc<RwLock<LightTransactionQueue>>,
) -> Self { ) -> Self {
LightDispatcher { LightDispatcher {
sync: sync, sync,
client: client, client,
on_demand: on_demand, on_demand,
cache: cache, cache,
transaction_queue: transaction_queue, transaction_queue,
} }
} }
@ -399,6 +407,11 @@ impl Dispatcher for LightDispatcher {
.and_then(move |nonce| with_nonce(filled, nonce))) .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<H256, Error> { fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result<H256, Error> {
let hash = signed_transaction.transaction.hash(); let hash = signed_transaction.transaction.hash();
@ -510,8 +523,8 @@ pub fn execute<D: Dispatcher + 'static>(
}, },
ConfirmationPayload::SignTransaction(request) => { ConfirmationPayload::SignTransaction(request) => {
Box::new(dispatcher.sign(accounts, request, pass) Box::new(dispatcher.sign(accounts, request, pass)
.map(|result| result .map(move |result| result
.map(RpcRichRawTransaction::from) .map(move |tx| dispatcher.enrich(tx))
.map(ConfirmationResponse::SignTransaction) .map(ConfirmationResponse::SignTransaction)
)) ))
}, },

View File

@ -73,8 +73,8 @@ impl<D: Dispatcher + 'static> SignerClient<D> {
SignerClient { SignerClient {
signer: signer.clone(), signer: signer.clone(),
accounts: store.clone(), accounts: store.clone(),
dispatcher: dispatcher, dispatcher,
subscribers: subscribers, subscribers,
} }
} }
@ -205,7 +205,8 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
}, },
ConfirmationPayload::SignTransaction(request) => { ConfirmationPayload::SignTransaction(request) => {
Self::verify_transaction(bytes, request, |pending_transaction| { 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) => { ConfirmationPayload::EthSignMessage(address, data) => {

View File

@ -26,7 +26,7 @@ use v1::impls::SigningQueueClient;
use v1::metadata::Metadata; use v1::metadata::Metadata;
use v1::traits::{EthSigning, ParitySigning, Parity}; use v1::traits::{EthSigning, ParitySigning, Parity};
use v1::helpers::{SignerService, SigningQueue, FullDispatcher}; use v1::helpers::{SignerService, SigningQueue, FullDispatcher};
use v1::types::ConfirmationResponse; use v1::types::{ConfirmationResponse, RichRawTransaction};
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use v1::tests::mocked::parity; use v1::tests::mocked::parity;
@ -334,7 +334,9 @@ fn should_add_sign_transaction_to_the_queue() {
::std::thread::spawn(move || loop { ::std::thread::spawn(move || loop {
if signer.requests().len() == 1 { if signer.requests().len() == 1 {
// respond // 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 break
} }
::std::thread::sleep(Duration::from_millis(100)) ::std::thread::sleep(Duration::from_millis(100))

View File

@ -158,11 +158,10 @@ pub struct RichRawTransaction {
pub transaction: Transaction pub transaction: Transaction
} }
impl RichRawTransaction {
impl From<SignedTransaction> for RichRawTransaction { /// Creates new `RichRawTransaction` from `SignedTransaction`.
fn from(t: SignedTransaction) -> Self { pub fn from_signed(tx: SignedTransaction, block_number: u64, eip86_transition: u64) -> Self {
// TODO: change transition to 0 when EIP-86 is commonly used. let tx = Transaction::from_signed(tx, block_number, eip86_transition);
let tx: Transaction = Transaction::from_signed(t, 0, u64::max_value());
RichRawTransaction { RichRawTransaction {
raw: tx.raw.clone(), raw: tx.raw.clone(),
transaction: tx, transaction: tx,