@@ -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
}
@@ -1781,6 +1780,12 @@ export class PgWriteStore extends PgStore {
1781
1780
} ) ;
1782
1781
}
1783
1782
1783
+ async updateBurnChainBlockHeight ( args : { blockHeight : number } ) : Promise < void > {
1784
+ await this . sql `
1785
+ UPDATE chain_tip SET burn_block_height = GREATEST(${ args . blockHeight } , burn_block_height)
1786
+ ` ;
1787
+ }
1788
+
1784
1789
async insertSlotHoldersBatch ( sql : PgSqlClient , slotHolders : DbRewardSlotHolder [ ] ) : Promise < void > {
1785
1790
const slotValues : RewardSlotHolderInsertValues [ ] = slotHolders . map ( slot => ( {
1786
1791
canonical : true ,
@@ -2515,10 +2520,6 @@ export class PgWriteStore extends PgStore {
2515
2520
AND (index_block_hash = ${ args . indexBlockHash } OR index_block_hash = '\\x'::bytea)
2516
2521
AND tx_id IN ${ sql ( txIds ) }
2517
2522
` ;
2518
- await this . updateNftCustodyFromReOrg ( sql , {
2519
- index_block_hash : args . indexBlockHash ,
2520
- microblocks : args . microblocks ,
2521
- } ) ;
2522
2523
}
2523
2524
2524
2525
// Update unanchored tx count in `chain_tip` table
@@ -2539,54 +2540,46 @@ export class PgWriteStore extends PgStore {
2539
2540
sql : PgSqlClient ,
2540
2541
args : {
2541
2542
index_block_hash : string ;
2542
- microblocks : string [ ] ;
2543
2543
}
2544
2544
) : 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
- }
2545
+ await sql `
2546
+ INSERT INTO nft_custody
2547
+ (asset_identifier, value, tx_id, index_block_hash, parent_index_block_hash, microblock_hash,
2548
+ microblock_sequence, recipient, event_index, tx_index, block_height)
2549
+ (
2550
+ SELECT
2551
+ DISTINCT ON(asset_identifier, value) asset_identifier, value, tx_id, txs.index_block_hash,
2552
+ txs.parent_index_block_hash, txs.microblock_hash, txs.microblock_sequence, recipient,
2553
+ nft.event_index, txs.tx_index, txs.block_height
2554
+ FROM
2555
+ nft_events AS nft
2556
+ INNER JOIN
2557
+ txs USING (tx_id)
2558
+ WHERE
2559
+ txs.canonical = true
2560
+ AND txs.microblock_canonical = true
2561
+ AND nft.canonical = true
2562
+ AND nft.microblock_canonical = true
2563
+ AND nft.index_block_hash = ${ args . index_block_hash }
2564
+ ORDER BY
2565
+ asset_identifier,
2566
+ value,
2567
+ txs.block_height DESC,
2568
+ txs.microblock_sequence DESC,
2569
+ txs.tx_index DESC,
2570
+ nft.event_index DESC
2571
+ )
2572
+ ON CONFLICT ON CONSTRAINT nft_custody_unique DO UPDATE SET
2573
+ tx_id = EXCLUDED.tx_id,
2574
+ index_block_hash = EXCLUDED.index_block_hash,
2575
+ parent_index_block_hash = EXCLUDED.parent_index_block_hash,
2576
+ microblock_hash = EXCLUDED.microblock_hash,
2577
+ microblock_sequence = EXCLUDED.microblock_sequence,
2578
+ recipient = EXCLUDED.recipient,
2579
+ event_index = EXCLUDED.event_index,
2580
+ tx_index = EXCLUDED.tx_index,
2581
+ block_height = EXCLUDED.block_height
2582
+ ` ;
2590
2583
}
2591
2584
2592
2585
/**
@@ -3050,10 +3043,7 @@ export class PgWriteStore extends PgStore {
3050
3043
updatedEntities . markedNonCanonical . nftEvents += nftResult . count ;
3051
3044
}
3052
3045
if ( nftResult . count )
3053
- await this . updateNftCustodyFromReOrg ( sql , {
3054
- index_block_hash : indexBlockHash ,
3055
- microblocks : [ ] ,
3056
- } ) ;
3046
+ await this . updateNftCustodyFromReOrg ( sql , { index_block_hash : indexBlockHash } ) ;
3057
3047
} ) ;
3058
3048
q . enqueue ( async ( ) => {
3059
3049
const pox2Result = await sql `
0 commit comments