mirror of
https://github.com/FlipsideCrypto/solana-models.git
synced 2026-02-06 13:36:46 +00:00
use python to get signers from accts (#56)
This commit is contained in:
parent
8eda6f1dd7
commit
8f22af7f7a
@ -1,6 +1,9 @@
|
||||
{% macro create_udfs() %}
|
||||
{% set sql %}
|
||||
{{ udf_bulk_get_decoded_instructions_data() }};
|
||||
{{ create_udf_ordered_signers(
|
||||
schema = "silver"
|
||||
) }}
|
||||
{% endset %}
|
||||
{% do run_query(sql) %}
|
||||
{% endmacro %}
|
||||
|
||||
17
macros/python/udfs.sql
Normal file
17
macros/python/udfs.sql
Normal file
@ -0,0 +1,17 @@
|
||||
{% macro create_udf_ordered_signers(schema) %}
|
||||
create or replace function {{ schema }}.udf_ordered_signers(accts array)
|
||||
returns array
|
||||
language python
|
||||
runtime_version = '3.8'
|
||||
handler = 'ordered_signers'
|
||||
as
|
||||
$$
|
||||
def ordered_signers(accts) -> list:
|
||||
signers = []
|
||||
for v in accts:
|
||||
if v["signer"]:
|
||||
signers.append(v["pubkey"])
|
||||
|
||||
return signers
|
||||
$$;
|
||||
{% endmacro %}
|
||||
@ -41,59 +41,13 @@ WITH base AS (
|
||||
{% if is_incremental() %}
|
||||
AND ingested_at :: DATE >= CURRENT_DATE - 2
|
||||
{% endif %}
|
||||
),
|
||||
trans_tmp AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
b.tx_id,
|
||||
recent_block_hash,
|
||||
fee,
|
||||
succeeded,
|
||||
account_keys,
|
||||
pre_balances,
|
||||
post_balances,
|
||||
pre_token_balances,
|
||||
post_token_balances,
|
||||
instructions,
|
||||
inner_instructions,
|
||||
log_messages,
|
||||
ingested_at
|
||||
FROM
|
||||
base b
|
||||
qualify(ROW_NUMBER() over(PARTITION BY b.block_id, b.tx_id
|
||||
ORDER BY
|
||||
b.ingested_at DESC)) = 1
|
||||
),
|
||||
signers_flattened AS (
|
||||
SELECT
|
||||
b.tx_id,
|
||||
A.index AS signer_index,
|
||||
A.value :pubkey :: STRING AS acct
|
||||
FROM
|
||||
trans_tmp b,
|
||||
TABLE(FLATTEN(b.account_keys)) A
|
||||
WHERE
|
||||
A.value :signer = TRUE
|
||||
),
|
||||
signers_arr AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
ARRAY_AGG(acct) within GROUP (
|
||||
ORDER BY
|
||||
signer_index
|
||||
) AS signers
|
||||
FROM
|
||||
signers_flattened
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
b.tx_id,
|
||||
recent_block_hash,
|
||||
s.signers AS signers,
|
||||
silver.udf_ordered_signers(account_keys) as signers,
|
||||
fee,
|
||||
succeeded,
|
||||
account_keys,
|
||||
@ -106,6 +60,7 @@ SELECT
|
||||
log_messages,
|
||||
ingested_at
|
||||
FROM
|
||||
trans_tmp b
|
||||
LEFT OUTER JOIN signers_arr s
|
||||
ON b.tx_id = s.tx_id
|
||||
base b
|
||||
qualify(ROW_NUMBER() over(PARTITION BY b.block_id, b.tx_id
|
||||
ORDER BY
|
||||
b.ingested_at DESC)) = 1
|
||||
Loading…
Reference in New Issue
Block a user