-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example with use of batching API
- Loading branch information
1 parent
3d1155f
commit bc1aaab
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |