#bitcoin #rpc #client #api

throttled_bitcoin_rpc

Throttled Bitcoin RPC API client for Rust

4 releases

0.1.3 Apr 1, 2019
0.1.2 Feb 8, 2019
0.1.1 Jan 24, 2019
0.1.0 Jan 24, 2019
Download history 22/week @ 2019-01-23 2/week @ 2019-01-30 12/week @ 2019-02-06 12/week @ 2019-02-13 2/week @ 2019-02-20 10/week @ 2019-02-27 7/week @ 2019-03-06 7/week @ 2019-03-13 44/week @ 2019-03-20 118/week @ 2019-03-27

83 downloads per month

MIT/Apache

31KB
678 lines

Throttled Bitcoin RPC Client

This crate started as a fork of JeanDudey's Bitcoin RPC client, but has since been almost entirely rewritten.

This crate implements an Bitcoin RPC client in Rust, it does not intend to be a complete implementation of all the bitcoin rpc methods so if you need some method you can create a pull request for it.

AltCoins

Works with LTC and DOGE using relevant compiler flags.

Usage

Add this to your Cargo.toml:

[dependencies]
throttled_bitcoin_rpc = "0.1.0"

And this to your crate root:

extern crate throttled_bitcoin_rpc;

Example: Connecting to bitcoin rpc server

extern crate throttled_bitcoin_rpc;

use throttled_bitcoin_rpc::BitcoinRpcClient;

fn main() {
    let client = BitcoinRpcClient::new(
        "example.org:8331",
        Some("bitcoin".to_owned()),
        Some("local321".to_owned()),
        3, // max number of concurrent requests
        10, // max number of requests per second
        1000, // max size of batched requests
    );

    let block_count = match client.getblockcount().unwrap();

    println!("Block count: {}", block_count);
    
    let txs = vec![
        "02617e68e8c3e3fa8763502c0e701bf5af1e8f57835b9bef1ee333b0fcf2527",
        "969947e164bbfca77cb09eab343b192cb5605bfa0483b4d2a3ec626e55ad70bc",
        "743f6202f89acc41adce4496244f152833ffb9f1f7a6d6e6fc94d85580ac9461",
    ];
    
    use throttled_bitcoin_rpc::BatchRequest;
    let mut batcher = client::batcher::<String>();
    
    for txid in txs {
        batcher.getrawtransaction(txid.to_owned(), false).unwrap();
    }
    
    println!("Raw TxData: {:?}", batcher.send().unwrap());
}

Dependencies

~17MB
~379K SLoC