-
Notifications
You must be signed in to change notification settings - Fork 260
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
RFC: Total refactor to support sync & async clients #294
Open
stevenroose
wants to merge
5
commits into
rust-bitcoin:master
Choose a base branch
from
stevenroose:syncasync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,162
−1,886
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "bitcoincore-rpc" | ||
version = "0.17.0" | ||
version = "1.0.0-rc0" | ||
authors = [ | ||
"Steven Roose <[email protected]>", | ||
"Jean Pierre Dudey <[email protected]>", | ||
|
@@ -18,13 +18,18 @@ edition = "2018" | |
name = "bitcoincore_rpc" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = [ "async" ] | ||
async = [ "async-trait" ] | ||
|
||
[dependencies] | ||
bitcoincore-rpc-json = { version = "0.17.0", path = "../json" } | ||
bitcoincore-rpc-json = { version = "1.0.0-rc0", path = "../json" } | ||
|
||
log = "0.4.5" | ||
jsonrpc = "0.14.0" | ||
jsonrpc = { git = "https://github.com/stevenroose/rust-jsonrpc", branch = "request" } | ||
|
||
# Used for deserialization of JSON. | ||
serde = "1" | ||
serde_json = "1" | ||
bitcoin-private = "0.1.0" | ||
|
||
async-trait = { version = "0.1.53", optional = true } |
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 |
---|---|---|
@@ -1,47 +1,47 @@ | ||
// 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/>. | ||
// | ||
//// 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 bitcoincore_rpc; | ||
extern crate jsonrpc; | ||
extern crate serde; | ||
extern crate serde_json; | ||
//extern crate bitcoincore_rpc; | ||
//extern crate jsonrpc; | ||
//extern crate serde; | ||
//extern crate serde_json; | ||
|
||
use bitcoincore_rpc::{Client, Error, Result, RpcApi}; | ||
//use bitcoincore_rpc::{Client, Error, Result, RpcApi}; | ||
|
||
pub struct RetryClient { | ||
client: Client, | ||
} | ||
//pub struct RetryClient { | ||
// client: Client, | ||
//} | ||
|
||
const INTERVAL: u64 = 1000; | ||
const RETRY_ATTEMPTS: u8 = 10; | ||
//const INTERVAL: u64 = 1000; | ||
//const RETRY_ATTEMPTS: u8 = 10; | ||
|
||
impl RpcApi for RetryClient { | ||
fn call<T: for<'a> serde::de::Deserialize<'a>>( | ||
&self, | ||
cmd: &str, | ||
args: &[serde_json::Value], | ||
) -> Result<T> { | ||
for _ in 0..RETRY_ATTEMPTS { | ||
match self.client.call(cmd, args) { | ||
Ok(ret) => return Ok(ret), | ||
Err(Error::JsonRpc(jsonrpc::error::Error::Rpc(ref rpcerr))) | ||
if rpcerr.code == -28 => | ||
{ | ||
::std::thread::sleep(::std::time::Duration::from_millis(INTERVAL)); | ||
continue; | ||
} | ||
Err(e) => return Err(e), | ||
} | ||
} | ||
self.client.call(cmd, args) | ||
} | ||
} | ||
//impl RpcApi for RetryClient { | ||
// fn call<T: for<'a> serde::de::Deserialize<'a>>( | ||
// &self, | ||
// cmd: &str, | ||
// args: &[serde_json::Value], | ||
// ) -> Result<T> { | ||
// for _ in 0..RETRY_ATTEMPTS { | ||
// match self.client.call(cmd, args) { | ||
// Ok(ret) => return Ok(ret), | ||
// Err(Error::JsonRpc(jsonrpc::error::Error::Rpc(ref rpcerr))) | ||
// if rpcerr.code == -28 => | ||
// { | ||
// ::std::thread::sleep(::std::time::Duration::from_millis(INTERVAL)); | ||
// continue; | ||
// } | ||
// Err(e) => return Err(e), | ||
// } | ||
// } | ||
// self.client.call(cmd, args) | ||
// } | ||
//} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -1,48 +1,50 @@ | ||
// 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/>. | ||
// | ||
|
||
//! A very simple example used as a self-test of this library against a Bitcoin | ||
//! Core node. | ||
extern crate bitcoincore_rpc; | ||
|
||
use bitcoincore_rpc::{bitcoin, Auth, Client, Error, RpcApi}; | ||
|
||
fn main_result() -> Result<(), Error> { | ||
let mut args = std::env::args(); | ||
|
||
let _exe_name = args.next().unwrap(); | ||
|
||
let url = args.next().expect("Usage: <rpc_url> <username> <password>"); | ||
let user = args.next().expect("no user given"); | ||
let pass = args.next().expect("no pass given"); | ||
|
||
let rpc = Client::new(&url, Auth::UserPass(user, pass)).unwrap(); | ||
|
||
let _blockchain_info = rpc.get_blockchain_info()?; | ||
|
||
let best_block_hash = rpc.get_best_block_hash()?; | ||
println!("best block hash: {}", best_block_hash); | ||
let bestblockcount = rpc.get_block_count()?; | ||
println!("best block height: {}", bestblockcount); | ||
let best_block_hash_by_height = rpc.get_block_hash(bestblockcount)?; | ||
println!("best block hash by height: {}", best_block_hash_by_height); | ||
assert_eq!(best_block_hash_by_height, best_block_hash); | ||
|
||
let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash)?; | ||
println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash); | ||
let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].txid())?; | ||
println!("tx by `get`: {}", bitcoin_tx.txid()); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
main_result().unwrap(); | ||
} | ||
//// 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/>. | ||
//// | ||
|
||
////! A very simple example used as a self-test of this library against a Bitcoin | ||
////! Core node. | ||
//extern crate bitcoincore_rpc; | ||
|
||
//use bitcoincore_rpc::{bitcoin, Auth, Client, Error, RpcApi}; | ||
|
||
//fn main_result() -> Result<(), Error> { | ||
// let mut args = std::env::args(); | ||
|
||
// let _exe_name = args.next().unwrap(); | ||
|
||
// let url = args.next().expect("Usage: <rpc_url> <username> <password>"); | ||
// let user = args.next().expect("no user given"); | ||
// let pass = args.next().expect("no pass given"); | ||
|
||
// let rpc = Client::new(&url, Auth::UserPass(user, pass)).unwrap(); | ||
|
||
// let _blockchain_info = rpc.get_blockchain_info()?; | ||
|
||
// let best_block_hash = rpc.get_best_block_hash()?; | ||
// println!("best block hash: {}", best_block_hash); | ||
// let bestblockcount = rpc.get_block_count()?; | ||
// println!("best block height: {}", bestblockcount); | ||
// let best_block_hash_by_height = rpc.get_block_hash(bestblockcount)?; | ||
// println!("best block hash by height: {}", best_block_hash_by_height); | ||
// assert_eq!(best_block_hash_by_height, best_block_hash); | ||
|
||
// let bitcoin_block: bitcoin::Block = rpc.get_by_id(&best_block_hash)?; | ||
// println!("best block hash by `get`: {}", bitcoin_block.header.prev_blockhash); | ||
// let bitcoin_tx: bitcoin::Transaction = rpc.get_by_id(&bitcoin_block.txdata[0].txid())?; | ||
// println!("tx by `get`: {}", bitcoin_tx.txid()); | ||
|
||
// Ok(()) | ||
//} | ||
|
||
//fn main() { | ||
// main_result().unwrap(); | ||
//} | ||
|
||
fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very Nit: I don't really have any history in this repo but just wanted to register a vote in favor of keeping
rustfmt
. We have had the discussion before elsewhere so won't repeat but IMHO formatting consistency is more important than disliking some of rustfmt behaviourThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 Let's say I did this to see if CI would work without having to already deal with how rustfmt is going to decide how I should have formatted my code.