diff --git a/migrations/1688739818725_change-location-constraint.ts b/migrations/1688739818725_change-location-constraint.ts new file mode 100644 index 00000000..d759a166 --- /dev/null +++ b/migrations/1688739818725_change-location-constraint.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate'; + +export const shorthands: ColumnDefinitions | undefined = undefined; + +export function up(pgm: MigrationBuilder): void { + pgm.dropConstraint('locations', 'locations_inscription_id_block_height_unique'); + pgm.createConstraint('locations', 'locations_output_offset_unique', 'UNIQUE(output, "offset")'); +} + +export function down(pgm: MigrationBuilder): void { + pgm.dropConstraint('locations', 'locations_output_offset_unique'); + pgm.createConstraint( + 'locations', + 'locations_inscription_id_block_height_unique', + 'UNIQUE(inscription_id, block_height)' + ); +} diff --git a/src/pg/pg-store.ts b/src/pg/pg-store.ts index ce906b90..8a7101f0 100644 --- a/src/pg/pg-store.ts +++ b/src/pg/pg-store.ts @@ -205,7 +205,7 @@ export class PgStore extends BasePgStore { } else { logger.warn( { block_height, genesis_id: transfer.inscription_id }, - `PgStore ignoring transfer for an inscription that does not exist` + `PgStore ignoring transfer for an inscription that does not exist (${transfer.inscription_id})` ); } } @@ -570,7 +570,7 @@ export class PgStore extends BasePgStore { SELECT id FROM inscriptions WHERE number = ${args.inscription.number} `; if (prevInscription.count !== 0) { - logger.warn( + logger.info( { block_height: args.location.block_height, genesis_id: args.inscription.genesis_id, @@ -583,7 +583,7 @@ export class PgStore extends BasePgStore { // Is it a cursed inscription? const maxCursed = await this.getMaxCursedInscriptionNumber(); if (maxCursed !== undefined && maxCursed - 1 !== args.inscription.number) { - logger.warn( + logger.info( { block_height: args.location.block_height, genesis_id: args.inscription.genesis_id, @@ -594,7 +594,7 @@ export class PgStore extends BasePgStore { } else { const maxNumber = await this.getMaxInscriptionNumber(); if (maxNumber !== undefined && maxNumber + 1 !== args.inscription.number) { - logger.warn( + logger.info( { block_height: args.location.block_height, genesis_id: args.inscription.genesis_id, @@ -607,7 +607,7 @@ export class PgStore extends BasePgStore { SELECT id FROM locations WHERE sat_ordinal = ${args.location.sat_ordinal} `; if (dup.count > 0) { - logger.warn( + logger.info( { block_height: args.location.block_height, genesis_id: args.inscription.genesis_id, @@ -648,12 +648,12 @@ export class PgStore extends BasePgStore { }; await sql` INSERT INTO locations ${sql(location)} - ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_unique DO UPDATE SET + ON CONFLICT ON CONSTRAINT locations_output_offset_unique DO UPDATE SET + inscription_id = EXCLUDED.inscription_id, + block_height = EXCLUDED.block_height, block_hash = EXCLUDED.block_hash, tx_id = EXCLUDED.tx_id, address = EXCLUDED.address, - output = EXCLUDED.output, - "offset" = EXCLUDED.offset, value = EXCLUDED.value, sat_ordinal = EXCLUDED.sat_ordinal, sat_rarity = EXCLUDED.sat_rarity, @@ -702,12 +702,12 @@ export class PgStore extends BasePgStore { }; await this.sql` INSERT INTO locations ${this.sql(location)} - ON CONFLICT ON CONSTRAINT locations_inscription_id_block_height_unique DO UPDATE SET + ON CONFLICT ON CONSTRAINT locations_output_offset_unique DO UPDATE SET + inscription_id = EXCLUDED.inscription_id, + block_height = EXCLUDED.block_height, block_hash = EXCLUDED.block_hash, tx_id = EXCLUDED.tx_id, address = EXCLUDED.address, - output = EXCLUDED.output, - "offset" = EXCLUDED.offset, value = EXCLUDED.value, sat_ordinal = EXCLUDED.sat_ordinal, sat_rarity = EXCLUDED.sat_rarity, @@ -731,7 +731,10 @@ export class PgStore extends BasePgStore { SELECT id FROM inscriptions WHERE genesis_id = ${args.genesis_id} `; if (inscription.count === 0) { - logger.warn(args, `PgStore ignoring rollback for a transfer that does not exist`); + logger.warn( + args, + `PgStore ignoring rollback for a transfer that does not exist (${args.genesis_id})` + ); return; } inscription_id = inscription[0].id; diff --git a/tests/cache.test.ts b/tests/cache.test.ts index 5755c93c..09e6bafb 100644 --- a/tests/cache.test.ts +++ b/tests/cache.test.ts @@ -153,15 +153,15 @@ describe('ETag cache', () => { const block3 = new TestChainhookPayloadBuilder() .apply() .block({ height: 775618 }) - .transaction({ hash: '0x38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc' }) + .transaction({ hash: 'ae9d273a10e899f0d2cad47ee2b0e77ab8a9addd9dd5bb5e4b03d6971c060d52' }) .inscriptionTransferred({ inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0', updated_address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td', satpoint_pre_transfer: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', satpoint_post_transfer: - '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc:0:0', - post_transfer_output_value: 102, + 'ae9d273a10e899f0d2cad47ee2b0e77ab8a9addd9dd5bb5e4b03d6971c060d52:0:0', + post_transfer_output_value: 100, }) .build(); await db.updateInscriptions(block3);