Skip to content

Commit

Permalink
Merge pull request #142 from alekseysidorov/release-0.11
Browse files Browse the repository at this point in the history
Release 0.11
  • Loading branch information
alekseysidorov committed Mar 15, 2019
2 parents f59f3fa + 51711cb commit 70f4f2f
Show file tree
Hide file tree
Showing 28 changed files with 183 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ addons:
rust:
# Feel free to bump this version if you need features of newer Rust.
# Sync with badge in README.md
- 1.31.0
- 1.33.0

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

## [Unreleased]

## 0.11.0 - 2018-03-15

### Internal improvements

- Updated to the `Rust-bitcoin 0.17` release. (#142)
- Crate has been updated to Rust 2018 edition. This means that it is required
to use Rust 1.31 or newer for compilation. (#142)

## 0.10.0 - 2018-12-14

### Internal improvements
Expand Down
29 changes: 15 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "exonum-btc-anchoring"
version = "0.10.0"
edition = "2018"
version = "0.11.0"
authors = ["The Exonum Team <[email protected]>"]
homepage = "https://exonum.com/doc/advanced/bitcoin-anchoring/"
repository = "https://github.com/exonum/exonum-btc-anchoring"
Expand All @@ -15,24 +16,25 @@ description = "An Exonum service that provides anchoring to Bitcoin blockchain."
travis-ci = { repository = "exonum/exonum-btc-anchoring" }

[dependencies]
bitcoin = { version = "0.15", features = ["serde"] }
btc-transaction-utils = "0.4"
byteorder = "1.2"
bitcoin = { version = "0.17", features = ["serde"] }
bitcoin_hashes = { version = "0.3", features = ["serde"] }
btc-transaction-utils = "0.5"
byteorder = "1.3"
clap = "2.32"
derive_more = "0.13"
exonum = "0.10.0"
derive_more = "0.14"
exonum = "0.11.0"
exonum_bitcoinrpc = "0.6"
exonum-derive = "0.10.0"
exonum-testkit = "0.10.0"
exonum-derive = "0.11.0"
exonum-testkit = "0.11.0"
failure = "0.1"
failure_derive = "0.1"
hex = "0.3"
log = "0.4"
maplit = "1.0"
matches = "0.1"
protobuf = { version = "2.2", features = ["with-serde"] }
protobuf = { version = "2.4", features = ["with-serde"] }
rand = "0.4"
secp256k1 = { version = "0.11", features = ["serde"] }
secp256k1 = { version = "0.12", features = ["serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand All @@ -41,10 +43,9 @@ structopt = "0.2"
toml = "0.4"

[dev-dependencies]
exonum-configuration = "0.10.0"
exonum-configuration = "0.11.0"
libc = "0.2"
pretty_assertions = "0.5"
proptest = "0.8"
proptest = "0.9"

[build-dependencies]
exonum-build = "0.10.0"
exonum-build = "0.11.0"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ btc_anchoring generate-template template.toml \
Each node generates its own public and secret node configuration files.

```bash
btc_anchoring generate-config template.toml pub/0.toml sec/0.toml \
btc_anchoring generate-config template.toml 0/pub.toml 0/sec.toml \
--consensus-path 0/.keys/consensus.toml
--service-path 0/.keys/service.toml
--peer-address 127.0.0.0:7000 \
--btc-anchoring-rpc-host http://localhost:18332 \
--btc-anchoring-rpc-user user \
Expand Down
4 changes: 2 additions & 2 deletions exonum-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ precommits
prevote
prevotes
println
privkey
Privkey
PrivateKey
PrivateKey
proptest
proto
protobuf
Expand Down
7 changes: 4 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ use exonum::helpers::Height;
use exonum::storage::{ListProof, MapProof};

use failure::Fail;
use serde_derive::{Deserialize, Serialize};

use std::cmp::{
self,
Ordering::{self, Equal, Greater, Less},
};

use blockchain::BtcAnchoringSchema;
use btc;
use BTC_ANCHORING_SERVICE_ID;
use crate::blockchain::BtcAnchoringSchema;
use crate::btc;
use crate::BTC_ANCHORING_SERVICE_ID;

/// Query parameters for the find transaction request.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down
5 changes: 3 additions & 2 deletions src/blockchain/data_layout/input_signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};

use exonum::crypto::{self, CryptoHash, Hash};
use exonum::helpers::ValidatorId;
use exonum::storage::StorageValue;

use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use serde_derive::{Deserialize, Serialize};

use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::iter::{FilterMap, IntoIterator};
Expand Down
5 changes: 4 additions & 1 deletion src/blockchain/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

//! Error types of the BTC anchoring service.

use btc;
use exonum::blockchain::ExecutionError;
use exonum::crypto::Hash;
use exonum::helpers::ValidatorId;

use failure_derive::Fail;

use crate::btc;

/// Possible errors during execution of the `Signature` transaction.
#[derive(Debug, Fail)]
pub enum SignatureError {
Expand Down
4 changes: 2 additions & 2 deletions src/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use bitcoin::blockdata::script::Script;
use btc_transaction_utils::multisig::RedeemScript;
use btc_transaction_utils::p2wsh;

use btc::Address;
use config::GlobalConfig;
use crate::btc::Address;
use crate::config::GlobalConfig;

pub mod data_layout;
pub mod errors;
Expand Down
7 changes: 4 additions & 3 deletions src/blockchain/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ use exonum::helpers::Height;
use exonum::storage::{Fork, ProofListIndex, ProofMapIndex, Snapshot};

use btc_transaction_utils::multisig::RedeemScript;
use log::{error, trace};
use serde_json;

use btc::{BtcAnchoringTransactionBuilder, BuilderError, Transaction};
use config::GlobalConfig;
use BTC_ANCHORING_SERVICE_NAME;
use crate::btc::{BtcAnchoringTransactionBuilder, BuilderError, Transaction};
use crate::config::GlobalConfig;
use crate::BTC_ANCHORING_SERVICE_NAME;

use super::data_layout::*;
use super::BtcAnchoringState;
Expand Down
12 changes: 7 additions & 5 deletions src/blockchain/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ use exonum::{
blockchain::{ExecutionResult, Transaction, TransactionContext},
helpers::ValidatorId,
};
use exonum_derive::{ProtobufConvert, TransactionSet};

use btc_transaction_utils::{p2wsh::InputSigner, InputSignature, TxInRef};
use secp256k1::Secp256k1;
use log::{info, trace};
use serde_derive::{Deserialize, Serialize};

use crate::btc;
use crate::proto;

use super::data_layout::TxInputId;
use super::errors::SignatureError;
use super::BtcAnchoringSchema;
use btc;
use proto;

/// Exonum message with the signature for the new anchoring transaction.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, ProtobufConvert)]
Expand Down Expand Up @@ -102,7 +105,6 @@ impl Transaction for TxSignature {
};

let input_signer = InputSigner::new(redeem_script.clone());
let context = Secp256k1::without_caps();

// Checks signature content.
let input_signature_ref = self.input_signature.as_ref();
Expand Down Expand Up @@ -145,7 +147,7 @@ impl Transaction for TxSignature {
&mut tx.0.input[index],
input_signatures
.into_iter()
.map(|bytes| InputSignature::from_bytes(&context, bytes).unwrap()),
.map(|bytes| InputSignature::from_bytes(bytes).unwrap()),
);
}

Expand Down
4 changes: 0 additions & 4 deletions src/btc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[macro_export]
macro_rules! impl_wrapper_for_bitcoin_type {
($name:ident) => {
impl_wrapper_for_bitcoin_consensus_encoding! { $name }
Expand All @@ -21,7 +20,6 @@ macro_rules! impl_wrapper_for_bitcoin_type {
};
}

#[macro_export]
macro_rules! impl_wrapper_for_bitcoin_consensus_encoding {
($name:ident) => {
impl ::exonum::storage::StorageValue for $name {
Expand Down Expand Up @@ -66,7 +64,6 @@ macro_rules! impl_wrapper_for_bitcoin_consensus_encoding {
};
}

#[macro_export]
macro_rules! impl_string_conversions_for_hex {
($name:ident) => {
impl ::std::fmt::LowerHex for $name {
Expand Down Expand Up @@ -95,7 +92,6 @@ macro_rules! impl_string_conversions_for_hex {
};
}

#[macro_export]
macro_rules! impl_serde_str {
($name:ident) => {
impl ::serde::Serialize for $name {
Expand Down
57 changes: 27 additions & 30 deletions src/btc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@ pub use self::transaction::{BtcAnchoringTransactionBuilder, BuilderError, Transa

use bitcoin::network::constants::Network;
use bitcoin::util::address;
use bitcoin::util::privkey;
use btc_transaction_utils;
use derive_more::{From, Into};
use hex::{self, FromHex, ToHex};

use rand::{self, Rng};
use secp256k1;
use rand::Rng;
use std::ops::Deref;

#[macro_use]
mod macros;

pub use btc_transaction_utils::test_data::{secp_gen_keypair, secp_gen_keypair_with_rng};

pub(crate) mod payload;
pub(crate) mod transaction;

/// Bitcoin ECDSA private key wrapper.
#[derive(Clone, From, Into, PartialEq, Eq)]
pub struct Privkey(pub privkey::Privkey);
pub struct PrivateKey(pub bitcoin::PrivateKey);

/// Secp256k1 public key wrapper, used for verification of signatures.
#[derive(Debug, Clone, Copy, From, Into, PartialEq, Eq)]
pub struct PublicKey(pub secp256k1::PublicKey);
pub struct PublicKey(pub bitcoin::PublicKey);

/// Bitcoin address wrapper.
#[derive(Debug, Clone, From, Into, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand All @@ -49,23 +50,23 @@ pub struct Address(pub address::Address);
#[derive(Debug, Clone, PartialEq, Into, From)]
pub struct InputSignature(pub btc_transaction_utils::InputSignature);

impl ToString for Privkey {
impl ToString for PrivateKey {
fn to_string(&self) -> String {
self.0.to_string()
}
}

impl ::std::str::FromStr for Privkey {
type Err = <privkey::Privkey as ::std::str::FromStr>::Err;
impl ::std::str::FromStr for PrivateKey {
type Err = <bitcoin::PrivateKey as ::std::str::FromStr>::Err;

fn from_str(s: &str) -> Result<Self, Self::Err> {
privkey::Privkey::from_str(s).map(From::from)
bitcoin::PrivateKey::from_str(s).map(From::from)
}
}

impl ::std::fmt::Debug for Privkey {
impl ::std::fmt::Debug for PrivateKey {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct("Privkey").finish()
f.debug_struct("PrivateKey").finish()
}
}

Expand All @@ -74,21 +75,22 @@ impl FromHex for PublicKey {

fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let bytes = hex::decode(hex)?;
let context = secp256k1::Secp256k1::without_caps();
let inner = secp256k1::PublicKey::from_slice(&context, &bytes)?;
let inner = bitcoin::PublicKey::from_slice(&bytes)?;
Ok(PublicKey(inner))
}
}

impl ToHex for PublicKey {
fn write_hex<W: ::std::fmt::Write>(&self, w: &mut W) -> ::std::fmt::Result {
let bytes = self.0.serialize();
bytes.as_ref().write_hex(w)
let mut bytes = Vec::default();
self.0.write_into(&mut bytes);
bytes.write_hex(w)
}

fn write_hex_upper<W: ::std::fmt::Write>(&self, w: &mut W) -> ::std::fmt::Result {
let bytes = self.0.serialize();
bytes.as_ref().write_hex_upper(w)
let mut bytes = Vec::default();
self.0.write_into(&mut bytes);
bytes.write_hex_upper(w)
}
}

Expand Down Expand Up @@ -120,8 +122,7 @@ impl FromHex for InputSignature {

fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
let bytes = hex::decode(hex)?;
let context = secp256k1::Secp256k1::without_caps();
let inner = btc_transaction_utils::InputSignature::from_bytes(&context, bytes)?;
let inner = btc_transaction_utils::InputSignature::from_bytes(bytes)?;
Ok(InputSignature(inner))
}
}
Expand Down Expand Up @@ -151,25 +152,21 @@ impl From<InputSignature> for Vec<u8> {
impl_string_conversions_for_hex! { PublicKey }
impl_string_conversions_for_hex! { InputSignature }

impl_serde_str! { Privkey }
impl_serde_str! { PrivateKey }
impl_serde_str! { PublicKey }
impl_serde_str! { Address }
impl_serde_str! { InputSignature }

/// Generates public and secret keys for Bitcoin node
/// using given random number generator.
pub fn gen_keypair_with_rng<R: Rng>(network: Network, rng: &mut R) -> (PublicKey, Privkey) {
let context = secp256k1::Secp256k1::new();
let sk = secp256k1::key::SecretKey::new(&context, rng);

let priv_key = privkey::Privkey::from_secret_key(sk, true, network);
let pub_key = secp256k1::PublicKey::from_secret_key(&context, &sk);
(pub_key.into(), priv_key.into())
pub fn gen_keypair_with_rng<R: Rng>(rng: &mut R, network: Network) -> (PublicKey, PrivateKey) {
let (pk, sk) = secp_gen_keypair_with_rng(rng, network);
(PublicKey(pk), PrivateKey(sk))
}

/// Same as [`gen_keypair_with_rng`](fn.gen_keypair_with_rng.html)
/// but it uses default random number generator.
pub fn gen_keypair(network: Network) -> (PublicKey, Privkey) {
let mut rng = rand::thread_rng();
gen_keypair_with_rng(network, &mut rng)
pub fn gen_keypair(network: Network) -> (PublicKey, PrivateKey) {
let (pk, sk) = secp_gen_keypair(network);
(PublicKey(pk), PrivateKey(sk))
}
Loading

0 comments on commit 70f4f2f

Please sign in to comment.