dust threshold. misc.
This commit is contained in:
parent
cc22e97dae
commit
5e330c513e
@ -178,6 +178,7 @@ Output.prototype.toJSON = function toJSON() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Output.prototype.getDustThreshold = function getDustThreshold(rate) {
|
Output.prototype.getDustThreshold = function getDustThreshold(rate) {
|
||||||
|
var scale = constants.WITNESS_SCALE_FACTOR;
|
||||||
var size;
|
var size;
|
||||||
|
|
||||||
if (rate == null)
|
if (rate == null)
|
||||||
@ -186,7 +187,14 @@ Output.prototype.getDustThreshold = function getDustThreshold(rate) {
|
|||||||
if (this.script.isUnspendable())
|
if (this.script.isUnspendable())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size = this.getSize() + 148;
|
size = this.getSize();
|
||||||
|
|
||||||
|
if (this.script.isProgram()) {
|
||||||
|
// 75% segwit discount applied to script size.
|
||||||
|
size += 32 + 4 + 1 + (107 / scale | 0) + 4;
|
||||||
|
} else {
|
||||||
|
size += 32 + 4 + 1 + 107 + 4;
|
||||||
|
}
|
||||||
|
|
||||||
return 3 * bcoin.tx.getMinFee(size, rate);
|
return 3 * bcoin.tx.getMinFee(size, rate);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -45,6 +45,14 @@ function Witness(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Witness.prototype.__defineGetter__('length', function() {
|
||||||
|
return this.items.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
Witness.prototype.__defineSetter__('length', function(length) {
|
||||||
|
return this.items.length = length;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject properties from options object.
|
* Inject properties from options object.
|
||||||
* @private
|
* @private
|
||||||
@ -435,14 +443,6 @@ Witness.prototype.set = function set(i, data) {
|
|||||||
this.items[i] = Witness.encodeItem(data);
|
this.items[i] = Witness.encodeItem(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Witness.prototype.__defineGetter__('length', function() {
|
|
||||||
return this.items.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
Witness.prototype.__defineSetter__('length', function(length) {
|
|
||||||
return this.items.length = length;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode a witness item.
|
* Encode a witness item.
|
||||||
* @param {Number|String|Buffer|BN} data
|
* @param {Number|String|Buffer|BN} data
|
||||||
@ -576,6 +576,14 @@ function Stack(items) {
|
|||||||
this.items = items || [];
|
this.items = items || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stack.prototype.__defineGetter__('length', function() {
|
||||||
|
return this.items.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
Stack.prototype.__defineSetter__('length', function(length) {
|
||||||
|
return this.items.length = length;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect the stack.
|
* Inspect the stack.
|
||||||
* @returns {String} Human-readable stack.
|
* @returns {String} Human-readable stack.
|
||||||
@ -604,14 +612,6 @@ Stack.prototype.toASM = function toASM(decode) {
|
|||||||
return Script.formatASM(this.items, decode);
|
return Script.formatASM(this.items, decode);
|
||||||
};
|
};
|
||||||
|
|
||||||
Stack.prototype.__defineGetter__('length', function() {
|
|
||||||
return this.items.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
Stack.prototype.__defineSetter__('length', function(length) {
|
|
||||||
return this.items.length = length;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pop the redeem script off the stack and deserialize it.
|
* Pop the redeem script off the stack and deserialize it.
|
||||||
* @returns {Script|null} The redeem script.
|
* @returns {Script|null} The redeem script.
|
||||||
@ -746,6 +746,13 @@ Stack.prototype.set = function set(i, value) {
|
|||||||
return this.items[i] = value;
|
return this.items[i] = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swap stack values.
|
||||||
|
* @private
|
||||||
|
* @param {Number} i1 - Index 1.
|
||||||
|
* @param {Number} i2 - Index 2.
|
||||||
|
*/
|
||||||
|
|
||||||
Stack.prototype._swap = function _swap(i1, i2) {
|
Stack.prototype._swap = function _swap(i1, i2) {
|
||||||
var v1, v2;
|
var v1, v2;
|
||||||
|
|
||||||
@ -795,7 +802,7 @@ Stack.prototype.ifdup = function ifdup() {
|
|||||||
throw new ScriptError('INVALID_STACK_OPERATION', opcodes.OP_IFDUP);
|
throw new ScriptError('INVALID_STACK_OPERATION', opcodes.OP_IFDUP);
|
||||||
|
|
||||||
if (Script.bool(this.top(-1)))
|
if (Script.bool(this.top(-1)))
|
||||||
this.push(Script.array(this.top(-1)));
|
this.push(this.top(-1));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1090,6 +1097,14 @@ function Script(options) {
|
|||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Script.prototype.__defineGetter__('length', function() {
|
||||||
|
return this.code.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
Script.prototype.__defineSetter__('length', function(length) {
|
||||||
|
return this.code.length = length;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject properties from options object.
|
* Inject properties from options object.
|
||||||
* @private
|
* @private
|
||||||
@ -3309,14 +3324,6 @@ Script.prototype.set = function set(i, data) {
|
|||||||
this.code[i] = Opcode.from(data);
|
this.code[i] = Opcode.from(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Script.prototype.__defineGetter__('length', function() {
|
|
||||||
return this.code.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
Script.prototype.__defineSetter__('length', function(length) {
|
|
||||||
return this.code.length = length;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the data element is a ripemd160 hash.
|
* Test whether the data element is a ripemd160 hash.
|
||||||
* @param {Buffer?} hash
|
* @param {Buffer?} hash
|
||||||
@ -3939,21 +3946,6 @@ Script.getSmall = function getSmall(op) {
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a number to a small integer (OP_0-OP_16).
|
|
||||||
* @param {Number} num
|
|
||||||
* @returns {Number} opcode
|
|
||||||
*/
|
|
||||||
|
|
||||||
Script.toSmall = function toSmall(op) {
|
|
||||||
assert(op >= 0 && op <= 16);
|
|
||||||
|
|
||||||
if (op === 0)
|
|
||||||
return opcodes.OP_0;
|
|
||||||
|
|
||||||
return op + 0x50;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify an input and output script, and a witness if present.
|
* Verify an input and output script, and a witness if present.
|
||||||
* @param {Script} input
|
* @param {Script} input
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user