Return proper SignedTransactions representation.
This commit is contained in:
parent
4ba2587226
commit
42e23a9633
@ -71,6 +71,9 @@ pub trait Dispatcher: Send + Sync + Clone {
|
||||
fn sign(&self, accounts: Arc<AccountProvider>, filled: FilledTransactionRequest, password: SignWith)
|
||||
-> BoxFuture<WithToken<SignedTransaction>, Error>;
|
||||
|
||||
/// Converts a `SignedTransaction` into `RichRawTransaction`
|
||||
fn enrich(&self, SignedTransaction) -> RpcRichRawTransaction;
|
||||
|
||||
/// "Dispatch" a local transaction.
|
||||
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> {
|
||||
let hash = signed_transaction.transaction.hash();
|
||||
|
||||
@ -261,11 +269,11 @@ impl LightDispatcher {
|
||||
transaction_queue: Arc<RwLock<LightTransactionQueue>>,
|
||||
) -> 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<H256, Error> {
|
||||
let hash = signed_transaction.transaction.hash();
|
||||
|
||||
@ -510,8 +523,8 @@ pub fn execute<D: Dispatcher + 'static>(
|
||||
},
|
||||
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)
|
||||
))
|
||||
},
|
||||
|
@ -73,8 +73,8 @@ impl<D: Dispatcher + 'static> SignerClient<D> {
|
||||
SignerClient {
|
||||
signer: signer.clone(),
|
||||
accounts: store.clone(),
|
||||
dispatcher: dispatcher,
|
||||
subscribers: subscribers,
|
||||
dispatcher,
|
||||
subscribers,
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +205,8 @@ impl<D: Dispatcher + 'static> Signer for SignerClient<D> {
|
||||
},
|
||||
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) => {
|
||||
|
@ -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))
|
||||
|
@ -158,11 +158,10 @@ pub struct RichRawTransaction {
|
||||
pub transaction: Transaction
|
||||
}
|
||||
|
||||
|
||||
impl From<SignedTransaction> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user