improve tx.maxSize for p2sh and multisig.

This commit is contained in:
Christopher Jeffrey 2015-12-05 20:53:06 -08:00
parent 6295642f20
commit ae394fad11

View File

@ -355,7 +355,10 @@ TX.prototype.isCoinbase = function isCoinbase() {
return this.inputs.length === 1 && +this.inputs[0].out.hash === 0;
};
TX.prototype.maxSize = function maxSize() {
TX.prototype.maxSize = function maxSize(m, n) {
m = m || 1;
n = n || 1;
// Create copy with 0-script inputs
var copy = this.clone();
copy.inputs.forEach(function(input) {
@ -367,7 +370,8 @@ TX.prototype.maxSize = function maxSize() {
// Add size for signatures and public keys
copy.inputs.forEach(function(input) {
var s = input.out.tx.outputs[input.out.index].script;
if (bcoin.script.isPubkeyhash(s)) {
if (bcoin.script.isPubkeyhash(s) || bcoin.script.isSimplePubkeyhash(s)) {
// Signature + len
size += 74;
// Pub key + len
@ -375,11 +379,39 @@ TX.prototype.maxSize = function maxSize() {
return;
}
// Multisig
// Empty byte
size += 1;
// Signature + len
size += 74;
if (bcoin.script.isMultisig(s)) {
// Multisig
// Empty byte
size += 1;
// Signature + len
size += 74 * m;
return;
}
// 1 empty byte
// 1 mcode byte
// loop:
// 1 byte key length
// 65? byte key
// 1 ncode byte
// 1 checkmultisig byte
if (bcoin.script.isScripthash(s)) {
// Multisig
// Empty byte
size += 1;
// Signature + len
size += 74 * m;
// Redeem script
// m byte
size += 1;
// 1 byte length + 65 byte pubkey
size += 66 * n;
// n byte
size += 1;
// checkmultisig byte
size += 1;
return;
}
});
return size;