[code hygiene] remove deprecated rustc-serialize

Addresses #96.

Turns out it was being used for hex encoding/decoding, so replaced that with the `hex` crate.

i chose to import the `decode` method as:
```
use hex::decode as hex_decode
```

so that it is clear to the reader what is being decoded when it is called. "decode" is such a generic sounding function name that it would get confusing otherwise.
This commit is contained in:
Savil Srivastava 2018-07-24 11:43:03 -07:00
parent f7ab3241a7
commit 933dcaeb82
15 changed files with 59 additions and 61 deletions

View File

@ -24,11 +24,14 @@ bitcoin-bech32 = "0.8.0"
byteorder = "1.1" byteorder = "1.1"
rand = "0.3" rand = "0.3"
rust-crypto = "0.2" rust-crypto = "0.2"
rustc-serialize = "0.3"
serde = "0.6" serde = "0.6"
strason = "0.3" strason = "0.3"
bitcoinconsensus = { version = "0.16", optional=true } bitcoinconsensus = { version = "0.16", optional=true }
[dependencies.hex]
git = "https://github.com/KokaKiwi/rust-hex"
rev = "19fd37137686c30058bd9d11d21590e726ffdf31"
[dependencies.secp256k1] [dependencies.secp256k1]
version = "0.9" version = "0.9"
features = [ "rand" ] features = [ "rand" ]

File diff suppressed because one or more lines are too long

View File

@ -141,7 +141,7 @@ pub fn genesis_block(network: Network) -> Block {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::default::Default; use std::default::Default;
use serialize::hex::FromHex; use hex::decode as hex_decode;
use network::constants::Network; use network::constants::Network;
use network::serialize::{BitcoinHash, serialize}; use network::serialize::{BitcoinHash, serialize};
@ -157,12 +157,12 @@ mod test {
assert_eq!(gen.input[0].prev_hash, Default::default()); assert_eq!(gen.input[0].prev_hash, Default::default());
assert_eq!(gen.input[0].prev_index, 0xFFFFFFFF); assert_eq!(gen.input[0].prev_index, 0xFFFFFFFF);
assert_eq!(serialize(&gen.input[0].script_sig).ok(), assert_eq!(serialize(&gen.input[0].script_sig).ok(),
Some("4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73".from_hex().unwrap())); Some(hex_decode("4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73").unwrap()));
assert_eq!(gen.input[0].sequence, MAX_SEQUENCE); assert_eq!(gen.input[0].sequence, MAX_SEQUENCE);
assert_eq!(gen.output.len(), 1); assert_eq!(gen.output.len(), 1);
assert_eq!(serialize(&gen.output[0].script_pubkey).ok(), assert_eq!(serialize(&gen.output[0].script_pubkey).ok(),
Some("434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac".from_hex().unwrap())); Some(hex_decode("434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac").unwrap()));
assert_eq!(gen.output[0].value, 50 * COIN_VALUE); assert_eq!(gen.output[0].value, 50 * COIN_VALUE);
assert_eq!(gen.lock_time, 0); assert_eq!(gen.lock_time, 0);

View File

@ -572,8 +572,6 @@ impl serde::Deserialize for Script {
fn deserialize<D>(d: &mut D) -> Result<Script, D::Error> fn deserialize<D>(d: &mut D) -> Result<Script, D::Error>
where D: serde::Deserializer where D: serde::Deserializer
{ {
use serialize::hex::FromHex;
struct ScriptVisitor; struct ScriptVisitor;
impl serde::de::Visitor for ScriptVisitor { impl serde::de::Visitor for ScriptVisitor {
type Value = Script; type Value = Script;
@ -587,7 +585,7 @@ impl serde::Deserialize for Script {
fn visit_str<E>(&mut self, hex_str: &str) -> Result<Script, E> fn visit_str<E>(&mut self, hex_str: &str) -> Result<Script, E>
where E: serde::de::Error where E: serde::de::Error
{ {
let raw_vec: Vec<u8> = try!(hex_str.from_hex() let raw_vec: Vec<u8> = try!(::hex::decode(hex_str)
.map_err(|_| serde::de::Error::syntax("bad script hex"))); .map_err(|_| serde::de::Error::syntax("bad script hex")));
Ok(Script::from(raw_vec)) Ok(Script::from(raw_vec))
} }
@ -614,7 +612,7 @@ impl<D: SimpleDecoder> ConsensusDecodable<D> for Script {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use serialize::hex::FromHex; use hex::decode as hex_decode;
use super::*; use super::*;
use super::build_scriptint; use super::build_scriptint;
@ -645,7 +643,7 @@ mod test {
// data // data
script = script.push_slice("NRA4VR".as_bytes()); comp.extend([6u8, 78, 82, 65, 52, 86, 82].iter().cloned()); assert_eq!(&script[..], &comp[..]); script = script.push_slice("NRA4VR".as_bytes()); comp.extend([6u8, 78, 82, 65, 52, 86, 82].iter().cloned()); assert_eq!(&script[..], &comp[..]);
// opcodes // opcodes
script = script.push_opcode(opcodes::All::OP_CHECKSIG); comp.push(0xACu8); assert_eq!(&script[..], &comp[..]); script = script.push_opcode(opcodes::All::OP_CHECKSIG); comp.push(0xACu8); assert_eq!(&script[..], &comp[..]);
script = script.push_opcode(opcodes::All::OP_CHECKSIG); comp.push(0xACu8); assert_eq!(&script[..], &comp[..]); script = script.push_opcode(opcodes::All::OP_CHECKSIG); comp.push(0xACu8); assert_eq!(&script[..], &comp[..]);
} }
@ -655,7 +653,7 @@ mod test {
// from txid 3bb5e6434c11fb93f64574af5d116736510717f2c595eb45b52c28e31622dfff which was in my mempool when I wrote the test // from txid 3bb5e6434c11fb93f64574af5d116736510717f2c595eb45b52c28e31622dfff which was in my mempool when I wrote the test
let script = Builder::new().push_opcode(opcodes::All::OP_DUP) let script = Builder::new().push_opcode(opcodes::All::OP_DUP)
.push_opcode(opcodes::All::OP_HASH160) .push_opcode(opcodes::All::OP_HASH160)
.push_slice(&"16e1ae70ff0fa102905d4af297f6912bda6cce19".from_hex().unwrap()) .push_slice(&hex_decode("16e1ae70ff0fa102905d4af297f6912bda6cce19").unwrap())
.push_opcode(opcodes::All::OP_EQUALVERIFY) .push_opcode(opcodes::All::OP_EQUALVERIFY)
.push_opcode(opcodes::All::OP_CHECKSIG) .push_opcode(opcodes::All::OP_CHECKSIG)
.into_script(); .into_script();
@ -664,7 +662,7 @@ mod test {
#[test] #[test]
fn script_serialize() { fn script_serialize() {
let hex_script = "6c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52".from_hex().unwrap(); let hex_script = hex_decode("6c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52").unwrap();
let script: Result<Script, _> = deserialize(&hex_script); let script: Result<Script, _> = deserialize(&hex_script);
assert!(script.is_ok()); assert!(script.is_ok());
assert_eq!(serialize(&script.unwrap()).ok(), Some(hex_script)); assert_eq!(serialize(&script.unwrap()).ok(), Some(hex_script));
@ -769,8 +767,8 @@ mod test {
#[cfg(feature="bitcoinconsensus")] #[cfg(feature="bitcoinconsensus")]
fn test_bitcoinconsensus () { fn test_bitcoinconsensus () {
// a random segwit transaction from the blockchain using native segwit // a random segwit transaction from the blockchain using native segwit
let spent = Builder::from("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d".from_hex().unwrap()).into_script(); let spent = Builder::from(hex_decode("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d").unwrap()).into_script();
let spending = "010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000".from_hex().unwrap(); let spending = hex_decode("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000").unwrap();
spent.verify(0, 18393430, spending.as_slice()).unwrap(); spent.verify(0, 18393430, spending.as_slice()).unwrap();
} }
} }

View File

@ -899,18 +899,18 @@ mod tests {
#[test] #[test]
#[cfg(feature="bitcoinconsensus")] #[cfg(feature="bitcoinconsensus")]
fn test_transaction_verify () { fn test_transaction_verify () {
use serialize::hex::FromHex; use hex::decode as hex_decode;
use std::collections::HashMap; use std::collections::HashMap;
use blockdata::script; use blockdata::script;
// a random recent segwit transaction from blockchain using both old and segwit inputs // a random recent segwit transaction from blockchain using both old and segwit inputs
let mut spending: Transaction = deserialize("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700" let mut spending: Transaction = deserialize(hex_decode("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
.from_hex().unwrap().as_slice()).unwrap(); .unwrap().as_slice()).unwrap();
let spent1: Transaction = deserialize("020000000001040aacd2c49f5f3c0968cfa8caf9d5761436d95385252e3abb4de8f5dcf8a582f20000000017160014bcadb2baea98af0d9a902e53a7e9adff43b191e9feffffff96cd3c93cac3db114aafe753122bd7d1afa5aa4155ae04b3256344ecca69d72001000000171600141d9984579ceb5c67ebfbfb47124f056662fe7adbfeffffffc878dd74d3a44072eae6178bb94b9253177db1a5aaa6d068eb0e4db7631762e20000000017160014df2a48cdc53dae1aba7aa71cb1f9de089d75aac3feffffffe49f99275bc8363f5f593f4eec371c51f62c34ff11cc6d8d778787d340d6896c0100000017160014229b3b297a0587e03375ab4174ef56eeb0968735feffffff03360d0f00000000001976a9149f44b06f6ee92ddbc4686f71afe528c09727a5c788ac24281b00000000001976a9140277b4f68ff20307a2a9f9b4487a38b501eb955888ac227c0000000000001976a9148020cd422f55eef8747a9d418f5441030f7c9c7788ac0247304402204aa3bd9682f9a8e101505f6358aacd1749ecf53a62b8370b97d59243b3d6984f02200384ad449870b0e6e89c92505880411285ecd41cf11e7439b973f13bad97e53901210205b392ffcb83124b1c7ce6dd594688198ef600d34500a7f3552d67947bbe392802473044022033dfd8d190a4ae36b9f60999b217c775b96eb10dee3a1ff50fb6a75325719106022005872e4e36d194e49ced2ebcf8bb9d843d842e7b7e0eb042f4028396088d292f012103c9d7cbf369410b090480de2aa15c6c73d91b9ffa7d88b90724614b70be41e98e0247304402207d952de9e59e4684efed069797e3e2d993e9f98ec8a9ccd599de43005fe3f713022076d190cc93d9513fc061b1ba565afac574e02027c9efbfa1d7b71ab8dbb21e0501210313ad44bc030cc6cb111798c2bf3d2139418d751c1e79ec4e837ce360cc03b97a024730440220029e75edb5e9413eb98d684d62a077b17fa5b7cc19349c1e8cc6c4733b7b7452022048d4b9cae594f03741029ff841e35996ef233701c1ea9aa55c301362ea2e2f68012103590657108a72feb8dc1dec022cf6a230bb23dc7aaa52f4032384853b9f8388baf9d20700" let spent1: Transaction = deserialize(hex_decode("020000000001040aacd2c49f5f3c0968cfa8caf9d5761436d95385252e3abb4de8f5dcf8a582f20000000017160014bcadb2baea98af0d9a902e53a7e9adff43b191e9feffffff96cd3c93cac3db114aafe753122bd7d1afa5aa4155ae04b3256344ecca69d72001000000171600141d9984579ceb5c67ebfbfb47124f056662fe7adbfeffffffc878dd74d3a44072eae6178bb94b9253177db1a5aaa6d068eb0e4db7631762e20000000017160014df2a48cdc53dae1aba7aa71cb1f9de089d75aac3feffffffe49f99275bc8363f5f593f4eec371c51f62c34ff11cc6d8d778787d340d6896c0100000017160014229b3b297a0587e03375ab4174ef56eeb0968735feffffff03360d0f00000000001976a9149f44b06f6ee92ddbc4686f71afe528c09727a5c788ac24281b00000000001976a9140277b4f68ff20307a2a9f9b4487a38b501eb955888ac227c0000000000001976a9148020cd422f55eef8747a9d418f5441030f7c9c7788ac0247304402204aa3bd9682f9a8e101505f6358aacd1749ecf53a62b8370b97d59243b3d6984f02200384ad449870b0e6e89c92505880411285ecd41cf11e7439b973f13bad97e53901210205b392ffcb83124b1c7ce6dd594688198ef600d34500a7f3552d67947bbe392802473044022033dfd8d190a4ae36b9f60999b217c775b96eb10dee3a1ff50fb6a75325719106022005872e4e36d194e49ced2ebcf8bb9d843d842e7b7e0eb042f4028396088d292f012103c9d7cbf369410b090480de2aa15c6c73d91b9ffa7d88b90724614b70be41e98e0247304402207d952de9e59e4684efed069797e3e2d993e9f98ec8a9ccd599de43005fe3f713022076d190cc93d9513fc061b1ba565afac574e02027c9efbfa1d7b71ab8dbb21e0501210313ad44bc030cc6cb111798c2bf3d2139418d751c1e79ec4e837ce360cc03b97a024730440220029e75edb5e9413eb98d684d62a077b17fa5b7cc19349c1e8cc6c4733b7b7452022048d4b9cae594f03741029ff841e35996ef233701c1ea9aa55c301362ea2e2f68012103590657108a72feb8dc1dec022cf6a230bb23dc7aaa52f4032384853b9f8388baf9d20700")
.from_hex().unwrap().as_slice()).unwrap(); .unwrap().as_slice()).unwrap();
let spent2: Transaction = deserialize("0200000000010166c3d39490dc827a2594c7b17b7d37445e1f4b372179649cd2ce4475e3641bbb0100000017160014e69aa750e9bff1aca1e32e57328b641b611fc817fdffffff01e87c5d010000000017a914f3890da1b99e44cd3d52f7bcea6a1351658ea7be87024830450221009eb97597953dc288de30060ba02d4e91b2bde1af2ecf679c7f5ab5989549aa8002202a98f8c3bd1a5a31c0d72950dd6e2e3870c6c5819a6c3db740e91ebbbc5ef4800121023f3d3b8e74b807e32217dea2c75c8d0bd46b8665b3a2d9b3cb310959de52a09bc9d20700" let spent2: Transaction = deserialize(hex_decode("0200000000010166c3d39490dc827a2594c7b17b7d37445e1f4b372179649cd2ce4475e3641bbb0100000017160014e69aa750e9bff1aca1e32e57328b641b611fc817fdffffff01e87c5d010000000017a914f3890da1b99e44cd3d52f7bcea6a1351658ea7be87024830450221009eb97597953dc288de30060ba02d4e91b2bde1af2ecf679c7f5ab5989549aa8002202a98f8c3bd1a5a31c0d72950dd6e2e3870c6c5819a6c3db740e91ebbbc5ef4800121023f3d3b8e74b807e32217dea2c75c8d0bd46b8665b3a2d9b3cb310959de52a09bc9d20700")
.from_hex().unwrap().as_slice()).unwrap(); .unwrap().as_slice()).unwrap();
let spent3: Transaction = deserialize("01000000027a1120a30cef95422638e8dab9dedf720ec614b1b21e451a4957a5969afb869d000000006a47304402200ecc318a829a6cad4aa9db152adbf09b0cd2de36f47b53f5dade3bc7ef086ca702205722cda7404edd6012eedd79b2d6f24c0a0c657df1a442d0a2166614fb164a4701210372f4b97b34e9c408741cd1fc97bcc7ffdda6941213ccfde1cb4075c0f17aab06ffffffffc23b43e5a18e5a66087c0d5e64d58e8e21fcf83ce3f5e4f7ecb902b0e80a7fb6010000006b483045022100f10076a0ea4b4cf8816ed27a1065883efca230933bf2ff81d5db6258691ff75202206b001ef87624e76244377f57f0c84bc5127d0dd3f6e0ef28b276f176badb223a01210309a3a61776afd39de4ed29b622cd399d99ecd942909c36a8696cfd22fc5b5a1affffffff0200127a000000000017a914f895e1dd9b29cb228e9b06a15204e3b57feaf7cc8769311d09000000001976a9144d00da12aaa51849d2583ae64525d4a06cd70fde88ac00000000" let spent3: Transaction = deserialize(hex_decode("01000000027a1120a30cef95422638e8dab9dedf720ec614b1b21e451a4957a5969afb869d000000006a47304402200ecc318a829a6cad4aa9db152adbf09b0cd2de36f47b53f5dade3bc7ef086ca702205722cda7404edd6012eedd79b2d6f24c0a0c657df1a442d0a2166614fb164a4701210372f4b97b34e9c408741cd1fc97bcc7ffdda6941213ccfde1cb4075c0f17aab06ffffffffc23b43e5a18e5a66087c0d5e64d58e8e21fcf83ce3f5e4f7ecb902b0e80a7fb6010000006b483045022100f10076a0ea4b4cf8816ed27a1065883efca230933bf2ff81d5db6258691ff75202206b001ef87624e76244377f57f0c84bc5127d0dd3f6e0ef28b276f176badb223a01210309a3a61776afd39de4ed29b622cd399d99ecd942909c36a8696cfd22fc5b5a1affffffff0200127a000000000017a914f895e1dd9b29cb228e9b06a15204e3b57feaf7cc8769311d09000000001976a9144d00da12aaa51849d2583ae64525d4a06cd70fde88ac00000000")
.from_hex().unwrap().as_slice()).unwrap(); .unwrap().as_slice()).unwrap();
let mut spent = HashMap::new(); let mut spent = HashMap::new();
spent.insert(spent1.txid(), spent1); spent.insert(spent1.txid(), spent1);

View File

@ -281,10 +281,10 @@ macro_rules! display_from_debug {
} }
#[cfg(test)] #[cfg(test)]
macro_rules! hex_script (($s:expr) => (::blockdata::script::Script::from($s.from_hex().unwrap()))); macro_rules! hex_script (($s:expr) => (::blockdata::script::Script::from(::hex::decode($s).unwrap())));
#[cfg(test)] #[cfg(test)]
macro_rules! hex_hash (($s:expr) => (::util::hash::Sha256dHash::from(&$s.from_hex().unwrap()[..]))); macro_rules! hex_hash (($s:expr) => (::util::hash::Sha256dHash::from(&::hex::decode($s).unwrap()[..])));
// Macros to replace serde's codegen while that is not stable // Macros to replace serde's codegen while that is not stable

View File

@ -44,8 +44,8 @@
extern crate bitcoin_bech32; extern crate bitcoin_bech32;
extern crate byteorder; extern crate byteorder;
extern crate crypto; extern crate crypto;
extern crate hex;
extern crate rand; extern crate rand;
extern crate rustc_serialize as serialize;
extern crate secp256k1; extern crate secp256k1;
extern crate serde; extern crate serde;
extern crate strason; extern crate strason;

View File

@ -136,15 +136,15 @@ impl<D: SimpleDecoder> ConsensusDecodable<D> for Inventory {
mod tests { mod tests {
use super::{GetHeadersMessage, GetBlocksMessage}; use super::{GetHeadersMessage, GetBlocksMessage};
use serialize::hex::FromHex; use hex::decode as hex_decode;
use network::serialize::{deserialize, serialize}; use network::serialize::{deserialize, serialize};
use std::default::Default; use std::default::Default;
#[test] #[test]
fn getblocks_message_test() { fn getblocks_message_test() {
let from_sat = "72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap(); let from_sat = hex_decode("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let genhash = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".from_hex().unwrap(); let genhash = hex_decode("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
let decode: Result<GetBlocksMessage, _> = deserialize(&from_sat); let decode: Result<GetBlocksMessage, _> = deserialize(&from_sat);
assert!(decode.is_ok()); assert!(decode.is_ok());
@ -159,8 +159,8 @@ mod tests {
#[test] #[test]
fn getheaders_message_test() { fn getheaders_message_test() {
let from_sat = "72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap(); let from_sat = hex_decode("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let genhash = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".from_hex().unwrap(); let genhash = hex_decode("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
let decode: Result<GetHeadersMessage, _> = deserialize(&from_sat); let decode: Result<GetHeadersMessage, _> = deserialize(&from_sat);
assert!(decode.is_ok()); assert!(decode.is_ok());

View File

@ -79,14 +79,14 @@ impl_consensus_encoding!(VersionMessage, version, services, timestamp,
mod tests { mod tests {
use super::VersionMessage; use super::VersionMessage;
use serialize::hex::FromHex; use hex::decode as hex_decode;
use network::serialize::{deserialize, serialize}; use network::serialize::{deserialize, serialize};
#[test] #[test]
fn version_message_test() { fn version_message_test() {
// This message is from my satoshi node, morning of May 27 2014 // This message is from my satoshi node, morning of May 27 2014
let from_sat = "721101000100000000000000e6e0845300000000010000000000000000000000000000000000ffff0000000000000100000000000000fd87d87eeb4364f22cf54dca59412db7208d47d920cffce83ee8102f5361746f7368693a302e392e39392f2c9f040001".from_hex().unwrap(); let from_sat = hex_decode("721101000100000000000000e6e0845300000000010000000000000000000000000000000000ffff0000000000000100000000000000fd87d87eeb4364f22cf54dca59412db7208d47d920cffce83ee8102f5361746f7368693a302e392e39392f2c9f040001").unwrap();
let decode: Result<VersionMessage, _> = deserialize(&from_sat); let decode: Result<VersionMessage, _> = deserialize(&from_sat);
assert!(decode.is_ok()); assert!(decode.is_ok());

View File

@ -21,7 +21,7 @@
use std::io::{Cursor, Read, Write}; use std::io::{Cursor, Read, Write};
use byteorder::{LittleEndian, WriteBytesExt, ReadBytesExt}; use byteorder::{LittleEndian, WriteBytesExt, ReadBytesExt};
use serialize::hex::ToHex; use hex::encode as hex_encode;
use network::encodable::{ConsensusDecodable, ConsensusEncodable}; use network::encodable::{ConsensusDecodable, ConsensusEncodable};
use util::hash::Sha256dHash; use util::hash::Sha256dHash;
@ -54,7 +54,7 @@ pub fn serialize_hex<T: ?Sized>(data: &T) -> Result<String, util::Error>
where T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>> where T: ConsensusEncodable<RawEncoder<Cursor<Vec<u8>>>>
{ {
let serial = try!(serialize(data)); let serial = try!(serialize(data));
Ok(serial.to_hex()) Ok(hex_encode(serial))
} }
/// Deserialize an object from a vector /// Deserialize an object from a vector
@ -93,7 +93,7 @@ impl<R: Read> RawDecoder<R> {
pub trait SimpleEncoder { pub trait SimpleEncoder {
/// An encoding error /// An encoding error
type Error; type Error;
/// Output a 64-bit uint /// Output a 64-bit uint
fn emit_u64(&mut self, v: u64) -> Result<(), Self::Error>; fn emit_u64(&mut self, v: u64) -> Result<(), Self::Error>;
/// Output a 32-bit uint /// Output a 32-bit uint

View File

@ -315,14 +315,14 @@ mod tests {
use secp256k1::Secp256k1; use secp256k1::Secp256k1;
use secp256k1::key::PublicKey; use secp256k1::key::PublicKey;
use serialize::hex::FromHex; use hex::decode as hex_decode;
use blockdata::script::Script; use blockdata::script::Script;
use network::constants::Network::{Bitcoin, Testnet}; use network::constants::Network::{Bitcoin, Testnet};
use util::hash::Hash160; use util::hash::Hash160;
use super::*; use super::*;
macro_rules! hex (($hex:expr) => ($hex.from_hex().unwrap())); macro_rules! hex (($hex:expr) => (hex_decode($hex).unwrap()));
macro_rules! hex_key (($secp:expr, $hex:expr) => (PublicKey::from_slice($secp, &hex!($hex)).unwrap())); macro_rules! hex_key (($secp:expr, $hex:expr) => (PublicKey::from_slice($secp, &hex!($hex)).unwrap()));
macro_rules! hex_script (($hex:expr) => (Script::from(hex!($hex)))); macro_rules! hex_script (($hex:expr) => (Script::from(hex!($hex))));
@ -331,7 +331,7 @@ mod tests {
let addr = Address { let addr = Address {
network: Bitcoin, network: Bitcoin,
payload: Payload::PubkeyHash( payload: Payload::PubkeyHash(
Hash160::from(&"162c5ea71c0b23f5b9022ef047c4a86470a5b070".from_hex().unwrap()[..]) Hash160::from(&hex_decode("162c5ea71c0b23f5b9022ef047c4a86470a5b070").unwrap()[..])
) )
}; };
@ -367,7 +367,7 @@ mod tests {
let addr = Address { let addr = Address {
network: Bitcoin, network: Bitcoin,
payload: Payload::ScriptHash( payload: Payload::ScriptHash(
Hash160::from(&"162c5ea71c0b23f5b9022ef047c4a86470a5b070".from_hex().unwrap()[..]) Hash160::from(&hex_decode("162c5ea71c0b23f5b9022ef047c4a86470a5b070").unwrap()[..])
) )
}; };

View File

@ -194,9 +194,8 @@ pub fn check_encode_slice(data: &[u8]) -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serialize::hex::FromHex;
use super::*; use super::*;
use hex::decode as hex_decode;
#[test] #[test]
fn test_base58_encode() { fn test_base58_encode() {
@ -211,7 +210,7 @@ mod tests {
assert_eq!(&encode_slice(&[0, 0, 0, 0, 13, 36][..]), "1111211"); assert_eq!(&encode_slice(&[0, 0, 0, 0, 13, 36][..]), "1111211");
// Addresses // Addresses
let addr = "00f8917303bfa8ef24f292e8fa1419b20460ba064d".from_hex().unwrap(); let addr = hex_decode("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap();
assert_eq!(&check_encode_slice(&addr[..]), "1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH"); assert_eq!(&check_encode_slice(&addr[..]), "1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH");
} }
@ -229,7 +228,7 @@ mod tests {
// Addresses // Addresses
assert_eq!(from_check("1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH").ok(), assert_eq!(from_check("1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH").ok(),
Some("00f8917303bfa8ef24f292e8fa1419b20460ba064d".from_hex().unwrap())) Some(hex_decode("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap()))
} }
#[test] #[test]

View File

@ -105,8 +105,6 @@ impl SighashComponents {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serialize::hex::FromHex;
use blockdata::transaction::Transaction; use blockdata::transaction::Transaction;
use network::serialize::deserialize; use network::serialize::deserialize;
use util::misc::hex_bytes; use util::misc::hex_bytes;

View File

@ -460,7 +460,7 @@ mod tests {
use std::string::ToString; use std::string::ToString;
use secp256k1::Secp256k1; use secp256k1::Secp256k1;
use serialize::hex::FromHex; use hex::decode as hex_decode;
use network::constants::Network::{self, Bitcoin}; use network::constants::Network::{self, Bitcoin};
@ -504,7 +504,7 @@ mod tests {
#[test] #[test]
fn test_vector_1() { fn test_vector_1() {
let secp = Secp256k1::new(); let secp = Secp256k1::new();
let seed = "000102030405060708090a0b0c0d0e0f".from_hex().unwrap(); let seed = hex_decode("000102030405060708090a0b0c0d0e0f").unwrap();
// m // m
test_path(&secp, Bitcoin, &seed, &[], test_path(&secp, Bitcoin, &seed, &[],
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi", "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
@ -539,7 +539,7 @@ mod tests {
#[test] #[test]
fn test_vector_2() { fn test_vector_2() {
let secp = Secp256k1::new(); let secp = Secp256k1::new();
let seed = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542".from_hex().unwrap(); let seed = hex_decode("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542").unwrap();
// m // m
test_path(&secp, Bitcoin, &seed, &[], test_path(&secp, Bitcoin, &seed, &[],

View File

@ -157,7 +157,7 @@ impl Template {
} }
impl<'a> From<&'a [u8]> for Template { impl<'a> From<&'a [u8]> for Template {
fn from(slice: &'a [u8]) -> Template { fn from(slice: &'a [u8]) -> Template {
Template(slice.iter().map(|&byte| { Template(slice.iter().map(|&byte| {
if byte == PUBKEY { if byte == PUBKEY {
TemplateElement::Key TemplateElement::Key
@ -274,7 +274,7 @@ pub fn untemplate(script: &script::Script) -> Result<(Template, Vec<PublicKey>),
if mode == Mode::CopyingKeys { return Err(Error::ExpectedKey); } if mode == Mode::CopyingKeys { return Err(Error::ExpectedKey); }
mode = Mode::SeekingKeys; mode = Mode::SeekingKeys;
} }
// Numbers after keys mean we expect a CHECKMULTISIG. // Numbers after keys mean we expect a CHECKMULTISIG.
opcodes::Class::PushNum(_) => { opcodes::Class::PushNum(_) => {
if mode == Mode::SeekingCheckMulti { return Err(Error::ExpectedChecksig); } if mode == Mode::SeekingCheckMulti { return Err(Error::ExpectedChecksig); }
if mode == Mode::CopyingKeys { mode = Mode::SeekingCheckMulti; } if mode == Mode::CopyingKeys { mode = Mode::SeekingCheckMulti; }
@ -294,7 +294,7 @@ pub fn untemplate(script: &script::Script) -> Result<(Template, Vec<PublicKey>),
mod tests { mod tests {
use secp256k1::Secp256k1; use secp256k1::Secp256k1;
use secp256k1::key::PublicKey; use secp256k1::key::PublicKey;
use serialize::hex::FromHex; use hex::decode as hex_decode;
use rand::thread_rng; use rand::thread_rng;
use blockdata::script::Script; use blockdata::script::Script;
@ -302,7 +302,7 @@ mod tests {
use super::*; use super::*;
macro_rules! hex (($hex:expr) => ($hex.from_hex().unwrap())); macro_rules! hex (($hex:expr) => (hex_decode($hex).unwrap()));
macro_rules! hex_key (($secp:expr, $hex:expr) => (PublicKey::from_slice($secp, &hex!($hex)).unwrap())); macro_rules! hex_key (($secp:expr, $hex:expr) => (PublicKey::from_slice($secp, &hex!($hex)).unwrap()));
macro_rules! alpha_template(() => (Template::from(&hex!("55fefefefefefefe57AE")[..]))); macro_rules! alpha_template(() => (Template::from(&hex!("55fefefefefefefe57AE")[..])));
macro_rules! alpha_keys(($secp:expr) => ( macro_rules! alpha_keys(($secp:expr) => (