Fix for serde changes

This commit is contained in:
Andrew Poelstra 2015-09-20 13:10:20 -05:00
parent 835c8befae
commit 00421970a1
4 changed files with 8 additions and 5 deletions

View File

@ -28,5 +28,6 @@ rust-crypto = "0.2"
rustc-serialize = "0.3"
secp256k1 = "0.2"
serde = "0.6"
serde_json = "0.6"
time = "0.1"

View File

@ -46,6 +46,7 @@ extern crate rand;
extern crate rustc_serialize as serialize;
extern crate secp256k1;
extern crate serde;
extern crate serde_json as json;
#[cfg(all(test, feature = "unstable"))] extern crate test;
extern crate time;

View File

@ -124,7 +124,7 @@ macro_rules! user_enum {
where E: ::serde::de::Error
{
$( if s == $txt { Ok($name::$elem) } )else*
else { Err(::serde::de::Error::syntax_error()) }
else { Err(::serde::de::Error::syntax(stringify!($name))) }
}
}

View File

@ -187,10 +187,10 @@ impl serde::Deserialize for Sha256dHash {
where E: serde::de::Error
{
if hex_str.len() != 64 {
return Err(serde::de::Error::syntax_error());
return Err(serde::de::Error::syntax(&format!("Hash had character-length {} (should be 64)", hex_str.len())));
}
let raw_str = try!(hex_str.from_hex()
.map_err(|_| serde::de::Error::syntax_error()));
.map_err(|e| serde::de::Error::syntax(&format!("Hash was not hex-encoded: {}", e))));
let mut ret = [0u8; 32];
for i in 0..32 {
ret[i] = raw_str[31 - i];
@ -262,7 +262,8 @@ impl <T: BitcoinHash> MerkleRoot for Vec<T> {
#[cfg(test)]
mod tests {
use num::FromPrimitive;
use serde::{json, Serialize, Deserialize};
use serde::{Serialize, Deserialize};
use json;
use network::serialize::{serialize, deserialize};
use util::hash::Sha256dHash;
@ -296,7 +297,7 @@ mod tests {
}
assert_eq!(&writer[..],
"\"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d\"".as_bytes());
let mut deserializer = json::de::Deserializer::new(writer.iter().map(|c| Ok(*c))).unwrap();
let mut deserializer = json::de::Deserializer::new(writer.iter().map(|c| Ok(*c)));
assert_eq!(hash, Deserialize::deserialize(&mut deserializer).unwrap());
}