diff --git a/Cargo.toml b/Cargo.toml index 333f78e..5f40b6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,6 @@ path = "src/lib.rs" [dependencies.rust-crypto] git = "https://github.com/DaGenix/rust-crypto.git" -[dependencies.bitcoin-secp256k1-rs] +[dependencies.secp256k1] git = "https://github.com/apoelstra/bitcoin-secp256k1-rs.git" diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index fe3ffd9..873000e 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -22,7 +22,8 @@ use std::num::{Zero, from_u64}; -use util::error::{BitcoinResult, SpvBadTarget, SpvBadProofOfWork}; +use util::error::{BitcoinResult}; +use util::error::BitcoinError::{SpvBadTarget, SpvBadProofOfWork}; use util::hash::Sha256dHash; use util::uint::Uint256; use network::encodable::{ConsensusEncodable, VarInt}; diff --git a/src/blockdata/blockchain.rs b/src/blockdata/blockchain.rs index f4614b6..7493a96 100644 --- a/src/blockdata/blockchain.rs +++ b/src/blockdata/blockchain.rs @@ -29,11 +29,12 @@ use blockdata::block::{Block, BlockHeader}; use blockdata::transaction::Transaction; use blockdata::constants::{DIFFCHANGE_INTERVAL, DIFFCHANGE_TIMESPAN, TARGET_BLOCK_SPACING, max_target, genesis_block}; -use network::constants::{Network, BitcoinTestnet}; +use network::constants::Network::{self, BitcoinTestnet}; use network::encodable::{ConsensusDecodable, ConsensusEncodable}; use network::serialize::{BitcoinHash, SimpleDecoder, SimpleEncoder}; use util::BitArray; -use util::error::{BitcoinResult, BlockNotFound, DuplicateHash, PrevHashNotFound}; +use util::error::BitcoinResult; +use util::error::BitcoinError::{BlockNotFound, DuplicateHash, PrevHashNotFound}; use util::uint::Uint256; use util::hash::Sha256dHash; use util::patricia_tree::PatriciaTree; @@ -613,7 +614,7 @@ mod tests { use blockdata::blockchain::Blockchain; use blockdata::constants::genesis_block; - use network::constants::Bitcoin; + use network::constants::Network::Bitcoin; use network::serialize::{BitcoinHash, deserialize, serialize}; #[test] diff --git a/src/blockdata/constants.rs b/src/blockdata/constants.rs index ce574de..0b1d307 100644 --- a/src/blockdata/constants.rs +++ b/src/blockdata/constants.rs @@ -26,7 +26,7 @@ use blockdata::opcodes; use blockdata::script::Script; use blockdata::transaction::{Transaction, TxOut, TxIn}; use blockdata::block::{Block, BlockHeader}; -use network::constants::{Network, Bitcoin, BitcoinTestnet}; +use network::constants::Network::{Bitcoin, BitcoinTestnet}; use util::misc::hex_bytes; use util::hash::MerkleRoot; use util::uint::Uint256; @@ -123,7 +123,7 @@ mod test { use std::default::Default; use serialize::hex::FromHex; - use network::constants::{Bitcoin, BitcoinTestnet}; + use network::constants::Network::{Bitcoin, BitcoinTestnet}; use network::serialize::{BitcoinHash, serialize}; use blockdata::constants::{genesis_block, bitcoin_genesis_tx}; use blockdata::constants::{MAX_SEQUENCE, COIN_VALUE}; diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index bbbf238..65ab097 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -2453,7 +2453,7 @@ mod test { use super::{Script, build_scriptint, read_scriptint, read_scriptbool}; use super::{EqualVerifyFailed, NoTransaction, PopEmptyStack}; - use super::Owned; + use super::MaybeOwned::Owned; use network::serialize::{deserialize, serialize}; use blockdata::opcodes; diff --git a/src/blockdata/utxoset.rs b/src/blockdata/utxoset.rs index dbb4eed..8dca43f 100644 --- a/src/blockdata/utxoset.rs +++ b/src/blockdata/utxoset.rs @@ -27,7 +27,7 @@ use std::os::num_cpus; use std::sync::Future; use blockdata::transaction::{Transaction, TxOut}; -use blockdata::transaction::{TransactionError, InputNotFound}; +use blockdata::transaction::TransactionError::{self, InputNotFound}; use blockdata::constants::genesis_block; use blockdata::block::Block; use network::constants::Network; @@ -437,7 +437,7 @@ mod tests { use super::{UtxoSet, TxoValidation}; use blockdata::block::Block; - use network::constants::Bitcoin; + use network::constants::Network::Bitcoin; use network::serialize::{BitcoinHash, deserialize, serialize}; #[test] diff --git a/src/lib.rs b/src/lib.rs index 74f7011..56f1ea4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,7 +51,7 @@ extern crate serialize; extern crate test; extern crate time; -extern crate "bitcoin-secp256k1-rs" as secp256k1; +extern crate secp256k1; extern crate crypto; #[macro_use] diff --git a/src/network/constants.rs b/src/network/constants.rs index c214ad8..34ad148 100644 --- a/src/network/constants.rs +++ b/src/network/constants.rs @@ -67,7 +67,7 @@ impl, E> ConsensusDecodable for Network { #[cfg(test)] mod tests { - use super::{Network, Bitcoin, BitcoinTestnet}; + use super::Network::{self, Bitcoin, BitcoinTestnet}; use network::serialize::{deserialize, serialize}; diff --git a/src/network/listener.rs b/src/network/listener.rs index 259f66a..df01e8c 100644 --- a/src/network/listener.rs +++ b/src/network/listener.rs @@ -21,7 +21,9 @@ use std::io::{IoResult, standard_error, ConnectionFailed}; use network::constants::Network; -use network::message::{self, SocketResponse, MessageReceived, Verack}; +use network::message; +use network::message::SocketResponse::{self, MessageReceived}; +use network::message::NetworkMessage::Verack; use network::socket::Socket; /// A message which can be sent on the Bitcoin network diff --git a/src/network/socket.rs b/src/network/socket.rs index 7fbc5a5..7a8a1e5 100644 --- a/src/network/socket.rs +++ b/src/network/socket.rs @@ -28,7 +28,8 @@ use std::sync::{Arc, Mutex}; use network::constants; use network::address::Address; use network::encodable::{ConsensusEncodable, ConsensusDecodable}; -use network::message::{RawNetworkMessage, NetworkMessage, Version}; +use network::message::{RawNetworkMessage, NetworkMessage}; +use network::message::NetworkMessage::Version; use network::message_network::VersionMessage; use network::serialize::{RawEncoder, RawDecoder}; use util::misc::prepend_err; diff --git a/src/util/patricia_tree.rs b/src/util/patricia_tree.rs index e4bce52..4c8116a 100644 --- a/src/util/patricia_tree.rs +++ b/src/util/patricia_tree.rs @@ -529,8 +529,8 @@ mod tests { use network::serialize::{deserialize, serialize}; use util::hash::Sha256dHash; - use util::usize::Uint128; - use util::usize::Uint256; + use util::uint::Uint128; + use util::uint::Uint256; use util::patricia_tree::PatriciaTree; #[test] diff --git a/src/util/thinvec.rs b/src/util/thinvec.rs index 29750a8..7c052aa 100644 --- a/src/util/thinvec.rs +++ b/src/util/thinvec.rs @@ -21,7 +21,7 @@ use alloc::heap::{allocate, reallocate, deallocate}; use std::raw; -use std::slice::{Items, MutItems}; +use std::slice::{Iter, MutIter}; use std::{fmt, mem, ptr}; use std::u32; @@ -63,13 +63,13 @@ impl ThinVec { /// Iterator over elements of the vector #[inline] - pub fn iter<'a>(&'a self) -> Items<'a, T> { + pub fn iter<'a>(&'a self) -> Iter<'a, T> { self.as_slice().iter() } /// Mutable iterator over elements of the vector #[inline] - pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { + pub fn iter_mut<'a>(&'a mut self) -> MutIter<'a, T> { self.as_mut_slice().iter_mut() } diff --git a/src/wallet/address.rs b/src/wallet/address.rs index 53d07a0..7aa15d5 100644 --- a/src/wallet/address.rs +++ b/src/wallet/address.rs @@ -22,11 +22,10 @@ use crypto::sha2::Sha256; use blockdata::script::Script; use blockdata::opcodes::all; -use network::constants::{Network, Bitcoin, BitcoinTestnet}; +use network::constants::Network::{self, Bitcoin, BitcoinTestnet}; use util::hash::Ripemd160Hash; -use util::base58::{Base58Error, - InvalidLength, InvalidVersion, - FromBase58, ToBase58}; +use util::base58::Base58Error::{self, InvalidLength, InvalidVersion}; +use util::base58::{FromBase58, ToBase58}; #[deriving(Clone, PartialEq, Eq)] /// A Bitcoin address @@ -130,7 +129,7 @@ mod tests { use secp256k1::Secp256k1; - use network::constants::Bitcoin; + use network::constants::Network::Bitcoin; use util::hash::Ripemd160Hash; use util::base58::{FromBase58, ToBase58}; use super::Address; diff --git a/src/wallet/address_index.rs b/src/wallet/address_index.rs index 8ea6637..2158124 100644 --- a/src/wallet/address_index.rs +++ b/src/wallet/address_index.rs @@ -23,7 +23,8 @@ use collections::hash::sip::hash_with_keys; use secp256k1::key::SecretKey; -use blockdata::transaction::{TxOut, PayToPubkeyHash}; +use blockdata::transaction::TxOut; +use blockdata::transaction::ScriptPubkeyTemplate::PayToPubkeyHash; use blockdata::utxoset::UtxoSet; use blockdata::script::Script; use network::constants::Network; diff --git a/src/wallet/bip32.rs b/src/wallet/bip32.rs index f7bfde5..6daa302 100644 --- a/src/wallet/bip32.rs +++ b/src/wallet/bip32.rs @@ -29,10 +29,10 @@ use crypto::sha2::Sha512; use secp256k1::key::{PublicKey, SecretKey}; use secp256k1; -use network::constants::{Network, Bitcoin, BitcoinTestnet}; -use util::base58::{Base58Error, - InvalidLength, InvalidVersion, OtherBase58Error, - FromBase58, ToBase58}; +use network::constants::Network::{self, Bitcoin, BitcoinTestnet}; +use util::base58::Base58Error::{self, InvalidLength, InvalidVersion, + OtherBase58Error}; +use util::base58::{FromBase58, ToBase58}; /// A chain code pub struct ChainCode([u8; 32]); @@ -96,8 +96,8 @@ pub enum ChildNumber { impl, E> Encodable for ChildNumber { fn encode(&self, s: &mut S) -> Result<(), E> { match *self { - Hardened(n) => (n + (1 << 31)).encode(s), - Normal(n) => n.encode(s) + ChildNumber::Hardened(n) => (n + (1 << 31)).encode(s), + ChildNumber::Normal(n) => n.encode(s) } } } @@ -106,9 +106,9 @@ impl, E> Decodable for ChildNumber { fn decode(d: &mut D) -> Result { let n: u32 = try!(Decodable::decode(d)); if n < (1 << 31) { - Ok(Normal(n)) + Ok(ChildNumber::Normal(n)) } else { - Ok(Hardened(n - (1 << 31))) + Ok(ChildNumber::Hardened(n - (1 << 31))) } } } @@ -138,7 +138,7 @@ impl ExtendedPrivKey { network: network, depth: 0, parent_fingerprint: Default::default(), - child_number: Normal(0), + child_number: ChildNumber::Normal(0), secret_key: try!(SecretKey::from_slice(result.slice_to(32)).map_err(EcdsaError)), chain_code: ChainCode::from_slice(result.slice_from(32)) }) @@ -159,7 +159,7 @@ impl ExtendedPrivKey { let mut result = [0; 64]; let mut hmac = Hmac::new(Sha512::new(), self.chain_code.as_slice()); match i { - Normal(n) => { + ChildNumber::Normal(n) => { if n >= (1 << 31) { return Err(InvalidChildNumber(i)) } // Non-hardened key: compute public data and use that secp256k1::init(); @@ -167,7 +167,7 @@ impl ExtendedPrivKey { hmac.input(PublicKey::from_secret_key(&self.secret_key, true).as_slice()); u64_to_be_bytes(n as u64, 4, |raw| hmac.input(raw)); } - Hardened(n) => { + ChildNumber::Hardened(n) => { if n >= (1 << 31) { return Err(InvalidChildNumber(i)) } // Hardened key: use only secret data to prevent public derivation hmac.input([0]); @@ -230,14 +230,14 @@ impl ExtendedPubKey { /// Public->Public child key derivation pub fn ckd_pub(&self, i: ChildNumber) -> Result { match i { - Hardened(n) => { + ChildNumber::Hardened(n) => { if n >= (1 << 31) { Err(InvalidChildNumber(i)) } else { Err(CannotDeriveFromHardenedKey) } } - Normal(n) => { + ChildNumber::Normal(n) => { let mut hmac = Hmac::new(Sha512::new(), self.chain_code.as_slice()); hmac.input(self.public_key.as_slice()); u64_to_be_bytes(n as u64, 4, |raw| hmac.input(raw)); @@ -293,10 +293,10 @@ impl ToBase58 for ExtendedPrivKey { ret.push(self.depth as u8); ret.push_all(self.parent_fingerprint.as_slice()); match self.child_number { - Hardened(n) => { + ChildNumber::Hardened(n) => { u64_to_be_bytes(n as u64 + (1 << 31), 4, |raw| ret.push_all(raw)); } - Normal(n) => { + ChildNumber::Normal(n) => { u64_to_be_bytes(n as u64, 4, |raw| ret.push_all(raw)); } } @@ -314,8 +314,8 @@ impl FromBase58 for ExtendedPrivKey { } let cn_int = u64_from_be_bytes(data.as_slice(), 9, 4) as u32; - let child_number = if cn_int < (1 << 31) { Normal(cn_int) } - else { Hardened(cn_int - (1 << 31)) }; + let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) } + else { ChildNumber::Hardened(cn_int - (1 << 31)) }; Ok(ExtendedPrivKey { network: match data.slice_to(4) { @@ -345,10 +345,10 @@ impl ToBase58 for ExtendedPubKey { ret.push(self.depth as u8); ret.push_all(self.parent_fingerprint.as_slice()); match self.child_number { - Hardened(n) => { + ChildNumber::Hardened(n) => { u64_to_be_bytes(n as u64 + (1 << 31), 4, |raw| ret.push_all(raw)); } - Normal(n) => { + ChildNumber::Normal(n) => { u64_to_be_bytes(n as u64, 4, |raw| ret.push_all(raw)); } } @@ -365,8 +365,8 @@ impl FromBase58 for ExtendedPubKey { } let cn_int = u64_from_be_bytes(data.as_slice(), 9, 4) as u32; - let child_number = if cn_int < (1 << 31) { Normal(cn_int) } - else { Hardened(cn_int - (1 << 31)) }; + let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) } + else { ChildNumber::Hardened(cn_int - (1 << 31)) }; Ok(ExtendedPubKey { network: match data.slice_to(4) { @@ -390,10 +390,11 @@ mod tests { use serialize::hex::FromHex; use test::{Bencher, black_box}; - use network::constants::{Network, Bitcoin}; + use network::constants::Network::{self, Bitcoin}; use util::base58::{FromBase58, ToBase58}; - use super::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, Hardened, Normal}; + use super::{ChildNumber, ExtendedPrivKey, ExtendedPubKey}; + use super::ChildNumber::{Hardened, Normal}; fn test_path(network: Network, seed: &[u8], diff --git a/src/wallet/wallet.rs b/src/wallet/wallet.rs index 0544740..2d97a8d 100644 --- a/src/wallet/wallet.rs +++ b/src/wallet/wallet.rs @@ -25,7 +25,8 @@ use secp256k1::key::PublicKey; use blockdata::utxoset::UtxoSet; use network::constants::Network; -use wallet::bip32::{self, ChildNumber, ExtendedPrivKey, ExtendedPubKey, Normal, Hardened}; +use wallet::bip32::{self, ChildNumber, ExtendedPrivKey, ExtendedPubKey}; +use wallet::bip32::ChildNumber::{Normal, Hardened}; use wallet::address::Address; use wallet::address_index::AddressIndex;