Skip to content

Commit

Permalink
fix: allow multiple transfers of an inscription in one block (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jul 7, 2023
1 parent d6513be commit bc545f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
6 changes: 1 addition & 5 deletions migrations/1677284495299_locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ export function up(pgm: MigrationBuilder): void {
'locations_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'locations',
'locations_genesis_id_block_height_unique',
'UNIQUE(genesis_id, block_height)'
);
pgm.createConstraint('locations', 'locations_output_offset_unique', 'UNIQUE(output, "offset")');
pgm.createIndex('locations', ['genesis_id']);
pgm.createIndex('locations', ['block_height']);
pgm.createIndex('locations', ['block_hash']);
Expand Down
13 changes: 7 additions & 6 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,13 @@ export class PgStore extends BasePgStore {
};
await sql<DbLocation[]>`
INSERT INTO locations ${sql(location)}
ON CONFLICT ON CONSTRAINT locations_genesis_id_block_height_unique DO UPDATE SET
ON CONFLICT ON CONSTRAINT locations_output_offset_unique DO UPDATE SET
inscription_id = EXCLUDED.inscription_id,
genesis_id = EXCLUDED.genesis_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,
timestamp = EXCLUDED.timestamp
`;
Expand Down Expand Up @@ -681,12 +681,13 @@ export class PgStore extends BasePgStore {
};
await this.sql`
INSERT INTO locations ${this.sql(location)}
ON CONFLICT ON CONSTRAINT locations_genesis_id_block_height_unique DO UPDATE SET
ON CONFLICT ON CONSTRAINT locations_output_offset_unique DO UPDATE SET
inscription_id = EXCLUDED.inscription_id,
genesis_id = EXCLUDED.genesis_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,
timestamp = EXCLUDED.timestamp
`;
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

0 comments on commit bc545f0

Please sign in to comment.