@@ -1416,10 +1416,9 @@ export class PgWriteStore extends PgStore {
14161416 INSERT INTO nft_events ${ sql ( nftEventInserts ) }
14171417 ` ;
14181418 if ( tx . canonical && tx . microblock_canonical ) {
1419- const table = microblock ? sql `nft_custody_unanchored` : sql `nft_custody` ;
14201419 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
14231422 tx_id = EXCLUDED.tx_id,
14241423 index_block_hash = EXCLUDED.index_block_hash,
14251424 parent_index_block_hash = EXCLUDED.parent_index_block_hash,
@@ -1431,22 +1430,22 @@ export class PgWriteStore extends PgStore {
14311430 block_height = EXCLUDED.block_height
14321431 WHERE
14331432 (
1434- EXCLUDED.block_height > ${ table } .block_height
1433+ EXCLUDED.block_height > nft_custody .block_height
14351434 )
14361435 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
14391438 )
14401439 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
14441443 )
14451444 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
14501449 )
14511450 ` ;
14521451 }
@@ -2515,10 +2514,6 @@ export class PgWriteStore extends PgStore {
25152514 AND (index_block_hash = ${ args . indexBlockHash } OR index_block_hash = '\\x'::bytea)
25162515 AND tx_id IN ${ sql ( txIds ) }
25172516 ` ;
2518- await this . updateNftCustodyFromReOrg ( sql , {
2519- index_block_hash : args . indexBlockHash ,
2520- microblocks : args . microblocks ,
2521- } ) ;
25222517 }
25232518
25242519 // Update unanchored tx count in `chain_tip` table
@@ -2539,54 +2534,46 @@ export class PgWriteStore extends PgStore {
25392534 sql : PgSqlClient ,
25402535 args : {
25412536 index_block_hash : string ;
2542- microblocks : string [ ] ;
25432537 }
25442538 ) : 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+ ` ;
25902577 }
25912578
25922579 /**
@@ -3050,10 +3037,7 @@ export class PgWriteStore extends PgStore {
30503037 updatedEntities . markedNonCanonical . nftEvents += nftResult . count ;
30513038 }
30523039 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 } ) ;
30573041 } ) ;
30583042 q . enqueue ( async ( ) => {
30593043 const pox2Result = await sql `
0 commit comments