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

Update rust-bitcoin and use bitcoin hashes new library #22

Merged
merged 2 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/Cargo.toml
Expand Up @@ -29,7 +29,8 @@ serde_json = "1"
hex = "0.3"

# Used for Bitcoin-specific types.
bitcoin = { version = "0.16", features = [ "serde-decimal" ] }
bitcoin = { version = "0.17", features = [ "serde-decimal" ] }
bitcoin_hashes = "0.3"
bitcoin-amount = { version = "0.1.4", features = [ "serde" ] }
secp256k1 = { version = "0.12", features = [ "serde" ] }
num-bigint = { version = "0.2", features = [ "serde" ] }
42 changes: 21 additions & 21 deletions client/src/client.rs
Expand Up @@ -16,7 +16,7 @@ use jsonrpc;
use serde;
use serde_json;

use bitcoin::util::hash::Sha256dHash;
use bitcoin_hashes::sha256d;
use bitcoin::{Address, Block, BlockHeader, Transaction};
use bitcoin_amount::Amount;
use log::Level::Trace;
Expand Down Expand Up @@ -165,30 +165,30 @@ pub trait RpcApi: Sized {
self.call("getconnectioncount", &[])
}

fn get_block(&self, hash: &Sha256dHash) -> Result<Block> {
fn get_block(&self, hash: &sha256d::Hash) -> Result<Block> {
let hex: String = self.call("getblock", &[into_json(hash)?, 0.into()])?;
let bytes = hex::decode(hex)?;
Ok(bitcoin::consensus::encode::deserialize(&bytes)?)
}

fn get_block_hex(&self, hash: &Sha256dHash) -> Result<String> {
fn get_block_hex(&self, hash: &sha256d::Hash) -> Result<String> {
self.call("getblock", &[into_json(hash)?, 0.into()])
}

fn get_block_info(&self, hash: &Sha256dHash) -> Result<json::GetBlockResult> {
fn get_block_info(&self, hash: &sha256d::Hash) -> Result<json::GetBlockResult> {
self.call("getblock", &[into_json(hash)?, 1.into()])
}
//TODO(stevenroose) add getblock_txs

fn get_block_header_raw(&self, hash: &Sha256dHash) -> Result<BlockHeader> {
fn get_block_header_raw(&self, hash: &sha256d::Hash) -> Result<BlockHeader> {
let hex: String = self.call("getblockheader", &[into_json(hash)?, false.into()])?;
let bytes = hex::decode(hex)?;
Ok(bitcoin::consensus::encode::deserialize(&bytes)?)
}

fn get_block_header_verbose(
&self,
hash: &Sha256dHash,
hash: &sha256d::Hash,
) -> Result<json::GetBlockHeaderResult> {
self.call("getblockheader", &[into_json(hash)?, true.into()])
}
Expand All @@ -209,19 +209,19 @@ pub trait RpcApi: Sized {
}

/// Returns the hash of the best (tip) block in the longest blockchain.
fn get_best_block_hash(&self) -> Result<Sha256dHash> {
fn get_best_block_hash(&self) -> Result<sha256d::Hash> {
self.call("getbestblockhash", &[])
}

/// Get block hash at a given height
fn get_block_hash(&self, height: u64) -> Result<Sha256dHash> {
fn get_block_hash(&self, height: u64) -> Result<sha256d::Hash> {
self.call("getblockhash", &[height.into()])
}

fn get_raw_transaction(
&self,
txid: &Sha256dHash,
block_hash: Option<&Sha256dHash>,
txid: &sha256d::Hash,
block_hash: Option<&sha256d::Hash>,
) -> Result<Transaction> {
let mut args = [into_json(txid)?, into_json(false)?, opt_into_json(block_hash)?];
let hex: String = self.call("getrawtransaction", handle_defaults(&mut args, &[null()]))?;
Expand All @@ -231,17 +231,17 @@ pub trait RpcApi: Sized {

fn get_raw_transaction_hex(
&self,
txid: &Sha256dHash,
block_hash: Option<&Sha256dHash>,
txid: &sha256d::Hash,
block_hash: Option<&sha256d::Hash>,
) -> Result<String> {
let mut args = [into_json(txid)?, into_json(false)?, opt_into_json(block_hash)?];
self.call("getrawtransaction", handle_defaults(&mut args, &[null()]))
}

fn get_raw_transaction_verbose(
&self,
txid: &Sha256dHash,
block_hash: Option<&Sha256dHash>,
txid: &sha256d::Hash,
block_hash: Option<&sha256d::Hash>,
) -> Result<json::GetRawTransactionResult> {
let mut args = [into_json(txid)?, into_json(true)?, opt_into_json(block_hash)?];
self.call("getrawtransaction", handle_defaults(&mut args, &[null()]))
Expand All @@ -258,7 +258,7 @@ pub trait RpcApi: Sized {

fn get_transaction(
&self,
txid: &Sha256dHash,
txid: &sha256d::Hash,
include_watchonly: Option<bool>,
) -> Result<json::GetTransactionResult> {
let mut args = [into_json(txid)?, opt_into_json(include_watchonly)?];
Expand All @@ -267,7 +267,7 @@ pub trait RpcApi: Sized {

fn get_tx_out(
&self,
txid: &Sha256dHash,
txid: &sha256d::Hash,
vout: u32,
include_mempool: Option<bool>,
) -> Result<Option<json::GetTxOutResult>> {
Expand Down Expand Up @@ -437,7 +437,7 @@ pub trait RpcApi: Sized {
&self,
block_num: u64,
address: &str,
) -> Result<Vec<Sha256dHash>> {
) -> Result<Vec<sha256d::Hash>> {
self.call("generatetoaddress", &[block_num.into(), address.into()])
}

Expand All @@ -447,12 +447,12 @@ pub trait RpcApi: Sized {
&self,
block_num: u64,
maxtries: Option<u64>,
) -> Result<Vec<Sha256dHash>> {
) -> Result<Vec<sha256d::Hash>> {
self.call("generate", &[block_num.into(), opt_into_json(maxtries)?])
}

/// Mark a block as invalid by `block_hash`
fn invalidate_block(&self, block_hash: &Sha256dHash) -> Result<()> {
fn invalidate_block(&self, block_hash: &sha256d::Hash) -> Result<()> {
self.call("invalidateblock", &[into_json(block_hash)?])
}

Expand All @@ -463,7 +463,7 @@ pub trait RpcApi: Sized {
comment: Option<&str>,
comment_to: Option<&str>,
substract_fee: Option<bool>,
) -> Result<Sha256dHash> {
) -> Result<sha256d::Hash> {
let mut args = [
into_json(addr)?,
into_json(amount)?,
Expand Down Expand Up @@ -527,7 +527,7 @@ pub trait RpcApi: Sized {
/// indicates no timeout.
fn wait_for_block(
&self,
blockhash: &Sha256dHash,
blockhash: &sha256d::Hash,
timeout: u64,
) -> Result<json::BlockRef> {
let args = [into_json(blockhash)?, into_json(timeout)?];
Expand Down
1 change: 1 addition & 0 deletions client/src/lib.rs
Expand Up @@ -20,6 +20,7 @@
extern crate log;
extern crate bitcoin;
extern crate bitcoin_amount;
extern crate bitcoin_hashes;
extern crate hex;
extern crate jsonrpc;
extern crate num_bigint;
Expand Down
6 changes: 3 additions & 3 deletions client/src/queryable.rs
Expand Up @@ -11,7 +11,7 @@
use bitcoin;
use serde_json;

use bitcoin::util::hash::Sha256dHash;
use bitcoin_hashes::sha256d;
use client::RpcApi;
use client::Result;

Expand All @@ -24,7 +24,7 @@ pub trait Queryable<C: RpcApi>: Sized {
}

impl<C: RpcApi> Queryable<C> for bitcoin::blockdata::block::Block {
type Id = Sha256dHash;
type Id = sha256d::Hash;

fn query(rpc: &C, id: &Self::Id) -> Result<Self> {
let rpc_name = "getblock";
Expand All @@ -35,7 +35,7 @@ impl<C: RpcApi> Queryable<C> for bitcoin::blockdata::block::Block {
}

impl<C: RpcApi> Queryable<C> for bitcoin::blockdata::transaction::Transaction {
type Id = Sha256dHash;
type Id = sha256d::Hash;

fn query(rpc: &C, id: &Self::Id) -> Result<Self> {
let rpc_name = "getrawtransaction";
Expand Down
3 changes: 2 additions & 1 deletion json/Cargo.toml
Expand Up @@ -23,7 +23,8 @@ serde_derive = "1"
serde_json = "1"
hex = "0.3"

bitcoin = { version = "0.16", features = [ "serde-decimal" ] }
bitcoin = { version = "0.17", features = [ "serde-decimal" ] }
bitcoin_hashes = "0.3"
bitcoin-amount = { version = "0.1.4", features = [ "serde" ] }
secp256k1 = { version = "0.12", features = [ "serde" ] }
num-bigint = { version = "0.2", features = [ "serde" ] }