@@ -1416,10 +1416,9 @@ export class PgWriteStore extends PgStore {
1416
1416
INSERT INTO nft_events ${ sql ( nftEventInserts ) }
1417
1417
` ;
1418
1418
if ( tx . canonical && tx . microblock_canonical ) {
1419
- const table = microblock ? sql `nft_custody_unanchored` : sql `nft_custody` ;
1420
1419
await sql `
1421
- INSERT INTO ${ table } ${ sql ( Array . from ( custodyInsertsMap . values ( ) ) ) }
1422
- ON CONFLICT ON CONSTRAINT ${ table } _unique DO UPDATE SET
1420
+ INSERT INTO nft_custody ${ sql ( Array . from ( custodyInsertsMap . values ( ) ) ) }
1421
+ ON CONFLICT ON CONSTRAINT nft_custody_unique DO UPDATE SET
1423
1422
tx_id = EXCLUDED.tx_id,
1424
1423
index_block_hash = EXCLUDED.index_block_hash,
1425
1424
parent_index_block_hash = EXCLUDED.parent_index_block_hash,
@@ -1431,22 +1430,22 @@ export class PgWriteStore extends PgStore {
1431
1430
block_height = EXCLUDED.block_height
1432
1431
WHERE
1433
1432
(
1434
- EXCLUDED.block_height > ${ table } .block_height
1433
+ EXCLUDED.block_height > nft_custody .block_height
1435
1434
)
1436
1435
OR (
1437
- EXCLUDED.block_height = ${ table } .block_height
1438
- AND EXCLUDED.microblock_sequence > ${ table } .microblock_sequence
1436
+ EXCLUDED.block_height = nft_custody .block_height
1437
+ AND EXCLUDED.microblock_sequence > nft_custody .microblock_sequence
1439
1438
)
1440
1439
OR (
1441
- EXCLUDED.block_height = ${ table } .block_height
1442
- AND EXCLUDED.microblock_sequence = ${ table } .microblock_sequence
1443
- AND EXCLUDED.tx_index > ${ table } .tx_index
1440
+ EXCLUDED.block_height = nft_custody .block_height
1441
+ AND EXCLUDED.microblock_sequence = nft_custody .microblock_sequence
1442
+ AND EXCLUDED.tx_index > nft_custody .tx_index
1444
1443
)
1445
1444
OR (
1446
- EXCLUDED.block_height = ${ table } .block_height
1447
- AND EXCLUDED.microblock_sequence = ${ table } .microblock_sequence
1448
- AND EXCLUDED.tx_index = ${ table } .tx_index
1449
- AND EXCLUDED.event_index > ${ table } .event_index
1445
+ EXCLUDED.block_height = nft_custody .block_height
1446
+ AND EXCLUDED.microblock_sequence = nft_custody .microblock_sequence
1447
+ AND EXCLUDED.tx_index = nft_custody .tx_index
1448
+ AND EXCLUDED.event_index > nft_custody .event_index
1450
1449
)
1451
1450
` ;
1452
1451
}
@@ -2515,10 +2514,6 @@ export class PgWriteStore extends PgStore {
2515
2514
AND (index_block_hash = ${ args . indexBlockHash } OR index_block_hash = '\\x'::bytea)
2516
2515
AND tx_id IN ${ sql ( txIds ) }
2517
2516
` ;
2518
- await this . updateNftCustodyFromReOrg ( sql , {
2519
- index_block_hash : args . indexBlockHash ,
2520
- microblocks : args . microblocks ,
2521
- } ) ;
2522
2517
}
2523
2518
2524
2519
// Update unanchored tx count in `chain_tip` table
@@ -2539,54 +2534,46 @@ export class PgWriteStore extends PgStore {
2539
2534
sql : PgSqlClient ,
2540
2535
args : {
2541
2536
index_block_hash : string ;
2542
- microblocks : string [ ] ;
2543
2537
}
2544
2538
) : Promise < void > {
2545
- for ( const table of [ sql `nft_custody` , sql `nft_custody_unanchored` ] ) {
2546
- await sql `
2547
- INSERT INTO ${ table }
2548
- (asset_identifier, value, tx_id, index_block_hash, parent_index_block_hash, microblock_hash,
2549
- microblock_sequence, recipient, event_index, tx_index, block_height)
2550
- (
2551
- SELECT
2552
- DISTINCT ON(asset_identifier, value) asset_identifier, value, tx_id, txs.index_block_hash,
2553
- txs.parent_index_block_hash, txs.microblock_hash, txs.microblock_sequence, recipient,
2554
- nft.event_index, txs.tx_index, txs.block_height
2555
- FROM
2556
- nft_events AS nft
2557
- INNER JOIN
2558
- txs USING (tx_id)
2559
- WHERE
2560
- txs.canonical = true
2561
- AND txs.microblock_canonical = true
2562
- AND nft.canonical = true
2563
- AND nft.microblock_canonical = true
2564
- AND nft.index_block_hash = ${ args . index_block_hash }
2565
- ${
2566
- args . microblocks . length > 0
2567
- ? sql `AND nft.microblock_hash IN ${ sql ( args . microblocks ) } `
2568
- : sql ``
2569
- }
2570
- ORDER BY
2571
- asset_identifier,
2572
- value,
2573
- txs.block_height DESC,
2574
- txs.microblock_sequence DESC,
2575
- txs.tx_index DESC,
2576
- nft.event_index DESC
2577
- )
2578
- ON CONFLICT ON CONSTRAINT ${ table } _unique DO UPDATE SET
2579
- tx_id = EXCLUDED.tx_id,
2580
- index_block_hash = EXCLUDED.index_block_hash,
2581
- parent_index_block_hash = EXCLUDED.parent_index_block_hash,
2582
- microblock_hash = EXCLUDED.microblock_hash,
2583
- microblock_sequence = EXCLUDED.microblock_sequence,
2584
- recipient = EXCLUDED.recipient,
2585
- event_index = EXCLUDED.event_index,
2586
- tx_index = EXCLUDED.tx_index,
2587
- block_height = EXCLUDED.block_height
2588
- ` ;
2589
- }
2539
+ await sql `
2540
+ INSERT INTO nft_custody
2541
+ (asset_identifier, value, tx_id, index_block_hash, parent_index_block_hash, microblock_hash,
2542
+ microblock_sequence, recipient, event_index, tx_index, block_height)
2543
+ (
2544
+ SELECT
2545
+ DISTINCT ON(asset_identifier, value) asset_identifier, value, tx_id, txs.index_block_hash,
2546
+ txs.parent_index_block_hash, txs.microblock_hash, txs.microblock_sequence, recipient,
2547
+ nft.event_index, txs.tx_index, txs.block_height
2548
+ FROM
2549
+ nft_events AS nft
2550
+ INNER JOIN
2551
+ txs USING (tx_id)
2552
+ WHERE
2553
+ txs.canonical = true
2554
+ AND txs.microblock_canonical = true
2555
+ AND nft.canonical = true
2556
+ AND nft.microblock_canonical = true
2557
+ AND nft.index_block_hash = ${ args . index_block_hash }
2558
+ ORDER BY
2559
+ asset_identifier,
2560
+ value,
2561
+ txs.block_height DESC,
2562
+ txs.microblock_sequence DESC,
2563
+ txs.tx_index DESC,
2564
+ nft.event_index DESC
2565
+ )
2566
+ ON CONFLICT ON CONSTRAINT nft_custody_unique DO UPDATE SET
2567
+ tx_id = EXCLUDED.tx_id,
2568
+ index_block_hash = EXCLUDED.index_block_hash,
2569
+ parent_index_block_hash = EXCLUDED.parent_index_block_hash,
2570
+ microblock_hash = EXCLUDED.microblock_hash,
2571
+ microblock_sequence = EXCLUDED.microblock_sequence,
2572
+ recipient = EXCLUDED.recipient,
2573
+ event_index = EXCLUDED.event_index,
2574
+ tx_index = EXCLUDED.tx_index,
2575
+ block_height = EXCLUDED.block_height
2576
+ ` ;
2590
2577
}
2591
2578
2592
2579
/**
@@ -3050,10 +3037,7 @@ export class PgWriteStore extends PgStore {
3050
3037
updatedEntities . markedNonCanonical . nftEvents += nftResult . count ;
3051
3038
}
3052
3039
if ( nftResult . count )
3053
- await this . updateNftCustodyFromReOrg ( sql , {
3054
- index_block_hash : indexBlockHash ,
3055
- microblocks : [ ] ,
3056
- } ) ;
3040
+ await this . updateNftCustodyFromReOrg ( sql , { index_block_hash : indexBlockHash } ) ;
3057
3041
} ) ;
3058
3042
q . enqueue ( async ( ) => {
3059
3043
const pox2Result = await sql `
0 commit comments