HIP-904 Support Token Airdrops
Problem
Add support for the following transactions and persist to the token_airdrop table:
-
TokenAirdrop -
TokenCancelAirdrop -
TokenClaimAirdrop
Solution
- Add a
TokenAirdropdomain object with the same fields as the schema below. - Add
onTokenAirdropmethod to EntityListener to handle inserts to thetoken_airdroptable. - Add
TokenAirdropTransactionHandlerwhich will add a new entry to thetoken_airdroptable with the default state ofPENDING. - Add
TokenCancelAirdropTransactionHandlerwhich will set the state of the airdrop toCANCELLED - Add
TokenClaimAirdropTransactionHandlerwhich will set the state of the airdrop toCLAIMED
If a TokenAirdrop transaction occurs for a fungible token that already exists in the token_airdrop table then the existing entry should have the timestamp range closed, and it should be moved into the token_airdrop_history table. If the entry was in the PENDING state, then the new entry should be updated with amount set to the sum of the existing amount and the new amount. If the existing entry is in any other state, then the amount should be set to the amount of the new entry.
If a TokenAirdrop transaction occurs for a nft that already exists in the token_airdrop table i.e matching sender, receiver, token_id and serial_number, then the existing entry should have the timestamp range closed, and it should be moved into the token_airdrop_history table.
Token airdrop schema:
create type airdrop_state as enum ('PENDING', 'CANCELLED', 'CLAIMED');
create table if not exists token_airdrop
(
amount bigint,
receiver_account_id bigint not null,
sender_account_id bigint not null,
serial_number bigint,
state airdrop_state not null default 'PENDING',
timestamp_range int8range not null,
token_id bigint not null
);
create unique index if not exists token_airdrop__sender_id on token_airdrop (sender_account_id, receiver_account_id, token_id, serial_number);
create index if not exists token_airdrop__receiver_id on token_airdrop (receiver_account_id, sender_account_id, token_id, serial_number);
create table if not exists token_airdrop_history
(
like token_airdrop including defaults
);
create index if not exists token_airdrop_history__token_serial_lower_timestamp
on token_airdrop_history using gist (timestamp_range);
Alternatives
No response