script: .isScripthash(s)/.isNullData(s)
This commit is contained in:
parent
e0e54aa52c
commit
b76f33047e
@ -290,3 +290,22 @@ script.isPubkeyhashInput = function isPubkeyhashInput(s) {
|
|||||||
return 9 <= s[0].length && s[0].length <= 73 &&
|
return 9 <= s[0].length && s[0].length <= 73 &&
|
||||||
33 <= s[1].length && s[1].length <= 65;
|
33 <= s[1].length && s[1].length <= 65;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
script.isScripthash = function isScripthash(s) {
|
||||||
|
if (s.length !== 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return s[0] === 'hash160' &&
|
||||||
|
Array.isArray(s[1]) &&
|
||||||
|
s[1].length === 20 &&
|
||||||
|
s[2] === 'eq';
|
||||||
|
};
|
||||||
|
|
||||||
|
script.isNullData = function isNullData(s) {
|
||||||
|
if (s.length !== 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return s[0] === 'ret' &&
|
||||||
|
Array.isArray(s[1]) &&
|
||||||
|
s[1].length <= 40;
|
||||||
|
};
|
||||||
|
|||||||
@ -30,4 +30,18 @@ describe('Script', function() {
|
|||||||
var decoded = bcoin.script.decode(encoded);
|
var decoded = bcoin.script.decode(encoded);
|
||||||
assert.deepEqual(decoded, script);
|
assert.deepEqual(decoded, script);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should recognize a P2SH output', function () {
|
||||||
|
var hex = 'a91419a7d869032368fd1f1e26e5e73a4ad0e474960e87'
|
||||||
|
var encoded = bcoin.utils.toArray(hex, 'hex')
|
||||||
|
var decoded = bcoin.script.decode(encoded);
|
||||||
|
assert(bcoin.script.isScripthash(decoded))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should recognize a Null Data output', function () {
|
||||||
|
var hex = '6a28590c080112220a1b353930632e6f7267282a5f5e294f7665726c6179404f7261636c65103b1a010c'
|
||||||
|
var encoded = bcoin.utils.toArray(hex, 'hex')
|
||||||
|
var decoded = bcoin.script.decode(encoded);
|
||||||
|
assert(bcoin.script.isNullData(decoded))
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user