mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:26:52 +00:00
Merge pull request #8 from MetricsDAO/add_actions
add actions_events table
This commit is contained in:
commit
3d447bd74b
53
models/core/actions_events.sql
Normal file
53
models/core/actions_events.sql
Normal 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
|
||||
38
models/core/actions_events.yml
Normal file
38
models/core/actions_events.yml
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user