Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow multiple transfers per inscription per block #131

Merged
merged 1 commit into from
Jul 7, 2023
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
18 changes: 18 additions & 0 deletions migrations/1688739818725_change-location-constraint.ts
Original file line number Diff line number Diff line change
@@ -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)'
);
}
27 changes: 15 additions & 12 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
);
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -648,12 +648,12 @@ export class PgStore extends BasePgStore {
};
await sql<DbLocation[]>`
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading