Skip to content

Commit

Permalink
Release 0.3.0 (#5)
Browse files Browse the repository at this point in the history
* Use new rust bitcoin release

* Release 0.3.0

* Fix lints

* Update fmt script
  • Loading branch information
alekseysidorov authored Aug 31, 2018
1 parent 596c830 commit 771fe28
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 79 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
include:
# Formatting & other lints that do not require compilation
- env: FEATURE=lints
rust: 1.26.0
rust: 1.28.0
install:
- rustup component add rustfmt-preview
- rustfmt --version
Expand All @@ -66,16 +66,17 @@ jobs:
- npm install markdownlint-cli
- ./node_modules/.bin/markdownlint --version
script:
- cargo fmt --all -- --write-mode=diff
- cargo fmt --all -- --check
- ./node_modules/.bin/cspell {src,examples,tests}/**/*.rs
- find . -not -path "./node_modules/*" -name "*.md" | xargs ./node_modules/.bin/cspell
- find . -not -path "./node_modules/*" -name "*.md" | xargs ./node_modules/.bin/markdownlint --config .markdownlintrc

# Clippy linting
- env: FEATURE=clippy
rust: nightly-2018-05-05
rust: nightly-2018-08-30
install:
- cargo clippy --version | grep $CLIPPY_VERS || cargo install clippy --force --vers $CLIPPY_VERS
- rustup component add clippy-preview
- cargo clippy --version
script:
- cargo clippy --all -- -D warnings

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## 0.3 - 2018-08-31

### Breaking changes

- `bitcoin` dependency has been updated to the new major release `0.14.1`. (#5)

## 0.2 - 2018-05-24

### New features
Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "btc-transaction-utils"
version = "0.2.0"
version = "0.3.0"
description = "A collection of helpers for signing bitcoin transactions with segwit."
authors = ["The Exonum Team <[email protected]>"]
readme = "README.md"
Expand All @@ -11,13 +11,13 @@ categories = ["cryptography"]
keywords = ["crypto", "bitcoin", "segwit"]

[dependencies]
bitcoin = { version = "0.13.0" }
bitcoin = { version = "0.14.1" }
display_derive = "0.0.0"
failure = "0.1.1"
failure_derive = "0.1.1"
hex = "0.3.1"
rand = "0.4.0"
secp256k1 = { version = "0.9.0", features = ["rand"] }
serde = "1.0.37"
failure = "0.1.2"
failure_derive = "0.1.2"
hex = "0.3.2"
rand = "0.4.3"
secp256k1 = { version = "0.11.1", features = ["rand"] }
serde = "1.0.75"
serde_str = "0.1.0"
pretty_assertions = "0.5.1"
1 change: 1 addition & 0 deletions exonum-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ usize
validator
validator's
validators
vout
webhook
webhooks
Webhooks
Expand Down
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
//!
//! use bitcoin::blockdata::opcodes::All;
//! use bitcoin::blockdata::script::{Builder, Script};
//! use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
//! use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut};
//! use bitcoin::network::constants::Network;
//! use btc_transaction_utils::p2wpk;
//! use btc_transaction_utils::test_data::{secp_gen_keypair_with_rng, btc_tx_from_hex};
Expand Down Expand Up @@ -88,8 +88,10 @@
//! lock_time: 0,
//! input: vec![
//! TxIn {
//! prev_hash: prev_tx.txid(),
//! prev_index: 1,
//! previous_output: OutPoint {
//! txid: prev_tx.txid(),
//! vout: 1,
//! },
//! script_sig: Script::default(),
//! sequence: 0xFFFFFFFF,
//! witness: Vec::default(),
Expand Down Expand Up @@ -124,7 +126,7 @@
//!
//! use bitcoin::blockdata::opcodes::All;
//! use bitcoin::blockdata::script::{Builder, Script};
//! use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
//! use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut};
//! use bitcoin::network::constants::Network;
//! use btc_transaction_utils::multisig::RedeemScriptBuilder;
//! use btc_transaction_utils::p2wsh;
Expand Down Expand Up @@ -164,8 +166,10 @@
//! lock_time: 0,
//! input: vec![
//! TxIn {
//! prev_hash: prev_tx.txid(),
//! prev_index: 1,
//! previous_output: OutPoint {
//! txid: prev_tx.txid(),
//! vout: 1,
//! },
//! script_sig: Script::default(),
//! sequence: 0xFFFFFFFF,
//! witness: Vec::default(),
Expand Down Expand Up @@ -281,7 +285,7 @@ impl<'a> UnspentTxOutValue<'a> {
match self {
UnspentTxOutValue::Balance(value) => value,
UnspentTxOutValue::PrevTx(prev_tx) => {
prev_tx.output[txin.input().prev_index as usize].value
prev_tx.output[txin.input().previous_output.vout as usize].value
}
UnspentTxOutValue::PrevOut(out) => out.value,
}
Expand Down
6 changes: 3 additions & 3 deletions src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use bitcoin::blockdata::opcodes::{All, Class};
use bitcoin::blockdata::script::{read_uint, Builder, Instruction, Script};
use failure;
use hex;
use secp256k1::{PublicKey, Secp256k1};
use secp256k1::{None, PublicKey, Secp256k1};

/// A standard redeem script.
#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -110,7 +110,7 @@ impl RedeemScriptContent {
/// Tries to fetch redeem script content from the given raw script and returns error
/// if the script doesn't satisfy `BIP-16` standard.
pub fn parse(
context: &Secp256k1,
context: &Secp256k1<None>,
script: &Script,
) -> Result<RedeemScriptContent, RedeemScriptError> {
// The lint is false positive in this case.
Expand All @@ -132,7 +132,7 @@ impl RedeemScriptContent {
}
};

let mut instructions = script.into_iter().peekable();
let mut instructions = script.iter(true).peekable();
// Parses quorum.
let quorum = instructions
.next()
Expand Down
44 changes: 21 additions & 23 deletions src/p2wpk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bitcoin::blockdata::transaction::TxIn;
use bitcoin::network::constants::Network;
use bitcoin::util::address::Address;
use bitcoin::util::hash::{Hash160, Sha256dHash};
use secp256k1::{self, PublicKey, Secp256k1, SecretKey};
use secp256k1::{self, All, PublicKey, Secp256k1, SecretKey};

use sign;
use {InputSignature, InputSignatureRef, TxInRef, UnspentTxOutValue};
Expand All @@ -42,7 +42,7 @@ pub fn script_pubkey(pk: &PublicKey) -> Script {
/// An input signer.
#[derive(Debug)]
pub struct InputSigner {
context: Secp256k1,
context: Secp256k1<All>,
public_key: PublicKey,
network: Network,
}
Expand All @@ -58,12 +58,12 @@ impl InputSigner {
}

/// Returns a reference to the secp256k1 engine, used to execute all signature operations.
pub fn secp256k1_context(&self) -> &Secp256k1 {
pub fn secp256k1_context(&self) -> &Secp256k1<All> {
&self.context
}

/// Returns a mutable reference to the secp256k1 engine, used to execute all signature operations.
pub fn secp256k1_context_mut(&mut self) -> &mut Secp256k1 {
pub fn secp256k1_context_mut(&mut self) -> &mut Secp256k1<All> {
&mut self.context
}

Expand Down Expand Up @@ -136,13 +136,13 @@ impl InputSigner {
mod tests {
use bitcoin::blockdata::opcodes::All;
use bitcoin::blockdata::script::{Builder, Script};
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut};
use bitcoin::network::constants::Network;
use rand::{SeedableRng, StdRng};

use TxInRef;
use p2wpk;
use test_data::{btc_tx_from_hex, secp_gen_keypair_with_rng};
use TxInRef;

#[test]
fn test_native_segwit() {
Expand All @@ -163,24 +163,22 @@ mod tests {
let mut transaction = Transaction {
version: 2,
lock_time: 0,
input: vec![
TxIn {
prev_hash: prev_tx.txid(),
prev_index: 1,
script_sig: Script::default(),
sequence: 0xFFFFFFFF,
witness: Vec::default(),
},
],
output: vec![
TxOut {
value: 0,
script_pubkey: Builder::new()
.push_opcode(All::OP_RETURN)
.push_slice(b"Hello Exonum!")
.into_script(),
input: vec![TxIn {
previous_output: OutPoint {
txid: prev_tx.txid(),
vout: 1,
},
],
script_sig: Script::default(),
sequence: 0xFFFFFFFF,
witness: Vec::default(),
}],
output: vec![TxOut {
value: 0,
script_pubkey: Builder::new()
.push_opcode(All::OP_RETURN)
.push_slice(b"Hello Exonum!")
.into_script(),
}],
};
// Makes signature.
let mut signer = p2wpk::InputSigner::new(pk, Network::Testnet);
Expand Down
44 changes: 21 additions & 23 deletions src/p2wsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bitcoin::blockdata::transaction::TxIn;
use bitcoin::network::constants::Network;
use bitcoin::util::address::Address;
use bitcoin::util::hash::Sha256dHash;
use secp256k1::{self, PublicKey, Secp256k1, SecretKey};
use secp256k1::{self, All, PublicKey, Secp256k1, SecretKey};

use multisig::RedeemScript;
use sign;
Expand All @@ -38,7 +38,7 @@ pub fn script_pubkey(redeem_script: &RedeemScript) -> Script {
/// An input signer.
#[derive(Debug)]
pub struct InputSigner {
context: Secp256k1,
context: Secp256k1<All>,
script: RedeemScript,
}

Expand All @@ -52,12 +52,12 @@ impl InputSigner {
}

/// Returns a reference to the secp256k1 engine, used to execute all signature operations.
pub fn secp256k1_context(&self) -> &Secp256k1 {
pub fn secp256k1_context(&self) -> &Secp256k1<All> {
&self.context
}

/// Returns a mutable reference to the secp256k1 engine, used to execute all signature operations.
pub fn secp256k1_context_mut(&mut self) -> &mut Secp256k1 {
pub fn secp256k1_context_mut(&mut self) -> &mut Secp256k1<All> {
&mut self.context
}

Expand Down Expand Up @@ -123,7 +123,7 @@ impl InputSigner {
fn witness_data<I: IntoIterator<Item = Vec<u8>>>(&self, signatures: I) -> Vec<Vec<u8>> {
let mut witness_stack = vec![Vec::default()];
witness_stack.extend(signatures);
witness_stack.push(self.script.0.clone().into_vec());
witness_stack.push(self.script.0[..].to_vec());
witness_stack
}
}
Expand All @@ -132,7 +132,7 @@ impl InputSigner {
mod tests {
use bitcoin::blockdata::opcodes::All;
use bitcoin::blockdata::script::{Builder, Script};
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut};
use rand::{SeedableRng, StdRng};

use multisig::RedeemScriptBuilder;
Expand Down Expand Up @@ -173,24 +173,22 @@ mod tests {
let mut transaction = Transaction {
version: 2,
lock_time: 0,
input: vec![
TxIn {
prev_hash: prev_tx.txid(),
prev_index: 1,
script_sig: Script::default(),
sequence: 0xFFFFFFFF,
witness: Vec::default(),
input: vec![TxIn {
previous_output: OutPoint {
txid: prev_tx.txid(),
vout: 1,
},
],
output: vec![
TxOut {
value: 0,
script_pubkey: Builder::new()
.push_opcode(All::OP_RETURN)
.push_slice(b"Hello Exonum with multisig!")
.into_script(),
},
],
script_sig: Script::default(),
sequence: 0xFFFFFFFF,
witness: Vec::default(),
}],
output: vec![TxOut {
value: 0,
script_pubkey: Builder::new()
.push_opcode(All::OP_RETURN)
.push_slice(b"Hello Exonum with multisig!")
.into_script(),
}],
};

// Signs transaction.
Expand Down
Loading

0 comments on commit 771fe28

Please sign in to comment.