Fix for serde changes
This commit is contained in:
parent
835c8befae
commit
00421970a1
|
@ -28,5 +28,6 @@ rust-crypto = "0.2"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
secp256k1 = "0.2"
|
secp256k1 = "0.2"
|
||||||
serde = "0.6"
|
serde = "0.6"
|
||||||
|
serde_json = "0.6"
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ extern crate rand;
|
||||||
extern crate rustc_serialize as serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate secp256k1;
|
extern crate secp256k1;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate serde_json as json;
|
||||||
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ macro_rules! user_enum {
|
||||||
where E: ::serde::de::Error
|
where E: ::serde::de::Error
|
||||||
{
|
{
|
||||||
$( if s == $txt { Ok($name::$elem) } )else*
|
$( if s == $txt { Ok($name::$elem) } )else*
|
||||||
else { Err(::serde::de::Error::syntax_error()) }
|
else { Err(::serde::de::Error::syntax(stringify!($name))) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,10 +187,10 @@ impl serde::Deserialize for Sha256dHash {
|
||||||
where E: serde::de::Error
|
where E: serde::de::Error
|
||||||
{
|
{
|
||||||
if hex_str.len() != 64 {
|
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()
|
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];
|
let mut ret = [0u8; 32];
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
ret[i] = raw_str[31 - i];
|
ret[i] = raw_str[31 - i];
|
||||||
|
@ -262,7 +262,8 @@ impl <T: BitcoinHash> MerkleRoot for Vec<T> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use num::FromPrimitive;
|
use num::FromPrimitive;
|
||||||
use serde::{json, Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use json;
|
||||||
|
|
||||||
use network::serialize::{serialize, deserialize};
|
use network::serialize::{serialize, deserialize};
|
||||||
use util::hash::Sha256dHash;
|
use util::hash::Sha256dHash;
|
||||||
|
@ -296,7 +297,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
assert_eq!(&writer[..],
|
assert_eq!(&writer[..],
|
||||||
"\"56944c5d3f98413ef45cf54545538103cc9f298e0575820ad3591376e2e0f65d\"".as_bytes());
|
"\"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());
|
assert_eq!(hash, Deserialize::deserialize(&mut deserializer).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue