[STREAM-1068] update logic on balance

This commit is contained in:
Jensen Yap 2024-10-25 20:27:11 +09:00 committed by Julius Remigio
parent 01bd6dd51e
commit d5f6103f4d
2 changed files with 14 additions and 5 deletions

View File

@ -438,7 +438,7 @@
- [block_height, INTEGER, The start block height to get the transfers from]
- [to_latest, BOOLEAN, Whether to continue fetching transfers until the latest block or not]
return_type:
- "TABLE(block_number NUMBER, block_timestamp TIMESTAMP_NTZ, address STRING, contract_address STRING, balance INTEGER, fact_token_balances_id STRING, inserted_timestamp TIMESTAMP_NTZ, modified_timestamp TIMESTAMP_NTZ)"
- "TABLE(block_number NUMBER, block_timestamp TIMESTAMP_NTZ, address STRING, contract_address STRING, balance NUMBER(38,0), fact_token_balances_id STRING, inserted_timestamp TIMESTAMP_NTZ, modified_timestamp TIMESTAMP_NTZ)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT

View File

@ -591,12 +591,22 @@ SELECT
block_timestamp,
address,
contract_address,
IFF(DATA :: STRING = '{}', NULL, DATA :: STRING) AS casted_data,
CASE
WHEN
LENGTH(
casted_data
) <= 4300
AND casted_data IS NOT NULL THEN LEFT(casted_data, 66)
ELSE NULL
END
AS hex_balance,
TRY_TO_NUMBER(
CASE
WHEN LENGTH(
DATA :result :: STRING
hex_balance
) <= 4300
AND DATA :result IS NOT NULL THEN utils.udf_hex_to_int(LEFT(DATA :result :: STRING, 66))
AND hex_balance IS NOT NULL THEN utils.udf_hex_to_int(hex_balance)
ELSE NULL
END
) AS balance,
@ -618,8 +628,7 @@ SELECT
id AS token_balances_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
balances
FROM balances
{% endmacro %}
-- Get EVM chain fact data