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