solana-models/macros/python/udfs.sql
desmond-hui c8918927e3
An 1705/ez staking desmond (#70)
* ez staking model

* extra cte to remove null values on join

* fixed issues pulling correct acct

* updates for edge cases

* wip

* wip

* wip

* wip

* tx_api source

* ignore null stake accounts

* integrate new lambda calls

* modify what stake accts to get txs for

* An 1705 ez staking v2 jessica (#69)

* add missing mints without mint price (#67)

* add missing mints without mint price

* fix block gap test

* fix to incremental

* add incremental to 1st part of union

* add incremental to 1st part of union

Co-authored-by: jhuhnke <jessica@flipsidecrypto.com>

* historical LP actions table

* removes non-staking txs

* vote accts for split & destination

* fix to join for vote acct

* fix join

* Fix data type issues

* fixed where clause that limits blocks

* parsed out inner instructions staking txs

* fixes to joins

* wip

* make block_timestamp a cluster key (#68)

* wip

* cleaned up tables

* flattening fix

* resolve conflicts

Co-authored-by: desmond-hui <97470747+desmond-hui@users.noreply.github.com>
Co-authored-by: Desmond Hui <desmond@flipsidecrypto.com>

* incremental will not work due to having to re-get historial txs

* fix table ref names and filter out any stake_acct=validator

Co-authored-by: jhuhnke <jessica@flipsidecrypto.com>
Co-authored-by: Jessica Huhnke <91915469+jhuhnke@users.noreply.github.com>
2022-07-14 13:04:29 -07:00

55 lines
1.5 KiB
PL/PgSQL

{% 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 %}
{% macro create_udf_get_all_inner_instruction_events(schema) %}
create or replace function {{ schema }}.udf_get_all_inner_instruction_events(inner_instruction array)
returns array
language python
runtime_version = '3.8'
handler = 'get_all_inner_instruction_events'
as
$$
def get_all_inner_instruction_events(inner_instruction) -> list:
event_types = []
if inner_instruction:
for v in inner_instruction:
if type(v) is dict and v.get("parsed") and type(v["parsed"]) is dict and v["parsed"].get("type"):
event_types.append(v["parsed"]["type"])
else:
event_types.append(None)
return event_types
$$;
{% endmacro %}
{% macro create_udf_get_account_balances_index(schema) %}
create or replace function {{ schema }}.udf_get_account_balances_index(account string, account_keys array)
returns int
language python
runtime_version = '3.8'
handler = 'get_account_balances_index'
as
$$
def get_account_balances_index(account, account_keys) -> int:
for i,a in enumerate(account_keys):
if a and a.get("pubkey") == account:
return i
return None
$$;
{% endmacro %}