Remove the hex dependency
This commit is contained in:
parent
5452260884
commit
c19b736566
|
@ -18,7 +18,7 @@ path = "src/lib.rs"
|
||||||
fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
|
fuzztarget = ["secp256k1/fuzztarget", "bitcoin_hashes/fuzztarget"]
|
||||||
unstable = []
|
unstable = []
|
||||||
rand = ["secp256k1/rand-std"]
|
rand = ["secp256k1/rand-std"]
|
||||||
use-serde = ["hex", "serde", "bitcoin_hashes/serde", "secp256k1/serde"]
|
use-serde = ["serde", "bitcoin_hashes/serde", "secp256k1/serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bech32 = "0.7.2"
|
bech32 = "0.7.2"
|
||||||
|
@ -27,7 +27,6 @@ secp256k1 = "0.17.1"
|
||||||
|
|
||||||
bitcoinconsensus = { version = "0.19.0-1", optional = true }
|
bitcoinconsensus = { version = "0.19.0-1", optional = true }
|
||||||
serde = { version = "1", optional = true }
|
serde = { version = "1", optional = true }
|
||||||
hex = { version = "=0.3.2", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex = "=0.3.2"
|
hex = "=0.3.2"
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -84,7 +84,7 @@ fn bitcoin_genesis_tx() -> Transaction {
|
||||||
|
|
||||||
// Outputs
|
// Outputs
|
||||||
let out_script = script::Builder::new()
|
let out_script = script::Builder::new()
|
||||||
.push_slice(&Vec::<u8>::from_hex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f").unwrap())
|
.push_slice(&Vec::from_hex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f").unwrap())
|
||||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||||
.into_script();
|
.into_script();
|
||||||
ret.output.push(TxOut {
|
ret.output.push(TxOut {
|
||||||
|
@ -147,7 +147,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 hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
use network::constants::Network;
|
use network::constants::Network;
|
||||||
use consensus::encode::serialize;
|
use consensus::encode::serialize;
|
||||||
|
@ -163,12 +163,12 @@ mod test {
|
||||||
assert_eq!(gen.input[0].previous_output.txid, Default::default());
|
assert_eq!(gen.input[0].previous_output.txid, Default::default());
|
||||||
assert_eq!(gen.input[0].previous_output.vout, 0xFFFFFFFF);
|
assert_eq!(gen.input[0].previous_output.vout, 0xFFFFFFFF);
|
||||||
assert_eq!(serialize(&gen.input[0].script_sig),
|
assert_eq!(serialize(&gen.input[0].script_sig),
|
||||||
hex_decode("4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73").unwrap());
|
Vec::from_hex("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),
|
assert_eq!(serialize(&gen.output[0].script_pubkey),
|
||||||
hex_decode("434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac").unwrap());
|
Vec::from_hex("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);
|
||||||
|
|
||||||
|
|
|
@ -693,6 +693,7 @@ impl<'de> serde::Deserialize<'de> for Script {
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use std::fmt::Formatter;
|
use std::fmt::Formatter;
|
||||||
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
impl<'de> serde::de::Visitor<'de> for Visitor {
|
impl<'de> serde::de::Visitor<'de> for Visitor {
|
||||||
|
@ -706,7 +707,7 @@ impl<'de> serde::Deserialize<'de> for Script {
|
||||||
where
|
where
|
||||||
E: serde::de::Error,
|
E: serde::de::Error,
|
||||||
{
|
{
|
||||||
let v: Vec<u8> = ::hex::decode(v).map_err(E::custom)?;
|
let v = Vec::from_hex(v).map_err(E::custom)?;
|
||||||
Ok(Script::from(v))
|
Ok(Script::from(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +762,7 @@ impl Decodable for Script {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::build_scriptint;
|
use super::build_scriptint;
|
||||||
|
@ -796,10 +797,10 @@ mod test {
|
||||||
// keys
|
// keys
|
||||||
let keystr = "21032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af";
|
let keystr = "21032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af";
|
||||||
let key = PublicKey::from_str(&keystr[2..]).unwrap();
|
let key = PublicKey::from_str(&keystr[2..]).unwrap();
|
||||||
script = script.push_key(&key); comp.extend(hex_decode(keystr).unwrap().iter().cloned()); assert_eq!(&script[..], &comp[..]);
|
script = script.push_key(&key); comp.extend(Vec::from_hex(keystr).unwrap().iter().cloned()); assert_eq!(&script[..], &comp[..]);
|
||||||
let keystr = "41042e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af191923a2964c177f5b5923ae500fca49e99492d534aa3759d6b25a8bc971b133";
|
let keystr = "41042e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af191923a2964c177f5b5923ae500fca49e99492d534aa3759d6b25a8bc971b133";
|
||||||
let key = PublicKey::from_str(&keystr[2..]).unwrap();
|
let key = PublicKey::from_str(&keystr[2..]).unwrap();
|
||||||
script = script.push_key(&key); comp.extend(hex_decode(keystr).unwrap().iter().cloned()); assert_eq!(&script[..], &comp[..]);
|
script = script.push_key(&key); comp.extend(Vec::from_hex(keystr).unwrap().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[..]);
|
||||||
|
@ -811,7 +812,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(&hex_decode("16e1ae70ff0fa102905d4af297f6912bda6cce19").unwrap())
|
.push_slice(&Vec::from_hex("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();
|
||||||
|
@ -892,7 +893,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn script_serialize() {
|
fn script_serialize() {
|
||||||
let hex_script = hex_decode("6c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52").unwrap();
|
let hex_script = Vec::from_hex("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()), hex_script);
|
assert_eq!(serialize(&script.unwrap()), hex_script);
|
||||||
|
@ -1082,8 +1083,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(hex_decode("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d").unwrap()).into_script();
|
let spent = Builder::from(Vec::from_hex("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d").unwrap()).into_script();
|
||||||
let spending = hex_decode("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000").unwrap();
|
let spending = Vec::from_hex("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000").unwrap();
|
||||||
spent.verify(0, 18393430, spending.as_slice()).unwrap();
|
spent.verify(0, 18393430, spending.as_slice()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,7 +669,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_txin() {
|
fn test_txin() {
|
||||||
let txin: Result<TxIn, _> = deserialize(&Vec::<u8>::from_hex("a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff").unwrap());
|
let txin: Result<TxIn, _> = deserialize(&Vec::from_hex("a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff").unwrap());
|
||||||
assert!(txin.is_ok());
|
assert!(txin.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,14 +690,14 @@ mod tests {
|
||||||
|
|
||||||
let genesis = constants::genesis_block(Network::Bitcoin);
|
let genesis = constants::genesis_block(Network::Bitcoin);
|
||||||
assert! (genesis.txdata[0].is_coin_base());
|
assert! (genesis.txdata[0].is_coin_base());
|
||||||
let tx_bytes = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
let tx_bytes = Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
||||||
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
||||||
assert!(!tx.is_coin_base());
|
assert!(!tx.is_coin_base());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nonsegwit_transaction() {
|
fn test_nonsegwit_transaction() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
let tx_bytes = Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
||||||
let tx: Result<Transaction, _> = deserialize(&tx_bytes);
|
let tx: Result<Transaction, _> = deserialize(&tx_bytes);
|
||||||
assert!(tx.is_ok());
|
assert!(tx.is_ok());
|
||||||
let realtx = tx.unwrap();
|
let realtx = tx.unwrap();
|
||||||
|
@ -722,7 +722,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segwit_transaction() {
|
fn test_segwit_transaction() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex(
|
let tx_bytes = Vec::from_hex(
|
||||||
"02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
|
"02000000000101595895ea20179de87052b4046dfe6fd515860505d6511a9004cf12a1f93cac7c01000000\
|
||||||
00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
|
00ffffffff01deb807000000000017a9140f3444e271620c736808aa7b33e370bd87cb5a078702483045022\
|
||||||
100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
|
100fb60dad8df4af2841adc0346638c16d0b8035f5e3f3753b88db122e70c79f9370220756e6633b17fd271\
|
||||||
|
@ -753,7 +753,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tx_no_input_deserialization() {
|
fn tx_no_input_deserialization() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex(
|
let tx_bytes = Vec::from_hex(
|
||||||
"010000000001000100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"
|
"010000000001000100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
let tx: Transaction = deserialize(&tx_bytes).expect("deserialize tx");
|
let tx: Transaction = deserialize(&tx_bytes).expect("deserialize tx");
|
||||||
|
@ -767,7 +767,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ntxid() {
|
fn test_ntxid() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
let tx_bytes = Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
||||||
let mut tx: Transaction = deserialize(&tx_bytes).unwrap();
|
let mut tx: Transaction = deserialize(&tx_bytes).unwrap();
|
||||||
|
|
||||||
let old_ntxid = tx.ntxid();
|
let old_ntxid = tx.ntxid();
|
||||||
|
@ -783,7 +783,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_txid() {
|
fn test_txid() {
|
||||||
// segwit tx from Liquid integration tests, txid/hash from Core decoderawtransaction
|
// segwit tx from Liquid integration tests, txid/hash from Core decoderawtransaction
|
||||||
let tx_bytes = Vec::<u8>::from_hex(
|
let tx_bytes = Vec::from_hex(
|
||||||
"01000000000102ff34f95a672bb6a4f6ff4a7e90fa8c7b3be7e70ffc39bc99be3bda67942e836c00000000\
|
"01000000000102ff34f95a672bb6a4f6ff4a7e90fa8c7b3be7e70ffc39bc99be3bda67942e836c00000000\
|
||||||
23220020cde476664d3fa347b8d54ef3aee33dcb686a65ced2b5207cbf4ec5eda6b9b46e4f414d4c934ad8\
|
23220020cde476664d3fa347b8d54ef3aee33dcb686a65ced2b5207cbf4ec5eda6b9b46e4f414d4c934ad8\
|
||||||
1d330314e888888e3bd22c7dde8aac2ca9227b30d7c40093248af7812201000000232200200af6f6a071a6\
|
1d330314e888888e3bd22c7dde8aac2ca9227b30d7c40093248af7812201000000232200200af6f6a071a6\
|
||||||
|
@ -820,7 +820,7 @@ mod tests {
|
||||||
assert_eq!(tx.get_weight(), 2718);
|
assert_eq!(tx.get_weight(), 2718);
|
||||||
|
|
||||||
// non-segwit tx from my mempool
|
// non-segwit tx from my mempool
|
||||||
let tx_bytes = Vec::<u8>::from_hex(
|
let tx_bytes = Vec::from_hex(
|
||||||
"01000000010c7196428403d8b0c88fcb3ee8d64f56f55c8973c9ab7dd106bb4f3527f5888d000000006a47\
|
"01000000010c7196428403d8b0c88fcb3ee8d64f56f55c8973c9ab7dd106bb4f3527f5888d000000006a47\
|
||||||
30440220503a696f55f2c00eee2ac5e65b17767cd88ed04866b5637d3c1d5d996a70656d02202c9aff698f\
|
30440220503a696f55f2c00eee2ac5e65b17767cd88ed04866b5637d3c1d5d996a70656d02202c9aff698f\
|
||||||
343abb6d176704beda63fcdec503133ea4f6a5216b7f925fa9910c0121024d89b5a13d6521388969209df2\
|
343abb6d176704beda63fcdec503133ea4f6a5216b7f925fa9910c0121024d89b5a13d6521388969209df2\
|
||||||
|
@ -837,15 +837,15 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_txn_encode_decode() {
|
fn test_txn_encode_decode() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
let tx_bytes = Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
|
||||||
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
||||||
serde_round_trip!(tx);
|
serde_round_trip!(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_test_sighash(tx: &str, script: &str, input_index: usize, hash_type: i32, expected_result: &str) {
|
fn run_test_sighash(tx: &str, script: &str, input_index: usize, hash_type: i32, expected_result: &str) {
|
||||||
let tx: Transaction = deserialize(&Vec::<u8>::from_hex(tx).unwrap()[..]).unwrap();
|
let tx: Transaction = deserialize(&Vec::from_hex(tx).unwrap()[..]).unwrap();
|
||||||
let script = Script::from(Vec::<u8>::from_hex(script).unwrap());
|
let script = Script::from(Vec::from_hex(script).unwrap());
|
||||||
let mut raw_expected = Vec::<u8>::from_hex(expected_result).unwrap();
|
let mut raw_expected = Vec::from_hex(expected_result).unwrap();
|
||||||
raw_expected.reverse();
|
raw_expected.reverse();
|
||||||
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
|
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
|
||||||
|
|
||||||
|
@ -858,7 +858,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
fn test_segwit_tx_decode() {
|
fn test_segwit_tx_decode() {
|
||||||
let tx_bytes = Vec::<u8>::from_hex("010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3603da1b0e00045503bd5704c7dd8a0d0ced13bb5785010800000000000a636b706f6f6c122f4e696e6a61506f6f6c2f5345475749542fffffffff02b4e5a212000000001976a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac0000000000000000266a24aa21a9edf91c46b49eb8a29089980f02ee6b57e7d63d33b18b4fddac2bcd7db2a39837040120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
let tx_bytes = Vec::from_hex("010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3603da1b0e00045503bd5704c7dd8a0d0ced13bb5785010800000000000a636b706f6f6c122f4e696e6a61506f6f6c2f5345475749542fffffffff02b4e5a212000000001976a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac0000000000000000266a24aa21a9edf91c46b49eb8a29089980f02ee6b57e7d63d33b18b4fddac2bcd7db2a39837040120000000000000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||||
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
let tx: Transaction = deserialize(&tx_bytes).unwrap();
|
||||||
assert_eq!(tx.get_weight(), 780);
|
assert_eq!(tx.get_weight(), 780);
|
||||||
serde_round_trip!(tx);
|
serde_round_trip!(tx);
|
||||||
|
@ -1167,17 +1167,17 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature="bitcoinconsensus")]
|
#[cfg(feature="bitcoinconsensus")]
|
||||||
fn test_transaction_verify () {
|
fn test_transaction_verify () {
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
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(hex_decode("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
|
let mut spending: Transaction = deserialize(Vec::from_hex("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
|
||||||
.unwrap().as_slice()).unwrap();
|
.unwrap().as_slice()).unwrap();
|
||||||
let spent1: Transaction = deserialize(hex_decode("020000000001040aacd2c49f5f3c0968cfa8caf9d5761436d95385252e3abb4de8f5dcf8a582f20000000017160014bcadb2baea98af0d9a902e53a7e9adff43b191e9feffffff96cd3c93cac3db114aafe753122bd7d1afa5aa4155ae04b3256344ecca69d72001000000171600141d9984579ceb5c67ebfbfb47124f056662fe7adbfeffffffc878dd74d3a44072eae6178bb94b9253177db1a5aaa6d068eb0e4db7631762e20000000017160014df2a48cdc53dae1aba7aa71cb1f9de089d75aac3feffffffe49f99275bc8363f5f593f4eec371c51f62c34ff11cc6d8d778787d340d6896c0100000017160014229b3b297a0587e03375ab4174ef56eeb0968735feffffff03360d0f00000000001976a9149f44b06f6ee92ddbc4686f71afe528c09727a5c788ac24281b00000000001976a9140277b4f68ff20307a2a9f9b4487a38b501eb955888ac227c0000000000001976a9148020cd422f55eef8747a9d418f5441030f7c9c7788ac0247304402204aa3bd9682f9a8e101505f6358aacd1749ecf53a62b8370b97d59243b3d6984f02200384ad449870b0e6e89c92505880411285ecd41cf11e7439b973f13bad97e53901210205b392ffcb83124b1c7ce6dd594688198ef600d34500a7f3552d67947bbe392802473044022033dfd8d190a4ae36b9f60999b217c775b96eb10dee3a1ff50fb6a75325719106022005872e4e36d194e49ced2ebcf8bb9d843d842e7b7e0eb042f4028396088d292f012103c9d7cbf369410b090480de2aa15c6c73d91b9ffa7d88b90724614b70be41e98e0247304402207d952de9e59e4684efed069797e3e2d993e9f98ec8a9ccd599de43005fe3f713022076d190cc93d9513fc061b1ba565afac574e02027c9efbfa1d7b71ab8dbb21e0501210313ad44bc030cc6cb111798c2bf3d2139418d751c1e79ec4e837ce360cc03b97a024730440220029e75edb5e9413eb98d684d62a077b17fa5b7cc19349c1e8cc6c4733b7b7452022048d4b9cae594f03741029ff841e35996ef233701c1ea9aa55c301362ea2e2f68012103590657108a72feb8dc1dec022cf6a230bb23dc7aaa52f4032384853b9f8388baf9d20700")
|
let spent1: Transaction = deserialize(Vec::from_hex("020000000001040aacd2c49f5f3c0968cfa8caf9d5761436d95385252e3abb4de8f5dcf8a582f20000000017160014bcadb2baea98af0d9a902e53a7e9adff43b191e9feffffff96cd3c93cac3db114aafe753122bd7d1afa5aa4155ae04b3256344ecca69d72001000000171600141d9984579ceb5c67ebfbfb47124f056662fe7adbfeffffffc878dd74d3a44072eae6178bb94b9253177db1a5aaa6d068eb0e4db7631762e20000000017160014df2a48cdc53dae1aba7aa71cb1f9de089d75aac3feffffffe49f99275bc8363f5f593f4eec371c51f62c34ff11cc6d8d778787d340d6896c0100000017160014229b3b297a0587e03375ab4174ef56eeb0968735feffffff03360d0f00000000001976a9149f44b06f6ee92ddbc4686f71afe528c09727a5c788ac24281b00000000001976a9140277b4f68ff20307a2a9f9b4487a38b501eb955888ac227c0000000000001976a9148020cd422f55eef8747a9d418f5441030f7c9c7788ac0247304402204aa3bd9682f9a8e101505f6358aacd1749ecf53a62b8370b97d59243b3d6984f02200384ad449870b0e6e89c92505880411285ecd41cf11e7439b973f13bad97e53901210205b392ffcb83124b1c7ce6dd594688198ef600d34500a7f3552d67947bbe392802473044022033dfd8d190a4ae36b9f60999b217c775b96eb10dee3a1ff50fb6a75325719106022005872e4e36d194e49ced2ebcf8bb9d843d842e7b7e0eb042f4028396088d292f012103c9d7cbf369410b090480de2aa15c6c73d91b9ffa7d88b90724614b70be41e98e0247304402207d952de9e59e4684efed069797e3e2d993e9f98ec8a9ccd599de43005fe3f713022076d190cc93d9513fc061b1ba565afac574e02027c9efbfa1d7b71ab8dbb21e0501210313ad44bc030cc6cb111798c2bf3d2139418d751c1e79ec4e837ce360cc03b97a024730440220029e75edb5e9413eb98d684d62a077b17fa5b7cc19349c1e8cc6c4733b7b7452022048d4b9cae594f03741029ff841e35996ef233701c1ea9aa55c301362ea2e2f68012103590657108a72feb8dc1dec022cf6a230bb23dc7aaa52f4032384853b9f8388baf9d20700")
|
||||||
.unwrap().as_slice()).unwrap();
|
.unwrap().as_slice()).unwrap();
|
||||||
let spent2: Transaction = deserialize(hex_decode("0200000000010166c3d39490dc827a2594c7b17b7d37445e1f4b372179649cd2ce4475e3641bbb0100000017160014e69aa750e9bff1aca1e32e57328b641b611fc817fdffffff01e87c5d010000000017a914f3890da1b99e44cd3d52f7bcea6a1351658ea7be87024830450221009eb97597953dc288de30060ba02d4e91b2bde1af2ecf679c7f5ab5989549aa8002202a98f8c3bd1a5a31c0d72950dd6e2e3870c6c5819a6c3db740e91ebbbc5ef4800121023f3d3b8e74b807e32217dea2c75c8d0bd46b8665b3a2d9b3cb310959de52a09bc9d20700")
|
let spent2: Transaction = deserialize(Vec::from_hex("0200000000010166c3d39490dc827a2594c7b17b7d37445e1f4b372179649cd2ce4475e3641bbb0100000017160014e69aa750e9bff1aca1e32e57328b641b611fc817fdffffff01e87c5d010000000017a914f3890da1b99e44cd3d52f7bcea6a1351658ea7be87024830450221009eb97597953dc288de30060ba02d4e91b2bde1af2ecf679c7f5ab5989549aa8002202a98f8c3bd1a5a31c0d72950dd6e2e3870c6c5819a6c3db740e91ebbbc5ef4800121023f3d3b8e74b807e32217dea2c75c8d0bd46b8665b3a2d9b3cb310959de52a09bc9d20700")
|
||||||
.unwrap().as_slice()).unwrap();
|
.unwrap().as_slice()).unwrap();
|
||||||
let spent3: Transaction = deserialize(hex_decode("01000000027a1120a30cef95422638e8dab9dedf720ec614b1b21e451a4957a5969afb869d000000006a47304402200ecc318a829a6cad4aa9db152adbf09b0cd2de36f47b53f5dade3bc7ef086ca702205722cda7404edd6012eedd79b2d6f24c0a0c657df1a442d0a2166614fb164a4701210372f4b97b34e9c408741cd1fc97bcc7ffdda6941213ccfde1cb4075c0f17aab06ffffffffc23b43e5a18e5a66087c0d5e64d58e8e21fcf83ce3f5e4f7ecb902b0e80a7fb6010000006b483045022100f10076a0ea4b4cf8816ed27a1065883efca230933bf2ff81d5db6258691ff75202206b001ef87624e76244377f57f0c84bc5127d0dd3f6e0ef28b276f176badb223a01210309a3a61776afd39de4ed29b622cd399d99ecd942909c36a8696cfd22fc5b5a1affffffff0200127a000000000017a914f895e1dd9b29cb228e9b06a15204e3b57feaf7cc8769311d09000000001976a9144d00da12aaa51849d2583ae64525d4a06cd70fde88ac00000000")
|
let spent3: Transaction = deserialize(Vec::from_hex("01000000027a1120a30cef95422638e8dab9dedf720ec614b1b21e451a4957a5969afb869d000000006a47304402200ecc318a829a6cad4aa9db152adbf09b0cd2de36f47b53f5dade3bc7ef086ca702205722cda7404edd6012eedd79b2d6f24c0a0c657df1a442d0a2166614fb164a4701210372f4b97b34e9c408741cd1fc97bcc7ffdda6941213ccfde1cb4075c0f17aab06ffffffffc23b43e5a18e5a66087c0d5e64d58e8e21fcf83ce3f5e4f7ecb902b0e80a7fb6010000006b483045022100f10076a0ea4b4cf8816ed27a1065883efca230933bf2ff81d5db6258691ff75202206b001ef87624e76244377f57f0c84bc5127d0dd3f6e0ef28b276f176badb223a01210309a3a61776afd39de4ed29b622cd399d99ecd942909c36a8696cfd22fc5b5a1affffffff0200127a000000000017a914f895e1dd9b29cb228e9b06a15204e3b57feaf7cc8769311d09000000001976a9144d00da12aaa51849d2583ae64525d4a06cd70fde88ac00000000")
|
||||||
.unwrap().as_slice()).unwrap();
|
.unwrap().as_slice()).unwrap();
|
||||||
|
|
||||||
let mut spent = HashMap::new();
|
let mut spent = HashMap::new();
|
||||||
|
|
|
@ -224,10 +224,10 @@ macro_rules! display_from_debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_script (($s:expr) => (::blockdata::script::Script::from(::hex::decode($s).unwrap())));
|
macro_rules! hex_script (($s:expr) => (::blockdata::script::Script::from(<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap())));
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&::hex::decode($s).unwrap()).unwrap()));
|
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
||||||
|
|
||||||
macro_rules! serde_struct_impl {
|
macro_rules! serde_struct_impl {
|
||||||
($name:ident, $($fe:ident),*) => (
|
($name:ident, $($fe:ident),*) => (
|
||||||
|
|
|
@ -56,7 +56,6 @@
|
||||||
pub extern crate secp256k1;
|
pub extern crate secp256k1;
|
||||||
pub extern crate bech32;
|
pub extern crate bech32;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "serde"))] extern crate hex;
|
|
||||||
#[cfg(feature = "serde")] extern crate serde;
|
#[cfg(feature = "serde")] extern crate serde;
|
||||||
#[cfg(all(test, feature = "serde"))] #[macro_use] extern crate serde_derive; // for 1.22.0 compat
|
#[cfg(all(test, feature = "serde"))] #[macro_use] extern crate serde_derive; // for 1.22.0 compat
|
||||||
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
|
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -136,15 +136,15 @@ impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash);
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{GetHeadersMessage, GetBlocksMessage};
|
use super::{GetHeadersMessage, GetBlocksMessage};
|
||||||
|
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
use consensus::encode::{deserialize, serialize};
|
use consensus::encode::{deserialize, serialize};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn getblocks_message_test() {
|
fn getblocks_message_test() {
|
||||||
let from_sat = hex_decode("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
let from_sat = Vec::from_hex("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||||
let genhash = hex_decode("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
|
let genhash = Vec::from_hex("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 = hex_decode("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
let from_sat = Vec::from_hex("72110100014a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
|
||||||
let genhash = hex_decode("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
|
let genhash = Vec::from_hex("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b").unwrap();
|
||||||
|
|
||||||
let decode: Result<GetHeadersMessage, _> = deserialize(&from_sat);
|
let decode: Result<GetHeadersMessage, _> = deserialize(&from_sat);
|
||||||
assert!(decode.is_ok());
|
assert!(decode.is_ok());
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl_consensus_encoding!(Reject, message, ccode, reason, hash);
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::VersionMessage;
|
use super::VersionMessage;
|
||||||
|
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
use network::constants::ServiceFlags;
|
use network::constants::ServiceFlags;
|
||||||
|
|
||||||
use consensus::encode::{deserialize, serialize};
|
use consensus::encode::{deserialize, serialize};
|
||||||
|
@ -155,7 +155,7 @@ mod tests {
|
||||||
#[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 = hex_decode("721101000100000000000000e6e0845300000000010000000000000000000000000000000000ffff0000000000000100000000000000fd87d87eeb4364f22cf54dca59412db7208d47d920cffce83ee8102f5361746f7368693a302e392e39392f2c9f040001").unwrap();
|
let from_sat = Vec::from_hex("721101000100000000000000e6e0845300000000010000000000000000000000000000000000ffff0000000000000100000000000000fd87d87eeb4364f22cf54dca59412db7208d47d920cffce83ee8102f5361746f7368693a302e392e39392f2c9f040001").unwrap();
|
||||||
|
|
||||||
let decode: Result<VersionMessage, _> = deserialize(&from_sat);
|
let decode: Result<VersionMessage, _> = deserialize(&from_sat);
|
||||||
assert!(decode.is_ok());
|
assert!(decode.is_ok());
|
||||||
|
|
|
@ -315,13 +315,13 @@ mod test {
|
||||||
fn read_block_from_file_test() {
|
fn read_block_from_file_test() {
|
||||||
use std::io;
|
use std::io;
|
||||||
use consensus::serialize;
|
use consensus::serialize;
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
use Block;
|
use Block;
|
||||||
|
|
||||||
let normal_data = hex_decode("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac00000000").unwrap();
|
let normal_data = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac00000000").unwrap();
|
||||||
let cutoff_data = hex_decode("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").unwrap();
|
let cutoff_data = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").unwrap();
|
||||||
let prevhash = hex_decode("4ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000").unwrap();
|
let prevhash = Vec::from_hex("4ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000").unwrap();
|
||||||
let merkle = hex_decode("bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c").unwrap();
|
let merkle = Vec::from_hex("bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c").unwrap();
|
||||||
|
|
||||||
let stream = io::BufReader::new(&normal_data[..]);
|
let stream = io::BufReader::new(&normal_data[..]);
|
||||||
let mut reader = StreamReader::new(stream, None);
|
let mut reader = StreamReader::new(stream, None);
|
||||||
|
|
|
@ -506,8 +506,7 @@ mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
|
||||||
use hashes::Hash;
|
use hashes::hex::{FromHex, ToHex};
|
||||||
use hex::{decode as hex_decode, encode as hex_encode};
|
|
||||||
|
|
||||||
use blockdata::script::Script;
|
use blockdata::script::Script;
|
||||||
use network::constants::Network::{Bitcoin, Testnet};
|
use network::constants::Network::{Bitcoin, Testnet};
|
||||||
|
@ -515,11 +514,11 @@ mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
macro_rules! hex (($hex:expr) => (hex_decode($hex).unwrap()));
|
macro_rules! hex (($hex:expr) => (Vec::from_hex($hex).unwrap()));
|
||||||
macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap()));
|
macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap()));
|
||||||
macro_rules! hex_script (($hex:expr) => (Script::from(hex!($hex))));
|
macro_rules! hex_script (($hex:expr) => (Script::from(hex!($hex))));
|
||||||
macro_rules! hex_pubkeyhash (($hex:expr) => (PubkeyHash::from_slice(&hex!($hex)).unwrap()));
|
macro_rules! hex_pubkeyhash (($hex:expr) => (PubkeyHash::from_hex(&$hex).unwrap()));
|
||||||
macro_rules! hex_scripthash (($hex:expr) => (ScriptHash::from_slice(&hex!($hex)).unwrap()));
|
macro_rules! hex_scripthash (($hex:expr) => (ScriptHash::from_hex($hex).unwrap()));
|
||||||
|
|
||||||
fn roundtrips(addr: &Address) {
|
fn roundtrips(addr: &Address) {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -664,7 +663,7 @@ mod tests {
|
||||||
];
|
];
|
||||||
for vector in &valid_vectors {
|
for vector in &valid_vectors {
|
||||||
let addr: Address = vector.0.parse().unwrap();
|
let addr: Address = vector.0.parse().unwrap();
|
||||||
assert_eq!(&hex_encode(addr.script_pubkey().as_bytes()), vector.1);
|
assert_eq!(&addr.script_pubkey().as_bytes().to_hex(), vector.1);
|
||||||
roundtrips(&addr);
|
roundtrips(&addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,10 +249,11 @@ pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt::
|
||||||
format_iter(fmt, iter)
|
format_iter(fmt, iter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_base58_encode() {
|
fn test_base58_encode() {
|
||||||
|
@ -275,7 +276,7 @@ mod tests {
|
||||||
assert_eq!(&res, exp);
|
assert_eq!(&res, exp);
|
||||||
|
|
||||||
// Addresses
|
// Addresses
|
||||||
let addr = hex_decode("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap();
|
let addr = Vec::from_hex("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap();
|
||||||
assert_eq!(&check_encode_slice(&addr[..]), "1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH");
|
assert_eq!(&check_encode_slice(&addr[..]), "1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ mod tests {
|
||||||
|
|
||||||
// Addresses
|
// Addresses
|
||||||
assert_eq!(from_check("1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH").ok(),
|
assert_eq!(from_check("1PfJpZsjreyVrqeoAfabrRwwjQyoSQMmHH").ok(),
|
||||||
Some(hex_decode("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap()))
|
Some(Vec::from_hex("00f8917303bfa8ef24f292e8fa1419b20460ba064d").unwrap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -109,12 +109,11 @@ mod tests {
|
||||||
use util::address::Address;
|
use util::address::Address;
|
||||||
use util::key::PublicKey;
|
use util::key::PublicKey;
|
||||||
use hashes::hex::FromHex;
|
use hashes::hex::FromHex;
|
||||||
use hex;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn p2pkh_hex(pk: &str) -> Script {
|
fn p2pkh_hex(pk: &str) -> Script {
|
||||||
let pk = hex::decode(pk).unwrap();
|
let pk = Vec::from_hex(pk).unwrap();
|
||||||
let pk = PublicKey::from_slice(pk.as_slice()).unwrap();
|
let pk = PublicKey::from_slice(pk.as_slice()).unwrap();
|
||||||
let witness_script = Address::p2pkh(&pk, Network::Bitcoin).script_pubkey();
|
let witness_script = Address::p2pkh(&pk, Network::Bitcoin).script_pubkey();
|
||||||
witness_script
|
witness_script
|
||||||
|
@ -123,7 +122,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bip143_p2wpkh() {
|
fn bip143_p2wpkh() {
|
||||||
let tx = deserialize::<Transaction>(
|
let tx = deserialize::<Transaction>(
|
||||||
&Vec::<u8>::from_hex(
|
&Vec::from_hex(
|
||||||
"0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f000000\
|
"0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f000000\
|
||||||
0000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000\
|
0000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000\
|
||||||
00ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093\
|
00ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093\
|
||||||
|
@ -161,7 +160,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bip143_p2wpkh_nested_in_p2sh() {
|
fn bip143_p2wpkh_nested_in_p2sh() {
|
||||||
let tx = deserialize::<Transaction>(
|
let tx = deserialize::<Transaction>(
|
||||||
&Vec::<u8>::from_hex(
|
&Vec::from_hex(
|
||||||
"0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477010000\
|
"0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477010000\
|
||||||
0000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac00\
|
0000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac00\
|
||||||
08af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000",
|
08af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000",
|
||||||
|
@ -170,7 +169,6 @@ mod tests {
|
||||||
|
|
||||||
let witness_script = p2pkh_hex("03ad1d8e89212f0b92c74d23bb710c00662ad1470198ac48c43f7d6f93a2a26873");
|
let witness_script = p2pkh_hex("03ad1d8e89212f0b92c74d23bb710c00662ad1470198ac48c43f7d6f93a2a26873");
|
||||||
let value = 1_000_000_000;
|
let value = 1_000_000_000;
|
||||||
|
|
||||||
let comp = SighashComponents::new(&tx);
|
let comp = SighashComponents::new(&tx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
comp,
|
comp,
|
||||||
|
@ -198,7 +196,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bip143_p2wsh_nested_in_p2sh() {
|
fn bip143_p2wsh_nested_in_p2sh() {
|
||||||
let tx = deserialize::<Transaction>(
|
let tx = deserialize::<Transaction>(
|
||||||
&Vec::<u8>::from_hex(
|
&Vec::from_hex(
|
||||||
"010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000\
|
"010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000\
|
||||||
ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f\
|
ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f\
|
||||||
05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000").unwrap()[..],
|
05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000").unwrap()[..],
|
||||||
|
|
|
@ -688,7 +688,7 @@ mod tests {
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
|
||||||
use secp256k1::{self, Secp256k1};
|
use secp256k1::{self, Secp256k1};
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
|
|
||||||
use network::constants::Network::{self, Bitcoin};
|
use network::constants::Network::{self, Bitcoin};
|
||||||
|
|
||||||
|
@ -856,7 +856,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vector_1() {
|
fn test_vector_1() {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let seed = hex_decode("000102030405060708090a0b0c0d0e0f").unwrap();
|
let seed = Vec::from_hex("000102030405060708090a0b0c0d0e0f").unwrap();
|
||||||
|
|
||||||
// m
|
// m
|
||||||
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
||||||
|
@ -892,7 +892,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vector_2() {
|
fn test_vector_2() {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let seed = hex_decode("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542").unwrap();
|
let seed = Vec::from_hex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542").unwrap();
|
||||||
|
|
||||||
// m
|
// m
|
||||||
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
||||||
|
@ -928,7 +928,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vector_3() {
|
fn test_vector_3() {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let seed = hex_decode("4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be").unwrap();
|
let seed = Vec::from_hex("4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be").unwrap();
|
||||||
|
|
||||||
// m
|
// m
|
||||||
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
|
||||||
|
|
|
@ -284,7 +284,7 @@ pub fn untemplate(script: &script::Script) -> Result<(Template, Vec<PublicKey>),
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use secp256k1::Secp256k1;
|
use secp256k1::Secp256k1;
|
||||||
use hex::decode as hex_decode;
|
use hashes::hex::FromHex;
|
||||||
use secp256k1::rand::thread_rng;
|
use secp256k1::rand::thread_rng;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use PublicKey;
|
use PublicKey;
|
||||||
|
|
||||||
macro_rules! hex (($hex:expr) => (hex_decode($hex).unwrap()));
|
macro_rules! hex (($hex:expr) => (Vec::from_hex($hex).unwrap()));
|
||||||
macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap()));
|
macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap()));
|
||||||
macro_rules! alpha_template(() => (Template::from(&hex!("55fefefefefefefe57AE")[..])));
|
macro_rules! alpha_template(() => (Template::from(&hex!("55fefefefefefefe57AE")[..])));
|
||||||
macro_rules! alpha_keys(() => (
|
macro_rules! alpha_keys(() => (
|
||||||
|
|
|
@ -504,7 +504,7 @@ mod tests {
|
||||||
use consensus::encode::{deserialize, serialize};
|
use consensus::encode::{deserialize, serialize};
|
||||||
use util::hash::bitcoin_merkle_root;
|
use util::hash::bitcoin_merkle_root;
|
||||||
use util::merkleblock::{MerkleBlock, PartialMerkleTree};
|
use util::merkleblock::{MerkleBlock, PartialMerkleTree};
|
||||||
use {hex, Block};
|
use Block;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pmt_tests() {
|
fn pmt_tests() {
|
||||||
|
@ -615,7 +615,7 @@ mod tests {
|
||||||
ebe1ae264bc0e2289189ff0316cdc10511da71da757e553cada9f3b5b1434f3923673adb57d83caac392c38\
|
ebe1ae264bc0e2289189ff0316cdc10511da71da757e553cada9f3b5b1434f3923673adb57d83caac392c38\
|
||||||
af156d6fc30b55fad4112df2b95531e68114e9ad10011e72f7b7cfdb025700";
|
af156d6fc30b55fad4112df2b95531e68114e9ad10011e72f7b7cfdb025700";
|
||||||
|
|
||||||
let mb: MerkleBlock = deserialize(&hex::decode(mb_hex).unwrap()).unwrap();
|
let mb: MerkleBlock = deserialize(&Vec::from_hex(mb_hex).unwrap()).unwrap();
|
||||||
assert_eq!(get_block_13b8a().block_hash(), mb.header.block_hash());
|
assert_eq!(get_block_13b8a().block_hash(), mb.header.block_hash());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
mb.header.merkle_root,
|
mb.header.merkle_root,
|
||||||
|
@ -781,6 +781,6 @@ mod tests {
|
||||||
058b800a098fc1740ce3012e8fc8a00c96af966ffffffff02c0e1e400000000001976a9144134e75a6fcb60\
|
058b800a098fc1740ce3012e8fc8a00c96af966ffffffff02c0e1e400000000001976a9144134e75a6fcb60\
|
||||||
42034aab5e18570cf1f844f54788ac404b4c00000000001976a9142b6ba7c9d796b75eef7942fc9288edd37\
|
42034aab5e18570cf1f844f54788ac404b4c00000000001976a9142b6ba7c9d796b75eef7942fc9288edd37\
|
||||||
c32f5c388ac00000000";
|
c32f5c388ac00000000";
|
||||||
deserialize(&hex::decode(block_hex).unwrap()).unwrap()
|
deserialize(&Vec::from_hex(block_hex).unwrap()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! hex_psbt {
|
macro_rules! hex_psbt {
|
||||||
($s:expr) => { ::consensus::deserialize(&::hex::decode($s).unwrap()) };
|
($s:expr) => { ::consensus::deserialize(&<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! merge {
|
macro_rules! merge {
|
||||||
|
|
|
@ -167,8 +167,6 @@ mod tests {
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use hex::decode as hex_decode;
|
|
||||||
|
|
||||||
use secp256k1::Secp256k1;
|
use secp256k1::Secp256k1;
|
||||||
|
|
||||||
use blockdata::script::Script;
|
use blockdata::script::Script;
|
||||||
|
@ -206,7 +204,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_then_deserialize_output() {
|
fn serialize_then_deserialize_output() {
|
||||||
let secp = &Secp256k1::new();
|
let secp = &Secp256k1::new();
|
||||||
let seed = hex_decode("000102030405060708090a0b0c0d0e0f").unwrap();
|
let seed = Vec::from_hex("000102030405060708090a0b0c0d0e0f").unwrap();
|
||||||
|
|
||||||
let mut hd_keypaths: BTreeMap<PublicKey, (Fingerprint, DerivationPath)> = Default::default();
|
let mut hd_keypaths: BTreeMap<PublicKey, (Fingerprint, DerivationPath)> = Default::default();
|
||||||
|
|
||||||
|
@ -312,8 +310,6 @@ mod tests {
|
||||||
mod bip_vectors {
|
mod bip_vectors {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use hex::decode as hex_decode;
|
|
||||||
|
|
||||||
use hashes::hex::FromHex;
|
use hashes::hex::FromHex;
|
||||||
use hash_types::Txid;
|
use hash_types::Txid;
|
||||||
|
|
||||||
|
@ -399,8 +395,8 @@ mod tests {
|
||||||
script_sig: hex_script!("160014be18d152a9b012039daf3da7de4f53349eecb985"),
|
script_sig: hex_script!("160014be18d152a9b012039daf3da7de4f53349eecb985"),
|
||||||
sequence: 4294967295,
|
sequence: 4294967295,
|
||||||
witness: vec![
|
witness: vec![
|
||||||
hex_decode("304402202712be22e0270f394f568311dc7ca9a68970b8025fdd3b240229f07f8a5f3a240220018b38d7dcd314e734c9276bd6fb40f673325bc4baa144c800d2f2f02db2765c01").unwrap(),
|
Vec::from_hex("304402202712be22e0270f394f568311dc7ca9a68970b8025fdd3b240229f07f8a5f3a240220018b38d7dcd314e734c9276bd6fb40f673325bc4baa144c800d2f2f02db2765c01").unwrap(),
|
||||||
hex_decode("03d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f2105").unwrap(),
|
Vec::from_hex("03d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f2105").unwrap(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
TxIn {
|
TxIn {
|
||||||
|
@ -413,8 +409,8 @@ mod tests {
|
||||||
script_sig: hex_script!("160014fe3e9ef1a745e974d902c4355943abcb34bd5353"),
|
script_sig: hex_script!("160014fe3e9ef1a745e974d902c4355943abcb34bd5353"),
|
||||||
sequence: 4294967295,
|
sequence: 4294967295,
|
||||||
witness: vec![
|
witness: vec![
|
||||||
hex_decode("3045022100d12b852d85dcd961d2f5f4ab660654df6eedcc794c0c33ce5cc309ffb5fce58d022067338a8e0e1725c197fb1a88af59f51e44e4255b20167c8684031c05d1f2592a01").unwrap(),
|
Vec::from_hex("3045022100d12b852d85dcd961d2f5f4ab660654df6eedcc794c0c33ce5cc309ffb5fce58d022067338a8e0e1725c197fb1a88af59f51e44e4255b20167c8684031c05d1f2592a01").unwrap(),
|
||||||
hex_decode("0223b72beef0965d10be0778efecd61fcac6f79a4ea169393380734464f84f2ab3").unwrap(),
|
Vec::from_hex("0223b72beef0965d10be0778efecd61fcac6f79a4ea169393380734464f84f2ab3").unwrap(),
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
output: vec![
|
output: vec![
|
||||||
|
@ -556,9 +552,9 @@ mod tests {
|
||||||
let mut unknown: BTreeMap<raw::Key, Vec<u8>> = BTreeMap::new();
|
let mut unknown: BTreeMap<raw::Key, Vec<u8>> = BTreeMap::new();
|
||||||
let key: raw::Key = raw::Key {
|
let key: raw::Key = raw::Key {
|
||||||
type_value: 0x0fu8,
|
type_value: 0x0fu8,
|
||||||
key: hex_decode("010203040506070809").unwrap(),
|
key: Vec::from_hex("010203040506070809").unwrap(),
|
||||||
};
|
};
|
||||||
let value: Vec<u8> = hex_decode("0102030405060708090a0b0c0d0e0f").unwrap();
|
let value: Vec<u8> = Vec::from_hex("0102030405060708090a0b0c0d0e0f").unwrap();
|
||||||
|
|
||||||
unknown.insert(key, value);
|
unknown.insert(key, value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue