MemReader/MemWriter become Cursor, other rustc changes

This commit is contained in:
Andrew Poelstra 2015-04-04 12:56:40 -05:00
parent f1aed644c6
commit 467f76a37d
7 changed files with 22 additions and 22 deletions

View File

@ -33,6 +33,7 @@
#![feature(unboxed_closure_sugar)] #![feature(unboxed_closure_sugar)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(concat_idents)] #![feature(concat_idents)]
#![feature(slice_patterns)]
// Coding conventions // Coding conventions
#![warn(non_uppercase_statics)] #![warn(non_uppercase_statics)]

View File

@ -20,8 +20,7 @@
//! //!
use collections::Vec; use collections::Vec;
use std::io; use std::io::{self, Cursor};
use std::io::MemReader;
use blockdata::block; use blockdata::block;
use blockdata::transaction; use blockdata::transaction;
@ -161,7 +160,7 @@ impl<D:SimpleDecoder<io::Error>> ConsensusDecodable<D, io::Error> for RawNetwork
let CommandString(cmd): CommandString= try!(ConsensusDecodable::consensus_decode(d)); let CommandString(cmd): CommandString= try!(ConsensusDecodable::consensus_decode(d));
let CheckedData(raw_payload): CheckedData = try!(ConsensusDecodable::consensus_decode(d)); let CheckedData(raw_payload): CheckedData = try!(ConsensusDecodable::consensus_decode(d));
let mut mem_d = RawDecoder::new(MemReader::new(raw_payload)); let mut mem_d = RawDecoder::new(Cursor::new(raw_payload));
let payload = match cmd.as_slice() { let payload = match cmd.as_slice() {
"version" => Version(try!(prepend_err("version", ConsensusDecodable::consensus_decode(&mut mem_d)))), "version" => Version(try!(prepend_err("version", ConsensusDecodable::consensus_decode(&mut mem_d)))),
"verack" => Verack, "verack" => Verack,

View File

@ -20,7 +20,7 @@
//! //!
use collections::Vec; use collections::Vec;
use std::io::{self, MemReader, MemWriter}; use std::io::{self, Cursor};
use serialize::hex::ToHex; use serialize::hex::ToHex;
use network::encodable::{ConsensusDecodable, ConsensusEncodable}; use network::encodable::{ConsensusDecodable, ConsensusEncodable};
@ -52,8 +52,8 @@ pub fn serialize_hex<T: ConsensusEncodable<RawEncoder<MemWriter>, io::Error>>(ob
} }
/// Deserialize an object from a vector /// Deserialize an object from a vector
pub fn deserialize<T: ConsensusDecodable<RawDecoder<MemReader>, io::Error>>(data: Vec<u8>) -> io::Result<T> { pub fn deserialize<T: ConsensusDecodable<RawDecoder<Cursor>, io::Error>>(data: Vec<u8>) -> io::Result<T> {
let mut decoder = RawDecoder::new(MemReader::new(data)); let mut decoder = RawDecoder::new(Cursor::new(data));
ConsensusDecodable::consensus_decode(&mut decoder) ConsensusDecodable::consensus_decode(&mut decoder)
} }

View File

@ -19,7 +19,7 @@
use time::now; use time::now;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use std::io::{BufferedReader, BufferedWriter}; use std::io::Cursor;
use std::io::{Error, Result, ErrorKind}; use std::io::{Error, Result, ErrorKind};
use std::io::net::{ip, tcp}; use std::io::net::{ip, tcp};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -55,9 +55,9 @@ pub struct Socket {
/// quickly cancelling any read/writes and unlocking the Mutexes. /// quickly cancelling any read/writes and unlocking the Mutexes.
socket: Option<tcp::TcpStream>, socket: Option<tcp::TcpStream>,
/// The underlying network data stream read buffer /// The underlying network data stream read buffer
buffered_reader: Arc<Mutex<Option<BufferedReader<tcp::TcpStream>>>>, buffered_reader: Arc<Mutex<Option<tcp::TcpStream>>>,
/// The underlying network data stream write buffer /// The underlying network data stream write buffer
buffered_writer: Arc<Mutex<Option<BufferedWriter<tcp::TcpStream>>>>, buffered_writer: Arc<Mutex<Option<tcp::TcpStream>>>,
/// Services supported by us /// Services supported by us
pub services: u64, pub services: u64,
/// Our user agent /// Our user agent
@ -96,8 +96,8 @@ impl Socket {
let mut writer_lock = self.buffered_writer.lock(); let mut writer_lock = self.buffered_writer.lock();
match tcp::TcpStream::connect(host, port) { match tcp::TcpStream::connect(host, port) {
Ok(s) => { Ok(s) => {
*reader_lock = Some(BufferedReader::new(s.clone())); *reader_lock = Some(s.clone());
*writer_lock = Some(BufferedWriter::new(s.clone())); *writer_lock = Some(s.clone());
self.socket = Some(s); self.socket = Some(s);
Ok(()) Ok(())
} }

View File

@ -19,7 +19,7 @@ use core::char::from_digit;
use core::cmp::min; use core::cmp::min;
use std::default::Default; use std::default::Default;
use std::fmt; use std::fmt;
use std::io::MemWriter; use std::io::Cursor;
use std::mem::transmute; use std::mem::transmute;
use std::hash; use std::hash;
use serialize::json::{self, ToJson}; use serialize::json::{self, ToJson};
@ -282,7 +282,7 @@ impl<'a, T: BitcoinHash> MerkleRoot for &'a [T] {
for idx in range(0, (data.len() + 1) / 2) { for idx in range(0, (data.len() + 1) / 2) {
let idx1 = 2 * idx; let idx1 = 2 * idx;
let idx2 = min(idx1 + 1, data.len() - 1); let idx2 = min(idx1 + 1, data.len() - 1);
let mut encoder = RawEncoder::new(MemWriter::new()); let mut encoder = RawEncoder::new(Cursor::new(vec![]));
data[idx1].consensus_encode(&mut encoder).unwrap(); data[idx1].consensus_encode(&mut encoder).unwrap();
data[idx2].consensus_encode(&mut encoder).unwrap(); data[idx2].consensus_encode(&mut encoder).unwrap();
next.push(encoder.unwrap().unwrap().bitcoin_hash()); next.push(encoder.unwrap().unwrap().bitcoin_hash());
@ -303,7 +303,7 @@ impl <T: BitcoinHash> MerkleRoot for Vec<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::prelude::*; use std::prelude::*;
use std::io::MemWriter; use std::io::Cursor;
use std::str::from_utf8; use std::str::from_utf8;
use serialize::Encodable; use serialize::Encodable;
use serialize::json; use serialize::json;
@ -333,7 +333,7 @@ mod tests {
#[test] #[test]
fn test_hash_encode_decode() { fn test_hash_encode_decode() {
let hash = Sha256dHash::from_data(&[]); let hash = Sha256dHash::from_data(&[]);
let mut writer = MemWriter::new(); let mut writer = Cursor::new(vec![]);
{ {
let mut encoder = json::Encoder::new(&mut writer); let mut encoder = json::Encoder::new(&mut writer);
assert!(hash.encode(&mut encoder).is_ok()); assert!(hash.encode(&mut encoder).is_ok());

View File

@ -17,7 +17,7 @@
//! at https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki //! at https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
use std::default::Default; use std::default::Default;
use serialize::{Decoder, Decodable, Encoder, Encodable}; use serialize::{Decoder, Encoder};
use byteorder::{ByteOrder, BigEndian}; use byteorder::{ByteOrder, BigEndian};
use crypto::digest::Digest; use crypto::digest::Digest;
@ -51,7 +51,7 @@ impl Default for Fingerprint {
} }
/// Extended private key /// Extended private key
#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
pub struct ExtendedPrivKey { pub struct ExtendedPrivKey {
/// The network this key is to be used on /// The network this key is to be used on
pub network: Network, pub network: Network,
@ -68,7 +68,7 @@ pub struct ExtendedPrivKey {
} }
/// Extended public key /// Extended public key
#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
pub struct ExtendedPubKey { pub struct ExtendedPubKey {
/// The network this key is to be used on /// The network this key is to be used on
pub network: Network, pub network: Network,
@ -102,9 +102,9 @@ impl<S: Encoder<E>, E> Encodable<S, E> for ChildNumber {
} }
} }
impl<D: Decoder<E>, E> Decodable<D, E> for ChildNumber { impl<D: Decoder<E>, E> RustcDecodable<D, E> for ChildNumber {
fn decode(d: &mut D) -> Result<ChildNumber, E> { fn decode(d: &mut D) -> Result<ChildNumber, E> {
let n: u32 = try!(Decodable::decode(d)); let n: u32 = try!(RustcDecodable::decode(d));
if n < (1 << 31) { if n < (1 << 31) {
Ok(ChildNumber::Normal(n)) Ok(ChildNumber::Normal(n))
} else { } else {

View File

@ -18,7 +18,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::default::Default; use std::default::Default;
use serialize::{Decoder, Decodable, Encoder, Encodable}; use serialize::{Decoder, Encoder};
use secp256k1::key::PublicKey; use secp256k1::key::PublicKey;
@ -54,7 +54,7 @@ pub enum AccountChain {
} }
/// An account /// An account
#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
pub struct Account { pub struct Account {
name: String, name: String,
internal_path: Vec<ChildNumber>, internal_path: Vec<ChildNumber>,