Skip to content

Commit 83e30d1

Browse files
authored
Various bugfixes (#38)
1 parent 6dec80d commit 83e30d1

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function encodeRunestoneUnsafe(runestone: RunestoneSpec): {
118118
}));
119119

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

144-
if (etchingSpec.symbol && etchingSpec.symbol.codePointAt(1) !== undefined) {
144+
if (
145+
etchingSpec.symbol &&
146+
(etchingSpec.symbol.length === 1 ||
147+
(etchingSpec.symbol.length === 2 && etchingSpec.symbol.codePointAt(0)! >= 0x10000))
148+
) {
145149
throw Error('Symbol must be one code point');
146150
}
147151

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.5.0-alpha",
3+
"version": "0.6.0-alpha",
44
"description": "",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/indexer/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ export class RunestoneIndexer {
4040
if (this._network === Network.MAINNET) {
4141
this._storage.seedEtchings([
4242
{
43-
rune: 'UNCOMMONGOODS',
43+
rune: 'UNCOMMON•GOODS',
4444
runeId: { block: 1, tx: 0 },
4545
txid: '0000000000000000000000000000000000000000000000000000000000000000',
4646
valid: true,
47-
spacers: [7],
4847
symbol: '⧉',
4948
terms: { amount: 1n, cap: u128.MAX, height: { start: 840000n, end: 1050000n } },
5049
},

src/indexer/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ export type RuneUtxoBalance = {
118118
export type RuneMintCount = { mint: RuneLocation; count: number };
119119
export type RuneBalance = { runeId: RuneLocation; amount: bigint };
120120

121-
export type RuneEtchingSpec = {
122-
rune?: string;
121+
export type RuneEtchingBase = {
123122
divisibility?: number;
124123
premine?: bigint;
125124
symbol?: string;
@@ -138,7 +137,9 @@ export type RuneEtchingSpec = {
138137
turbo?: boolean;
139138
};
140139

141-
export type RuneEtching = ({ valid: false } | ({ valid: true } & RuneEtchingSpec)) & {
140+
export type RuneEtchingSpec = RuneEtchingBase & { rune?: string };
141+
142+
export type RuneEtching = ({ valid: false } | ({ valid: true } & RuneEtchingBase)) & {
142143
runeId: RuneLocation;
143144
rune: string;
144145
txid: string;

src/indexer/updater.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
RuneUtxoBalance,
2525
RunestoneStorage,
2626
} from './types';
27+
import { SpacedRune } from '../spacedrune';
2728

2829
function isScriptPubKeyHexOpReturn(scriptPubKeyHex: string) {
2930
return scriptPubKeyHex && Buffer.from(scriptPubKeyHex, 'hex')[0] === OP_RETURN;
@@ -330,6 +331,7 @@ export class RuneUpdater implements RuneBlockIndex {
330331
if (
331332
rune.value < this._minimum.value ||
332333
rune.reserved ||
334+
this.etchings.find((etching) => etching.rune === rune.toString()) ||
333335
(await this._storage.getRuneLocation(rune.toString())) !== null ||
334336
!(await this.txCommitsToRune(tx, rune))
335337
) {
@@ -507,26 +509,12 @@ export class RuneUpdater implements RuneBlockIndex {
507509
const { divisibility, terms, premine, spacers, symbol } = artifact.etching.unwrap();
508510
this.etchings.push({
509511
valid: true,
510-
rune: rune.toString(),
512+
rune: new SpacedRune(rune, Number(spacers.map(Number).unwrapOr(0))).toString(),
511513
runeId,
512514
txid,
513515
...(divisibility.isSome() ? { divisibility: divisibility.map(Number).unwrap() } : {}),
514516
...(premine.isSome() ? { premine: premine.unwrap() } : {}),
515517
...(symbol.isSome() ? { symbol: symbol.unwrap() } : {}),
516-
...(spacers.isSome()
517-
? {
518-
spacers: (() => {
519-
const spacersNumber = Number(spacers.unwrap());
520-
const spacersArray: number[] = [];
521-
for (const [i] of new Array(32).entries()) {
522-
if ((spacersNumber & (1 << i)) !== 0) {
523-
spacersArray.push(i);
524-
}
525-
}
526-
return spacersArray;
527-
})(),
528-
}
529-
: {}),
530518
...(terms.isSome()
531519
? {
532520
terms: (() => {

0 commit comments

Comments
 (0)