Skip to content

Commit

Permalink
refactor: change some precompile input and output to tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
KaoImin committed Dec 18, 2023
1 parent 983f023 commit b5ea694
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/executor/src/precompiles/ckb_mbt_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ impl PrecompileContract for CMBTVerify {
}
}

#[allow(unused_parens)]
fn parse_input(input: &[u8]) -> Result<VerifyProofPayload, PrecompileFailure> {
<VerifyProofPayload as AbiDecode>::decode(input).map_err(|_| err!(_, "decode input"))
<(VerifyProofPayload) as AbiDecode>::decode(input).map_err(|_| err!(_, "decode input"))
}

fn inner_verify_proof(payload: VerifyProofPayload) -> Result<(), PrecompileFailure> {
Expand Down
9 changes: 7 additions & 2 deletions core/executor/src/precompiles/get_header.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use ethers::abi::AbiDecode;
use ethers::abi::{AbiDecode, AbiEncode};
use evm::executor::stack::{PrecompileFailure, PrecompileOutput};
use evm::{Context, ExitError, ExitSucceed};

use protocol::types::{H160, H256};

use crate::precompiles::{axon_precompile_address, PrecompileContract};
use crate::system_contract::ckb_light_client::ckb_light_client_abi;
use crate::{err, system_contract::ckb_light_client::CkbHeaderReader, CURRENT_HEADER_CELL_ROOT};

#[derive(Default, Clone)]
Expand All @@ -14,6 +15,7 @@ impl PrecompileContract for GetHeader {
const ADDRESS: H160 = axon_precompile_address(0x02);
const MIN_GAS: u64 = 42000;

#[allow(unused_parens, clippy::double_parens)]
fn exec_fn(
input: &[u8],
gas_limit: Option<u64>,
Expand All @@ -39,10 +41,13 @@ impl PrecompileContract for GetHeader {
return err!("get header return None");
}

let header =
<ckb_light_client_abi::Header as AbiDecode>::decode(header_opt.unwrap()).unwrap();

Ok((
PrecompileOutput {
exit_status: ExitSucceed::Returned,
output: header_opt.unwrap(),
output: AbiEncode::encode((header)),
},
gas,
))
Expand Down

0 comments on commit b5ea694

Please sign in to comment.