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: btc indexer poc, update types and tables #7

Merged
merged 11 commits into from
Feb 27, 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
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,46 @@
},
"killBehavior": "polite",
},
{
"type": "node",
"request": "launch",
"name": "Run: readonly",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true",
"RUN_MODE": "readonly"
},
"killBehavior": "polite",
},
{
"type": "node",
"request": "launch",
"name": "Run: writeonly",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/index.ts"
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"NODE_ENV": "development",
"TS_NODE_SKIP_IGNORE": "true",
"RUN_MODE": "writeonly"
},
"killBehavior": "polite",
},
{
"type": "node",
"request": "launch",
Expand Down
53 changes: 7 additions & 46 deletions migrations/1676395230930_inscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,11 @@ export function up(pgm: MigrationBuilder): void {
type: 'serial',
primaryKey: true,
},
inscription_id: {
genesis_id: {
type: 'text',
notNull: true,
},
offset: {
type: 'int',
notNull: true,
},
block_height: {
type: 'int',
notNull: true,
},
block_hash: {
type: 'bytea',
notNull: true,
},
tx_id: {
type: 'bytea',
notNull: true,
},
address: {
type: 'text',
notNull: true,
},
sat_ordinal: {
type: 'numeric',
notNull: true,
},
sat_point: {
type: 'text',
notNull: true,
},
sat_rarity: {
type: 'text',
notNull: true,
},
fee: {
number: {
type: 'int',
notNull: true,
},
Expand All @@ -65,20 +33,13 @@ export function up(pgm: MigrationBuilder): void {
type: 'bytea',
notNull: true,
},
timestamp: {
type: 'timestamptz',
fee: {
type: 'bigint',
notNull: true,
},
});
pgm.createConstraint(
'inscriptions',
'inscriptions_inscription_id_unique',
'UNIQUE(inscription_id)'
);
pgm.createIndex('inscriptions', ['sat_ordinal']);
pgm.createIndex('inscriptions', ['sat_rarity']);
pgm.createIndex('inscriptions', ['block_height']);
pgm.createIndex('inscriptions', ['block_hash']);
pgm.createIndex('inscriptions', ['address']);
pgm.createConstraint('inscriptions', 'inscriptions_genesis_id_unique', 'UNIQUE(genesis_id)');
pgm.createIndex('inscriptions', ['genesis_id']);
pgm.createIndex('inscriptions', ['number']);
pgm.createIndex('inscriptions', ['mime_type']);
}
81 changes: 81 additions & 0 deletions migrations/1677284495299_locations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* 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('locations', {
id: {
type: 'serial',
primaryKey: true,
},
inscription_id: {
type: 'int',
notNull: true,
},
block_height: {
type: 'int',
notNull: true,
},
block_hash: {
type: 'text',
notNull: true,
},
tx_id: {
type: 'text',
notNull: true,
},
address: {
type: 'text',
notNull: true,
},
output: {
type: 'text',
notNull: true,
},
offset: {
type: 'bigint',
notNull: true,
},
value: {
type: 'bigint',
notNull: true,
},
sat_ordinal: {
type: 'bigint',
notNull: true,
},
sat_rarity: {
type: 'text',
notNull: true,
},
timestamp: {
type: 'timestamptz',
notNull: true,
},
genesis: {
type: 'boolean',
default: true,
notNull: true,
},
current: {
type: 'boolean',
default: true,
notNull: true,
},
});
pgm.createConstraint(
'locations',
'locations_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'locations',
'locations_inscription_id_block_hash_unique',
'UNIQUE(inscription_id, block_hash)'
);
pgm.createIndex('locations', ['block_height']);
pgm.createIndex('locations', ['block_hash']);
pgm.createIndex('locations', ['address']);
pgm.createIndex('locations', ['output']);
}
27 changes: 27 additions & 0 deletions migrations/1677360299810_chain-tip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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('chain_tip', {
id: {
type: 'bool',
primaryKey: true,
default: true,
},
block_height: {
type: 'int',
notNull: true,
default: 1,
},
});
// Ensure only a single row can exist
pgm.addConstraint('chain_tip', 'chain_tip_one_row', 'CHECK(id)');
// Create the single row
pgm.sql('INSERT INTO chain_tip VALUES(DEFAULT)');
}

export function down(pgm: MigrationBuilder): void {
pgm.dropTable('chain_tip');
}
Loading