-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bump jsonrpsee and ckb related crates version (#1438)
* chore: bump ckb related crates and jsonrpsee version * format some code * bump ckb-vm version * fix e2e test
- Loading branch information
Eason Gao
authored
Sep 21, 2023
1 parent
8e5d567
commit f7457d2
Showing
26 changed files
with
543 additions
and
389 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,152 @@ | ||
use jsonrpsee::core::Error; | ||
use jsonrpsee::types::error::{CallError, ErrorObject}; | ||
use jsonrpsee::types::{error::ErrorObject, ErrorObjectOwned}; | ||
|
||
use protocol::codec::hex_encode; | ||
use protocol::types::{ExitReason, TxResp}; | ||
use protocol::{codec::hex_encode, Display}; | ||
|
||
use core_executor::decode_revert_msg; | ||
|
||
const EXEC_ERROR: i32 = -32015; | ||
use crate::jsonrpc::web3_types::BlockId; | ||
|
||
#[derive(Clone, Debug)] | ||
#[derive(Clone, Display, Debug)] | ||
pub enum RpcError { | ||
#[display(fmt = "Decode interoperation signature r error")] | ||
DecodeInteroperationSigR(String), | ||
#[display(fmt = "Decode interoperation signature s error")] | ||
DecodeInteroperationSigS(String), | ||
#[display(fmt = "Invalid address source")] | ||
InvalidAddressSource, | ||
#[display(fmt = "Missing dummy input cell")] | ||
MissingDummyInputCell, | ||
#[display(fmt = "Cannot find image cell")] | ||
CannotFindImageCell, | ||
#[display(fmt = "Gas price is zero")] | ||
GasPriceIsZero, | ||
#[display(fmt = "Gas price is too large")] | ||
GasPriceIsTooLarge, | ||
#[display(fmt = "Gas limit is less than 21000")] | ||
GasLimitIsTooLow, | ||
#[display(fmt = "Gas limit is too large")] | ||
GasLimitIsTooLarge, | ||
#[display(fmt = "Gas limit is zero")] | ||
GasLimitIsZero, | ||
#[display(fmt = "Transaction is not signed")] | ||
TransactionIsNotSigned, | ||
#[display(fmt = "Cannot get receipt by hash")] | ||
CannotGetReceiptByHash, | ||
#[display(fmt = "Cannot get latest block")] | ||
CannotGetLatestBlock, | ||
#[display(fmt = "Invalid block hash")] | ||
InvalidBlockHash, | ||
#[display(fmt = "Invalid from block number {}", _0)] | ||
InvalidFromBlockNumber(u64), | ||
#[display(fmt = "Invalid block range from {} to {} limit to {}", _0, _1, _2)] | ||
InvalidBlockRange(u64, u64, u64), | ||
#[display(fmt = "Invalid newest block {:?}", _0)] | ||
InvalidNewestBlock(BlockId), | ||
#[display(fmt = "Invalid position {}", _0)] | ||
InvalidPosition(u64), | ||
#[display(fmt = "Cannot find the block")] | ||
CannotFindBlock, | ||
#[display(fmt = "Invalid reward percentiles {} {}", _0, _1)] | ||
InvalidRewardPercentiles(f64, f64), | ||
#[display(fmt = "Invalid from block number and to block number union")] | ||
InvalidFromBlockAndToBlockUnion, | ||
#[display(fmt = "Invalid filter id {}", _0)] | ||
CannotFindFilterId(u64), | ||
|
||
#[display(fmt = "CKB-VM error {}", "decode_revert_msg(&_0.ret)")] | ||
VM(TxResp), | ||
#[display(fmt = "Internal error")] | ||
Internal(String), | ||
} | ||
|
||
impl From<RpcError> for Error { | ||
impl From<RpcError> for String { | ||
fn from(err: RpcError) -> Self { | ||
match err { | ||
RpcError::VM(resp) => vm_err(resp), | ||
err.to_string() | ||
} | ||
} | ||
|
||
impl RpcError { | ||
fn code(&self) -> i32 { | ||
match self { | ||
RpcError::DecodeInteroperationSigR(_) => -40001, | ||
RpcError::DecodeInteroperationSigS(_) => -40002, | ||
RpcError::InvalidAddressSource => -40003, | ||
RpcError::MissingDummyInputCell => -40004, | ||
RpcError::CannotFindImageCell => -40005, | ||
RpcError::GasPriceIsZero => -40006, | ||
RpcError::GasPriceIsTooLarge => -40007, | ||
RpcError::GasLimitIsTooLow => -40008, | ||
RpcError::GasLimitIsTooLarge => -40009, | ||
RpcError::GasLimitIsZero => -40010, | ||
RpcError::TransactionIsNotSigned => -40011, | ||
RpcError::CannotGetReceiptByHash => -40012, | ||
RpcError::CannotGetLatestBlock => -40013, | ||
RpcError::InvalidBlockHash => -40014, | ||
RpcError::InvalidFromBlockNumber(_) => -40015, | ||
RpcError::InvalidBlockRange(_, _, _) => -40016, | ||
RpcError::InvalidNewestBlock(_) => -40017, | ||
RpcError::InvalidPosition(_) => -40018, | ||
RpcError::CannotFindBlock => -40019, | ||
RpcError::InvalidRewardPercentiles(_, _) => -40020, | ||
RpcError::InvalidFromBlockAndToBlockUnion => -40021, | ||
RpcError::CannotFindFilterId(_) => -40022, | ||
|
||
RpcError::VM(_) => -49998, | ||
RpcError::Internal(_) => -49999, | ||
} | ||
} | ||
} | ||
|
||
pub fn vm_err(resp: TxResp) -> Error { | ||
let data = match resp.exit_reason { | ||
impl From<RpcError> for ErrorObjectOwned { | ||
fn from(err: RpcError) -> Self { | ||
let none_data: Option<String> = None; | ||
let err_code = err.code(); | ||
match &err { | ||
RpcError::DecodeInteroperationSigR(msg) => { | ||
ErrorObject::owned(err_code, err.clone(), Some(msg)) | ||
} | ||
RpcError::DecodeInteroperationSigS(msg) => { | ||
ErrorObject::owned(err_code, err.clone(), Some(msg)) | ||
} | ||
RpcError::InvalidAddressSource => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::MissingDummyInputCell => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::CannotFindImageCell => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::GasPriceIsZero => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::GasPriceIsTooLarge => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::GasLimitIsTooLow => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::GasLimitIsTooLarge => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::GasLimitIsZero => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::TransactionIsNotSigned => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::CannotGetReceiptByHash => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::CannotGetLatestBlock => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidBlockHash => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidFromBlockNumber(_) => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidBlockRange(_, _, _) => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidNewestBlock(_) => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidPosition(_) => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::CannotFindBlock => ErrorObject::owned(err_code, err, none_data), | ||
RpcError::InvalidRewardPercentiles(_, _) => { | ||
ErrorObject::owned(err_code, err, none_data) | ||
} | ||
RpcError::InvalidFromBlockAndToBlockUnion => { | ||
ErrorObject::owned(err_code, err, none_data) | ||
} | ||
RpcError::CannotFindFilterId(_) => ErrorObject::owned(err_code, err, none_data), | ||
|
||
RpcError::VM(resp) => { | ||
ErrorObject::owned(err_code, err.clone(), Some(vm_err(resp.clone()))) | ||
} | ||
RpcError::Internal(msg) => ErrorObject::owned(err_code, err.clone(), Some(msg)), | ||
} | ||
} | ||
} | ||
|
||
pub fn vm_err(resp: TxResp) -> String { | ||
match resp.exit_reason { | ||
ExitReason::Revert(_) => format!("0x{}", hex_encode(&resp.ret),), | ||
ExitReason::Error(err) => format!("{:?}", err), | ||
ExitReason::Fatal(fatal) => format!("{:?}", fatal), | ||
_ => unreachable!(), | ||
}; | ||
|
||
into_rpc_err(ErrorObject::owned( | ||
EXEC_ERROR, | ||
decode_revert_msg(&resp.ret), | ||
Some(data), | ||
)) | ||
} | ||
|
||
fn into_rpc_err(obj: ErrorObject<'static>) -> Error { | ||
CallError::Custom(obj).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.