hirosystems / ordhook

Build indexers, standards and protocols on top of Ordinals and Inscriptions (BRC20, etc).
Apache License 2.0
182 stars 54 forks source link

`ordhook-sdk-js` experiment: from proof of concept to production-readiness #177

Closed lgalabru closed 3 months ago

lgalabru commented 1 year ago

The branch feat/improve-sdk is including a solid draft of the upcoming ordinals-api re-architecture. Instead of starting ordhook and registering ordinals-api as an http observer receiving payloads including ordinals inscriptions / transfers, the incoming version of ordinals-api will pull a NPM @hirosystems/ordhoook-sdk-js library and implement the following skeleton (present in components/ordhook-sdk-js/lib/test.ts:


import { OrdinalsIndexer } from "./index";

const indexer = new OrdinalsIndexer({
    bitcoinRpcUrl: 'http://0.0.0.0:8332',
    bitcoinRpcUsername: 'devnet',
    bitcoinRpcPassword: 'devnet',
    workingDirectory: '/Users/ludovic/ordhook-sdk-js',
    logs: false
});

indexer.applyBlock(block => {
    console.log(`Hello from JS ${JSON.stringify(block)}`);
});

indexer.undoBlock(block => {
    console.log(`Hello from JS ${JSON.stringify(block)}`);
});

indexer.streamBlocks();

The OrdinalsIndexer struct can be fully piloted in Typescript. In case of migrations, the following actions can also be performed:

// Delete blocks and inscriptions
indexer.dropBlocks([32103, 32104]);

// Re-download + index blocks
indexer.rewriteBlocks([32103, 32104]);

// Sync blocks until chain tip
indexer.syncBlocks();

// Replay a list of blocks
indexer.replayBlocks([32103, 32104]);

The ordhook-sdk-js is producing a state (rocksdb+sqlite) identical to the one being produced by ordhook-cli. So a state produced by ordhook-cli can be reused by an app being built with ordhook-sdk-js and vice-versa.

Remaining work:

smcclellan commented 8 months ago

@lgalabru Is this still relevant & has accurate info?

smcclellan commented 3 months ago

Changing ordhook to write to pg may solve this. Closing this optimistically.