alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
758 stars 131 forks source link

[Bug] abi_decode method error. TypeCheckFail #706

Closed senseiod closed 1 month ago

senseiod commented 1 month ago

Component

sol-types

What version of Alloy are you on?

0.2.1

Operating System

macOS (Apple Silicon)

Describe the bug

Here is the code

sol!(
#[derive(Debug)]
#[allow(missing_docs)]
#[allow(clippy::too_many_arguments)]
#[sol(rpc)]
Router,
"abi/Router.json"
);

fn get_decode_data(tx_info: Transaction, tx_input: &str) -> Option<Vec<Address>> {
    println!("{:?}", tx_info);

    let input = tx_input.as_bytes();
    let tx_selector: String = tx_input.chars().take(10).collect();
    if tx_selector == "0x18cbafe5" {
        Some(swapExactTokensForETHCall::abi_decode(input, false).unwrap().path)
    } else if tx_selector == "0x791ac947" {
        Some(swapExactTokensForETHSupportingFeeOnTransferTokensCall::abi_decode(input, false).unwrap().path)
    } else if tx_selector == "0x38ed1739" {
        Some(swapExactTokensForTokensCall::abi_decode(input, false).unwrap().path)
    } else if tx_selector == "0x5c11d795" {
        Some(swapExactTokensForTokensSupportingFeeOnTransferTokensCall::abi_decode(input, false).unwrap().path)
    } else if tx_selector == "0x4a25d94a" {
        Some(swapTokensForExactETHCall::abi_decode(input, false).unwrap().path)
    } else if tx_selector == "0x8803dbee" {
        Some(swapTokensForExactTokensCall::abi_decode(input, false).unwrap().path)
    } else {
        None
    }
}

tx_input value: 0x5c11d795000000000000000000000000000000000000000000000000000000004639e7c0000000000000000000000000000000000000000000000001865a8d7f29f2e00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000a2d62eeee9511f6ccbbbc7ec5be46b000b9a6e980000000000000000000000000000000000000000000000000000019125c467840000000000000000000000000000000000000000000000000000000000000002000000000000000000000000eb51d9a39ad5eef215dc0bf39a8821ff804a0f010000000000000000000000008f3cf7ad23cd3cadbd9735aff958023239c6a063

An error message is displayed every time it is run: calledResult::unwrap()on anErrvalue: TypeCheckFail { expected_type: "swapExactTokensForTokensSupportingFeeOnTransferTokens", data: "30783563" }

I tried the example at https://alloy.rs/examples/transactions/decode_input.html, but when I run,I get an error

senseiod commented 1 month ago

sorry,my fault