Coder Social home page Coder Social logo

wesreid / ordpool-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ordpool-space/ordpool-parser

0.0 0.0 0.0 745 KB

The parsing engine that detects inscriptions in Bitcoin transactions

License: Other

JavaScript 0.81% TypeScript 99.19%

ordpool-parser's Introduction

ordpool-parser

The parsing engine that detects inscriptions in Bitcoin transactions. The compiled code has zero dependencies and works in the Browser and in Node.js out of the box.

The latest version of this script is used by https://ordpool.space

๐Ÿš€ Usage

This package has zero dependencies and should "just work". First, install it:

npm install ordpool-parser

Then, you can use the parser in your project. It expects a transaction in JSON format from an Esplora API.

To avoid confusion, here are the different kinds of "Electrum" servers explained:

  • Electrum and ElectrumX are basic indexers for Bitcoin
  • romanz/electrs (Electrum Server in Rust) is re-implementation Electrum
  • "Esplora - Electrs backend API" is a fork by blockstream.info with a powerful REST API

Esplora is the backend mempool.space uses, and is also what powers blockstream.info! The ordpool-parser was only tested with this API.

import axios from 'axios';
import { InscriptionParserService } from 'ordpool-parser';

async function getInscriptions(txId: string) {

  const response = await axios.get(`https://mempool.space/api/tx/${txId}`);
  // OR 
  // const response = await axios.get(`https://blockstream.info/api/tx/${txId}`);
  const transaction = response.data;

  return InscriptionParserService.parse(transaction);
}

const parsedInscriptions = await getInscriptions('f1997166547da9784a3e7419d2b248551565211811d4f5e705b685efa244451f');

if (!parsedInscriptions.length) {
  console.log('No inscriptions found!');
} else {
  // Output: text/html;charset=utf-8
  console.log(parsedInscriptions[0].contentType);

  // UTF-8 encoded string (not intended for binary content like images or videos)
  // Output: <html><!--cubes.haushoppe.art--><body> [...]
  console.log(parsedInscriptions[0].getContent());

  // Base64 encoded data URI that can be displayed in an iframe
  // Output: data:text/html;charset=utf-8;base64,PGh0bWw+PCEtLWN1YmVzLmhhdXNob3BwZS5hcnQtLT48Ym9keT4 [...]
  console.log(parsedInscriptions[0].getDataUri());
}

This example uses axios, a popular HTTP client for both browser and Node.js environments. You can install it via npm install axios. Of course, any other compatible HTTP client will also work.

Note: This is a simplified example! Make sure to handle errors when making HTTP requests, as network issues can occur.

๐Ÿงก Contribute

Prerequisites

Node.js (Version 20 or later) to test & compile the TypeScript code to JavaScript.

Install

First, install Node.js version 20. Then, install the NPM dependencies and execute the tests with the following commands:

npm install
npm test

How to add a feature

Every feature must be tested in the browser and in the node environment! Use a mainnet transaction to create a test scenario. The goal of this parser is to parse byte-perfect inscriptions that are identical to ord.

  1. Fetch Transaction Test Data: Save the raw transaction JSON to the testdata folder.

    npm run fetch-tx-testdata

    Enter the transactionId (e.g.78fa9d6e9b2b49fbb9f4838e1792dba7c1ec836f22e3206561e2d52759708251) and check the results.

  2. Fetch Inscription Test Data: Save the reference inscription as a file in the testdata folder.

    npm run fetch-inscription-testdata

    Enter the inscriptionId, which is the transactionId + i + the index (e.g.78fa9d6e9b2b49fbb9f4838e1792dba7c1ec836f22e3206561e2d52759708251i0), and check the results!

  3. Contribute: Add your new feature, include meaningful tests, and submit a pull request if all tests pass.

  4. Hint: Debug the unit tests using VS Code. The launch.json file is already prepared for this purpose.

Build

To build a version without the tests:

npm run build

To publish a new version to NPM:

npm publish

ordpool-parser's People

Contributors

hans-crypto avatar ethspresso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.