Skip to content

Add output/op_return and inscription native endpoints#754

Open
eynhaender wants to merge 4 commits into
libbitcoin:masterfrom
eynhaender:feature/rest-endpoints
Open

Add output/op_return and inscription native endpoints#754
eynhaender wants to merge 4 commits into
libbitcoin:masterfrom
eynhaender:feature/rest-endpoints

Conversation

@eynhaender
Copy link
Copy Markdown
Contributor

Add OP_RETURN viewer and Ordinals inscription endpoints

Two new read-only endpoints added to the native REST interface, both following the existing ?format=data|text|json convention.

GET /v1/output/{txhash}/{vout}/op_return

Returns the payload bytes of an OP_RETURN output. All OP_RETURN variants are supported: standard null_data, Runes (OP_RETURN OP_13 <data>), and multi-chunk forms. The payload is the concatenation of all pushdata bytes following OP_RETURN.

JSON format additionally includes Base64 encoding, payload size, auto-detected overlay protocol (Runes, Omni Layer, Counterparty, Stamps, BIP-320), and UTF-8 decoding where valid.

GET /v1/inscription/{txhash}/{vin}

Parses an Ordinals inscription envelope from the tapscript witness of a reveal transaction input. The data format serves raw content bytes with the inscription's declared MIME type as Content-Type, so browsers render images and text directly. JSON format includes content_type, content_base64, size, and optional content_encoding.

Tapscript extraction follows BIP-341 (second-to-last stack item, with annex detection via chain::annex::is_annex_pattern()). The parser scans raw script bytes for the 6-byte Ordinals envelope marker 00 63 03 6f 72 64 and reads tag-value field pairs until the body separator, then collects body chunks until OP_ENDIF.

@evoskuil
Copy link
Copy Markdown
Member

Good info, but I don't see any need for the server to preprocess op_return. The caller just grabs the script and does it themselves. We already do this in the block explorer for several things. We want to server to provide the indexed data in convenient formats, but to push subsequent computation over that data to the caller.

@evoskuil
Copy link
Copy Markdown
Member

evoskuil commented May 14, 2026

As for the instruction extraction, the bulk of that code would go into system and/or database. System can just statically parse the tx/block/output as is done above. Database can provide an optimized query that does the same.

This would be the ordinal path, assuming that's the only way they are to be identified (txout).

/v1/tx/{txhash}/{vin}/inscription

or

/v1/tx/{txhash}/{vin}/spam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants