Skip to content

Commit

Permalink
Merge pull request #4 from t4t5/main
Browse files Browse the repository at this point in the history
Support explicitly setting pointer tag to zero
  • Loading branch information
paulmillr authored Dec 22, 2024
2 parents 6f0eda7 + b8f9391 commit fdfd8e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ const TagCoder: P.Coder<TagRaw[], Tags> = {
for (const p of to.parent) res.push({ tag: tagName, data: TagCoders.parent.encode(p) });
continue;
}
const bytes = TagCoders[field as TagName].encode(to[field as TagName]);
let bytes = TagCoders[field as TagName].encode(to[field as TagName]);

// Handle pointer = 0:
if (field === 'pointer' && bytes.length === 0) {
bytes = new Uint8Array([0]);
}

for (const data of splitChunks(bytes)) res.push({ tag: tagName, data });
}
if (to.unknown) {
Expand Down
13 changes: 12 additions & 1 deletion test/ordinals.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepStrictEqual } from 'node:assert';
import { deepStrictEqual, strictEqual } from 'node:assert';
import { describe, should } from 'micro-should';
import { hex, utf8 } from '@scure/base';
import * as btc from '@scure/btc-signer';
Expand Down Expand Up @@ -67,6 +67,17 @@ describe('Ordinals', () => {
});
});

should('support explicit pointer 0', () => {
const { TagCoder } = ordinals.__test__;
const encoded = TagCoder.decode({ pointer: 0n });

const encodedTag = encoded[0].tag[0]
const encodedValue = encoded[0].data[0]

strictEqual(encodedTag, 2);
strictEqual(encodedValue, 0);
})

should('inscription/11820782', () => {
// https://ordiscan.com/inscription/11820782
const rawTx = ordvectors[0].raw_tx;
Expand Down

0 comments on commit fdfd8e4

Please sign in to comment.