Skip to content

Commit 3c58e33

Browse files
authored
Real fix is adjusting getRuneLocation's usage (#50)
1 parent ee3e5f4 commit 3c58e33

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

package.json

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

src/indexer/types.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ export interface RunestoneStorage {
4343
saveBlockIndex(runeBlockIndex: RuneBlockIndex): Promise<void>;
4444

4545
/**
46-
* Get the etching that deployed the rune if it exists (up to given blockheight).
46+
* Get the etching that deployed the rune if it exists.
4747
* @param runeLocation rune id string representation
48-
* @param blockheight the block height
4948
*/
50-
getEtching(runeLocation: string, blockheight: number): Promise<RuneEtching | null>;
49+
getEtching(runeLocation: string): Promise<RuneEtching | null>;
5150

5251
/**
5352
* Get the total valid mint counts for rune up to and including specified block height.
@@ -56,6 +55,10 @@ export interface RunestoneStorage {
5655
*/
5756
getValidMintCount(runeLocation: string, blockheight: number): Promise<number>;
5857

58+
/**
59+
* Get rune location given rune ticker.
60+
* @param runeTicker rune ticker
61+
*/
5962
getRuneLocation(runeTicker: string): Promise<RuneLocation | null>;
6063

6164
/**

src/indexer/updater.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ export class RuneUpdater implements RuneBlockIndex {
280280
for (const balance of balances.values()) {
281281
const runeIdString = RuneLocation.toString(balance.runeId);
282282
const etching =
283-
etchingByRuneId.get(runeIdString) ??
284-
(await this._storage.getEtching(runeIdString, this.block.height - 1));
283+
etchingByRuneId.get(runeIdString) ?? (await this._storage.getEtching(runeIdString));
285284
if (etching === null) {
286285
throw new Error('Rune should exist at this point');
287286
}
@@ -330,17 +329,31 @@ export class RuneUpdater implements RuneBlockIndex {
330329
if (optionRune.isSome()) {
331330
rune = optionRune.unwrap();
332331

332+
if (rune.value < this._minimum.value) {
333+
return None;
334+
}
335+
336+
if (rune.reserved) {
337+
return None;
338+
}
339+
333340
if (
334-
rune.value < this._minimum.value ||
335-
rune.reserved ||
336341
this.etchings.find(
337342
(etching) => SpacedRune.fromString(etching.runeName).rune.toString() === rune.toString()
338-
) ||
339-
(await this._storage.getRuneLocation(rune.toString())) !== null ||
340-
!(await this.txCommitsToRune(tx, rune))
343+
)
341344
) {
342345
return None;
343346
}
347+
348+
const runeLocation = await this._storage.getRuneLocation(rune.toString());
349+
if (runeLocation && runeLocation.block < this.block.height) {
350+
return None;
351+
}
352+
353+
const txCommitsToRune = await this.txCommitsToRune(tx, rune);
354+
if (!txCommitsToRune) {
355+
return None;
356+
}
344357
} else {
345358
rune = Rune.getReserved(u64(this.block.height), u32(txIndex));
346359
}
@@ -362,8 +375,7 @@ export class RuneUpdater implements RuneBlockIndex {
362375
);
363376

364377
const etching =
365-
etchingByRuneId.get(runeLocation) ??
366-
(await this._storage.getEtching(runeLocation, this.block.height - 1));
378+
etchingByRuneId.get(runeLocation) ?? (await this._storage.getEtching(runeLocation));
367379
if (etching === null || !etching.valid || !etching.terms) {
368380
return None;
369381
}

0 commit comments

Comments
 (0)