TheLaughingMan[NEAR] NFT Paras marketplace BASE
    Updated 2022-07-27
    with base as (
    SELECT
    *
    FROM near.core.fact_transactions
    WHERE 1=1
    AND (tx_receiver LIKE '%paras%')
    ),

    extracts as (
    SELECT
    tx_hash, block_timestamp,
    --logs,
    replace(logs[0], '\\') as logs_pre, -- remove // | convert variant | parse json
    CASE WHEN logs_pre like 'EVENT_JSON:%' THEN replace( replace(split(logs_pre,'EVENT_JSON:')[1], '\:\"\{\"', '\:\{\"'), '\"}\"\}', '\"}\}') ELSE logs_pre END as logs_cleaned,
    check_json(logs_cleaned) as checks,
    TRY_PARSE_JSON(logs_cleaned) as log_json
    FROM near.core.fact_receipts
    WHERE 1=1
    AND tx_hash IN (SELECT tx_hash from base)
    AND ARRAY_SIZE(logs)>0
    ),

    types as (
    SELECT
    -- COUNT(*) as total,
    -- coalesce(log_json:type, log_json:event) as type,
    -- MAX(log_json) as sample_json,
    -- MAX(tx_hash) as sample_tx
    e.tx_hash,
    e.block_timestamp,
    tx_signer,
    tx_receiver,
    coalesce(log_json:type, log_json:event) as type,
    coalesce(coalesce(log_json:params:price, log_json:data[0]:memo:price, log_json:params:amount)/1e24, 0) as price,
    coalesce(log_json:params:buyer_id, log_json:data[0]:new_owner_id, log_json:data[0]:owner_id, log_json:params:creator_id ) as actor,
    Run a query to Download Data