diff --git a/index.ts b/index.ts index 38a23d9..2e26ca2 100644 --- a/index.ts +++ b/index.ts @@ -118,7 +118,7 @@ export function encodeRunestoneUnsafe(runestone: RunestoneSpec): { })); let etching: Option = None; - let etchingCommitment: string | undefined = undefined; + let etchingCommitment: Buffer | undefined = undefined; if (runestone.etching) { const etchingSpec = runestone.etching; let hasSpacers = false; @@ -141,7 +141,11 @@ export function encodeRunestoneUnsafe(runestone: RunestoneSpec): { const rune: Option = 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'); } diff --git a/package.json b/package.json index 6cec1d1..9a8b7d7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/indexer/index.ts b/src/indexer/index.ts index 1133483..b16afa9 100644 --- a/src/indexer/index.ts +++ b/src/indexer/index.ts @@ -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 } }, }, diff --git a/src/indexer/types.ts b/src/indexer/types.ts index e1a8d12..1bb5262 100644 --- a/src/indexer/types.ts +++ b/src/indexer/types.ts @@ -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; @@ -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; diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index a021f5e..f482590 100644 --- a/src/indexer/updater.ts +++ b/src/indexer/updater.ts @@ -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; @@ -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)) ) { @@ -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: (() => {