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

feat!: support reinscription transfers #348

Merged
merged 32 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
07a512b
chore: progress
rafaelcr Apr 18, 2024
719b4ec
feat: new apply
rafaelcr Apr 21, 2024
0f85e8a
fix: minted supply
rafaelcr Apr 21, 2024
03adaf5
fix: track tx counts
rafaelcr Apr 22, 2024
2b260ce
feat: rollbacks
rafaelcr Apr 22, 2024
c052d33
fix: transfer rollbacks
rafaelcr Apr 23, 2024
8c8b6a5
fix: activity addresses
rafaelcr Apr 23, 2024
13f95d5
fix: multiple transfer test
rafaelcr Apr 23, 2024
0e40d32
fix: holders
rafaelcr Apr 23, 2024
1944115
fix: operation indexes
rafaelcr Apr 23, 2024
e20a466
chore: draft
rafaelcr Apr 23, 2024
5be3252
fix: style
rafaelcr Apr 23, 2024
00baa7d
Merge branch 'feat/ordhook-brc20' into fix/reinscription
rafaelcr Apr 23, 2024
f7e868d
chore: optimize migrations
rafaelcr Apr 23, 2024
c19931a
chore: merge
rafaelcr Apr 23, 2024
df60904
fix: initial inserts
rafaelcr Apr 23, 2024
7f7b4f4
fix: get inscription endpoint
rafaelcr Apr 23, 2024
0ae8e91
fix: rollback
rafaelcr Apr 23, 2024
cd7e75a
fix: ordhook tests passing
rafaelcr Apr 23, 2024
12174cd
chore: logging
rafaelcr Apr 23, 2024
783625e
fix: recursion refs
rafaelcr Apr 23, 2024
863ee24
fix: current location comparison
rafaelcr Apr 24, 2024
65bd4f0
fix: transfers table
rafaelcr Apr 24, 2024
30513a8
test: sat reinscription transfers
rafaelcr Apr 24, 2024
663fb27
fix: start applying counts
rafaelcr Apr 25, 2024
aad72f7
fix: tests
rafaelcr Apr 25, 2024
1e677c0
fix: all api tests passing
rafaelcr Apr 25, 2024
b261b2a
test: transfers per block reinscription
rafaelcr Apr 26, 2024
b91d436
test: address transfer counts
rafaelcr Apr 26, 2024
54d1bd4
fix: brc20 tests
rafaelcr Apr 26, 2024
52bb379
chore: refactor block caches
rafaelcr Apr 26, 2024
576f08a
chore: clean unused exports
rafaelcr Apr 26, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- name: Lint Prettier
run: npm run lint:prettier

- name: Lint Unused Exports
run: npm run lint:unused-exports

test:
strategy:
fail-fast: false
Expand Down
22 changes: 22 additions & 0 deletions migrations/1676395230925_satoshis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* 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.createTable('satoshis', {
ordinal_number: {
type: 'numeric',
primaryKey: true,
},
rarity: {
type: 'text',
notNull: true,
},
coinbase_height: {
type: 'bigint',
notNull: true,
},
});
pgm.createIndex('satoshis', ['rarity']);
}
50 changes: 37 additions & 13 deletions migrations/1676395230930_inscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('inscriptions', {
id: {
type: 'bigserial',
primaryKey: true,
},
genesis_id: {
type: 'text',
primaryKey: true,
},
ordinal_number: {
type: 'numeric',
notNull: true,
},
number: {
type: 'bigint',
notNull: true,
},
sat_ordinal: {
type: 'numeric',
classic_number: {
type: 'bigint',
notNull: true,
},
sat_rarity: {
type: 'text',
block_height: {
type: 'bigint',
notNull: true,
},
sat_coinbase_height: {
tx_index: {
type: 'bigint',
notNull: true,
},
address: {
type: 'text',
},
mime_type: {
type: 'text',
notNull: true,
Expand All @@ -52,17 +55,38 @@ export function up(pgm: MigrationBuilder): void {
curse_type: {
type: 'text',
},
recursive: {
type: 'boolean',
default: false,
},
metadata: {
type: 'text',
},
parent: {
type: 'text',
},
timestamp: {
type: 'timestamptz',
notNull: true,
},
updated_at: {
type: 'timestamptz',
default: pgm.func('(NOW())'),
notNull: true,
},
});
pgm.createConstraint('inscriptions', 'inscriptions_number_unique', 'UNIQUE(number)');
pgm.createIndex('inscriptions', ['genesis_id']);
pgm.createConstraint(
'inscriptions',
'inscriptions_ordinal_number_fk',
'FOREIGN KEY(ordinal_number) REFERENCES satoshis(ordinal_number) ON DELETE CASCADE'
);
pgm.createIndex('inscriptions', ['mime_type']);
pgm.createIndex('inscriptions', ['sat_ordinal']);
pgm.createIndex('inscriptions', ['sat_rarity']);
pgm.createIndex('inscriptions', ['sat_coinbase_height']);
pgm.createIndex('inscriptions', ['recursive']);
pgm.createIndex('inscriptions', [
{ name: 'block_height', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
]);
pgm.createIndex('inscriptions', ['address']);
pgm.createIndex('inscriptions', [{ name: 'updated_at', sort: 'DESC' }]);
}
41 changes: 18 additions & 23 deletions migrations/1677284495299_locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@ import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createType('transfer_type', ['transferred', 'spent_in_fees', 'burnt']);
pgm.createTable('locations', {
id: {
type: 'bigserial',
primaryKey: true,
},
inscription_id: {
type: 'bigint',
},
genesis_id: {
type: 'text',
ordinal_number: {
type: 'numeric',
notNull: true,
},
block_height: {
type: 'bigint',
notNull: true,
},
block_hash: {
type: 'text',
tx_index: {
type: 'bigint',
notNull: true,
},
tx_id: {
type: 'text',
notNull: true,
},
tx_index: {
type: 'bigint',
block_hash: {
type: 'text',
notNull: true,
},
address: {
Expand All @@ -51,26 +45,27 @@ export function up(pgm: MigrationBuilder): void {
value: {
type: 'numeric',
},
transfer_type: {
type: 'transfer_type',
notNull: true,
},
timestamp: {
type: 'timestamptz',
notNull: true,
},
});
pgm.createConstraint('locations', 'locations_pkey', {
primaryKey: ['ordinal_number', 'block_height', 'tx_index'],
});
pgm.createConstraint(
'locations',
'locations_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
'locations_ordinal_number_fk',
'FOREIGN KEY(ordinal_number) REFERENCES satoshis(ordinal_number) ON DELETE CASCADE'
);
pgm.createConstraint('locations', 'locations_output_offset_unique', 'UNIQUE(output, "offset")');
pgm.createIndex('locations', ['inscription_id']);
pgm.createIndex('locations', ['output', 'offset']);
pgm.createIndex('locations', ['timestamp']);
pgm.createIndex('locations', [
'genesis_id',
{ name: 'block_height', sort: 'DESC' },
{ name: 'tx_index', sort: 'DESC' },
]);
pgm.createIndex('locations', ['block_height']);
pgm.createIndex('locations', ['block_hash']);
pgm.createIndex('locations', ['address']);
pgm.createIndex('locations', ['timestamp']);
pgm.createIndex('locations', ['prev_output']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('current_locations', {
inscription_id: {
type: 'bigint',
notNull: true,
},
location_id: {
type: 'bigint',
ordinal_number: {
type: 'numeric',
notNull: true,
},
block_height: {
Expand All @@ -27,10 +23,14 @@ export function up(pgm: MigrationBuilder): void {
});
pgm.createConstraint(
'current_locations',
'current_locations_inscription_id_unique',
'UNIQUE(inscription_id)'
'current_locations_locations_fk',
'FOREIGN KEY(ordinal_number, block_height, tx_index) REFERENCES locations(ordinal_number, block_height, tx_index) ON DELETE CASCADE'
);
pgm.createConstraint(
'locations',
'locations_satoshis_fk',
'FOREIGN KEY(ordinal_number) REFERENCES satoshis(ordinal_number) ON DELETE CASCADE'
);
pgm.createIndex('current_locations', ['location_id']);
pgm.createIndex('current_locations', ['block_height']);
pgm.createIndex('current_locations', ['ordinal_number'], { unique: true });
pgm.createIndex('current_locations', ['address']);
}
52 changes: 52 additions & 0 deletions migrations/1677284495501_inscription-transfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* 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.createTable('inscription_transfers', {
genesis_id: {
type: 'text',
notNull: true,
},
number: {
type: 'bigint',
notNull: true,
},
ordinal_number: {
type: 'numeric',
notNull: true,
},
block_height: {
type: 'bigint',
notNull: true,
},
tx_index: {
type: 'bigint',
notNull: true,
},
block_hash: {
type: 'text',
notNull: true,
},
block_transfer_index: {
type: 'int',
notNull: true,
},
});
pgm.createConstraint('inscription_transfers', 'inscription_transfers_pkey', {
primaryKey: ['block_height', 'block_transfer_index'],
});
pgm.createConstraint(
'inscription_transfers',
'inscription_transfers_locations_fk',
'FOREIGN KEY(ordinal_number, block_height, tx_index) REFERENCES locations(ordinal_number, block_height, tx_index) ON DELETE CASCADE'
);
pgm.createConstraint(
'inscription_transfers',
'inscription_transfers_satoshis_fk',
'FOREIGN KEY(ordinal_number) REFERENCES satoshis(ordinal_number) ON DELETE CASCADE'
);
pgm.createIndex('inscription_transfers', ['genesis_id']);
pgm.createIndex('inscription_transfers', ['number']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.dropMaterializedView('chain_tip');
pgm.createTable('chain_tip', {
id: {
type: 'bool',
Expand All @@ -19,20 +18,9 @@ export function up(pgm: MigrationBuilder): void {
},
});
pgm.addConstraint('chain_tip', 'chain_tip_one_row', 'CHECK(id)');
pgm.sql(`
INSERT INTO chain_tip (block_height) (
SELECT GREATEST(MAX(block_height), 767430) AS block_height FROM locations
)
`);
pgm.sql(`INSERT INTO chain_tip DEFAULT VALUES`);
}

export function down(pgm: MigrationBuilder): void {
pgm.dropTable('chain_tip');
pgm.createMaterializedView(
'chain_tip',
{ data: true },
// Set block height 767430 (inscription #0 genesis) as default.
`SELECT GREATEST(MAX(block_height), 767430) AS block_height FROM locations`
);
pgm.createIndex('chain_tip', ['block_height'], { unique: true });
}
25 changes: 25 additions & 0 deletions migrations/1677284495992_inscription-recursions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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.createTable('inscription_recursions', {
genesis_id: {
type: 'text',
notNull: true,
},
ref_genesis_id: {
type: 'text',
notNull: true,
},
});
pgm.createConstraint('inscription_recursions', 'inscription_recursions_pkey', {
primaryKey: ['genesis_id', 'ref_genesis_id'],
});
pgm.createConstraint(
'inscription_recursions',
'inscription_recursions_genesis_id_fk',
'FOREIGN KEY(genesis_id) REFERENCES inscriptions(genesis_id) ON DELETE CASCADE'
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.createTable('inscriptions_per_block', {
pgm.createTable('counts_by_block', {
block_height: {
type: 'bigint',
primaryKey: true,
Expand All @@ -26,4 +26,5 @@ export function up(pgm: MigrationBuilder): void {
notNull: true,
},
});
pgm.createIndex('counts_by_block', ['block_hash']);
}
14 changes: 0 additions & 14 deletions migrations/1677360299810_chain-tip.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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.createTable('counts_by_mime_type', {
mime_type: {
type: 'text',
primaryKey: true,
},
count: {
type: 'int',
notNull: true,
default: 0,
},
});
}

export function down(pgm: MigrationBuilder): void {
pgm.dropColumn('inscriptions', 'classic_number');
}
Loading
Loading