eth_checkTransaction renamed to eth_checkRequest (#1817)

* Making ConfirmationsQueue a bit more generic [WiP]

* Generalizing cofirmations

* New confirmations types - tests

* Separating transaction type in queue. Closes #1310

* Handling sign requests

* Speeding up tests

* Renaming methods

* eth_postSign

* Bumping ui

* Renaming checkRequest methods, adding tests

* Removing duplicate method [ci skip]

* Remove `_posted`

[ci:skip]

* Remove `_posted`
This commit is contained in:
Tomasz Drwięga
2016-08-04 16:42:29 +02:00
committed by Gav Wood
parent 03ba0cc498
commit 979f4e0617
4 changed files with 85 additions and 15 deletions

View File

@@ -26,7 +26,7 @@ use ethcore::account_provider::AccountProvider;
use v1::helpers::{SigningQueue, ConfirmationPromise, ConfirmationResult, ConfirmationsQueue, ConfirmationPayload, TransactionRequest as TRequest, FilledTransactionRequest as FilledRequest};
use v1::traits::EthSigning;
use v1::types::{TransactionRequest, H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, U256 as RpcU256};
use v1::impls::{default_gas_price, sign_and_dispatch, transaction_rejected_error, signer_disabled_error};
use v1::impls::{default_gas_price, sign_and_dispatch, request_rejected_error, request_not_found_error, signer_disabled_error};
fn fill_optional_fields<C, M>(request: TRequest, client: &C, miner: &M) -> FilledRequest
where C: MiningBlockChainClient, M: MinerService {
@@ -143,7 +143,7 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
})
}
fn check_transaction(&self, params: Params) -> Result<Value, Error> {
fn check_request(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
let mut pending = self.pending.lock();
from_params::<(RpcU256, )>(params).and_then(|(id, )| {
@@ -151,10 +151,10 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
let res = match pending.get(&id) {
Some(ref promise) => match promise.result() {
ConfirmationResult::Waiting => { return Ok(Value::Null); }
ConfirmationResult::Rejected => Err(transaction_rejected_error()),
ConfirmationResult::Rejected => Err(request_rejected_error()),
ConfirmationResult::Confirmed(rpc_response) => rpc_response,
},
_ => { return Err(Error::invalid_params()); }
_ => { return Err(request_not_found_error()); }
};
pending.remove(&id);
res
@@ -225,7 +225,7 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
Err(signer_disabled_error())
}
fn check_transaction(&self, _: Params) -> Result<Value, Error> {
fn check_request(&self, _: Params) -> Result<Value, Error> {
// We don't support this in non-signer mode.
Err(signer_disabled_error())
}

View File

@@ -72,10 +72,11 @@ mod error_codes {
pub const NO_AUTHOR_CODE: i64 = -32002;
pub const UNKNOWN_ERROR: i64 = -32009;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const TRANSACTION_REJECTED: i64 = -32011;
pub const ACCOUNT_LOCKED: i64 = -32020;
pub const PASSWORD_INVALID: i64 = -32021;
pub const SIGNER_DISABLED: i64 = -32030;
pub const REQUEST_REJECTED: i64 = -32040;
pub const REQUEST_NOT_FOUND: i64 = -32041;
}
fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error>
@@ -171,11 +172,20 @@ fn password_error(error: AccountError) -> Error {
}
}
/// Error returned when transaction is rejected (in Trusted Signer).
pub fn transaction_rejected_error() -> Error {
/// Error returned when request is rejected (in Trusted Signer).
pub fn request_rejected_error() -> Error {
Error {
code: ErrorCode::ServerError(error_codes::TRANSACTION_REJECTED),
message: "Transaction has been rejected.".into(),
code: ErrorCode::ServerError(error_codes::REQUEST_REJECTED),
message: "Request has been rejected.".into(),
data: None,
}
}
/// Error returned when request is not found in queue.
pub fn request_not_found_error() -> Error {
Error {
code: ErrorCode::ServerError(error_codes::REQUEST_NOT_FOUND),
message: "Request not found.".into(),
data: None,
}
}