Git Product home page Git Product logo

Comments (4)

swarna1101 avatar swarna1101 commented on May 30, 2024
if extract_timestamps is not None:
    timestamps = extract_timestamps(web3, start_block, end_block)

for log in logs:
    block_hash = log["blockHash"]
    block_number = int(log["blockNumber"], 16)
    # Retrofit our information to the dict
    event_signature = log["topics"][0]
    log["context"] = context
    log["event"] = filter.topics[event_signature]
    if extract_timestamps:
        try:
            log["timestamp"] = timestamps[block_hash]
        except KeyError as e:
            # If the block hash is not found in the timestamps table, it could be due to a chain reorg.
            # In this case, we can try to retrieve the timestamp using the block number instead.
            try:
                block = web3.eth.getBlock(block_number)
                log["timestamp"] = block["timestamp"]
            except Exception as e:
                raise RuntimeError(
                    f"Timestamp missing for block number {block_number:,}, hash {block_hash}, our timestamp table has {len(timestamps)} blocks"
                ) from e
    else:
        log["timestamp"] = None

This code first checks if extract_timestamps is not None, and if it is not, it retrieves the timestamps for the blocks within the specified range using the extract_timestamps function. Then, for each log in the logs list, it retrofits the information to the dict and tries to retrieve the timestamp for the block using the block hash. If a KeyError is raised, it means that the block hash is not found in the timestamps table, which could be due to a chain reorg. In this case, it tries to retrieve the timestamp using the block number instead using the web3.eth.getBlock method. If this also fails, it raises a RuntimeError with a message indicating that the timestamp is missing.

from web3-ethereum-defi.

swarna1101 avatar swarna1101 commented on May 30, 2024

#59 can you check this once @miohtama @hieuh25

from web3-ethereum-defi.

miohtama avatar miohtama commented on May 30, 2024

@swarna1101 Thank you for your feedback. I am sorry your comment is not relevant for this issue. Please do not post comments, unless you have more context on the issue.

from web3-ethereum-defi.

hieuh25 avatar hieuh25 commented on May 30, 2024

Fixed in #62

from web3-ethereum-defi.

Related Issues (20)

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.