Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Filling-in optional fields of TransactionRequest before sending to Si…
Browse files Browse the repository at this point in the history
…gner UI
  • Loading branch information
Tomasz Drwięga committed Jun 16, 2016
1 parent 07641b8 commit 1a6add8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion parity/rpc_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
27 changes: 22 additions & 5 deletions rpc/src/v1/impls/eth_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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()))
Expand Down
4 changes: 3 additions & 1 deletion rpc/src/v1/tests/mocked/eth_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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 {
Expand All @@ -29,8 +30,9 @@ struct EthSigningTester {
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,
Expand Down

0 comments on commit 1a6add8

Please sign in to comment.