Skip to content

Commit

Permalink
Changed getEtching call to also require blockheight
Browse files Browse the repository at this point in the history
  • Loading branch information
summraznboi committed Apr 18, 2024
1 parent 462f33b commit c91f736
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@magiceden-oss/runestone-lib",
"version": "0.9.3-alpha",
"version": "0.9.4-alpha",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
11 changes: 6 additions & 5 deletions src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ export interface RunestoneStorage {
saveBlockIndex(runeBlockIndex: RuneBlockIndex): Promise<void>;

/**
* Get the etching that deployed the rune if it exists.
* Get the etching that deployed the rune if it exists (up to given blockheight).
* @param runeLocation rune id string representation
* @param blockheight the block height
*/
getEtching(runeLocation: string): Promise<RuneEtching | null>;
getEtching(runeLocation: string, blockheight: number): Promise<RuneEtching | null>;

/**
* Get the total valid mint counts for rune.
* Get the total valid mint counts for rune up to and including specified block height.
* @param rune rune id string representation
* @param blockhash hash to specify explicit block chain tip to use
* @param blockheight block height to count up to
*/
getValidMintCount(runeLocation: string, blockhash: string): Promise<number>;
getValidMintCount(runeLocation: string, blockheight: number): Promise<number>;

getRuneLocation(runeTicker: string): Promise<RuneLocation | null>;

Expand Down
8 changes: 5 additions & 3 deletions src/indexer/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export class RuneUpdater implements RuneBlockIndex {
for (const balance of balances.values()) {
const runeIdString = RuneLocation.toString(balance.runeId);
const etching =
etchingByRuneId.get(runeIdString) ?? (await this._storage.getEtching(runeIdString));
etchingByRuneId.get(runeIdString) ??
(await this._storage.getEtching(runeIdString, this.block.height - 1));
if (etching === null) {
throw new Error('Rune should exist at this point');
}
Expand Down Expand Up @@ -361,7 +362,8 @@ export class RuneUpdater implements RuneBlockIndex {
);

const etching =
etchingByRuneId.get(runeLocation) ?? (await this._storage.getEtching(runeLocation));
etchingByRuneId.get(runeLocation) ??
(await this._storage.getEtching(runeLocation, this.block.height - 1));
if (etching === null || !etching.valid || !etching.terms) {
return None;
}
Expand Down Expand Up @@ -400,7 +402,7 @@ export class RuneUpdater implements RuneBlockIndex {

const totalMints =
currentBlockMints.count +
(await this._storage.getValidMintCount(runeLocation, this.block.previousblockhash));
(await this._storage.getValidMintCount(runeLocation, this.block.height - 1));

if (totalMints >= cap) {
return None;
Expand Down

0 comments on commit c91f736

Please sign in to comment.