Skip to content

nervana21/bitcoin-rpc-codegen

Repository files navigation

License: MIT Docs.rs crates.io

bitcoin-rpc-codegen

Generate bitcoin-rpc-midas, a Bitcoin Core client that supercharges Bitcoin testing and development.

Why Use This?

Compared to hand-written RPC clients, midas offers:

  • Reduced repetition
  • Fewer versioning issues
  • Increased compile-time checks
  • Improved isolation from environment glitches

Together, these features translate Bitcoin Core into idiomatic Rust.

Semantic Compression

This project applies semantic compression. It models the RPC surface as a structured schema and generates type-safe Rust clients directly from that schema. This unites Rust consumers of the RPC interface layer. All generated code is derived from a single source of truth: bitcoin-core-api.json. By adopting this schema, consistency is guaranteed not only within this codebase, but also across any Rust project that consumes Core RPCs.

Deep Dive: docs/semantic-compression.md

Architecture

See docs/architecture.mmd for a full system diagram.

Project Structure

The project is organized into several focused crates:

  • types: Type definitions for Bitcoin Core's JSON-RPC interface
  • conversions: For converting Bitcoin RPC types to Rust types
  • codegen: Emits idiomatic Rust modules and clients
  • pipeline: Coordinates end-to-end code generation
  • transport: RPC transport and error handling
  • node: Multi-node management and test client support
  • config: Configuration utilities

All components are modular and reusable.

Example

This asynchronous example uses Tokio and enables some optional features, so your Cargo.toml could look like this:

[dependencies]
bitcoin-rpc-midas = "29.1.2"
tokio = { version = "1.0", features = ["full"] }

And then the code:

use bitcoin_rpc_midas::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BitcoinTestClient::new_with_network(Network::Regtest).await?;

    let blockchain_info = client.getblockchaininfo().await?;
    println!("Blockchain info:\n{blockchain_info:#?}");

    Ok(())
}

Contributing

Contributors are warmly welcome, see CONTRIBUTING.md.

License

MIT OR Apache-2.0

Related Projects

Part of the bitcoin-rpc crate ecosystem, providing type-safe Rust primitives for testing and development at the Bitcoin Core JSON-RPC interface.

Security

This library communicates directly with bitcoind. For mainnet use, restrict RPC access to trusted hosts and avoid exposing RPC endpoints to untrusted networks.

About

Generate rust clients from Bitcoin Core

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages