better nonstandard signing.

This commit is contained in:
Christopher Jeffrey 2016-01-19 16:12:30 -08:00
parent 1258cbbbd4
commit 5e00e42903

View File

@ -194,16 +194,16 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
if (bcoin.script.isPubkey(s)) { if (bcoin.script.isPubkey(s)) {
// P2PK // P2PK
input.script = [ [] ]; input.script = [[]];
} else if (bcoin.script.isPubkeyhash(s)) { } else if (bcoin.script.isPubkeyhash(s)) {
// P2PKH // P2PKH
input.script = [ [], pub ]; input.script = [[], pub];
} else if (bcoin.script.isMultisig(s)) { } else if (bcoin.script.isMultisig(s)) {
// Multisig // Multisig
// Technically we should create m signature slots, // Technically we should create m signature slots,
// but we create n signature slots so we can order // but we create n signature slots so we can order
// the signatures properly. // the signatures properly.
input.script = [ [] ]; input.script = [[]];
// Grab `n` value (number of keys). // Grab `n` value (number of keys).
n = s[s.length - 2]; n = s[s.length - 2];
@ -213,10 +213,17 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
input.script[i + 1] = []; input.script[i + 1] = [];
} else { } else {
// Likely a non-standard scripthash multisig // Likely a non-standard scripthash multisig
// input. Just set up the empty array. Also, // input. Determine n value by counting keys.
// only allow nonstandard types for scripthash. // Also, only allow nonstandard types for
if (redeem) // scripthash.
input.script = [ [] ]; if (redeem) {
input.script = [[]];
// Fill script with `n` signature slots.
for (i = 0; i < s.length; i++) {
if (bcoin.script.isKey(s[i]))
input.script.push([]);
}
}
} }
// P2SH requires the redeem script after signatures // P2SH requires the redeem script after signatures
@ -782,7 +789,7 @@ TX.prototype.isCoinbase = function isCoinbase() {
TX.prototype.maxSize = function maxSize() { TX.prototype.maxSize = function maxSize() {
var copy = this.clone(); var copy = this.clone();
var i, input, total, size, s, m, n; var i, j, input, total, size, s, m, n;
// Create copy with 0-script inputs // Create copy with 0-script inputs
for (i = 0; i < copy.inputs.length; i++) for (i = 0; i < copy.inputs.length; i++)
@ -856,6 +863,12 @@ TX.prototype.maxSize = function maxSize() {
size += 1; size += 1;
// OP_CHECKMULTISIG // OP_CHECKMULTISIG
size += 1; size += 1;
} else {
// OP_PUSHDATA0 [signature]
for (j = 0; j < s.length; j++) {
if (bcoin.script.isKey(s[j]))
size += 1 + 73;
}
} }
// Byte for varint size of input script // Byte for varint size of input script