make scripthash input test less insane.
This commit is contained in:
parent
4b672d6337
commit
e68bab4ab3
@ -1978,8 +1978,8 @@ script.isMultisigInput = function isMultisigInput(s, keys, tx, i) {
|
||||
return true;
|
||||
};
|
||||
|
||||
script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
var raw, redeem;
|
||||
script.isScripthashInput = function isScripthashInput(s, redeem) {
|
||||
var raw;
|
||||
|
||||
// Grab the raw redeem script.
|
||||
raw = s[s.length - 1];
|
||||
@ -1994,9 +1994,20 @@ script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
if (!Array.isArray(raw))
|
||||
return false;
|
||||
|
||||
// If the last data element is a valid
|
||||
// signature or key, it's _extremely_
|
||||
// unlikely this is a scripthash.
|
||||
// Check data against last array in case
|
||||
// a raw redeem script was passed in.
|
||||
if (redeem)
|
||||
return utils.isEqual(redeem, raw);
|
||||
|
||||
// Testing for scripthash inputs requires
|
||||
// some evil magic to work. We do it by
|
||||
// ruling things _out_. This test will not
|
||||
// be correct 100% of the time. We rule
|
||||
// out that the last data element is: a
|
||||
// null dummy, a valid signature, a valid
|
||||
// key, and we ensure that it is at least
|
||||
// a script that does not use undefined
|
||||
// opcodes.
|
||||
if (script.isDummy(raw))
|
||||
return false;
|
||||
|
||||
@ -2006,40 +2017,8 @@ script.isScripthashInput = function isScripthashInput(s, data, strict) {
|
||||
if (script.isKeyEncoding(raw))
|
||||
return false;
|
||||
|
||||
// Ensure this is a valid encoded script
|
||||
// if (!script.isEncoded(raw))
|
||||
// return false;
|
||||
|
||||
// Check data against last array in case
|
||||
// a raw redeem script was passed in.
|
||||
if (data && utils.isEqual(data, raw))
|
||||
return true;
|
||||
|
||||
// Return here if we do not want to check
|
||||
// against standard transaction types.
|
||||
if (!strict)
|
||||
return true;
|
||||
|
||||
// P2SH redeem scripts can be nonstandard: make
|
||||
// it easier for other functions to parse this.
|
||||
redeem = script.decode(raw);
|
||||
|
||||
// Get the "real" scriptSig
|
||||
s = s.slice(0, -1);
|
||||
|
||||
// Do some sanity checking on the inputs
|
||||
if (!script.isPubkeyInput(s)
|
||||
&& !script.isPubkeyhashInput(s)
|
||||
&& !script.isMultisigInput(s)) {
|
||||
if (!script.isEncoded(raw))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test against all other script types
|
||||
if (!script.isPubkey(redeem, data)
|
||||
&& !script.isPubkeyhash(redeem, data)
|
||||
&& !script.isMultisig(redeem, data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user