signature hashes working correctly
This commit is contained in:
parent
4bfaa20921
commit
b9af3d58c8
|
@ -231,23 +231,4 @@ OP_ADD
|
||||||
"#;
|
"#;
|
||||||
assert_eq!(script.to_string(), s.to_string());
|
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);
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
22
src/sign.rs
22
src/sign.rs
|
@ -74,7 +74,8 @@ impl TransactionInputSigner {
|
||||||
let mut stream = Stream::default();
|
let mut stream = Stream::default();
|
||||||
stream.append(&tx);
|
stream.append(&tx);
|
||||||
stream.append(&u32::from(sighash));
|
stream.append(&u32::from(sighash));
|
||||||
dhash256(&stream.out())
|
let out = stream.out();
|
||||||
|
dhash256(&out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// input_index - index of input to sign
|
/// input_index - index of input to sign
|
||||||
|
@ -106,11 +107,11 @@ impl TransactionInputSigner {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use hex::{ToHex, FromHex};
|
use hex::FromHex;
|
||||||
use hash::h256_from_str;
|
use hash::h256_from_str;
|
||||||
use keys::{KeyPair, Private, Address};
|
use keys::{KeyPair, Private, Address};
|
||||||
use transaction::{OutPoint, TransactionOutput};
|
use transaction::{OutPoint, TransactionOutput};
|
||||||
use script::{Script, Sighash, SighashBase};
|
use script::{Sighash, SighashBase};
|
||||||
use super::{UnsignedTransactionInput, TransactionInputSigner};
|
use super::{UnsignedTransactionInput, TransactionInputSigner};
|
||||||
|
|
||||||
// http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
|
// 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 previous_output = "76a914df3bd30160e6c6145baaf2c88a8844c13a00d1d588ac".into();
|
||||||
let current_output = "76a914c8e90996c7c6080ee06284600c684ed904d14c5c88ac".from_hex().unwrap();
|
let current_output = "76a914c8e90996c7c6080ee06284600c684ed904d14c5c88ac".from_hex().unwrap();
|
||||||
let value = 91234;
|
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();
|
let kp = KeyPair::from_private(private).unwrap();
|
||||||
assert_eq!(kp.address(), from);
|
assert_eq!(kp.address(), from);
|
||||||
assert_eq!(¤t_output[3..23], &to.hash);
|
assert_eq!(¤t_output[3..23], &to.hash);
|
||||||
|
@ -151,14 +154,7 @@ mod tests {
|
||||||
outputs: vec![output],
|
outputs: vec![output],
|
||||||
};
|
};
|
||||||
|
|
||||||
let input = input_signer.signed_input(&kp, 0, &previous_output, Sighash::new(SighashBase::All, false));
|
let hash = input_signer.signature_hash(0, &previous_output, Sighash::new(SighashBase::All, false));
|
||||||
|
assert_eq!(hash.to_vec(), expected_signature_hash);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue