script: .isScripthash(s)/.isNullData(s)

This commit is contained in:
Stanislas Marion 2014-12-18 14:16:39 +01:00 committed by Fedor Indutny
parent e0e54aa52c
commit b76f33047e
2 changed files with 33 additions and 0 deletions

View File

@ -290,3 +290,22 @@ script.isPubkeyhashInput = function isPubkeyhashInput(s) {
return 9 <= s[0].length && s[0].length <= 73 &&
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;
};

View File

@ -30,4 +30,18 @@ describe('Script', function() {
var decoded = bcoin.script.decode(encoded);
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))
})
});