Returning error when transaction is rejected (for consistency) (#1667)

This commit is contained in:
Tomasz Drwięga 2016-07-22 14:48:05 +02:00 committed by Gav Wood
parent 10bdfe6926
commit aafb014d01
2 changed files with 12 additions and 3 deletions

View File

@ -26,7 +26,7 @@ use ethcore::account_provider::AccountProvider;
use v1::helpers::{SigningQueue, ConfirmationPromise, ConfirmationResult, ConfirmationsQueue, TransactionRequest as TRequest}; use v1::helpers::{SigningQueue, ConfirmationPromise, ConfirmationResult, ConfirmationsQueue, TransactionRequest as TRequest};
use v1::traits::EthSigning; use v1::traits::EthSigning;
use v1::types::{TransactionRequest, H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, U256 as RpcU256}; 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}; use v1::impls::{default_gas_price, sign_and_dispatch, transaction_rejected_error};
fn fill_optional_fields<C, M>(request: &mut TRequest, client: &C, miner: &M) fn fill_optional_fields<C, M>(request: &mut TRequest, client: &C, miner: &M)
where C: MiningBlockChainClient, M: MinerService { where C: MiningBlockChainClient, M: MinerService {
@ -129,7 +129,7 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
let res = match pending.get(&id) { let res = match pending.get(&id) {
Some(ref promise) => match promise.result() { Some(ref promise) => match promise.result() {
ConfirmationResult::Waiting => { return Ok(Value::Null); } ConfirmationResult::Waiting => { return Ok(Value::Null); }
ConfirmationResult::Rejected => to_value(&RpcH256::default()), ConfirmationResult::Rejected => Err(transaction_rejected_error()),
ConfirmationResult::Confirmed(rpc_response) => rpc_response, ConfirmationResult::Confirmed(rpc_response) => rpc_response,
}, },
_ => { return Err(Error::invalid_params()); } _ => { return Err(Error::invalid_params()); }

View File

@ -72,6 +72,7 @@ mod error_codes {
pub const NO_AUTHOR_CODE: i64 = -32002; pub const NO_AUTHOR_CODE: i64 = -32002;
pub const UNKNOWN_ERROR: i64 = -32009; pub const UNKNOWN_ERROR: i64 = -32009;
pub const TRANSACTION_ERROR: i64 = -32010; pub const TRANSACTION_ERROR: i64 = -32010;
pub const TRANSACTION_REJECTED: i64 = -32011;
pub const ACCOUNT_LOCKED: i64 = -32020; pub const ACCOUNT_LOCKED: i64 = -32020;
pub const PASSWORD_INVALID: i64 = -32021; pub const PASSWORD_INVALID: i64 = -32021;
pub const SIGNER_DISABLED: i64 = -32030; pub const SIGNER_DISABLED: i64 = -32030;
@ -139,7 +140,6 @@ fn default_gas_price<C, M>(client: &C, miner: &M) -> U256 where C: MiningBlockCh
.unwrap_or_else(|_| miner.sensible_gas_price()) .unwrap_or_else(|_| miner.sensible_gas_price())
} }
fn signing_error(error: AccountError) -> Error { fn signing_error(error: AccountError) -> Error {
Error { Error {
code: ErrorCode::ServerError(error_codes::ACCOUNT_LOCKED), code: ErrorCode::ServerError(error_codes::ACCOUNT_LOCKED),
@ -156,6 +156,15 @@ fn password_error(error: AccountError) -> Error {
} }
} }
/// Error returned when transaction is rejected (in Trusted Signer).
pub fn transaction_rejected_error() -> Error {
Error {
code: ErrorCode::ServerError(error_codes::TRANSACTION_REJECTED),
message: "Transaction has been rejected.".into(),
data: None,
}
}
fn transaction_error(error: EthcoreError) -> Error { fn transaction_error(error: EthcoreError) -> Error {
use ethcore::error::TransactionError::*; use ethcore::error::TransactionError::*;