Skip to content

Commit

Permalink
feat: support ordinals jubilee, ignore classic cursed inscriptions fo…
Browse files Browse the repository at this point in the history
…r BRC-20 (#286)

* fix: new schema

* fix: new column

* fix: ignore classic cursed
  • Loading branch information
rafaelcr authored Jan 4, 2024
1 parent d450bbf commit fde705c
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 94 deletions.
18 changes: 18 additions & 0 deletions migrations/1704341578275_jubilee-numbers.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.addColumn('inscriptions', {
classic_number: {
type: 'bigint',
},
});
pgm.sql(`UPDATE inscriptions SET classic_number = number`);
pgm.alterColumn('inscriptions', 'classic_number', { notNull: true });
}

export function down(pgm: MigrationBuilder): void {
pgm.dropColumn('inscriptions', 'classic_number');
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@hirosystems/api-toolkit": "^1.3.1",
"@hirosystems/chainhook-client": "^1.4.2",
"@hirosystems/chainhook-client": "^1.5.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^10.0.4",
"@semantic-release/git": "^10.0.1",
Expand Down
7 changes: 6 additions & 1 deletion src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export class Brc20PgStore extends BasePgStoreModule {
const pointer = args.pointers[i];
if (parseInt(pointer.block_height) < BRC20_GENESIS_BLOCK) continue;
if (reveal.inscription) {
if (reveal.location.transfer_type != DbLocationTransferType.transferred) continue;
if (
reveal.inscription.classic_number < 0 ||
reveal.inscription.number < 0 ||
reveal.location.transfer_type != DbLocationTransferType.transferred
)
continue;
const brc20 = brc20FromInscriptionContent(
hexToBuffer(reveal.inscription.content as string).toString('utf-8')
);
Expand Down
3 changes: 2 additions & 1 deletion src/pg/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ function revealInsertFromOrdhookInscriptionRevealed(args: {
mime_type: contentType.split(';')[0],
content_type: contentType,
content_length: args.reveal.content_length,
number: args.reveal.inscription_number,
number: args.reveal.inscription_number.jubilee,
classic_number: args.reveal.inscription_number.classic,
content: removeNullBytes(args.reveal.content_bytes),
fee: args.reveal.inscription_fee.toString(),
curse_type: args.reveal.curse_type ? JSON.stringify(args.reveal.curse_type) : null,
Expand Down
1 change: 1 addition & 0 deletions src/pg/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const LOCATIONS_COLUMNS = [
export type DbInscriptionInsert = {
genesis_id: string;
number: number;
classic_number: number;
mime_type: string;
content_type: string;
content_length: number;
Expand Down
40 changes: 40 additions & 0 deletions tests/brc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('BRC-20', () => {
const insert: DbInscriptionInsert = {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
number: 0,
classic_number: 0,
mime_type: 'application/json',
content_type: 'application/json',
content_length: content.length,
Expand Down Expand Up @@ -116,6 +117,7 @@ describe('BRC-20', () => {
const insert: DbInscriptionInsert = {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
number: 0,
classic_number: 0,
mime_type: 'foo/bar',
content_type: 'foo/bar;x=1',
content_length: content.length,
Expand Down Expand Up @@ -144,6 +146,7 @@ describe('BRC-20', () => {
const insert: DbInscriptionInsert = {
genesis_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
number: 0,
classic_number: 0,
mime_type: 'application/json',
content_type: 'application/json',
content_length: content.length,
Expand Down Expand Up @@ -695,6 +698,43 @@ describe('BRC-20', () => {
},
]);
});

test('ignores deploy from classic cursed inscription', async () => {
await db.updateInscriptions(
new TestChainhookPayloadBuilder()
.apply()
.block({
height: BRC20_GENESIS_BLOCK,
hash: '00000000000000000002a90330a99f67e3f01eb2ce070b45930581e82fb7a91d',
})
.transaction({
hash: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
})
.inscriptionRevealed(
brc20Reveal({
json: {
p: 'brc-20',
op: 'deploy',
tick: 'PEPE',
max: '21000000',
},
number: 0,
classic_number: -1,
tx_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dc',
address: 'bc1p3cyx5e2hgh53w7kpxcvm8s4kkega9gv5wfw7c4qxsvxl0u8x834qf0u2td',
})
)
.build()
);
const response1 = await fastify.inject({
method: 'GET',
url: `/ordinals/brc-20/tokens?ticker=PEPE`,
});
expect(response1.statusCode).toBe(200);
const responseJson1 = response1.json();
expect(responseJson1.total).toBe(0);
expect(responseJson1.results).toHaveLength(0);
});
});

describe('mint', () => {
Expand Down
35 changes: 28 additions & 7 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: 0,
inscription_number: {
classic: 0,
jubilee: 0,
},
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
Expand Down Expand Up @@ -160,7 +163,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'text/plain',
content_length: 5,
inscription_number: 0,
inscription_number: {
classic: 0,
jubilee: 0,
},
inscription_fee: 705,
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
inscription_output_value: 10000,
Expand All @@ -185,7 +191,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: 1,
inscription_number: {
classic: 1,
jubilee: 1,
},
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
Expand Down Expand Up @@ -257,7 +266,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'text/plain',
content_length: 5,
inscription_number: 0,
inscription_number: {
classic: 0,
jubilee: 0,
},
inscription_fee: 705,
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
inscription_output_value: 10000,
Expand Down Expand Up @@ -301,7 +313,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: 1,
inscription_number: {
classic: 1,
jubilee: 1,
},
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
Expand Down Expand Up @@ -337,7 +352,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'text/plain',
content_length: 5,
inscription_number: 0,
inscription_number: {
classic: 0,
jubilee: 0,
},
inscription_fee: 705,
inscription_id: '9f4a9b73b0713c5da01c0a47f97c6c001af9028d6bdd9e264dfacbc4e6790201i0',
inscription_output_value: 10000,
Expand Down Expand Up @@ -381,7 +399,10 @@ describe('ETag cache', () => {
content_bytes: '0x48656C6C6F',
content_type: 'image/png',
content_length: 5,
inscription_number: 1,
inscription_number: {
classic: 1,
jubilee: 1,
},
inscription_fee: 2805,
inscription_id: '38c46a8bf7ec90bc7f6b797e7dc84baa97f4e5fd4286b92fe1b50176d03b18dci0',
inscription_output_value: 10000,
Expand Down
6 changes: 5 additions & 1 deletion tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function rollBack(payload: Payload) {
export function brc20Reveal(args: {
json: Brc20;
number: number;
classic_number?: number;
address: string;
tx_id: string;
}): BitcoinInscriptionRevealed {
Expand All @@ -119,7 +120,10 @@ export function brc20Reveal(args: {
content_bytes: `0x${content.toString('hex')}`,
content_type: 'text/plain;charset=utf-8',
content_length: content.length,
inscription_number: args.number,
inscription_number: {
jubilee: args.number,
classic: args.classic_number ?? args.number,
},
inscription_fee: 2000,
inscription_id: `${args.tx_id}i0`,
inscription_output_value: 10000,
Expand Down
Loading

0 comments on commit fde705c

Please sign in to comment.