Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bitcoin)!: use mempool.space REST API #96

Merged
merged 27 commits into from
Apr 29, 2024
Merged

Conversation

ahonn
Copy link
Collaborator

@ahonn ahonn commented Apr 22, 2024

Changes

Use mempool.space API instead of bitcoind and electrs

  • APIs

    • For bitcoind part
      • ⚠️ getBlockchainInfo: we can assemble blockchain info by getting the tip block data (but the headers field cannot be obtained)
        • But fortunately, we hardly use this field before
      • sendRawTransaction: Exactly the same as postTx provided by mempool.space
    • For electrs part:
      • Most of the data is consistent since mempool.space is also based on electrs.
      • Objects use zod schema's parse to keep the interface consistent.
  • Using Electrs as a fallback for mempool.space API

    • When mempool.space API is not available, electrs will be used as a fallback
    • For compatibility and scalability, electrs can be used as the primary data provider (see BITCOIN_DATA_PROVIDER)
  • Error handles

    • No longer throw error codes related to Bitcoin RPC. (see src/services/bitcoind.ts)
    • Wrap BitcoinClientAPIError to handle mempool.space and electrs error
    • For BitcoinClientAPIError with a 404 status code, transaction processing needs to be delayed

Enhance Bitcoin transactions query

Wrap recommended fee rates API

Healthcheck updates

Remove bitcoind healthcheck and add mempool.space API healthcheck

Env variables

Added

/**
 * Bitcoin Mempool.space API URL
 * used to get bitcoin data and broadcast transaction
 */
BITCOIN_MEMPOOL_SPACE_API_URL: z.string(),
/**
 * Bitcoin data provider, support mempool and electrs
 * use mempool.space as default, electrs as fallback
 * change to electrs if you want to use electrs as default and mempool.space as fallback
 */
BITCOIN_DATA_PROVIDER: z.enum(['mempool', 'electrs']).default('mempool'),

BITCOIN_DATA_PROVIDER is used to determine which service to use as the primary data provider.

  • When BITCOIN_DATA_PROVIDER=mempool
    • mempool.space API as primary data provider
    • electrs API as fallback data provider (BITCOIN_ELECTRS_API_URL is optional)
  • When BITCOIN_DATA_PROVIDER=electrs
    • electrs API as primary data provider
    • mempool.space as fallback data provider (BITCOIN_MEMPOOL_SPACE_API_URL is optional)

Removed

We no longer need bitcoin RPC, we send transactions through mempool.space or our node indirectly through electrs

/**
 * The URL/USERNAME/PASSWORD of the Bitcoin JSON-RPC server.
 * The JSON-RPC server is used to query the Bitcoin blockchain.
 */
BITCOIN_JSON_RPC_URL: z.string(),
BITCOIN_JSON_RPC_USERNAME: z.string(),
BITCOIN_JSON_RPC_PASSWORD: z.string(),

Known Issues

Reviews

@Flouse @duanyytop @ShookLyngs @Dawn-githup @yuche

Copy link

vercel bot commented Apr 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
btc-assets-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 6:55am

@ahonn ahonn changed the title refactor: use cell.mempool.space [WIP] refactor: use cell.mempool.space Apr 22, 2024
@Flouse Flouse requested a review from yuche April 22, 2024 08:28
@ahonn ahonn force-pushed the feat/mempool-space-api branch from 0de48ad to 89bd56d Compare April 24, 2024 06:17
@ahonn ahonn changed the title [WIP] refactor: use cell.mempool.space refactor: use cell.mempool.space Apr 25, 2024
@ahonn ahonn force-pushed the feat/mempool-space-api branch from 6979297 to 543bee1 Compare April 25, 2024 11:20
@ahonn ahonn force-pushed the feat/mempool-space-api branch from 1bd8062 to 71c2379 Compare April 26, 2024 01:27
@ahonn
Copy link
Collaborator Author

ahonn commented Apr 29, 2024

It was found that the version of mempool/mempool.js npm package is stuck at v2.3.0 released two years ago and does not support the after_txid parameter.
So I fork the repository to publish @cell-studio/mempool.js and use it instead of mempool/mempool.js .

Raised the relevant issue to them: mempool/mempool.js#191, and will replace it with the npm package officially provided by mempool after a new version is released in the future. (If mempool is not updated, then we can also consider maintaining it ourselves)

cc @Flouse @ShookLyngs

@ahonn ahonn merged commit ce507f7 into develop Apr 29, 2024
4 checks passed
@ahonn ahonn deleted the feat/mempool-space-api branch April 29, 2024 07:36
@ahonn ahonn changed the title refactor: use mempool.space REST API feat(bitcoin)!: use mempool.space REST API May 6, 2024
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.

4 participants