Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions prisma/migrations/20250922/01_dag_spend_txs_in_actions_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ UNION ALL
'SpendTransaction', dst.snapshot_hash, gs.ordinal,
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
JOIN global_snapshots gs ON dst.snapshot_hash = gs.hash and currency_id is null

UNION ALL
SELECT
Expand Down Expand Up @@ -74,15 +74,12 @@ JOIN global_snapshots gs
ON ms.global_snapshot_hash = gs.hash
UNION ALL
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, currency_id,
gs.hash AS global_snapshot_hash, gs.ordinal AS global_snapshot_ordinal
FROM metagraph_spend_transactions mst
JOIN metagraph_snapshots ms
ON mst.metagraph_id = ms.metagraph_id AND mst.snapshot_hash = ms.hash AND mst.currency_id is not null
JOIN global_snapshots gs
ON ms.global_snapshot_hash = gs.hash
currency_id, dst.hash, dst.source_addr, dst.amount, dst.created_at, dst.updated_at,
'SpendTransaction', null, null,
dst.destination_addr, null, dst.allow_spend_ref, null,
currency_id, dst.snapshot_hash, gs.ordinal
FROM dag_spend_transactions dst
JOIN global_snapshots gs ON dst.snapshot_hash = gs.hash and currency_id is not null
UNION ALL
SELECT
mest.metagraph_id, mest.hash, mest.source_addr, mest.amount, mest.created_at, mest.updated_at,
Expand Down
7 changes: 3 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ model metagraph_actions_view {
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)
transaction_type String
metagraph_snapshot_hash String @db.VarChar
metagraph_snapshot_ordinal BigInt
metagraph_snapshot_hash String? @db.VarChar
metagraph_snapshot_ordinal BigInt?
global_snapshot_hash String @db.VarChar
global_snapshot_ordinal BigInt
destination_addr String? @db.VarChar
Expand All @@ -68,7 +68,7 @@ model metagraph_actions_view {
metagraph_spend_transaction metagraph_spend_transactions? @relation(fields: [hash], references: [hash], map: "metagraph_spend_transaction_ref")
metagraph_expired_spend_transaction metagraph_expired_spend_transactions? @relation(fields: [hash], references: [hash], map: "metagraph_expired_spend_transaction_ref")
metagraph_fee_transaction metagraph_fee_transactions? @relation(fields: [hash], references: [hash], map: "metagraph_fee_transaction_ref")
metagraph_snapshot metagraph_snapshots @relation(fields: [metagraph_snapshot_hash], references: [hash], onDelete: Cascade, onUpdate: Restrict, map: "metagraph_actions_view_metagraph_snapshot_ref")

}

model addresses {
Expand Down Expand Up @@ -437,7 +437,6 @@ model metagraph_snapshots {
metagraph_token_lock_blocks metagraph_token_lock_blocks[]
metagraph_spend_transactions metagraph_spend_transactions[]
metagraph_expired_spend_transactions metagraph_expired_spend_transactions[]
metagraph_actions_view metagraph_actions_view[]

@@id([metagraph_id, hash], map: "metagraph_snapshot_pk")
@@unique([metagraph_id, ordinal], map: "metagraph_snapshot_unique")
Expand Down
31 changes: 26 additions & 5 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const data_dag_allow_spends = [
},
{
hash: "allowSpendHash5",
currency_id: "currency-2",
currency_id: data_metagraphs[0].id,
source_addr: data_addresses[1].address,
destination_addr: data_addresses[2].address,
amount: 3000n,
Expand All @@ -333,8 +333,8 @@ export const data_dag_allow_spends = [

export const data_dag_spend_transactions = [
{
hash: "spendTxHash1",
currency_id: data_dag_allow_spends[0].currency_id,
hash: "spendTxHash1a",
currency_id: null,
source_addr: data_addresses[0].address,
destination_addr: data_addresses[1].address,
amount: 1000n,
Expand All @@ -344,16 +344,38 @@ export const data_dag_spend_transactions = [
updated_at: new Date("2024-01-05T10:00:00Z"),
},
{
hash: "spendTxHash5",
hash: "spendTxHash1b",
currency_id: data_dag_allow_spends[4].currency_id,
source_addr: data_addresses[2].address,
destination_addr: data_addresses[1].address,
amount: 3000n,
allow_spend_ref: null,
snapshot_hash: data_global_snapshots[2].hash,
created_at: new Date("2024-01-05T10:00:00Z"),
updated_at: new Date("2024-01-05T10:00:00Z"),
},
{
hash: "spendTxHash5a",
currency_id: null,
source_addr: data_addresses[0].address,
destination_addr: data_addresses[1].address,
amount: 1000n,
allow_spend_ref: data_dag_allow_spends[4].hash,
snapshot_hash: data_global_snapshots[2].hash,
created_at: new Date("2024-01-05T10:00:00Z"),
updated_at: new Date("2024-01-05T10:00:00Z"),
},
{
hash: "spendTxHash5b",
currency_id: data_dag_allow_spends[4].currency_id,
source_addr: data_addresses[2].address,
destination_addr: data_addresses[0].address,
amount: 3000n,
allow_spend_ref: null,
snapshot_hash: data_global_snapshots[2].hash,
created_at: new Date("2024-01-05T10:00:00Z"),
updated_at: new Date("2024-01-05T10:00:00Z"),
},
];

export const data_dag_expired_spend_transactions = [
Expand Down Expand Up @@ -701,7 +723,6 @@ export async function seed() {
"DROP TABLE delegate_stake_total_rewards_view"
);
await prisma.$executeRawUnsafe("DROP TABLE token_lock_total_rewards_view");
// runSqlFromFile("./migrations/20250609/02_add_staking_to_actions.sql"); // ?????????????????
runSqlFromFile("./migrations/20250606/01_total_rewards_view.sql");
runSqlFromFile("./migrations/20250922/01_dag_spend_txs_in_actions_view.sql");
}
Expand Down
4 changes: 2 additions & 2 deletions routes/allow-spends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ccyAddressAllowSpends:
method: GET

ccySnapshotSpendTransactions:
handler: src/handlers/allowSpendsHandler.currencySnapshotSpendTransactions
handler: src/handlers/allowSpendsHandler.currencySnapshotUnconfirmedSpendTransactions
events:
- httpApi:
path: /currency/{metagraph_id}/snapshots/{hash_or_ordinal}/spend-transactions
Expand All @@ -125,7 +125,7 @@ ccySpendTransactions:
method: GET

ccySpendTransaction:
handler: src/handlers/allowSpendsHandler.currencySpendTransaction
handler: src/handlers/allowSpendsHandler.currencyUnconfirmedSpendTransaction
events:
- httpApi:
path: /currency/{metagraph_id}/spend-transactions/{hash}
Expand Down
24 changes: 14 additions & 10 deletions src/handlers/actionsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const globalSnapshotActions = async (
const { term } = event.pathParameters || {};
const filter = extractHashOrdinal(term);

const dbFilter = filter.hash
? { global_snapshot_hash: filter.hash }
: { global_snapshot_ordinal: filter.ordinal };

const selectedTransactions = transactionFilter(event);

return await paginatedQuery(
Expand All @@ -88,7 +92,7 @@ export const globalSnapshotActions = async (
hashCursor,
{
where: {
global_snapshot: filter,
...dbFilter,
transaction_type: { in: selectedTransactions },
},
orderBy: [{ created_at: "desc" }, { hash: "desc" }],
Expand Down Expand Up @@ -142,7 +146,7 @@ export const currencyActions = async (
hashCursor,
{
where: {
OR: [{ metagraph_id }, { currency_id: metagraph_id }],
metagraph_id,
transaction_type: { in: selectedTransactions },
},
orderBy: [{ created_at: "desc" }, { hash: "desc" }],
Expand All @@ -161,17 +165,19 @@ export const currencySnapshotActions = async (
try {
const { metagraph_id, term } = event.pathParameters || {};
const filter = extractHashOrdinal(term);
const dbFilter = filter.hash
? { metagraph_snapshot_hash: filter.hash }
: { metagraph_snapshot_ordinal: filter.ordinal };

const selectedTransactions = transactionFilter(event);

return await paginatedQuery(
extractPagination(event),
hashCursor,
hashCursor,
{
where: {
OR: [{ metagraph_id }, { currency_id: metagraph_id }],
metagraph_snapshot: { ...filter },
metagraph_id,
...dbFilter,
transaction_type: { in: selectedTransactions },
},
orderBy: [{ created_at: "desc" }, { hash: "desc" }],
Expand All @@ -198,11 +204,9 @@ export const currencyAddressActions = async (
hashCursor,
{
where: {
AND: [
{ OR: [{ metagraph_id }, { currency_id: metagraph_id }] },
{ OR: [{ source_addr: address }, { destination_addr: address }] },
{ transaction_type: { in: selectedTransactions } },
],
metagraph_id,
OR: [{ source_addr: address }, { destination_addr: address }],
transaction_type: { in: selectedTransactions },
},
orderBy: [{ created_at: "desc" }, { hash: "desc" }],
},
Expand Down
Loading