more refacting.
This commit is contained in:
parent
e22d0c56b0
commit
a8a506aae0
@ -308,15 +308,19 @@ Block.reward = function reward(height) {
|
||||
|
||||
Block.prototype.getPrevout = function getPrevout() {
|
||||
var prevout = {};
|
||||
var i, j, tx, input;
|
||||
|
||||
for (i = 0; i < this.txs.length; i++) {
|
||||
tx = this.txs[i];
|
||||
|
||||
this.txs.forEach(function(tx) {
|
||||
if (tx.isCoinbase())
|
||||
return;
|
||||
continue;
|
||||
|
||||
tx.inputs.forEach(function(input) {
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
prevout[input.prevout.hash] = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(prevout);
|
||||
};
|
||||
|
||||
@ -93,16 +93,16 @@ Framer.prototype.getAddr = function getAddr() {
|
||||
return this.packet('getaddr', Framer.getAddr());
|
||||
};
|
||||
|
||||
Framer.prototype.submitOrder = function submitOrder() {
|
||||
return this.packet('submitorder', Framer.submitOrder());
|
||||
Framer.prototype.submitOrder = function submitOrder(order) {
|
||||
return this.packet('submitorder', Framer.submitOrder(order));
|
||||
};
|
||||
|
||||
Framer.prototype.checkOrder = function checkOrder() {
|
||||
return this.packet('checkorder', Framer.checkOrder());
|
||||
Framer.prototype.checkOrder = function checkOrder(order) {
|
||||
return this.packet('checkorder', Framer.checkOrder(order));
|
||||
};
|
||||
|
||||
Framer.prototype.reply = function reply() {
|
||||
return this.packet('reply', Framer.reply());
|
||||
Framer.prototype.reply = function reply(data) {
|
||||
return this.packet('reply', Framer.reply(data));
|
||||
};
|
||||
|
||||
Framer.prototype.sendHeaders = function sendHeaders() {
|
||||
|
||||
@ -218,18 +218,6 @@ TX.prototype.hasWitness = function hasWitness() {
|
||||
return false;
|
||||
};
|
||||
|
||||
TX.prototype._inputIndex = function _inputIndex(hash, index) {
|
||||
var i, ex;
|
||||
|
||||
for (i = 0; i < this.inputs.length; i++) {
|
||||
ex = this.inputs[i];
|
||||
if (ex.prevout.hash === hash && ex.prevout.index === index)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
TX.prototype.signatureHash = function signatureHash(index, prev, type, version) {
|
||||
assert(version >= 0 && version <= 1);
|
||||
|
||||
@ -459,35 +447,26 @@ TX.prototype.getFee = function getFee() {
|
||||
};
|
||||
|
||||
TX.prototype.getInputValue = function getInputValue() {
|
||||
var acc = new bn(0);
|
||||
|
||||
if (this.inputs.length === 0)
|
||||
return acc;
|
||||
var total = new bn(0);
|
||||
var i;
|
||||
|
||||
if (!this.hasCoins())
|
||||
return acc;
|
||||
return total;
|
||||
|
||||
return this.inputs.reduce(function(acc, input) {
|
||||
return acc.iadd(input.coin.value);
|
||||
}, acc);
|
||||
for (i = 0; i < this.inputs.length; i++)
|
||||
total.iadd(this.inputs[i].coin.value);
|
||||
|
||||
return total;
|
||||
};
|
||||
|
||||
TX.prototype.getOutputValue = function getOutputValue() {
|
||||
var acc = new bn(0);
|
||||
var total = new bn(0);
|
||||
var i;
|
||||
|
||||
if (this.outputs.length === 0)
|
||||
return acc;
|
||||
for (i = 0; i < this.outputs.length; i++)
|
||||
total.iadd(this.outputs[i].value);
|
||||
|
||||
return this.outputs.reduce(function(acc, output) {
|
||||
return acc.iadd(output.value);
|
||||
}, acc);
|
||||
};
|
||||
|
||||
TX.prototype.getFunds = function getFunds(side) {
|
||||
if (side === 'in' || side === 'input')
|
||||
return this.getInputValue();
|
||||
|
||||
return this.getOutputValue();
|
||||
return total;
|
||||
};
|
||||
|
||||
TX.prototype.getInputAddresses = function getInputAddresses() {
|
||||
@ -588,15 +567,17 @@ TX.prototype.testOutputs = function testOutputs(addressMap, index) {
|
||||
};
|
||||
|
||||
TX.prototype.hasCoins = function hasCoins() {
|
||||
var i;
|
||||
|
||||
if (this.inputs.length === 0)
|
||||
return false;
|
||||
|
||||
// if (this.isCoinbase())
|
||||
// return true;
|
||||
for (i = 0; i < this.inputs.length; i++) {
|
||||
if (!this.inputs[i].coin)
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.inputs.every(function(input) {
|
||||
return !!input.coin;
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
TX.prototype.fillCoins = function fillCoins(coins) {
|
||||
@ -1108,13 +1089,15 @@ TX.prototype.getConfirmations = function getConfirmations(height) {
|
||||
|
||||
TX.prototype.getPrevout = function getPrevout() {
|
||||
var prevout = {};
|
||||
var i, input;
|
||||
|
||||
if (this.isCoinbase())
|
||||
return [];
|
||||
|
||||
this.inputs.forEach(function(input) {
|
||||
for (i = 0; i < this.inputs.length; i++) {
|
||||
input = this.inputs[i];
|
||||
prevout[input.prevout.hash] = true;
|
||||
});
|
||||
}
|
||||
|
||||
return Object.keys(prevout);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user