Merge pull request #8 from MetricsDAO/add_actions

add actions_events table
This commit is contained in:
Jack Forgash 2022-02-22 11:23:32 -07:00 committed by GitHub
commit 3d447bd74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,53 @@
{{
config(
materialized='incremental',
cluster_by='block_timestamp',
unique_key='action_id',
tags=['actions']
)
}}
with
txs as (
select * from {{ ref('stg_txs') }}
where {{ incremental_load_filter('block_timestamp') }}
),
actions as (
select
tx_id,
block_timestamp,
index as action_index,
case
when value like '%CreateAccount%' then value
else OBJECT_KEYS(value)[0]::string
end as action_name,
case
when action_name = 'CreateAccount' then '{}'
else value[action_name]
end as action_data
from txs, lateral flatten( input => tx:actions )
),
final as (
select
concat_ws('-', tx_id, action_index) as action_id,
tx_id as tx_hash,
block_timestamp,
action_index,
action_name,
try_parse_json(action_data) as action_data
from actions
)
select * from final

View File

@ -0,0 +1,38 @@
version: 2
models:
- name: actions_events
description: |-
This table extracts all action events from a transaction and stores the argument data under action_data.
columns:
- name: action_id
description: The `action_id` as compiled from `tx_id` and `action_index`. This is unique for each record.
tests:
- unique
- not_null
- name: tx_hash
description: The hash of the transaction, this is the primary key for this table.
tests:
- not_null
- name: block_timestamp
description: The `block_timestamp` taken from block headers. The time when the block was created.
tests:
- not_null
- name: action_index
description: The index of the current `action_name` and `action_data` in the order in which it appeared in the transaction.
tests:
- not_null
- name: action_name
description: The name of the action performed.
tests:
- not_null
- name: action_data
description: A JSON object containing the argument data that was called by the `action_event`, if any.
tests:
- not_null