Skip to content

Commit 88ed8fd

Browse files
authored
Added time to BlockInfo and new seedEtchings method for storage (#29)
1 parent 5046fc8 commit 88ed8fd

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Terms } from './src/terms';
99
import { MAX_DIVISIBILITY } from './src/constants';
1010

1111
export {
12+
BlockIdentifier,
1213
BlockInfo,
1314
RuneBalance,
1415
RuneBlockIndex,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magiceden-oss/runestone-lib",
3-
"version": "0.4.0-alpha",
3+
"version": "0.4.1-alpha",
44
"description": "",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/indexer/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RunestoneStorage, RunestoneIndexerOptions } from './types';
22
import { Network } from '../network';
33
import { BitcoinRpcClient } from '../rpcclient';
44
import { RuneUpdater } from './updater';
5+
import { u128 } from '../integer';
56

67
export * from './types';
78

@@ -35,6 +36,20 @@ export class RunestoneIndexer {
3536
if (this._pollIntervalMs !== null) {
3637
this._intervalId = setInterval(() => this.updateRuneUtxoBalances(), this._pollIntervalMs);
3738
}
39+
40+
if (this._network === Network.MAINNET) {
41+
this._storage.seedEtchings([
42+
{
43+
rune: 'UNCOMMONGOODS',
44+
runeId: { block: 1, tx: 0 },
45+
txid: '0000000000000000000000000000000000000000000000000000000000000000',
46+
valid: true,
47+
spacers: [7],
48+
symbol: '⧉',
49+
terms: { amount: 1n, cap: u128.MAX, height: { start: 840000n, end: 1050000n } },
50+
},
51+
]);
52+
}
3853
}
3954

4055
async stop(): Promise<void> {

src/indexer/types.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ export interface RunestoneStorage {
2121
/**
2222
* Get the most recently indexed block's index and hash stored in IRunestoneStorage.
2323
*/
24-
getCurrentBlock(): Promise<BlockInfo | null>;
24+
getCurrentBlock(): Promise<BlockIdentifier | null>;
2525

2626
/**
2727
* Reset the most recent index block to a previous block height/hash by unindexing all blocks
2828
* following the specified block (this is used to handle reorgs).
2929
* @param block the block height and hash to reset current block to
3030
*/
31-
resetCurrentBlock(block: BlockInfo): Promise<void>;
31+
resetCurrentBlock(block: BlockIdentifier): Promise<void>;
32+
33+
/**
34+
* Seeds the database with any predefined etchings.
35+
* @param etchings etchings to seed the database with
36+
*/
37+
seedEtchings(etchings: RuneEtching[]): Promise<void>;
3238

3339
/**
3440
* Save new utxo balances for the given block.
@@ -73,10 +79,14 @@ export type RunestoneIndexerOptions = {
7379
pollIntervalMs?: number;
7480
};
7581

76-
export type BlockInfo = {
82+
export type BlockIdentifier = {
7783
height: number;
7884
hash: string;
85+
};
86+
87+
export type BlockInfo = BlockIdentifier & {
7988
previousblockhash: string;
89+
time: number;
8090
};
8191

8292
export type RuneLocation = {

src/indexer/updater.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class RuneUpdater implements RuneBlockIndex {
5656
height: block.height,
5757
hash: block.hash,
5858
previousblockhash: block.previousblockhash,
59+
time: block.time,
5960
};
6061
this._minimum = Rune.getMinimumAtHeight(network, u128(block.height));
6162
}

test/updater.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { OP_RETURN, TAPROOT_SCRIPT_PUBKEY_TYPE } from '../src/constants';
88
import _ from 'lodash';
99

1010
function getDefaultRuneUpdaterContext() {
11-
const block = { hash: 'hash', height: 100_000, previousblockhash: 'previousblockhash' };
11+
const block = {
12+
hash: 'hash',
13+
height: 100_000,
14+
previousblockhash: 'previousblockhash',
15+
time: 123,
16+
};
1217

1318
const storage = mock<RunestoneStorage>();
1419
storage.getEtching.mockResolvedValue(null);

0 commit comments

Comments
 (0)