rename colored coin check. all input script tests.
This commit is contained in:
parent
3e608c2cc6
commit
0c8168c697
@ -788,7 +788,7 @@ script.standard = function standard(s) {
|
|||||||
|| (script.isPubkeyhash(s) && 'pubkeyhash')
|
|| (script.isPubkeyhash(s) && 'pubkeyhash')
|
||||||
|| (script.isMultisig(s) && 'multisig')
|
|| (script.isMultisig(s) && 'multisig')
|
||||||
|| (script.isScripthash(s) && 'scripthash')
|
|| (script.isScripthash(s) && 'scripthash')
|
||||||
|| (script.isNullData(s) && 'colored')
|
|| (script.isColored(s) && 'colored')
|
||||||
|| 'nonstandard';
|
|| 'nonstandard';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -800,6 +800,23 @@ script.lockTime = function lockTime(s) {
|
|||||||
&& new bn(s[0]);
|
&& new bn(s[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
script.isPubkey = function isPubkey(s, hash) {
|
||||||
|
if (script.lockTime(s))
|
||||||
|
s = s.slice(3);
|
||||||
|
|
||||||
|
if (s.length !== 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var match = Array.isArray(s[0]) && s[1] === 'checksig';
|
||||||
|
if (!match)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (hash)
|
||||||
|
return utils.isEqual(s[0], hash);
|
||||||
|
else
|
||||||
|
return s[0];
|
||||||
|
};
|
||||||
|
|
||||||
script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
||||||
if (script.lockTime(s))
|
if (script.lockTime(s))
|
||||||
s = s.slice(3);
|
s = s.slice(3);
|
||||||
@ -821,23 +838,6 @@ script.isPubkeyhash = function isPubkeyhash(s, hash) {
|
|||||||
return s[2];
|
return s[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
script.isPubkey = function isPubkey(s, hash) {
|
|
||||||
if (script.lockTime(s))
|
|
||||||
s = s.slice(3);
|
|
||||||
|
|
||||||
if (s.length !== 2)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var match = Array.isArray(s[0]) && s[1] === 'checksig';
|
|
||||||
if (!match)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (hash)
|
|
||||||
return utils.isEqual(s[0], hash);
|
|
||||||
else
|
|
||||||
return s[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
script.isMultisig = function isMultisig(s, key) {
|
script.isMultisig = function isMultisig(s, key) {
|
||||||
if (script.lockTime(s))
|
if (script.lockTime(s))
|
||||||
s = s.slice(3);
|
s = s.slice(3);
|
||||||
@ -880,14 +880,6 @@ script.isMultisig = function isMultisig(s, key) {
|
|||||||
}).length;
|
}).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.isPubkeyhashInput = function isPubkeyhashInput(s) {
|
|
||||||
if (s.length !== 2)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return 9 <= s[0].length && s[0].length <= 73 &&
|
|
||||||
33 <= s[1].length && s[1].length <= 65;
|
|
||||||
};
|
|
||||||
|
|
||||||
script.isScripthash = function isScripthash(s, hash) {
|
script.isScripthash = function isScripthash(s, hash) {
|
||||||
if (script.lockTime(s))
|
if (script.lockTime(s))
|
||||||
s = s.slice(3);
|
s = s.slice(3);
|
||||||
@ -909,7 +901,7 @@ script.isScripthash = function isScripthash(s, hash) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
script.isNullData = function isNullData(s) {
|
script.isColored = function isColored(s) {
|
||||||
if (s.length !== 2)
|
if (s.length !== 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -918,6 +910,64 @@ script.isNullData = function isNullData(s) {
|
|||||||
s[1].length <= 40;
|
s[1].length <= 40;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
script.colored = function colored(s) {
|
||||||
|
if (!script.isColored(s))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return s[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
script.isPubkeyInput = function isPubkeyInput(s) {
|
||||||
|
if (s.length !== 1 || !Array.isArray(s[0]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return 9 <= s[0].length && s[0].length <= 73;
|
||||||
|
};
|
||||||
|
|
||||||
|
script.isPubkeyhashInput = function isPubkeyhashInput(s) {
|
||||||
|
if (s.length !== 2 || !Array.isArray(s[0]) || !Array.isArray(s[1]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return 9 <= s[0].length && s[0].length <= 73 &&
|
||||||
|
33 <= s[1].length && s[1].length <= 65;
|
||||||
|
};
|
||||||
|
|
||||||
|
script.isMultisigInput = function isMultisigInput(s) {
|
||||||
|
if (s.length < 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Array.isArray(s[0]) || s[0].length !== 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (var i = 1; i < s.length; i++) {
|
||||||
|
var ret = 9 <= s[i].length && s[i].length <= 73;
|
||||||
|
if (!ret)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
script.isScripthashInput = function isScripthashInput(s) {
|
||||||
|
if (s.length < 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!Array.isArray(s[0]) || s[0].length !== 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (var i = 1; i < s.length - 1; i++) {
|
||||||
|
var ret = Array.isArray(s[i]) && 9 <= s[i].length && s[i].length <= 73;
|
||||||
|
if (!ret)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var r = Array.isArray(s[s.length - 1]) && s[s.length - 1];
|
||||||
|
if (r[r.length - 1] !== constants.opcodes.checkmultisig)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
|
||||||
/**
|
/**
|
||||||
* A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
|
* A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
|
||||||
|
|||||||
@ -42,7 +42,7 @@ describe('Script', function() {
|
|||||||
var hex = '6a28590c080112220a1b353930632e6f7267282a5f5e294f7665726c6179404f7261636c65103b1a010c'
|
var hex = '6a28590c080112220a1b353930632e6f7267282a5f5e294f7665726c6179404f7261636c65103b1a010c'
|
||||||
var encoded = bcoin.utils.toArray(hex, 'hex')
|
var encoded = bcoin.utils.toArray(hex, 'hex')
|
||||||
var decoded = bcoin.script.decode(encoded);
|
var decoded = bcoin.script.decode(encoded);
|
||||||
assert(bcoin.script.isNullData(decoded))
|
assert(bcoin.script.isColored(decoded))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle if statements correctly', function () {
|
it('should handle if statements correctly', function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user