Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing debugger #315

Merged
merged 2 commits into from
Jul 11, 2024
Merged

Add parsing debugger #315

merged 2 commits into from
Jul 11, 2024

Conversation

araa47
Copy link
Contributor

@araa47 araa47 commented Jul 10, 2024

What?

We sometimes run into issues where the contract parser doesn't seem to be generating the correct files we need. In these cases its currently hard to debug things since we have no feedback that the parsing will work as intented.

[x] Log Parsing Support
[x] Trace Parsing Support

How?

I have created a generate_parse_sql.py file that can be called with the path of the json file + date.

Command

The command below tries to verify the json for ajna_v2 ERC721PoolFactory_event_PoolCreated events. Note i selected 2024-01-08 since I know there are events produced on that date from etherscan

python3 generate_parse_sql.py dags/resources/stages/parse/table_definitions/ajna_v2/ERC721PoolFactory_event_PoolCreated.json 2024-01-08

Output

WITH
abi AS 
(
SELECT
    JSON_QUERY(json_data, '$.parser.abi') AS abi,
    JSON_QUERY(json_data, '$.parser.field_mapping') AS field_mapping,
    JSON_QUERY(json_data, '$.table') AS table_details,
    JSON_EXTRACT_SCALAR(json_data, '$.parser.contract_address') AS contract_address,
    CAST(JSON_EXTRACT_SCALAR(json_data, '$.parser.type') AS STRING) AS parser_type
FROM (
    SELECT '{"parser": {"abi": {"anonymous": false, "inputs": [{"indexed": false, "internalType": "address", "name": "pool_", "type": "address"}, {"indexed": false, "internalType": "bytes32", "name": "subsetHash_", "type": "bytes32"}], "name": "PoolCreated", "type": "event"}, "contract_address": "0x27461199d3b7381de66a85d685828e967e35af4c", "field_mapping": {}, "type": "log"}, "table": {"dataset_name": "ajna_v2", "schema": [{"description": "", "name": "pool_", "type": "STRING"}, {"description": "", "name": "subsetHash_", "type": "STRING"}], "table_description": "", "table_name": "ERC721PoolFactory_event_PoolCreated"}}' AS json_data
)
),

details AS (
    SELECT 
        '0xee1fe091a5213b321c2662b35c0b7cd0d35d10dbcab52b3c9b8768983c67bce3' AS sig,
        abi.*
    FROM abi
),

logs AS (
  SELECT
    l.*,
    a.sig, 
    `blockchain-etl-internal.common.parse_log`(
            l.data,
            l.topics,
            REPLACE(a.abi, "'", '"')
        ) AS parsed_log
  FROM
    `bigquery-public-data.crypto_ethereum.logs` AS l
  INNER JOIN
        details AS a
    ON
        IFNULL(l.topics[SAFE_OFFSET(0)], "") = a.sig
  WHERE
    DATE(l.block_timestamp) = DATE("2024-01-08")
    AND (a.contract_address IS NULL OR l.address = LOWER(a.contract_address))
)

SELECT * FROM logs
LIMIT 100

This will generate some sql for you to test out the parsing and verify everything is woring as expected

Running SQL in BQ
Screenshot 2024-07-10 at 11 33 05 AM

We can use the parsed_log column to verify everything we need is correctly parsed

@araa47 araa47 requested a review from kome12 July 10, 2024 06:29
@araa47 araa47 merged commit c42d58d into main Jul 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants