Skip to content

Commit

Permalink
Merge pull request #144 from alekseysidorov/merkledb
Browse files Browse the repository at this point in the history
Release 0.12
  • Loading branch information
alekseysidorov committed Aug 15, 2019
2 parents 06f82bb + bf9b601 commit 4c9707b
Show file tree
Hide file tree
Showing 29 changed files with 362 additions and 420 deletions.
40 changes: 23 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ language: rust
addons:
apt:
sources:
- sourceline: 'ppa:giskou/librocksdb'
- sourceline: 'ppa:exonum/rocksdb'
- sourceline: 'ppa:maarten-fonville/protobuf'
- sourceline: 'ppa:fsgmhoward/shadowsocks-libev'
- sourceline: 'deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/prod xenial main'
key_url: https://packages.microsoft.com/keys/microsoft.asc
packages:
- binutils-dev
- build-essential
Expand All @@ -17,40 +19,37 @@ addons:
- libelf-dev
- libiberty-dev
- libprotobuf-dev
- librocksdb
- librocksdb5.17
- libsnappy-dev
- libsodium-dev
- libssl-dev
- pkg-config
- powershell
- protobuf-compiler
- unzip
- zlib1g-dev

rust:
# Feel free to bump this version if you need features of newer Rust.
# Sync with badge in README.md
- 1.35.0

matrix:
allow_failures:
- env: FEATURE=non-fatal-checks
fast_finish: true
- 1.36.0

cache:
cargo: true
npm: true
directories:
- node_modules
- $HOME/.local
- $HOME/.cargo
- $HOME/.kcov
- $TRAVIS_BUILD_DIR/target
timeout: 900

dist: trusty
dist: xenial
sudo: required

env:
global:
- DEADLINKS_VERS=0.3.0
- SODIUM_VERS=1.0.18
- RUSTFLAGS="-D warnings"
- ROCKSDB_LIB_DIR=/usr/lib/x86_64-linux-gnu
- ROCKSDB_LIB_DIR=/usr/lib
- SNAPPY_LIB_DIR=/usr/lib/x86_64-linux-gnu

jobs:
include:
# Formatting & other lints that do not require compilation
Expand Down Expand Up @@ -90,4 +89,11 @@ jobs:
script:
- cargo doc --no-deps
- cargo deadlinks --dir target/doc


before_cache:
- |
cd $TRAVIS_BUILD_DIR/target/debug
rm -rf incremental examples
find . -maxdepth 1 -type f -executable -delete
find deps -type f -size +20M -delete
du -h -d 1 .
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## 0.12.0 - 2018-08-14

- Updated to the [Exonum 0.12.0](https://github.com/exonum/exonum/releases/tag/v0.12)
release (#144).

## 0.11.0 - 2018-03-15

### Internal improvements
Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "exonum-btc-anchoring"
edition = "2018"
version = "0.11.0"
version = "0.12.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 @@ -20,32 +20,32 @@ 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.14"
exonum = "0.11.0"
derive_more = "0.15"
exonum = "0.12.0"
exonum-merkledb = "0.12.0"
exonum_bitcoinrpc = "0.6"
exonum-derive = "0.11.0"
exonum-testkit = "0.11.0"
exonum-derive = "0.12.0"
exonum-testkit = "0.12.0"
failure = "0.1"
failure_derive = "0.1"
hex = "0.3"
log = "0.4"
maplit = "1.0"
matches = "0.1"
protobuf = { version = "2.4", features = ["with-serde"] }
protobuf = { version = "2.8", features = ["with-serde"] }
rand = "0.4"
secp256k1 = { version = "0.12", features = ["serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_str = "0.1"
structopt = "0.2"
toml = "0.4"
toml = "0.5"

[dev-dependencies]
exonum-configuration = "0.11.0"
exonum-configuration = "0.12.0"
libc = "0.2"
proptest = "0.9"

[build-dependencies]
exonum-build = "0.11.0"
exonum-build = "0.12.0"
3 changes: 2 additions & 1 deletion exonum-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ memorydb
mempool
Merkelized
Merkle
merkledb
millis
mkdir
mmoXxKhAwnhtFiAMvxJ82CKCBia751mzfY
Expand Down Expand Up @@ -245,4 +246,4 @@ whitelisted
writeln
wtxid
Xqsmt
Zsmmr
Zsmmr
21 changes: 10 additions & 11 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

//! Anchoring HTTP API implementation.

use exonum::api::{self, ServiceApiBuilder, ServiceApiState};
use exonum::blockchain::{BlockProof, Schema as CoreSchema};
use exonum::crypto::Hash;
use exonum::helpers::Height;
use exonum::storage::{ListProof, MapProof};

use exonum::{
api::{self, ServiceApiBuilder, ServiceApiState},
blockchain::{BlockProof, Schema as CoreSchema},
crypto::Hash,
helpers::Height,
};
use exonum_merkledb::{ListProof, MapProof};
use failure::Fail;
use serde_derive::{Deserialize, Serialize};

Expand All @@ -28,9 +29,7 @@ use std::cmp::{
Ordering::{self, Equal, Greater, Less},
};

use crate::blockchain::BtcAnchoringSchema;
use crate::btc;
use crate::BTC_ANCHORING_SERVICE_ID;
use crate::{blockchain::BtcAnchoringSchema, btc, BTC_ANCHORING_SERVICE_ID};

/// Query parameters for the find transaction request.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down Expand Up @@ -108,13 +107,13 @@ impl PublicApi for ServiceApiState {

fn actual_address(&self, _query: ()) -> Result<btc::Address, Self::Error> {
let snapshot = self.snapshot();
let schema = BtcAnchoringSchema::new(snapshot);
let schema = BtcAnchoringSchema::new(&snapshot);
Ok(schema.actual_configuration().anchoring_address())
}

fn following_address(&self, _query: ()) -> Result<Option<btc::Address>, Self::Error> {
let snapshot = self.snapshot();
let schema = BtcAnchoringSchema::new(snapshot);
let schema = BtcAnchoringSchema::new(&snapshot);
Ok(schema
.following_configuration()
.map(|config| config.anchoring_address()))
Expand Down
38 changes: 21 additions & 17 deletions src/blockchain/data_layout/input_signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use exonum::{
crypto::{self, Hash},
helpers::ValidatorId,
};
use exonum_merkledb::{BinaryValue, ObjectHash};
use serde_derive::{Deserialize, Serialize};

use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::iter::{FilterMap, IntoIterator};
use std::vec::IntoIter;
use std::{
borrow::Cow,
io::{Cursor, Write},
iter::{FilterMap, IntoIterator},
vec::IntoIter,
};

/// A set of signatures for a transaction input ordered by the validators identifiers.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -70,8 +73,8 @@ impl IntoIterator for InputSignatures {
}
}

impl StorageValue for InputSignatures {
fn into_bytes(self) -> Vec<u8> {
impl BinaryValue for InputSignatures {
fn to_bytes(&self) -> Vec<u8> {
let mut buf = Cursor::new(Vec::new());
for signature in &self.content {
let bytes = signature
Expand All @@ -83,7 +86,7 @@ impl StorageValue for InputSignatures {
buf.into_inner()
}

fn from_bytes(value: Cow<[u8]>) -> Self {
fn from_bytes(value: Cow<[u8]>) -> Result<Self, failure::Error> {
let mut signatures = Vec::new();
let mut reader = value.as_ref();
while !reader.is_empty() {
Expand All @@ -98,15 +101,16 @@ impl StorageValue for InputSignatures {
};
signatures.push(signature);
}
Self {

Ok(Self {
content: signatures,
}
})
}
}

impl CryptoHash for InputSignatures {
fn hash(&self) -> Hash {
crypto::hash(&self.clone().into_bytes())
impl ObjectHash for InputSignatures {
fn object_hash(&self) -> Hash {
crypto::hash(&self.to_bytes())
}
}

Expand All @@ -122,7 +126,7 @@ fn test_input_signatures_storage_value() {
assert_eq!(signatures.len(), 2);

let bytes = signatures.clone().into_bytes();
let signatures2 = InputSignatures::from_bytes(bytes.into());
let signatures2 = InputSignatures::from_bytes(bytes.into()).unwrap();
assert_eq!(signatures, signatures2);
assert_eq!(signatures2.into_iter().collect::<Vec<_>>(), data);
}
3 changes: 1 addition & 2 deletions src/blockchain/data_layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

//! Additional data types for the BTC anchoring information schema.

pub use self::input_signatures::InputSignatures;
pub use self::tx_input_id::TxInputId;
pub use self::{input_signatures::InputSignatures, tx_input_id::TxInputId};

mod input_signatures;
mod tx_input_id;
18 changes: 8 additions & 10 deletions src/blockchain/data_layout/tx_input_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use exonum::crypto::{self, CryptoHash, Hash};
use exonum::storage::{HashedKey, StorageKey};

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use exonum::crypto::{self, Hash};
use exonum_merkledb::{BinaryKey, ObjectHash};

use std::io::{Cursor, Read, Write};

Expand All @@ -36,7 +35,7 @@ impl TxInputId {
}
}

impl StorageKey for TxInputId {
impl BinaryKey for TxInputId {
fn size(&self) -> usize {
self.txid.size() + self.input.size()
}
Expand All @@ -53,23 +52,22 @@ impl StorageKey for TxInputId {
Self { txid, input }
}

fn write(&self, out: &mut [u8]) {
fn write(&self, out: &mut [u8]) -> usize {
let mut writer = Cursor::new(out);
let _ = writer.write(self.txid.as_ref()).unwrap();
writer.write_u32::<LittleEndian>(self.input).unwrap();
self.size()
}
}

impl CryptoHash for TxInputId {
fn hash(&self) -> Hash {
impl ObjectHash for TxInputId {
fn object_hash(&self) -> Hash {
let mut bytes = [0_u8; 36];
self.write(&mut bytes);
crypto::hash(bytes.as_ref())
}
}

impl HashedKey for TxInputId {}

#[test]
fn test_tx_input_id_storage_key() {
let txout = TxInputId {
Expand All @@ -84,5 +82,5 @@ fn test_tx_input_id_storage_key() {
assert_eq!(txout, txout2);

let buf_hash = crypto::hash(&buf);
assert_eq!(txout2.hash(), buf_hash);
assert_eq!(txout2.object_hash(), buf_hash);
}
4 changes: 1 addition & 3 deletions src/blockchain/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

//! Error types of the BTC anchoring service.

use exonum::blockchain::ExecutionError;
use exonum::crypto::Hash;
use exonum::helpers::ValidatorId;
use exonum::{blockchain::ExecutionError, crypto::Hash, helpers::ValidatorId};

use failure_derive::Fail;

Expand Down
12 changes: 4 additions & 8 deletions src/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@

//! Blockchain implementation details for the BTC anchoring service.

pub use self::schema::BtcAnchoringSchema;
pub use self::transactions::Transactions;

use exonum::helpers::Height;
pub use self::{schema::BtcAnchoringSchema, transactions::Transactions};

use bitcoin::blockdata::script::Script;
use btc_transaction_utils::multisig::RedeemScript;
use btc_transaction_utils::p2wsh;
use btc_transaction_utils::{multisig::RedeemScript, p2wsh};
use exonum::helpers::Height;

use crate::btc::Address;
use crate::config::GlobalConfig;
use crate::{btc::Address, config::GlobalConfig};

pub mod data_layout;
pub mod errors;
Expand Down
Loading

0 comments on commit 4c9707b

Please sign in to comment.