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

Implement JSON-RPC batching #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ members = [
"json",
"client",
]

[patch.crates-io]
jsonrpc = { path = "/home/steven/code/rust/jsonrpc" }
42 changes: 42 additions & 0 deletions client/examples/batching.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//

extern crate bitcoin;
extern crate bitcoincore_rpc;

use bitcoincore_rpc::{Client, Error};

fn main_result() -> Result<(), Error> {
let url = "http://localhost:18332/".to_owned();
let user = Some("rpcuser".to_owned());
let pass = Some("rpcpass".to_owned());

let rpc = Client::new(url, user, pass);

let mut batch = rpc.start_batch();

let blockchain_info = batch.get_blockchain_info()?;
let best_block_hash = batch.get_best_block_hash()?;
let best_block_count = batch.get_block_count()?;

println!("result ready: {}", blockchain_info.ready());
batch.execute()?;
println!("result ready: {}", blockchain_info.ready());

println!("chain: {}", blockchain_info.take()?.chain);
println!("best block hash: {}", best_block_hash.take()?);
println!("best block height: {}", best_block_count.take()?);

Ok(())
}

fn main() {
main_result().unwrap();
}
Loading