signature hashes working correctly

This commit is contained in:
debris 2016-09-13 00:12:05 +02:00
parent 4bfaa20921
commit b9af3d58c8
2 changed files with 9 additions and 32 deletions

View File

@ -231,23 +231,4 @@ OP_ADD
"#;
assert_eq!(script.to_string(), s.to_string());
}
#[test]
fn playpen() {
let hex = "47304402202cb265bf10707bf49346c3515dd3d16fc454618c58ec0a0ff448a676c54ff71302206c6624d762a1fcef4618284ead8f08678ac05b13c84235f1654e6ad168233e8201410414e301b2328f17442c0b8310d787bf3d8a404cfbd0704f135b6ad4b2d3ee751310f981926e53a6e8c39bd7d3fefd576c543cce493cbac06388f2651d1aacbfcd".from_hex().unwrap();
let script = Script::new(hex);
let hex2 = "76a914c8e90996c7c6080ee06284600c684ed904d14c5c88ac".from_hex().unwrap();
let script2 = Script::new(hex2);
println!("1:\n{}", script);
println!("2:\n{}", script2);
assert!(false);
}
//#[test]
//fn test_playpen() {
//let script: Script = "47304402202cb265bf10707bf49346c3515dd3d16fc454618c58ec0a0ff448a676c54ff71302206c6624d762a1fcef4618284ead8f08678ac05b13c84235f1654e6ad168233e8201410414e301b2328f17442c0b8310d787bf3d8a404cfbd0704f135b6ad4b2d3ee751310f981926e53a6e8c39bd7d3fefd576c543cce493cbac06388f2651d1aacbfcd".into();
//println!("{}", script);
//assert!(false);
//}
}

View File

@ -74,7 +74,8 @@ impl TransactionInputSigner {
let mut stream = Stream::default();
stream.append(&tx);
stream.append(&u32::from(sighash));
dhash256(&stream.out())
let out = stream.out();
dhash256(&out)
}
/// input_index - index of input to sign
@ -106,11 +107,11 @@ impl TransactionInputSigner {
#[cfg(test)]
mod tests {
use hex::{ToHex, FromHex};
use hex::FromHex;
use hash::h256_from_str;
use keys::{KeyPair, Private, Address};
use transaction::{OutPoint, TransactionOutput};
use script::{Script, Sighash, SighashBase};
use script::{Sighash, SighashBase};
use super::{UnsignedTransactionInput, TransactionInputSigner};
// http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
@ -126,7 +127,9 @@ mod tests {
let previous_output = "76a914df3bd30160e6c6145baaf2c88a8844c13a00d1d588ac".into();
let current_output = "76a914c8e90996c7c6080ee06284600c684ed904d14c5c88ac".from_hex().unwrap();
let value = 91234;
let expected_script_sig = "47304402202cb265bf10707bf49346c3515dd3d16fc454618c58ec0a0ff448a676c54ff71302206c6624d762a1fcef4618284ead8f08678ac05b13c84235f1654e6ad168233e8201410414e301b2328f17442c0b8310d787bf3d8a404cfbd0704f135b6ad4b2d3ee751310f981926e53a6e8c39bd7d3fefd576c543cce493cbac06388f2651d1aacbfcd".from_hex().unwrap();
let expected_signature_hash = "5fda68729a6312e17e641e9a49fac2a4a6a680126610af573caab270d232f850".from_hex().unwrap();
// this is irrelevant
let kp = KeyPair::from_private(private).unwrap();
assert_eq!(kp.address(), from);
assert_eq!(&current_output[3..23], &to.hash);
@ -151,14 +154,7 @@ mod tests {
outputs: vec![output],
};
let input = input_signer.signed_input(&kp, 0, &previous_output, Sighash::new(SighashBase::All, false));
println!("input seq: {:?}", input.sequence);
println!("input outpoint index: {:?}", input.previous_output.index);
println!("input outpoint hash: {:?}", input.previous_output.hash.to_hex());
println!("input sig:\n{}", Script::new(input.script_sig.clone()));
println!("expec sig:\n{}", Script::new(expected_script_sig.clone()));
assert_eq!(input.script_sig, expected_script_sig);
let hash = input_signer.signature_hash(0, &previous_output, Sighash::new(SighashBase::All, false));
assert_eq!(hash.to_vec(), expected_signature_hash);
}
}