fill checkmultisig scripts with 0s if not enough keys are available. add format function.

This commit is contained in:
Christopher Jeffrey 2015-12-10 17:53:30 -08:00
parent c251def27c
commit 243d3fd69f

View File

@ -720,6 +720,9 @@ script.multisig = function(keys, m, n) {
assert(m >= 1 && m <= n);
assert(n >= 1 && n <= 15);
while (keys.length < n)
keys.push([]);
// Keys need to be in a predictable order.
keys = keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
@ -931,3 +934,37 @@ script.isValidSig = function(sig) {
return true;
};
script.format = function(input, output) {
var scripts = [];
if (input) {
var script = input.script;
scripts.push(script);
if (input.out.tx && input.out.tx.outputs[input.out.index]) {
var prev = input.out.tx.outputs[input.out.index].script;
scripts.push(prev);
if (script.isScripthash(prev)) {
var redeem = script.decode(input.script[input.script.length - 1]);
scripts.push(redeem);
}
}
} else if (output) {
scripts.push(output);
}
scripts = scripts.map(function(script) {
return script.map(function(chunk) {
if (Array.isArray(chunk)) {
if (chunk.length === 0)
return 0 + '';
return utils.toHex(chunk);
}
if (typeof chunk === 'number')
return chunk + '';
return chunk;
}).join(' ');
});
return scripts;
};