Skip to content

Commit

Permalink
Various bugfixes (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
summraznboi authored Apr 14, 2024
1 parent 6dec80d commit 83e30d1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function encodeRunestoneUnsafe(runestone: RunestoneSpec): {
}));

let etching: Option<Etching> = None;
let etchingCommitment: string | undefined = undefined;
let etchingCommitment: Buffer | undefined = undefined;
if (runestone.etching) {
const etchingSpec = runestone.etching;
let hasSpacers = false;
Expand All @@ -141,7 +141,11 @@ export function encodeRunestoneUnsafe(runestone: RunestoneSpec): {
const rune: Option<Rune> =
parsedRawRune !== undefined ? Some(parsedRawRune).map(() => parsedRawRune!) : None;

if (etchingSpec.symbol && etchingSpec.symbol.codePointAt(1) !== undefined) {
if (
etchingSpec.symbol &&
(etchingSpec.symbol.length === 1 ||
(etchingSpec.symbol.length === 2 && etchingSpec.symbol.codePointAt(0)! >= 0x10000))
) {
throw Error('Symbol must be one code point');
}

Expand Down
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.5.0-alpha",
"version": "0.6.0-alpha",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ export class RunestoneIndexer {
if (this._network === Network.MAINNET) {
this._storage.seedEtchings([
{
rune: 'UNCOMMONGOODS',
rune: 'UNCOMMON•GOODS',
runeId: { block: 1, tx: 0 },
txid: '0000000000000000000000000000000000000000000000000000000000000000',
valid: true,
spacers: [7],
symbol: '⧉',
terms: { amount: 1n, cap: u128.MAX, height: { start: 840000n, end: 1050000n } },
},
Expand Down
7 changes: 4 additions & 3 deletions src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export type RuneUtxoBalance = {
export type RuneMintCount = { mint: RuneLocation; count: number };
export type RuneBalance = { runeId: RuneLocation; amount: bigint };

export type RuneEtchingSpec = {
rune?: string;
export type RuneEtchingBase = {
divisibility?: number;
premine?: bigint;
symbol?: string;
Expand All @@ -138,7 +137,9 @@ export type RuneEtchingSpec = {
turbo?: boolean;
};

export type RuneEtching = ({ valid: false } | ({ valid: true } & RuneEtchingSpec)) & {
export type RuneEtchingSpec = RuneEtchingBase & { rune?: string };

export type RuneEtching = ({ valid: false } | ({ valid: true } & RuneEtchingBase)) & {
runeId: RuneLocation;
rune: string;
txid: string;
Expand Down
18 changes: 3 additions & 15 deletions src/indexer/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
RuneUtxoBalance,
RunestoneStorage,
} from './types';
import { SpacedRune } from '../spacedrune';

function isScriptPubKeyHexOpReturn(scriptPubKeyHex: string) {
return scriptPubKeyHex && Buffer.from(scriptPubKeyHex, 'hex')[0] === OP_RETURN;
Expand Down Expand Up @@ -330,6 +331,7 @@ export class RuneUpdater implements RuneBlockIndex {
if (
rune.value < this._minimum.value ||
rune.reserved ||
this.etchings.find((etching) => etching.rune === rune.toString()) ||
(await this._storage.getRuneLocation(rune.toString())) !== null ||
!(await this.txCommitsToRune(tx, rune))
) {
Expand Down Expand Up @@ -507,26 +509,12 @@ export class RuneUpdater implements RuneBlockIndex {
const { divisibility, terms, premine, spacers, symbol } = artifact.etching.unwrap();
this.etchings.push({
valid: true,
rune: rune.toString(),
rune: new SpacedRune(rune, Number(spacers.map(Number).unwrapOr(0))).toString(),
runeId,
txid,
...(divisibility.isSome() ? { divisibility: divisibility.map(Number).unwrap() } : {}),
...(premine.isSome() ? { premine: premine.unwrap() } : {}),
...(symbol.isSome() ? { symbol: symbol.unwrap() } : {}),
...(spacers.isSome()
? {
spacers: (() => {
const spacersNumber = Number(spacers.unwrap());
const spacersArray: number[] = [];
for (const [i] of new Array(32).entries()) {
if ((spacersNumber & (1 << i)) !== 0) {
spacersArray.push(i);
}
}
return spacersArray;
})(),
}
: {}),
...(terms.isSome()
? {
terms: (() => {
Expand Down

0 comments on commit 83e30d1

Please sign in to comment.