bro-n-bro / spacebox

MIT License
35 stars 4 forks source link

Add table wasm_events with writer #60

Closed bro-n-bro-0 closed 2 months ago

bro-n-bro-0 commented 4 months ago

table defenition

CREATE TABLE spacebox.wasm_events
(
    `height` Int64,
    `contract_address` String,
    `action` String,
    `attributes` String
)
ENGINE = MergeTree
ORDER BY (height, contract_address, action)

writer definition

CREATE MATERIALIZED VIEW spacebox.wasm_events_writer TO spacebox.wasm_events
(
    `timestamp` DateTime,
    `height` Int64,
    `txhash` String,
    `signer` String,
    `contract_address` String,
    `action` String,
    `attributes` String
) AS
WITH events AS
    (
        SELECT
            timestamp,
            height,
            txhash,
            signer,
            JSONExtractString(arrayJoin(JSONExtractArrayRaw(events)),
 'type') AS type,
            JSONExtractString(arrayJoin(JSONExtractArrayRaw(events)),
 'attributes') AS attributes
        FROM spacebox.raw_transaction
    )
SELECT
    timestamp,
    height,
    txhash,
    signer,
    JSONExtractString(arrayFilter(x -> (JSONExtractString(x,
 'key') = '_contract_address'),
 JSONExtractArrayRaw(attributes))[1],
 'value') AS contract_address,
    JSONExtractString(arrayFilter(x -> (JSONExtractString(x,
 'key') = 'action'),
 JSONExtractArrayRaw(attributes))[1],
 'value') AS action,
    attributes
FROM events
WHERE type = 'wasm'
iljagrabar14 commented 4 months ago

added few fields to table