Git Product home page Git Product logo

block-explorers's People

Contributors

ckoopmann avatar danipopes avatar evalir avatar klkvr avatar mattsse avatar nicolaswent avatar shekhirin avatar yash-atreya avatar zerosnacks avatar zhangzhuosjtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

block-explorers's Issues

Can not deserialize the block number in hex format

Hi, I'm using this library to get the ERC20TokenTransferEvent from etherscan and then save it into a JSON file.
But when deserialize the JSON file, I had this Error value: Error("digit 33 is out of range for base 16", line: 3, column: 39)'. It seems like the number in the JSON file is saved in the hex format.
Can someone help me to solve this issue?

Test code

mod test {
    use std::str::FromStr;

    use alloy_chains::Chain;
    use alloy_primitives::Address;
    use foundry_block_explorers::{account::ERC20TokenTransferEvent, Client};

    #[tokio::test]
    async fn test_serde() {
        let client = Client::new(Chain::from_id(137), "<API-KEY>>").unwrap();
        let addr = Address::from_str("<Address>").unwrap();

        let events = client
            .get_erc20_token_transfer_events(
                foundry_block_explorers::account::TokenQueryOption::ByAddress(addr),
                Some(foundry_block_explorers::account::TxListParams {
                    start_block: 0,
                    end_block: 99999999,
                    page: 1,
                    offset: 1,
                    sort: foundry_block_explorers::account::Sort::Desc,
                }),
            )
            .await
            .unwrap();

        let data = serde_json::to_string_pretty(&events).unwrap();

        println!("{}", data);

        let de_events: Vec<ERC20TokenTransferEvent> = serde_json::from_str(&data).unwrap();

        assert_eq!(events.len(), de_events.len())
    }
}

Cargo.toml

[dependencies]
alloy-chains = "0.1.4"
alloy-primitives = { version = "0.5.2", features = ["serde", "std"] }
alloy-json-abi = { version = "0.5", default-features = false, features = [
    "std",
    "serde_json",
] }
anyhow = "1.0.75"
foundry-block-explorers = "0.1.1"
rust_decimal = { version = "1.33.1", features = ["maths"] }
serde = "1.0.193"
serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }

Partial Incompatibility with Blockscout

While trying to implement a cast command to migrate a contract verification from on explorer to another (specifically from etherscan to blockscout), I encountered the issue that the contract_source_code and submit_contract_verification methods fail when run against blockscout. (more specifically against "https://eth.blockscout.com/api".

I created tests reproducing the issue for contract_source_code and submit_contract_verification.

Judging from the error messages (see screenshots), the former issue seems to be a pretty strait forward deserialziation issue whereas the latter has a pretty cryptic error message.
image
image

Questions about Explorer Cache

Hi all!

I was checking the code of block explorer, but realize some tricky issues.

pub async fn contract_source_code(&self, address: Address) -> Result<ContractMetadata> {
// apply caching
if let Some(ref cache) = self.cache {
// If this is None, then we have a cache miss
if let Some(src) = cache.get_source(address) {
// If this is None, then the contract is not verified
return match src {
Some(src) => Ok(src),
None => Err(EtherscanError::ContractCodeNotVerified(address)),
};
}
}
let query =
self.create_query("contract", "getsourcecode", HashMap::from([("address", address)]));
let response = self.get(&query).await?;
// Source code is not verified

Based on the code, it seems if the cache.get_source(address) returns None, the function will throw ContractCodeNotVerified errors.

However, based on the code of cache, there is another possibility that the contract is verified, but the cache is not alive. In that case, the function may misbehave.

SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time is before unix epoch")
// Check if the current time is less than the expiry time
// to determine if the cache item is still valid.
.lt(&Duration::from_secs(inner.expiry))
// If the cache item is still valid, return the data.
// Otherwise, return None.
.then_some(inner.data)

Please let me know if I misunderstood anything here. I am more than happy to open a PR if this is indeed an issue.

Thanks!

Remove `ethers-core` dependency

Right now we're coupled to ethers due to using RawAbi, and the Chain enum. This means we need to keep patches on foundry to keep ethers versions in sync. We should remove the dep as follows:

  • Integrate alloy-rs/chains when ready
  • Move RawAbi into block-explorers, as it's not an alloy-related type nor an RPC type. It just uses some metadata from the ABI for verification purposes.

Get the settings of verified contract crashes

Some Etherscan verified contracts do not have optimizer field in their compiler settings.
For example, contract 0xd689a304011d64d5bf1d662d9cddf8b2db81e6b6, the compiler settings given by Etherscan is

"settings": {
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "abi"
        ]
      }
    }
  }
}

However, the optimizer field in the Setting struct is not optional, leading to a crash when fetching compiler settings for this contract.
https://github.com/foundry-rs/compilers/blob/342f713da41c9738c6e775b7daf0bf6827041cde/src/artifacts/mod.rs#L266-L273

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.