Consolidating all RPC error codes

This commit is contained in:
Tomasz Drwięga 2016-06-15 18:32:21 +02:00
parent dcd64f73d4
commit 6803375301
2 changed files with 12 additions and 14 deletions

View File

@ -37,7 +37,7 @@ use ethcore::filter::Filter as EthcoreFilter;
use self::ethash::SeedHashCompute;
use v1::traits::Eth;
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, OptionalValue, Index, Filter, Log, Receipt};
use v1::impls::dispatch_transaction;
use v1::impls::{dispatch_transaction, error_codes};
use serde;
/// Eth rpc implementation.
@ -210,13 +210,9 @@ fn from_params_default_third<F1, F2>(params: Params) -> Result<(F1, F2, BlockNum
}
}
// must be in range [-32099, -32000]
const UNSUPPORTED_REQUEST_CODE: i64 = -32000;
const NO_WORK_CODE: i64 = -32001;
fn make_unsupported_err() -> Error {
Error {
code: ErrorCode::ServerError(UNSUPPORTED_REQUEST_CODE),
code: ErrorCode::ServerError(error_codes::UNSUPPORTED_REQUEST_CODE),
message: "Unsupported request.".into(),
data: None
}
@ -224,7 +220,7 @@ fn make_unsupported_err() -> Error {
fn no_work_err() -> Error {
Error {
code: ErrorCode::ServerError(NO_WORK_CODE),
code: ErrorCode::ServerError(error_codes::NO_WORK_CODE),
message: "Still syncing.".into(),
data: None
}

View File

@ -63,6 +63,15 @@ use util::rlp::encode;
use util::bytes::ToPretty;
use jsonrpc_core::{Error, ErrorCode, Value, to_value};
mod error_codes {
// NOTE [ToDr] Codes from [-32099, -32000]
pub const UNSUPPORTED_REQUEST_CODE: i64 = -32000;
pub const NO_WORK_CODE: i64 = -32001;
pub const UNKNOWN_ERROR: i64 = -32002;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const ACCOUNT_LOCKED: i64 = -32020;
}
fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error>
where C: MiningBlockChainClient, M: MinerService {
let hash = signed_transaction.hash();
@ -102,13 +111,6 @@ fn sign_and_dispatch<C, M>(client: &C, miner: &M, request: TransactionRequest, s
dispatch_transaction(&*client, &*miner, signed_transaction)
}
mod error_codes {
// NOTE [ToDr] Codes from -32000 to -32099
pub const UNKNOWN_ERROR: i64 = -32002;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const ACCOUNT_LOCKED: i64 = -32020;
}
fn transaction_error(error: EthcoreError) -> Error {
use ethcore::error::TransactionError::*;