add tx.getPriority and tx.isFree.
This commit is contained in:
parent
f6dc42924b
commit
704c95c90d
@ -179,6 +179,10 @@ Object.keys(exports.opcodes).forEach(function(name) {
|
|||||||
exports.opcodesByVal[val] = name;
|
exports.opcodesByVal[val] = name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exports.coin = new bn(10000000).muln(10);
|
||||||
|
exports.cent = new bn(1000000);
|
||||||
|
exports.maxMoney = new bn(21000000).mul(exports.coin);
|
||||||
|
|
||||||
exports.hashType = {
|
exports.hashType = {
|
||||||
all: 1,
|
all: 1,
|
||||||
none: 2,
|
none: 2,
|
||||||
@ -203,7 +207,9 @@ exports.tx = {
|
|||||||
maxSize: 100000,
|
maxSize: 100000,
|
||||||
fee: 10000,
|
fee: 10000,
|
||||||
dust: 5460,
|
dust: 5460,
|
||||||
bareMultisig: true
|
bareMultisig: true,
|
||||||
|
freeThreshold: exports.coin.muln(144).divn(250),
|
||||||
|
maxFreeSize: 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.script = {
|
exports.script = {
|
||||||
@ -259,9 +265,5 @@ exports.zeroHash = utils.toArray(
|
|||||||
exports.userVersion = require('../../../package.json').version;
|
exports.userVersion = require('../../../package.json').version;
|
||||||
exports.userAgent = '/bcoin:' + exports.userVersion + '/';
|
exports.userAgent = '/bcoin:' + exports.userVersion + '/';
|
||||||
|
|
||||||
exports.coin = new bn(10000000).muln(10);
|
|
||||||
exports.cent = new bn(1000000);
|
|
||||||
exports.maxMoney = new bn(21000000).mul(exports.coin);
|
|
||||||
|
|
||||||
exports.banTime = 24 * 60 * 60;
|
exports.banTime = 24 * 60 * 60;
|
||||||
exports.banScore = 100;
|
exports.banScore = 100;
|
||||||
|
|||||||
@ -1326,6 +1326,45 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TX.prototype.getPriority = function getPriority() {
|
||||||
|
var size, value, i, input, output, age;
|
||||||
|
|
||||||
|
size = this.maxSize();
|
||||||
|
value = new bn(0);
|
||||||
|
|
||||||
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
|
input = this.inputs[i];
|
||||||
|
|
||||||
|
if (!input.out.tx)
|
||||||
|
return constants.tx.freeThreshold.clone();
|
||||||
|
|
||||||
|
output = input.out.tx.outputs[input.out.index];
|
||||||
|
age = input.out.tx.getConfirmations();
|
||||||
|
|
||||||
|
if (age === -1)
|
||||||
|
age = 0;
|
||||||
|
|
||||||
|
if (age !== 0)
|
||||||
|
age += 1;
|
||||||
|
|
||||||
|
value.iadd(output.value.muln(age));
|
||||||
|
}
|
||||||
|
|
||||||
|
return priority.divn(size);
|
||||||
|
};
|
||||||
|
|
||||||
|
TX.prototype.isFree = function isFree() {
|
||||||
|
var size = this.maxSize();
|
||||||
|
var priority;
|
||||||
|
|
||||||
|
if (size >= constants.tx.maxFreeSize)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
priority = this.getPriority();
|
||||||
|
|
||||||
|
return priority.cmp(constants.tx.freeThreshold) > 0;
|
||||||
|
};
|
||||||
|
|
||||||
TX.prototype.getHeight = function getHeight() {
|
TX.prototype.getHeight = function getHeight() {
|
||||||
if (!this.chain)
|
if (!this.chain)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user