Open Protocol Indexer, OPI, is the best-in-slot open-source indexing client for meta-protocols on Bitcoin.

Related tags

Cryptography OPI
Overview

OPI - Open Protocol Indexer

Open Protocol Indexer, OPI, is the best-in-slot open-source indexing client for meta-protocols on Bitcoin. OPI uses a fork of ord 0.9.0 with minimal changes to maintain compatibility with base layer rules. Also, OPI is built with modularity in mind. The main indexer indexes all text/json inscriptions and modules can extend it with different meta-protocols. All modules in OPI have been built with reorg protection.

Currently OPI has modules for BRC-20 and Bitmap, we'll add new modules over time. Pull Requests are welcomed for other meta-protocols.

Main Meta-Protocol Indexer

Meta-Protocol indexer sits in the core of OPI. It indexes all json/text inscriptions and their first 2 transfers. Transfer limit can be changed via INDEX_TX_LIMIT variable in ord fork. This limit has been added since there are some UTXO's with a lot of inscription content and their movement floods transfers tables. Also, base indexing of most protocols only needs the first two transfers. BRC-20 becomes invalid after 2 hops, bitmap and SNS validity is calculated at inscription time.

BRC-20 Indexer / API

BRC-20 Indexer is the first module of OPI. It follows the official protocol rules hosted here. BRC-20 Indexer saves all historical balance changes and all BRC-20 events.

In addition to indexing all events, it also calculates a block hash and cumulative hash of all events for easier db comparison. Here's the pseudocode for hash calculation:

## Calculation starts at block 767430 which is the first inscription block

EVENT_SEPARATOR = '|'
## max_supply, limit_per_mint, amount decimal count is the same as ticker's decimals
## tickers are lowercase
for event in block_events:
  if event is 'deploy-inscribe':
    block_str += 'deploy-inscribe;<inscr_id>;<deployer_pkscript>;<ticker>;<max_supply>;<decimals>;<limit_per_mint>' + EVENT_SEPARATOR
  if event is 'mint-inscribe':
    block_str += 'mint-inscribe;<inscr_id>;<minter_pkscript>;<ticker>;<amount>' + EVENT_SEPARATOR
  if event is 'transfer-inscribe':
    block_str += 'transfer-inscribe;<inscr_id>;<source_pkscript>;<ticker>;<amount>' + EVENT_SEPARATOR
  if event is 'transfer-transfer':
    ## if sent as fee, sent_pkscript is empty
    block_str += 'transfer-transfer;<inscr_id>;<source_pkscript>;<sent_pkscript>;<ticker>;<amount>' + EVENT_SEPARATOR

block_hash = sha256_hex(block_str)
## for first block last_cumulative_hash is empty
cumulative_hash = sha256_hex(last_cumulative_hash + block_hash)

BRC-20 API exposes activity on block (block events), balance of a wallet at the start of a given height, current balance of a wallet, block hash and cumulative hash at a given block and hash of all current balances.

Bitmap Indexer / API

Bitmap Indexer is the second module of OPI. It follows the official protocol rules hosted here. Bitmap Indexer saves all bitmap-number inscription-id pairs.

In addition to indexing all pairs, it also calculates a block hash and cumulative hash of all events for easier db comparison. Here's the pseudocode for hash calculation:

## Calculation starts at block 767430 which is the first inscription block

EVENT_SEPARATOR = '|'
for bitmap in new_bitmaps_in_block:
  block_str += 'inscribe;<inscr_id>;<bitmap_number>' + EVENT_SEPARATOR

block_hash = sha256_hex(block_str)
## for first block last_cumulative_hash is empty
cumulative_hash = sha256_hex(last_cumulative_hash + block_hash)

Bitmap API exposes block hash and cumulative hash at a given block, hash of all bitmaps and inscription_id of a given bitmap.

Setup

OPI uses PostgreSQL as DB. Before running the indexer, setup a PostgreSQL DB (all modules can write into different databases as well as use a single database). Run init_db.sql for each module on their respective database.

Build ord:

cd ord; cargo build --release;

Install node modules

cd modules/main_index; npm install;
cd ../brc20_api; npm install;
cd ../bitmap_api; npm install;

Optional: Remove the following from modules/main_index/node_modules/bitcoinjs-lib/src/payments/p2tr.js

if (pubkey && pubkey.length) {
  if (!(0, ecc_lib_1.getEccLib)().isXOnlyPoint(pubkey))
    throw new TypeError('Invalid pubkey for p2tr');
}

Otherwise, it cannot decode some addresses such as 512057cd4cfa03f27f7b18c2fe45fe2c2e0f7b5ccb034af4dec098977c28562be7a2

Install python libraries

pip3 install python-dotenv;
pip3 install psycopg2-binary;

Setup .env files

Copy .env_sample in main_index, brc20_index, brc20_api, bitmap_index and bitmap_api as .env and fill necessary information.

Run

Main Meta-Protocol Indexer

cd modules/main_index; node index.js;

BRC-20 Indexer

cd modules/brc20_index; python3 brc20_index.py;

BRC-20 API

cd modules/brc20_api; node api.js;

Bitmap Indexer

cd modules/bitmap_index; python3 bitmap_index.py;

Bitmap API

cd modules/bitmap_api; node api.js;
You might also like...
Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend  ๐Ÿ‘๏ธ๐Ÿฆ€
Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend ๐Ÿ‘๏ธ๐Ÿฆ€

witnet-rust is an open source implementation of the Witnet Decentralized Oracle Network protocol written in Rust. Components witnet-rust implements ma

An open source desktop wallet for nano and banano with end-to-end encrypted, on chain messaging using the dagchat protocol.
An open source desktop wallet for nano and banano with end-to-end encrypted, on chain messaging using the dagchat protocol.

An open source wallet with end-to-end encrypted, on chain messaging for nano and banano using the dagchat protocol.

IDO protocol is now open source

Project Overview Uprock IDO Protocol facilitates Initial DEX Offerings (IDOs) with advanced features for managing token distribution, whitelisting, an

Meta-repository for Miscreant: misuse-resistant symmetric encryption library with AES-SIV (RFC 5297) and AES-PMAC-SIV support

The best crypto you've never heard of, brought to you by Phil Rogaway A misuse resistant symmetric encryption library designed to support authenticate

The Parity Bitcoin client

The Parity Bitcoin client. Gitter Installing from source Installing the snap Running tests Going online Importing bitcoind database Command line inter

Low-level Bitcoin P2P Network Client

Peerlink What is Peerlink? Peerlink is a low-level network client for the Bitcoin P2P network written in Rust. It uses a nonblocking reactor to accept

Koofr Vault is an open-source, client-side encrypted folder for your Koofr cloud storage offering an extra layer of security for your most sensitive files.

Koofr Vault https://vault.koofr.net Koofr Vault is an open-source, client-side encrypted folder for your Koofr cloud storage offering an extra layer o

Teach best practices by violating them.

Substrate Node Template A fresh FRAME-based Substrate node, ready for hacking ๐Ÿš€ Getting Started Follow the steps below to get started with the Node T

Taking the best of Substrate Recipes and applying them to a new framework for structuring a collection of how-to guides.

Attention: This repository has been archived and is no longer being maintained. It has been replaced by the Substrate How-to Guides. Please use the Su

Comments
  • Ord 0.9.0 running service exception

    Ord 0.9.0 running service exception

    After compiling and installing ord, run:

    export bitcoinDataDir="/var/lib/bitcoind" export bitcoinCookie="$bitcoinDataDir/regtest/.cookie" export ordDataDir="/var/lib/ord" export ordWalletName="ord"

    ord --bitcoin-data-dir $bitcoinDataDir --cookie-file $bitcoinCookie --data-dir $ordDataDir --chain regtest --index-sats --enable-json-api server --http

    Listening on http://0.0.0.0:80 cmd;0;new_block;0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 thread '' panicked at src/index/updater.rs:326:91: called Result::unwrap() on an Err value: Os { code: 2, kind: NotFound, message: "No such file or directory" } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

    Another little question is that the ord in the project is 0.9.0. Compared with https://github.com/ordinals/ord/tree/0.9.0, it seems different. I don't know if I made a mistake.

    opened by softwarecheng 3
  • Add `DB_MAX_CONNECTIONS` env variable

    Add `DB_MAX_CONNECTIONS` env variable

    When running the main index module, I quickly ran into the following Postgres error: Sorry, too many clients already!

    It probably makes sense to let the user decide how many concurrent connections their database can handle! ๐Ÿ‘

    opened by t4t5 3
Owner
Best in Slot
Best in Slot
Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transactions of your non-custodial wallets on a provider of your choice, all while respecting your privacy

Bitcoin Push Notification Service (BPNS) Description Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transacti

BPNS 1 May 2, 2022
Minimal Bitcoin wallet intended for teaching rust-bitcoin

Insanely minimal Bitcoin wallet intended for demonstration of Rust Bitcoin ecosystem Absolutely DO NOT use with mainnet funds!!! No privacy - address

Martin Habovลกtiak 4 May 5, 2023
Modern, lightweight & standard-compliant bitcoin wallet runtime & cli without rust-bitcoin dependencies

Bitcoin protocol command-line wallet & tools Modern, minimalistic & standard-compliant cold wallet from LNP/BP Standards Association. Contributing Con

BP: Bitcoin protocol 3 Jul 31, 2023
Minimalistic EVM-compatible chain indexer.

EVM Indexer Minimalistic EVM-compatible blockchain indexer written in rust. This repository contains a program to index helpful information from any E

Kike B 14 Dec 24, 2022
Minimalistic EVM-compatible chain indexer.

EVM Indexer Minimalistic EVM-compatible blockchain indexer written in rust. This repository contains a program to index helpful information from any E

LlamaFolio 11 Dec 15, 2022
reth-indexer reads directly from the reth db and indexes the data into a postgres database all decoded with a simple config file and no extra setup alongside exposing a API ready to query the data.

reth-indexer reth-indexer reads directly from the reth db and indexes the data into a postgres database all decoded with a simple config file and no e

Josh Stevens 306 Jul 12, 2023
Ethereum (and Ethereum like) indexer using P2P message to fetch blocks and transactions

Ethereum P2P indexer This project is an indexer for Ethereum and Ethereum forks. It takes advantage of the ETH (Ethereum Wire Protocol) to fetch block

null 5 Nov 10, 2023
A high-performance, highly compatible EVM Inscriptions Indexer

Insdexer A high-performance, highly compatible EVM Inscriptions Indexer by Rust. An accessible and complete version of the documentation is available

null 105 Mar 17, 2024
Rust implementation of the i2p client/server/router protocols

ri2p Rust implementation of the i2p client/server/router protocols Status Common Commands cargo build: Builds the ri2p binary cargo run: Runs the ri2p

Christopher Bilger 8 Nov 25, 2022
Flexible Rust implementation of the MuSig2 multisignature protocol, compatible with Bitcoin.

MuSig2 This crate provides a flexible rust implementation of MuSig2, an optimized digital signature aggregation protocol, on the secp256k1 elliptic cu

null 4 Oct 31, 2023