Skip to content

Commit ecaf84f

Browse files
committed
sync/async refactor
1 parent f841396 commit ecaf84f

21 files changed

+5129
-1849
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ members = [
55
"client",
66
"integration_test",
77
]
8+
9+
[patch."crates-io"]
10+
bitcoin = { git = "https://github.com/stevenroose/rust-bitcoin", branch = "dev" }
11+
bitcoin_hashes = { git = "https://github.com/stevenroose/rust-bitcoin", branch = "dev" }

client/Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bitcoincore-rpc"
3-
version = "0.17.0"
3+
version = "1.0.0-rc0"
44
authors = [
55
"Steven Roose <[email protected]>",
66
"Jean Pierre Dudey <[email protected]>",
@@ -18,13 +18,18 @@ edition = "2018"
1818
name = "bitcoincore_rpc"
1919
path = "src/lib.rs"
2020

21+
[features]
22+
default = [ "async" ]
23+
async = [ "async-trait" ]
24+
2125
[dependencies]
22-
bitcoincore-rpc-json = { version = "0.17.0", path = "../json" }
26+
bitcoincore-rpc-json = { version = "1.0.0-rc0", path = "../json" }
2327

2428
log = "0.4.5"
25-
jsonrpc = "0.14.0"
29+
jsonrpc = { git = "https://github.com/stevenroose/rust-jsonrpc", branch = "request" }
2630

2731
# Used for deserialization of JSON.
2832
serde = "1"
2933
serde_json = "1"
30-
bitcoin-private = "0.1.0"
34+
35+
async-trait = { version = "0.1.53", optional = true }

client/examples/retry_client.rs

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
// To the extent possible under law, the author(s) have dedicated all
2-
// copyright and related and neighboring rights to this software to
3-
// the public domain worldwide. This software is distributed without
4-
// any warranty.
5-
//
6-
// You should have received a copy of the CC0 Public Domain Dedication
7-
// along with this software.
8-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9-
//
1+
//// To the extent possible under law, the author(s) have dedicated all
2+
//// copyright and related and neighboring rights to this software to
3+
//// the public domain worldwide. This software is distributed without
4+
//// any warranty.
5+
////
6+
//// You should have received a copy of the CC0 Public Domain Dedication
7+
//// along with this software.
8+
//// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9+
////
1010

11-
extern crate bitcoincore_rpc;
12-
extern crate jsonrpc;
13-
extern crate serde;
14-
extern crate serde_json;
11+
//extern crate bitcoincore_rpc;
12+
//extern crate jsonrpc;
13+
//extern crate serde;
14+
//extern crate serde_json;
1515

16-
use bitcoincore_rpc::{Client, Error, Result, RpcApi};
16+
//use bitcoincore_rpc::{Client, Error, Result, RpcApi};
1717

18-
pub struct RetryClient {
19-
client: Client,
20-
}
18+
//pub struct RetryClient {
19+
// client: Client,
20+
//}
2121

22-
const INTERVAL: u64 = 1000;
23-
const RETRY_ATTEMPTS: u8 = 10;
22+
//const INTERVAL: u64 = 1000;
23+
//const RETRY_ATTEMPTS: u8 = 10;
2424

25-
impl RpcApi for RetryClient {
26-
fn call<T: for<'a> serde::de::Deserialize<'a>>(
27-
&self,
28-
cmd: &str,
29-
args: &[serde_json::Value],
30-
) -> Result<T> {
31-
for _ in 0..RETRY_ATTEMPTS {
32-
match self.client.call(cmd, args) {
33-
Ok(ret) => return Ok(ret),
34-
Err(Error::JsonRpc(jsonrpc::error::Error::Rpc(ref rpcerr)))
35-
if rpcerr.code == -28 =>
36-
{
37-
::std::thread::sleep(::std::time::Duration::from_millis(INTERVAL));
38-
continue;
39-
}
40-
Err(e) => return Err(e),
41-
}
42-
}
43-
self.client.call(cmd, args)
44-
}
45-
}
25+
//impl RpcApi for RetryClient {
26+
// fn call<T: for<'a> serde::de::Deserialize<'a>>(
27+
// &self,
28+
// cmd: &str,
29+
// args: &[serde_json::Value],
30+
// ) -> Result<T> {
31+
// for _ in 0..RETRY_ATTEMPTS {
32+
// match self.client.call(cmd, args) {
33+
// Ok(ret) => return Ok(ret),
34+
// Err(Error::JsonRpc(jsonrpc::error::Error::Rpc(ref rpcerr)))
35+
// if rpcerr.code == -28 =>
36+
// {
37+
// ::std::thread::sleep(::std::time::Duration::from_millis(INTERVAL));
38+
// continue;
39+
// }
40+
// Err(e) => return Err(e),
41+
// }
42+
// }
43+
// self.client.call(cmd, args)
44+
// }
45+
//}
4646

4747
fn main() {}

client/examples/test_against_node.rs

+50-48
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
1-
// To the extent possible under law, the author(s) have dedicated all
2-
// copyright and related and neighboring rights to this software to
3-
// the public domain worldwide. This software is distributed without
4-
// any warranty.
5-
//
6-
// You should have received a copy of the CC0 Public Domain Dedication
7-
// along with this software.
8-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9-
//
10-
11-
//! A very simple example used as a self-test of this library against a Bitcoin
12-
//! Core node.
13-
extern crate bitcoincore_rpc;
14-
15-
use bitcoincore_rpc::{bitcoin, Auth, Client, Error, RpcApi};
16-
17-
fn main_result() -> Result<(), Error> {
18-
let mut args = std::env::args();
19-
20-
let _exe_name = args.next().unwrap();
21-
22-
let url = args.next().expect("Usage: <rpc_url> <username> <password>");
23-
let user = args.next().expect("no user given");
24-
let pass = args.next().expect("no pass given");
25-
26-
let rpc = Client::new(&url, Auth::UserPass(user, pass)).unwrap();
27-
28-
let _blockchain_info = rpc.get_blockchain_info()?;
29-
30-
let best_block_hash = rpc.get_best_block_hash()?;
31-
println!("best block hash: {}", best_block_hash);
32-
let bestblockcount = rpc.get_block_count()?;
33-
println!("best block height: {}", bestblockcount);
34-
let best_block_hash_by_height = rpc.get_block_hash(bestblockcount)?;
35-
println!("best block hash by height: {}", best_block_hash_by_height);
36-
assert_eq!(best_block_hash_by_height, best_block_hash);
37-
38-
let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash)?;
39-
println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash);
40-
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].txid())?;
41-
println!("tx by `get`: {}", bitcoin_tx.txid());
42-
43-
Ok(())
44-
}
45-
46-
fn main() {
47-
main_result().unwrap();
48-
}
1+
//// To the extent possible under law, the author(s) have dedicated all
2+
//// copyright and related and neighboring rights to this software to
3+
//// the public domain worldwide. This software is distributed without
4+
//// any warranty.
5+
////
6+
//// You should have received a copy of the CC0 Public Domain Dedication
7+
//// along with this software.
8+
//// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9+
////
10+
11+
////! A very simple example used as a self-test of this library against a Bitcoin
12+
////! Core node.
13+
//extern crate bitcoincore_rpc;
14+
15+
//use bitcoincore_rpc::{bitcoin, Auth, Client, Error, RpcApi};
16+
17+
//fn main_result() -> Result<(), Error> {
18+
// let mut args = std::env::args();
19+
20+
// let _exe_name = args.next().unwrap();
21+
22+
// let url = args.next().expect("Usage: <rpc_url> <username> <password>");
23+
// let user = args.next().expect("no user given");
24+
// let pass = args.next().expect("no pass given");
25+
26+
// let rpc = Client::new(&url, Auth::UserPass(user, pass)).unwrap();
27+
28+
// let _blockchain_info = rpc.get_blockchain_info()?;
29+
30+
// let best_block_hash = rpc.get_best_block_hash()?;
31+
// println!("best block hash: {}", best_block_hash);
32+
// let bestblockcount = rpc.get_block_count()?;
33+
// println!("best block height: {}", bestblockcount);
34+
// let best_block_hash_by_height = rpc.get_block_hash(bestblockcount)?;
35+
// println!("best block hash by height: {}", best_block_hash_by_height);
36+
// assert_eq!(best_block_hash_by_height, best_block_hash);
37+
38+
// let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash)?;
39+
// println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash);
40+
// let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].txid())?;
41+
// println!("tx by `get`: {}", bitcoin_tx.txid());
42+
43+
// Ok(())
44+
//}
45+
46+
//fn main() {
47+
// main_result().unwrap();
48+
//}
49+
50+
fn main() {}

0 commit comments

Comments
 (0)