Address History: Combine addresses so that history is txid unique.
This commit is contained in:
parent
da1513edb2
commit
5fbd8991ed
|
@ -280,14 +280,14 @@ describe('Node Functionality', function() {
|
||||||
}
|
}
|
||||||
results.length.should.equal(1);
|
results.length.should.equal(1);
|
||||||
var info = results[0];
|
var info = results[0];
|
||||||
info.address.should.equal(address);
|
should.exist(info.addresses[address]);
|
||||||
|
info.addresses[address].outputIndexes.length.should.equal(1);
|
||||||
|
info.addresses[address].outputIndexes[0].should.be.within(0, 1);
|
||||||
|
info.addresses[address].inputIndexes.should.deep.equal([]);
|
||||||
info.satoshis.should.equal(10 * 1e8);
|
info.satoshis.should.equal(10 * 1e8);
|
||||||
info.confirmations.should.equal(3);
|
info.confirmations.should.equal(3);
|
||||||
info.timestamp.should.be.a('number');
|
info.timestamp.should.be.a('number');
|
||||||
info.fees.should.be.within(190, 193);
|
info.fees.should.be.within(190, 193);
|
||||||
info.outputIndexes.length.should.equal(1);
|
|
||||||
info.outputIndexes[0].should.be.within(0, 1);
|
|
||||||
info.inputIndexes.should.deep.equal([]);
|
|
||||||
info.tx.should.be.an.instanceof(Transaction);
|
info.tx.should.be.an.instanceof(Transaction);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -423,18 +423,17 @@ describe('Node Functionality', function() {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
history.length.should.equal(5);
|
history.length.should.equal(4);
|
||||||
history[0].height.should.equal(157);
|
history[0].height.should.equal(157);
|
||||||
history[0].confirmations.should.equal(1);
|
history[0].confirmations.should.equal(1);
|
||||||
history[1].height.should.equal(157);
|
history[1].height.should.equal(156);
|
||||||
history[2].height.should.equal(156);
|
should.exist(history[1].addresses[address4]);
|
||||||
history[2].address.should.equal(address4);
|
history[2].height.should.equal(155);
|
||||||
history[3].height.should.equal(155);
|
should.exist(history[2].addresses[address3]);
|
||||||
history[3].address.should.equal(address3);
|
history[3].height.should.equal(154);
|
||||||
history[4].height.should.equal(154);
|
should.exist(history[3].addresses[address2]);
|
||||||
history[4].address.should.equal(address2);
|
history[3].satoshis.should.equal(99990000);
|
||||||
history[4].satoshis.should.equal(99990000);
|
history[3].confirmations.should.equal(4);
|
||||||
history[4].confirmations.should.equal(4);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -455,12 +454,11 @@ describe('Node Functionality', function() {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
history.length.should.equal(3);
|
history.length.should.equal(2);
|
||||||
history[0].height.should.equal(157);
|
history[0].height.should.equal(157);
|
||||||
history[0].confirmations.should.equal(1);
|
history[0].confirmations.should.equal(1);
|
||||||
history[1].height.should.equal(157);
|
history[1].height.should.equal(156);
|
||||||
history[2].height.should.equal(156);
|
should.exist(history[1].addresses[address4]);
|
||||||
history[2].address.should.equal(address4);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -507,9 +505,8 @@ describe('Node Functionality', function() {
|
||||||
history.length.should.equal(3);
|
history.length.should.equal(3);
|
||||||
history[0].height.should.equal(157);
|
history[0].height.should.equal(157);
|
||||||
history[0].confirmations.should.equal(1);
|
history[0].confirmations.should.equal(1);
|
||||||
history[1].height.should.equal(157);
|
history[1].height.should.equal(156);
|
||||||
history[2].height.should.equal(156);
|
should.exist(history[1].addresses[address4]);
|
||||||
history[2].address.should.equal(address4);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -525,16 +522,16 @@ describe('Node Functionality', function() {
|
||||||
}
|
}
|
||||||
history.length.should.equal(6);
|
history.length.should.equal(6);
|
||||||
history[0].height.should.equal(157);
|
history[0].height.should.equal(157);
|
||||||
history[0].inputIndexes.should.deep.equal([0, 1]);
|
history[0].addresses[address].inputIndexes.should.deep.equal([0, 1]);
|
||||||
history[0].outputIndexes.should.deep.equal([2]);
|
history[0].addresses[address].outputIndexes.should.deep.equal([2]);
|
||||||
history[0].confirmations.should.equal(1);
|
history[0].confirmations.should.equal(1);
|
||||||
history[1].height.should.equal(156);
|
history[1].height.should.equal(156);
|
||||||
history[2].height.should.equal(155);
|
history[2].height.should.equal(155);
|
||||||
history[3].height.should.equal(154);
|
history[3].height.should.equal(154);
|
||||||
history[4].height.should.equal(153);
|
history[4].height.should.equal(153);
|
||||||
history[4].satoshis.should.equal(-10000);
|
history[4].satoshis.should.equal(-10000);
|
||||||
history[4].outputIndexes.should.deep.equal([0, 1, 2, 3, 4]);
|
history[4].addresses[address].outputIndexes.should.deep.equal([0, 1, 2, 3, 4]);
|
||||||
history[4].inputIndexes.should.deep.equal([0]);
|
history[4].addresses[address].inputIndexes.should.deep.equal([0]);
|
||||||
history[5].height.should.equal(150);
|
history[5].height.should.equal(150);
|
||||||
history[5].satoshis.should.equal(10 * 1e8);
|
history[5].satoshis.should.equal(10 * 1e8);
|
||||||
done();
|
done();
|
||||||
|
@ -624,8 +621,8 @@ describe('Node Functionality', function() {
|
||||||
history.length.should.equal(1);
|
history.length.should.equal(1);
|
||||||
history[0].height.should.equal(153);
|
history[0].height.should.equal(153);
|
||||||
history[0].satoshis.should.equal(-10000);
|
history[0].satoshis.should.equal(-10000);
|
||||||
history[0].outputIndexes.should.deep.equal([0, 1, 2, 3, 4]);
|
history[0].addresses[address].outputIndexes.should.deep.equal([0, 1, 2, 3, 4]);
|
||||||
history[0].inputIndexes.should.deep.equal([0]);
|
history[0].addresses[address].inputIndexes.should.deep.equal([0]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -133,25 +133,35 @@ AddressHistory.prototype.combineTransactionInfo = function() {
|
||||||
var l = this.transactionInfo.length;
|
var l = this.transactionInfo.length;
|
||||||
for(var i = 0; i < l; i++) {
|
for(var i = 0; i < l; i++) {
|
||||||
var item = this.transactionInfo[i];
|
var item = this.transactionInfo[i];
|
||||||
var mapKey = item.address + item.txid;
|
var mapKey = item.txid;
|
||||||
if (combinedArrayMap[mapKey] >= 0) {
|
if (combinedArrayMap[mapKey] >= 0) {
|
||||||
var combined = this.combinedArray[combinedArrayMap[mapKey]];
|
var combined = this.combinedArray[combinedArrayMap[mapKey]];
|
||||||
|
if (!combined.addresses[item.address]) {
|
||||||
|
combined.addresses[item.address] = {
|
||||||
|
outputIndexes: [],
|
||||||
|
inputIndexes: []
|
||||||
|
};
|
||||||
|
}
|
||||||
if (item.outputIndex >= 0) {
|
if (item.outputIndex >= 0) {
|
||||||
combined.satoshis += item.satoshis;
|
combined.satoshis += item.satoshis;
|
||||||
combined.outputIndexes.push(item.outputIndex);
|
combined.addresses[item.address].outputIndexes.push(item.outputIndex);
|
||||||
} else if (item.inputIndex >= 0) {
|
} else if (item.inputIndex >= 0) {
|
||||||
combined.inputIndexes.push(item.inputIndex);
|
combined.addresses[item.address].inputIndexes.push(item.inputIndex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.outputIndexes = [];
|
item.addresses = {};
|
||||||
item.inputIndexes = [];
|
item.addresses[item.address] = {
|
||||||
|
outputIndexes: [],
|
||||||
|
inputIndexes: []
|
||||||
|
};
|
||||||
if (item.outputIndex >= 0) {
|
if (item.outputIndex >= 0) {
|
||||||
item.outputIndexes.push(item.outputIndex);
|
item.addresses[item.address].outputIndexes.push(item.outputIndex);
|
||||||
delete item.outputIndex;
|
|
||||||
} else if (item.inputIndex >= 0) {
|
} else if (item.inputIndex >= 0) {
|
||||||
item.inputIndexes.push(item.inputIndex);
|
item.addresses[item.address].inputIndexes.push(item.inputIndex);
|
||||||
delete item.inputIndex;
|
|
||||||
}
|
}
|
||||||
|
delete item.outputIndex;
|
||||||
|
delete item.inputIndex;
|
||||||
|
delete item.address;
|
||||||
this.combinedArray.push(item);
|
this.combinedArray.push(item);
|
||||||
combinedArrayMap[mapKey] = this.combinedArray.length - 1;
|
combinedArrayMap[mapKey] = this.combinedArray.length - 1;
|
||||||
}
|
}
|
||||||
|
@ -206,15 +216,13 @@ AddressHistory.prototype.getDetailedInfo = function(txInfo, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.detailedArray.push({
|
self.detailedArray.push({
|
||||||
address: txInfo.address,
|
addresses: txInfo.addresses,
|
||||||
satoshis: self.getSatoshisDetail(transaction, txInfo),
|
satoshis: self.getSatoshisDetail(transaction, txInfo),
|
||||||
height: transaction.__height,
|
height: transaction.__height,
|
||||||
confirmations: self.getConfirmationsDetail(transaction),
|
confirmations: self.getConfirmationsDetail(transaction),
|
||||||
timestamp: transaction.__timestamp,
|
timestamp: transaction.__timestamp,
|
||||||
// TODO bitcore should return null instead of throwing error on coinbase
|
// TODO bitcore should return null instead of throwing error on coinbase
|
||||||
fees: !transaction.isCoinbase() ? transaction.getFee() : null,
|
fees: !transaction.isCoinbase() ? transaction.getFee() : null,
|
||||||
outputIndexes: txInfo.outputIndexes,
|
|
||||||
inputIndexes: txInfo.inputIndexes,
|
|
||||||
tx: transaction
|
tx: transaction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -235,11 +243,14 @@ AddressHistory.prototype.getConfirmationsDetail = function(transaction) {
|
||||||
AddressHistory.prototype.getSatoshisDetail = function(transaction, txInfo) {
|
AddressHistory.prototype.getSatoshisDetail = function(transaction, txInfo) {
|
||||||
var satoshis = txInfo.satoshis || 0;
|
var satoshis = txInfo.satoshis || 0;
|
||||||
|
|
||||||
if (txInfo.inputIndexes.length >= 0) {
|
for(var address in txInfo.addresses) {
|
||||||
for(var j = 0; j < txInfo.inputIndexes.length; j++) {
|
if (txInfo.addresses[address].inputIndexes.length >= 0) {
|
||||||
satoshis -= transaction.inputs[txInfo.inputIndexes[j]].output.satoshis;
|
for(var j = 0; j < txInfo.addresses[address].inputIndexes.length; j++) {
|
||||||
|
satoshis -= transaction.inputs[txInfo.addresses[address].inputIndexes[j]].output.satoshis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return satoshis;
|
return satoshis;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -639,26 +639,29 @@ describe('Address Service History', function() {
|
||||||
addresses: []
|
addresses: []
|
||||||
});
|
});
|
||||||
var transactionInfo = {
|
var transactionInfo = {
|
||||||
|
addresses: {},
|
||||||
txid: txid,
|
txid: txid,
|
||||||
timestamp: 1407292005,
|
timestamp: 1407292005,
|
||||||
outputIndexes: [1],
|
|
||||||
inputIndexes: [],
|
|
||||||
satoshis: 48020000,
|
satoshis: 48020000,
|
||||||
address: txAddress
|
address: txAddress
|
||||||
};
|
};
|
||||||
|
transactionInfo.addresses[txAddress] = {};
|
||||||
|
transactionInfo.addresses[txAddress].outputIndexes = [1];
|
||||||
|
transactionInfo.addresses[txAddress].inputIndexes = [];
|
||||||
history.getDetailedInfo(transactionInfo, function(err) {
|
history.getDetailedInfo(transactionInfo, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
var info = history.detailedArray[0];
|
var info = history.detailedArray[0];
|
||||||
info.address.should.equal(txAddress);
|
info.addresses[txAddress].should.deep.equal({
|
||||||
|
outputIndexes: [1],
|
||||||
|
inputIndexes: []
|
||||||
|
});
|
||||||
info.satoshis.should.equal(48020000);
|
info.satoshis.should.equal(48020000);
|
||||||
info.height.should.equal(314159);
|
info.height.should.equal(314159);
|
||||||
info.confirmations.should.equal(1);
|
info.confirmations.should.equal(1);
|
||||||
info.timestamp.should.equal(1407292005);
|
info.timestamp.should.equal(1407292005);
|
||||||
info.fees.should.equal(20000);
|
info.fees.should.equal(20000);
|
||||||
info.outputIndexes.should.deep.equal([1]);
|
|
||||||
info.inputIndexes.should.deep.equal([]);
|
|
||||||
info.tx.should.equal(transaction);
|
info.tx.should.equal(transaction);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -701,8 +704,10 @@ describe('Address Service History', function() {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
var txInfo = {
|
var txInfo = {
|
||||||
inputIndexes: [0]
|
addresses: {}
|
||||||
};
|
};
|
||||||
|
txInfo.addresses[address] = {};
|
||||||
|
txInfo.addresses[address].inputIndexes = [0];
|
||||||
history.getSatoshisDetail(transaction, txInfo).should.equal(-10000);
|
history.getSatoshisDetail(transaction, txInfo).should.equal(-10000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue