-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: btc indexer poc, update types and tables (#7)
* chore: indexer draft * chore: ideas * fix: draft of new scan * refactor: some * feat: successful import * feat: track chain tip * feat: run modeS * fix: bigint * fix: filters and ordering * docs: types
- Loading branch information
Showing
21 changed files
with
1,516 additions
and
1,271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
Oops, something went wrong.