add tx.getPriority and tx.isFree.

This commit is contained in:
Christopher Jeffrey 2016-01-20 12:31:42 -08:00
parent f6dc42924b
commit 704c95c90d
2 changed files with 46 additions and 5 deletions

View File

@ -179,6 +179,10 @@ Object.keys(exports.opcodes).forEach(function(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 = {
all: 1,
none: 2,
@ -203,7 +207,9 @@ exports.tx = {
maxSize: 100000,
fee: 10000,
dust: 5460,
bareMultisig: true
bareMultisig: true,
freeThreshold: exports.coin.muln(144).divn(250),
maxFreeSize: 1000
};
exports.script = {
@ -259,9 +265,5 @@ exports.zeroHash = utils.toArray(
exports.userVersion = require('../../../package.json').version;
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.banScore = 100;

View File

@ -1326,6 +1326,45 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
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() {
if (!this.chain)
return -1;