Checkpoint commit -- we're onto move errors :D

This commit is contained in:
Andrew Poelstra 2015-04-10 13:34:31 -05:00
parent e658ffaeea
commit 1d78dccb9e
7 changed files with 34 additions and 32 deletions

View File

@ -20,7 +20,7 @@
use std::cmp;
use std::collections::HashMap;
use std::collections::hash::map::Iter;
use std::collections::hash_map::Iter;
use std::default::Default;
use std::mem;
use eventual;

View File

@ -165,6 +165,7 @@ macro_rules! impl_array_newtype_encodable {
None => return Err(::serde::de::Error::end_of_stream_error())
};
}
v.end();
Ok($thing(ret))
}
}

View File

@ -92,7 +92,7 @@ macro_rules! user_enum {
impl ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.pad(match *self {
$($elem => $txt),*
$($name::$elem => $txt),*
})
}
}
@ -100,7 +100,7 @@ macro_rules! user_enum {
impl ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.pad(match *self {
$($elem => $txt),*
$($name::$elem => $txt),*
})
}
}

View File

@ -20,7 +20,7 @@
use time::now;
use rand::{thread_rng, Rng};
use std::io::{self, Cursor, Write};
use std::net::{ip, tcp};
use std::net;
use std::sync::{Arc, Mutex};
use network::constants;
@ -33,10 +33,10 @@ use network::serialize::{RawEncoder, RawDecoder};
use util::{self, propagate_err};
/// Format an IP address in the 16-byte bitcoin protocol serialization
fn ipaddr_to_bitcoin_addr(ipaddr: &ip::IpAddr) -> [u16; 8] {
fn ipaddr_to_bitcoin_addr(ipaddr: &net::IpAddr) -> [u16; 8] {
match *ipaddr {
ip::IpAddr::V4(ref addr) => &addr.to_ipv6_mapped(),
ip::IpAddr::V6(ref addr) => addr
net::IpAddr::V4(ref addr) => &addr.to_ipv6_mapped(),
net::IpAddr::V6(ref addr) => addr
}.segments()
}
@ -44,7 +44,7 @@ fn ipaddr_to_bitcoin_addr(ipaddr: &ip::IpAddr) -> [u16; 8] {
#[derive(Clone)]
pub struct Socket {
/// The underlying TCP socket
socket: Arc<Mutex<Option<tcp::TcpStream>>>,
socket: Arc<Mutex<Option<net::TcpStream>>>,
/// Services supported by us
pub services: u64,
/// Our user agent
@ -73,7 +73,7 @@ impl Socket {
pub fn connect(&mut self, host: &str, port: u16) -> Result<(), util::Error> {
// Entirely replace the Mutex, in case it was poisoned;
// this will also drop any preexisting socket that might be open
match tcp::TcpStream::connect((host, port)) {
match net::TcpStream::connect((host, port)) {
Ok(s) => {
self.socket = Arc::new(Mutex::new(Some(s)));
Ok(())
@ -85,7 +85,7 @@ impl Socket {
}
}
fn socket(&mut self) -> Result<&mut tcp::TcpStream, util::Error> {
fn socket(&mut self) -> Result<&mut net::TcpStream, util::Error> {
let mut sock_lock = self.socket.lock();
match sock_lock {
Err(_) => {

View File

@ -364,7 +364,7 @@ impl<K, V> PatriciaTree<K, V>
impl<K:BitArray, V:Debug> Debug for PatriciaTree<K, V> {
/// Print the entire tree
pub fn fmt<'a>(&'a self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn fmt<'a>(&'a self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn recurse<'a, K:BitArray, V:Debug>(tree: &'a PatriciaTree<K, V>, f: &mut fmt::Formatter, depth: usize) -> Result<(), fmt::Error> {
for i in 0..tree.skip_len as usize {
try!(write!(f, "{:}", if tree.skip_prefix.bit(i) { 1 } else { 0 }));
@ -394,7 +394,7 @@ impl<K:BitArray, V:Debug> Debug for PatriciaTree<K, V> {
}
Ok(())
}
recurse(self, f, 0);
recurse(self, f, 0)
}
}

View File

@ -17,9 +17,10 @@
//! at https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
use std::default::Default;
use std::io::Cursor;
use serde::{Serialize, Deserialize, Serializer, Deserializer};
use crypto::cryptoutil::{read_u32_be, write_u32_be};
use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
use crypto::digest::Digest;
use crypto::hmac::Hmac;
use crypto::mac::Mac;
@ -167,14 +168,14 @@ impl ExtendedPrivKey {
secp256k1::init();
// Note the unwrap: this is fine, we checked the SK when we created it
hmac.input(&PublicKey::from_secret_key(&self.secret_key, true)[..]);
write_u32_be(&mut be_n, n);
BigEndian::write_u32(&mut be_n, n);
}
ChildNumber::Hardened(n) => {
if n >= (1 << 31) { return Err(Error::InvalidChildNumber(i)) }
// Hardened key: use only secret data to prevent public derivation
hmac.input(&[0u8]);
hmac.input(&self.secret_key[..]);
write_u32_be(&mut be_n, n + (1 << 31));
BigEndian::write_u32(&mut be_n, n + (1 << 31));
}
}
hmac.input(&be_n);
@ -244,7 +245,7 @@ impl ExtendedPubKey {
let mut hmac = Hmac::new(Sha512::new(), &self.chain_code[..]);
hmac.input(&self.public_key[..]);
let mut be_n = [0; 32];
write_u32_be(&mut be_n, n);
BigEndian::write_u32(&mut be_n, n);
hmac.input(&be_n);
let mut result = [0; 64];
@ -300,10 +301,10 @@ impl ToBase58 for ExtendedPrivKey {
let mut be_n = [0; 32];
match self.child_number {
ChildNumber::Hardened(n) => {
write_u32_be(&mut be_n, n + (1 << 31));
BigEndian::write_u32(&mut be_n, n + (1 << 31));
}
ChildNumber::Normal(n) => {
write_u32_be(&mut be_n, n);
BigEndian::write_u32(&mut be_n, n);
}
}
ret.push_all(&be_n);
@ -320,7 +321,7 @@ impl FromBase58 for ExtendedPrivKey {
return Err(base58::Error::InvalidLength(data.len()));
}
let cn_int = read_u32_be(&data[9..13]);
let cn_int = Cursor::new(&data[9..13]).read_u32::<BigEndian>().unwrap();
let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) }
else { ChildNumber::Hardened(cn_int - (1 << 31)) };
@ -354,10 +355,10 @@ impl ToBase58 for ExtendedPubKey {
let mut be_n = [0; 32];
match self.child_number {
ChildNumber::Hardened(n) => {
write_u32_be(&mut be_n, n + (1 << 31));
BigEndian::write_u32(&mut be_n, n + (1 << 31));
}
ChildNumber::Normal(n) => {
write_u32_be(&mut be_n, n);
BigEndian::write_u32(&mut be_n, n);
}
}
ret.push_all(&be_n);
@ -373,7 +374,7 @@ impl FromBase58 for ExtendedPubKey {
return Err(base58::Error::InvalidLength(data.len()));
}
let cn_int = read_u32_be(&data[9..13]);
let cn_int = Cursor::new(&data[9..13]).read_u32::<BigEndian>().unwrap();
let child_number = if cn_int < (1 << 31) { ChildNumber::Normal(cn_int) }
else { ChildNumber::Hardened(cn_int - (1 << 31)) };

View File

@ -173,11 +173,11 @@ impl Wallet {
let index = match self.index { Some(ref i) => i, None => return Err(Error::NoAddressIndex) };
let (mut i, master) = match chain {
Internal => (account.internal_next,
AccountChain::Internal => (account.internal_next,
try!(ExtendedPrivKey::from_path(
&self.master,
account.internal_path.as_slice()).map_err(Error::Bip32Error))),
External => (account.external_next,
AccountChain::External => (account.external_next,
try!(ExtendedPrivKey::from_path(
&self.master,
account.external_path.as_slice()).map_err(Error::Bip32Error))),
@ -197,11 +197,11 @@ impl Wallet {
}
match chain {
Internal => {
AccountChain::Internal => {
account.internal_used.push(Normal(i));
account.internal_next = i + 1;
}
External => {
AccountChain::External => {
account.external_used.push(Normal(i));
account.external_next = i + 1;
}