diff --git a/prisma/migrations/20250609/01_add_currency_id_to_spends.sql b/prisma/migrations/20250609/01_add_currency_id_to_spends.sql new file mode 100644 index 0000000..1ae69f3 --- /dev/null +++ b/prisma/migrations/20250609/01_add_currency_id_to_spends.sql @@ -0,0 +1,31 @@ +ALTER TABLE dag_allow_spends ADD currency_id varchar NULL; +ALTER TABLE dag_allow_spends ADD CONSTRAINT dag_allow_spends_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE dag_spend_transactions ADD currency_id varchar NULL; +ALTER TABLE dag_spend_transactions ADD CONSTRAINT dag_spend_transactions_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE dag_expired_spend_transactions ADD currency_id varchar NULL; +ALTER TABLE dag_expired_spend_transactions ADD CONSTRAINT dag_expired_spend_transactions_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE metagraph_allow_spends ADD currency_id varchar NULL; +ALTER TABLE metagraph_allow_spends ADD CONSTRAINT metagraph_allow_spends_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE metagraph_spend_transactions ADD currency_id varchar NULL; +ALTER TABLE metagraph_spend_transactions ADD CONSTRAINT metagraph_spend_transactions_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE metagraph_expired_spend_transactions ADD currency_id varchar NULL; +ALTER TABLE metagraph_expired_spend_transactions ADD CONSTRAINT metagraph_expired_spend_transactions_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + + + +ALTER TABLE dag_token_locks ADD currency_id varchar NULL; +ALTER TABLE dag_token_locks ADD CONSTRAINT dag_token_locks_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE dag_token_unlocks ADD currency_id varchar NULL; +ALTER TABLE dag_token_unlocks ADD CONSTRAINT dag_token_unlocks_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE metagraph_token_locks ADD currency_id varchar NULL; +ALTER TABLE metagraph_token_locks ADD CONSTRAINT metagraph_token_locks_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; + +ALTER TABLE metagraph_token_unlocks ADD currency_id varchar NULL; +ALTER TABLE metagraph_token_unlocks ADD CONSTRAINT metagraph_token_unlocks_metagraphs_fk FOREIGN KEY (currency_id) REFERENCES public.metagraphs(id) ON DELETE CASCADE; diff --git a/prisma/migrations/20250529/01_add_staking_to_actions.sql b/prisma/migrations/20250609/02_add_staking_to_actions.sql similarity index 74% rename from prisma/migrations/20250529/01_add_staking_to_actions.sql rename to prisma/migrations/20250609/02_add_staking_to_actions.sql index 3498b22..968cea0 100644 --- a/prisma/migrations/20250529/01_add_staking_to_actions.sql +++ b/prisma/migrations/20250609/02_add_staking_to_actions.sql @@ -1,57 +1,57 @@ -- DAG Tables CREATE OR REPLACE VIEW dag_actions_view AS SELECT - das.hash, source_addr, amount, das.created_at, das.updated_at, - 'AllowSpend' as transaction_type, snapshot_hash as global_snapshot_hash, gs.ordinal as global_snapshot_ordinal, - destination_addr, last_valid_epoch_progress AS unlock_epoch, parent_hash, fee - FROM dag_allow_spends das + das.hash, source_addr, amount, das.created_at, das.updated_at, + 'AllowSpend' as transaction_type, snapshot_hash as global_snapshot_hash, gs.ordinal as global_snapshot_ordinal, + destination_addr, last_valid_epoch_progress AS unlock_epoch, parent_hash, fee, currency_id + FROM dag_allow_spends das JOIN global_snapshots gs ON das.snapshot_hash = gs.hash UNION ALL SELECT - dst.hash, dst.source_addr, dst.amount, dst.created_at, dst.updated_at, + dst.hash, dst.source_addr, dst.amount, dst.created_at, dst.updated_at, 'SpendTransaction', dst.snapshot_hash, gs.ordinal, - dst.destination_addr, null, dst.allow_spend_ref, null - FROM dag_spend_transactions dst + dst.destination_addr, null, dst.allow_spend_ref, null, currency_id + FROM dag_spend_transactions dst JOIN global_snapshots gs ON dst.snapshot_hash = gs.hash UNION ALL SELECT - dest.hash, dest.source_addr, dest.amount, dest.created_at, dest.updated_at, + dest.hash, dest.source_addr, dest.amount, dest.created_at, dest.updated_at, 'ExpiredAllowSpend', dest.snapshot_hash, gs.ordinal, - null, null, dest.allow_spend_ref, null - FROM dag_expired_spend_transactions dest + null, null, dest.allow_spend_ref, null, currency_id + FROM dag_expired_spend_transactions dest JOIN global_snapshots gs ON dest.snapshot_hash = gs.hash UNION ALL SELECT - dtl.hash, dtl.source_addr, dtl.amount, dtl.created_at, dtl.updated_at, + dtl.hash, dtl.source_addr, dtl.amount, dtl.created_at, dtl.updated_at, 'TokenLock', dtl.snapshot_hash, gs.ordinal, - null, dtl.unlock_epoch, dtl.parent_hash, null - FROM dag_token_locks dtl + null, dtl.unlock_epoch, dtl.parent_hash, null, currency_id + FROM dag_token_locks dtl JOIN global_snapshots gs ON dtl.snapshot_hash = gs.hash UNION ALL - SELECT - dtu.hash, dtu.source_addr, dtu.amount, dtu.created_at, dtu.updated_at, + SELECT + dtu.hash, dtu.source_addr, dtu.amount, dtu.created_at, dtu.updated_at, 'TokenUnlock', dtu.snapshot_hash, gs.ordinal, - null, null, dtu.lock_reference_hash, null - FROM dag_token_unlocks dtu + null, null, dtu.lock_reference_hash, null, currency_id + FROM dag_token_unlocks dtu JOIN global_snapshots gs ON dtu.snapshot_hash = gs.hash UNION ALL SELECT - dsce.hash, dsce.source_addr, dsce.amount, dsce.created_at, dsce.updated_at, + dsce.hash, dsce.source_addr, dsce.amount, dsce.created_at, dsce.updated_at, 'DelegateStakeCreate', dsce.global_snapshot_hash, gs.ordinal, - null, null, dsce.parent_hash, dsce.fee - FROM delegate_stake_create_events dsce + null, null, dsce.parent_hash, dsce.fee, null + FROM delegate_stake_create_events dsce JOIN global_snapshots gs ON dsce.global_snapshot_hash = gs.hash UNION ALL SELECT - dswe.hash, dswe.source_addr, dsce.amount, dswe.created_at, dswe.updated_at, + dswe.hash, dswe.source_addr, dsce.amount, dswe.created_at, dswe.updated_at, 'DelegateStakeWithdraw', dswe.global_snapshot_hash, gs.ordinal, - null, dswe.unlock_epoch, dswe.stake_create_hash, null + null, dswe.unlock_epoch, dswe.stake_create_hash, null, null FROM delegate_stake_withdraw_events dswe LEFT JOIN delegate_stake_create_events dsce ON dswe.stake_create_hash = dsce.hash JOIN global_snapshots gs ON dswe.global_snapshot_hash = gs.hash; @@ -59,69 +59,69 @@ UNION ALL -- Metagraph Tables CREATE OR REPLACE VIEW metagraph_actions_view AS -SELECT +SELECT mas.metagraph_id, mas.hash, mas.source_addr, mas.amount, mas.created_at, mas.updated_at, 'AllowSpend' AS transaction_type, mas.snapshot_hash as metagraph_snapshot_hash, ms.ordinal as metagraph_snapshot_ordinal, mas.destination_addr, mas.last_valid_epoch_progress AS unlock_epoch, - mas.parent_hash, mas.fee, + mas.parent_hash, mas.fee, currency_id, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_allow_spends mas -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mas.metagraph_id = ms.metagraph_id AND mas.snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash UNION ALL -SELECT +SELECT mst.metagraph_id, mst.hash, mst.source_addr, mst.amount, mst.created_at, mst.updated_at, 'SpendTransaction', mst.snapshot_hash as metagraph_snapshot_hash, ms.ordinal as metagraph_snapshot_ordinal, - mst.destination_addr, NULL, mst.allow_spend_ref, NULL, + mst.destination_addr, NULL, mst.allow_spend_ref, NULL, currency_id, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_spend_transactions mst -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mst.metagraph_id = ms.metagraph_id AND mst.snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash UNION ALL -SELECT +SELECT mest.metagraph_id, mest.hash, mest.source_addr, mest.amount, mest.created_at, mest.updated_at, 'ExpiredAllowSpend', mest.snapshot_hash as metagraph_snapshot_hash, ms.ordinal as metagraph_snapshot_ordinal, - NULL, NULL, mest.allow_spend_ref, NULL, + NULL, NULL, mest.allow_spend_ref, NULL, currency_id, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_expired_spend_transactions mest -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mest.metagraph_id = ms.metagraph_id AND mest.snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash UNION ALL -SELECT +SELECT mtl.metagraph_id, mtl.hash, mtl.source_addr, mtl.amount, mtl.created_at, mtl.updated_at, 'TokenLock', mtl.snapshot_hash as metagraph_snapshot_hash, ms.ordinal as metagraph_snapshot_ordinal, - NULL, mtl.unlock_epoch, mtl.parent_hash, NULL, + NULL, mtl.unlock_epoch, mtl.parent_hash, NULL, currency_id, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_token_locks mtl -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mtl.metagraph_id = ms.metagraph_id AND mtl.snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash UNION ALL -SELECT +SELECT mtu.metagraph_id, mtu.hash, mtu.source_addr, mtu.amount, mtu.created_at, mtu.updated_at, 'TokenUnlock', mtu.snapshot_hash as metagraph_snapshot_hash, ms.ordinal as metagraph_snapshot_ordinal, - NULL, NULL, mtu.lock_reference_hash, NULL, + NULL, NULL, mtu.lock_reference_hash, NULL, currency_id, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_token_unlocks mtu -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mtu.metagraph_id = ms.metagraph_id AND mtu.snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash UNION ALL -SELECT +SELECT mft.metagraph_id, mft.hash, mft.source_addr, mft.amount, mft.created_at, mft.updated_at, 'FeeTransaction', mft.metagraph_snapshot_hash, ms.ordinal, - mft.destination_addr, NULL, mft.data_update_ref, NULL, + mft.destination_addr, NULL, mft.data_update_ref, NULL, null, gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal FROM metagraph_fee_transactions mft -JOIN metagraph_snapshots ms +JOIN metagraph_snapshots ms ON mft.metagraph_id = ms.metagraph_id AND mft.metagraph_snapshot_hash = ms.hash -JOIN global_snapshots gs +JOIN global_snapshots gs ON ms.global_snapshot_hash = gs.hash; diff --git a/prisma/migrations/20250609/03_drop_abstract_triggers.sql b/prisma/migrations/20250609/03_drop_abstract_triggers.sql new file mode 100644 index 0000000..18cde02 --- /dev/null +++ b/prisma/migrations/20250609/03_drop_abstract_triggers.sql @@ -0,0 +1,18 @@ +delete from only abstract_transactions; +delete from only abstract_blocks; + +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_allow_spends" ON "dag_allow_spends"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_blocks_dag" ON "dag_blocks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_spend_transactions" ON "dag_spend_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_expired_spend_transact" ON "dag_expired_spend_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_token_locks" ON "dag_token_locks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_token_unlocks" ON "dag_token_unlocks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_token_locks" ON "metagraph_token_locks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_token_unlocks" ON "metagraph_token_unlocks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_allow_spends" ON "metagraph_allow_spends"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_blocks_metagraph" ON "metagraph_blocks"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_fee_transactions" ON "metagraph_fee_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_spend_transactio" ON "metagraph_spend_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_expired_spend_tr" ON "metagraph_expired_spend_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_dag_transactions" ON "dag_transactions"; +DROP TRIGGER IF EXISTS "trigger_insert_abstract_transactions_metagraph_transactions" ON "metagraph_transactions"; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1217939..6fbe7aa 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -32,6 +32,7 @@ model dag_actions_view { unlock_epoch BigInt? parent_hash String? @db.VarChar fee BigInt? + currency_id String? @db.VarChar dag_token_lock dag_token_locks? @relation(fields: [hash], references: [hash], map: "dag_token_locks_ref") dag_token_unlock dag_token_unlocks? @relation(fields: [hash], references: [hash], map: "dag_token_unlocks_ref") @@ -57,6 +58,7 @@ model metagraph_actions_view { unlock_epoch BigInt? parent_hash String? @db.VarChar fee BigInt? + currency_id String? @db.VarChar metagraph_token_lock metagraph_token_locks? @relation(fields: [hash], references: [hash], map: "metagraph_token_locks_ref") metagraph_token_unlock metagraph_token_unlocks? @relation(fields: [hash], references: [hash], map: "metagraph_token_unlocks_ref") @@ -133,6 +135,7 @@ model dag_allow_spends { round_id String @db.Uuid ordinal BigInt @unique(map: "dag_allow_spends_ordinal") snapshot_hash String @db.VarChar + currency_id String? @db.VarChar dag_allow_spend_approvers dag_allow_spend_approvers[] addresses_dag_allow_spends_destination_addrToaddresses addresses @relation("dag_allow_spends_destination_addrToaddresses", fields: [destination_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "dag_allow_spends_destination_addr_fk") addresses_dag_allow_spends_source_addrToaddresses addresses @relation("dag_allow_spends_source_addrToaddresses", fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "dag_allow_spends_source_addr_fk") @@ -193,6 +196,7 @@ model dag_spend_transactions { destination_addr String? @db.VarChar allow_spend_ref String? @unique @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar dag_allow_spend dag_allow_spends? @relation(fields: [allow_spend_ref], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "dag_spend_transactions_dag_allow_spends_fk") addresses addresses? @relation(fields: [destination_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "dag_spend_transactions_destination_addr_fk") @@ -211,6 +215,7 @@ model dag_token_locks { round_id String @db.Uuid snapshot_hash String @db.VarChar parent_hash String? @db.VarChar + currency_id String? @db.VarChar addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "dag_token_locks_source_addr_fk") global_snapshot global_snapshots @relation(fields: [snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "dag_token_lock_global_snapshot_fk") dag_token_unlock dag_token_unlocks? @@ -228,6 +233,7 @@ model dag_token_unlocks { updated_at DateTime @default(now()) @db.Timestamp(6) lock_reference_hash String @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar global_snapshot global_snapshots @relation(fields: [snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "dag_token_unlock_global_snapshot_fk") dag_token_lock dag_token_locks @relation(fields: [lock_reference_hash], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "dag_token_unlocks_token_locks_fk") addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "ddag_token_unlocks_address_fk") @@ -320,6 +326,7 @@ model metagraph_allow_spends { round_id String @db.Uuid ordinal BigInt @unique(map: "metagraph_allow_spends_ordinal") snapshot_hash String @db.VarChar + currency_id String? @db.VarChar metagraph_allow_spend_approvers metagraph_allow_spend_approvers[] addresses_metagraph_allow_spends_destination_addrToaddresses addresses @relation("metagraph_allow_spends_destination_addrToaddresses", fields: [destination_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_allow_spends_destination_addr_fk") addresses_metagraph_allow_spends_source_addrToaddresses addresses @relation("metagraph_allow_spends_source_addrToaddresses", fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_allow_spends_source_addr_fk") @@ -443,6 +450,7 @@ model metagraph_spend_transactions { destination_addr String @db.VarChar allow_spend_ref String? @unique @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar addresses addresses @relation(fields: [destination_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_spend_transactions_destination_addr_fk") metagraph_allow_spend metagraph_allow_spends? @relation(fields: [allow_spend_ref], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "mg_spend_transactions_mg_allow_spends_fk") metagraphs metagraphs @relation(fields: [metagraph_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_spend_transactions_metagraph_id_fk") @@ -463,6 +471,7 @@ model metagraph_token_locks { parent_hash String? @db.VarChar round_id String @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar metagraph metagraphs @relation(fields: [metagraph_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_id_fk") addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_token_locks_source_addr_fk") @@ -484,6 +493,7 @@ model metagraph_token_unlocks { metagraph_id String @db.VarChar lock_reference_hash String @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar addresses addresses @relation(fields: [source_addr], references: [address], onDelete: Cascade, onUpdate: NoAction, map: "address_fk") metagraphs metagraphs @relation(fields: [metagraph_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_id_fk") @@ -544,6 +554,7 @@ model dag_expired_spend_transactions { updated_at DateTime @default(now()) @db.Timestamp(6) allow_spend_ref String @unique @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar dag_allow_spend dag_allow_spends @relation(fields: [allow_spend_ref], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "dag_expired_spend_transactions_dag_allow_spends_fk") global_snapshot global_snapshots @relation(fields: [snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: NoAction) @@ -559,6 +570,7 @@ model metagraph_expired_spend_transactions { metagraph_id String @db.VarChar allow_spend_ref String @unique @db.VarChar snapshot_hash String @db.VarChar + currency_id String? @db.VarChar metagraph_allow_spend metagraph_allow_spends @relation(fields: [allow_spend_ref], references: [hash], onDelete: Cascade, onUpdate: NoAction, map: "metagraph_expired_spend_transactions_metagraph_allow_spends_fk") metagraph_snapshot metagraph_snapshots? @relation(fields: [metagraph_id, snapshot_hash], references: [metagraph_id, hash]) diff --git a/prisma/seed.ts b/prisma/seed.ts index c08672a..c082e27 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -157,6 +157,7 @@ export const data_metagraph_snapshots = [ export const data_dag_token_locks = [ { hash: `token-lock-hash-001`, + currency_id: "currency-1", source_addr: data_addresses[0].address, amount: 1200n, ordinal: 1n, @@ -166,6 +167,7 @@ export const data_dag_token_locks = [ }, { hash: `token-lock-hash-002`, + currency_id: "currency-2", source_addr: data_addresses[0].address, amount: 1000n, ordinal: 2n, @@ -175,6 +177,7 @@ export const data_dag_token_locks = [ }, { hash: `token-lock-hash-003`, + currency_id: "currency-3", source_addr: data_addresses[0].address, amount: 1200n, ordinal: 3n, @@ -188,6 +191,7 @@ export const data_dag_token_locks = [ export const data_dag_token_unlocks = [ { hash: "token-unlock-hash-0010", + currency_id: data_dag_token_locks[0].currency_id, source_addr: data_addresses[0].address, amount: 1000n, lock_reference_hash: data_dag_token_locks[0].hash, @@ -199,6 +203,7 @@ export const data_dag_token_unlocks = [ export const data_metagraph_token_locks = [ { hash: "metagraph-token-lock-hash-0010", + currency_id: "currency-1", metagraph_id: data_metagraphs[0].id, source_addr: data_addresses[0].address, amount: 3000n, @@ -209,6 +214,7 @@ export const data_metagraph_token_locks = [ }, { hash: "metagraph-token-lock-hash-0020", + currency_id: "currency-2", metagraph_id: data_metagraphs[0].id, source_addr: data_addresses[0].address, amount: 4000n, @@ -219,6 +225,7 @@ export const data_metagraph_token_locks = [ }, { hash: "metagraph-token-lock-hash-0030", + currency_id: "currency-3", metagraph_id: data_metagraphs[0].id, source_addr: data_addresses[0].address, amount: 4000n, @@ -234,6 +241,7 @@ export const data_metagraph_token_unlocks = [ { hash: "metagraph-token-unlock-hash-001", metagraph_id: data_metagraphs[0].id, + currency_id: data_metagraph_token_locks[0].currency_id, source_addr: data_addresses[0].address, amount: 3000n, lock_reference_hash: data_metagraph_token_locks[0].hash, @@ -242,6 +250,7 @@ export const data_metagraph_token_unlocks = [ { hash: "metagraph-token-unlock-hash-002", metagraph_id: data_metagraphs[0].id, + currency_id: data_metagraph_token_locks[2].currency_id, source_addr: data_addresses[0].address, amount: 3000n, lock_reference_hash: data_metagraph_token_locks[2].hash, @@ -252,6 +261,7 @@ export const data_metagraph_token_unlocks = [ export const data_dag_allow_spends = [ { hash: "allowSpendHash1", + currency_id: "currency-1", source_addr: data_addresses[0].address, destination_addr: data_addresses[1].address, amount: 1000n, @@ -265,6 +275,7 @@ export const data_dag_allow_spends = [ }, { hash: "allowSpendHash2", + currency_id: "currency-2", source_addr: data_addresses[0].address, destination_addr: data_addresses[2].address, amount: 2000n, @@ -278,6 +289,7 @@ export const data_dag_allow_spends = [ }, { hash: "allowSpendHash3", + currency_id: "currency-1", source_addr: data_addresses[2].address, destination_addr: data_addresses[1].address, amount: 300n, @@ -291,6 +303,7 @@ export const data_dag_allow_spends = [ }, { hash: "allowSpendHash4", + currency_id: "currency-2", source_addr: data_addresses[2].address, destination_addr: data_addresses[3].address, amount: 300n, @@ -307,6 +320,7 @@ export const data_dag_allow_spends = [ export const data_dag_spend_transactions = [ { hash: "spendTxHash1", + currency_id: data_dag_allow_spends[0].currency_id, source_addr: data_addresses[0].address, destination_addr: data_addresses[1].address, amount: 1000n, @@ -320,6 +334,7 @@ export const data_dag_spend_transactions = [ export const data_dag_expired_spend_transactions = [ { hash: "expiredSpendTxHash1", + currency_id: data_dag_allow_spends[1].currency_id, source_addr: data_addresses[2].address, amount: 3000n, allow_spend_ref: data_dag_allow_spends[1].hash, @@ -333,6 +348,7 @@ export const data_metagraph_allow_spends = [ { metagraph_id: data_metagraphs[0].id, hash: "metaAllowSpendHash1", + currency_id: "currency-1", source_addr: data_addresses[0].address, destination_addr: data_addresses[1].address, amount: 500n, @@ -347,6 +363,7 @@ export const data_metagraph_allow_spends = [ { metagraph_id: data_metagraphs[0].id, hash: "metaAllowSpendHash2", + currency_id: "currency-2", source_addr: data_addresses[0].address, destination_addr: data_addresses[1].address, amount: 500n, @@ -361,6 +378,7 @@ export const data_metagraph_allow_spends = [ { metagraph_id: data_metagraphs[0].id, hash: "metaAllowSpendHash3", + currency_id: "currency-3", source_addr: data_addresses[2].address, destination_addr: data_addresses[3].address, amount: 750n, @@ -378,6 +396,7 @@ export const data_metagraph_spend_transactions = [ { metagraph_id: data_metagraphs[0].id, hash: "metaSpendTxHash1", + currency_id: data_metagraph_allow_spends[0].currency_id, source_addr: data_addresses[0].address, destination_addr: data_addresses[1].address, amount: 500n, @@ -392,6 +411,7 @@ export const data_metagraph_expired_spend_transactions = [ { metagraph_id: data_metagraphs[0].id, hash: "metaExpiredTxHash1", + currency_id: data_metagraph_allow_spends[2].currency_id, source_addr: data_addresses[2].address, amount: 750n, allow_spend_ref: data_metagraph_allow_spends[2].hash, @@ -610,7 +630,7 @@ export async function seed() { "DROP TABLE delegate_stake_total_rewards_view" ); await prisma.$executeRawUnsafe("DROP TABLE token_lock_total_rewards_view"); - runSqlFromFile("./migrations/20250529/01_add_staking_to_actions.sql"); + runSqlFromFile("./migrations/20250609/02_add_staking_to_actions.sql"); runSqlFromFile("./migrations/20250606/01_total_rewards_view.sql"); } diff --git a/src/handlers/actionsHandler.ts b/src/handlers/actionsHandler.ts index b3fa5b2..c5e78ba 100644 --- a/src/handlers/actionsHandler.ts +++ b/src/handlers/actionsHandler.ts @@ -34,12 +34,12 @@ const transactionFilter = (event): TransactionType[] => { return filtered.length > 0 ? filtered : actionsTransactions; }; -const currencyId = (transaction) => - transaction.metagraph_snapshot?.metagraph_id ?? null; - const actionResponse = (transaction) => ({ type: transaction.transaction_type, - currencyId: currencyId(transaction), + currencyId: + transaction.currency_id ?? + transaction.metagraph_snapshot?.metagraph_id ?? + null, hash: transaction.hash, amount: transaction.amount, source: transaction.source_addr, diff --git a/src/handlers/allowSpendsHandler.ts b/src/handlers/allowSpendsHandler.ts index ed50e8d..0541b2e 100644 --- a/src/handlers/allowSpendsHandler.ts +++ b/src/handlers/allowSpendsHandler.ts @@ -12,7 +12,7 @@ import { includes } from "lodash"; const prisma = new PrismaClient(); const allowSpendResponse = (transaction) => ({ - currencyId: transaction.currencyId, + currencyId: transaction.currency_id, hash: transaction.hash, ordinal: transaction.ordinal, amount: transaction.amount, @@ -33,7 +33,7 @@ const allowSpendResponse = (transaction) => ({ const allowSpendResponses = (txs) => txs.map(allowSpendResponse); const spendTransactionResponse = (transaction) => ({ - currencyId: transaction.currencyId, + currencyId: transaction.currency_id, hash: transaction.hash, amount: transaction.amount, source: transaction.source_addr, @@ -52,7 +52,7 @@ const spendTransactionResponse = (transaction) => ({ const spendTransactionResponses = (txs) => txs.map(spendTransactionResponse); const spendExpiredResponse = (transaction) => ({ - currencyId: transaction.currencyId, + currencyId: transaction.currency_id, hash: transaction.hash, amount: transaction.amount, source: transaction.source_addr, diff --git a/src/handlers/tokenLocksHandler.ts b/src/handlers/tokenLocksHandler.ts index 0cb70e2..51ea845 100644 --- a/src/handlers/tokenLocksHandler.ts +++ b/src/handlers/tokenLocksHandler.ts @@ -11,7 +11,7 @@ import { handleError, respond } from "../response"; const prisma = new PrismaClient(); const commonTokenLockResponse = (transaction) => ({ - currencyId: transaction.currencyId, + currencyId: transaction.currency_id, hash: transaction.hash, amount: transaction.amount, source: transaction.source_addr, @@ -44,7 +44,7 @@ const metagraphTokenLockResponses = (txs) => txs.map(metagraphTokenLockResponse); const commonTokenUnlockResponse = (transaction) => ({ - currencyId: transaction.currencyId, + currencyId: transaction.currency_id, hash: transaction.hash, amount: transaction.amount, source: transaction.source_addr, diff --git a/tests/handlers/tokenLocksHandler.test.ts b/tests/handlers/tokenLocksHandler.test.ts index 46bee50..7270acf 100644 --- a/tests/handlers/tokenLocksHandler.test.ts +++ b/tests/handlers/tokenLocksHandler.test.ts @@ -25,6 +25,7 @@ const validateDagTokenLock = (lock) => { if (!match) return; expect(lock.hash).toBe(match.hash); + expect(lock.currencyId).toBe(match.currency_id); expect(lock.source).toBe(match.source_addr); expect(Number(lock.amount)).toBe(Number(match.amount)); expect(Number(lock.ordinal)).toBe(Number(match.ordinal)); @@ -41,6 +42,7 @@ const validateDagTokenUnlock = (unlock) => { if (!match) return; expect(unlock.hash).toBe(match.hash); + expect(unlock.currencyId).toBe(match.currency_id); expect(unlock.source).toBe(match.source_addr); expect(Number(unlock.amount)).toBe(Number(match.amount)); expect(unlock.tokenLockRef).toBe(match.lock_reference_hash); @@ -55,6 +57,7 @@ const validateMetagraphTokenLock = (lock) => { if (!match) return; expect(lock.hash).toBe(match.hash); + expect(lock.currencyId).toBe(match.currency_id); expect(lock.source).toBe(match.source_addr); expect(Number(lock.amount)).toBe(Number(match.amount)); expect(Number(lock.ordinal)).toBe(Number(match.ordinal)); @@ -73,6 +76,7 @@ const validateMetagraphTokenUnlock = (unlock) => { if (!match) return; expect(unlock.hash).toBe(match.hash); + expect(unlock.currencyId).toBe(match.currency_id); expect(unlock.source).toBe(match.source_addr); expect(Number(unlock.amount)).toBe(Number(match.amount)); expect(unlock.tokenLockRef).toBe(match.lock_reference_hash);