Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache history and just resume where we left when restarting.
- Loading branch information
Showing
7 changed files
with
386 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
'use strict'; | ||
|
||
define(['bitcoinjs-lib', 'util/btc'], function(Bitcoin, BtcUtils) { | ||
|
||
function HistoryRow(hash, identity, txObj) { | ||
this.identity = identity; | ||
this._tx = txObj; | ||
this.hash = hash; | ||
this.outAddresses = identity.txdb.getOutAddresses(hash).map(function(address) { | ||
return identity.wallet.getWalletAddress(address);}).filter(function(address){return address !== undefined; | ||
}); | ||
this.isStealth = this.outAddresses.some(function(walletAddress) { return walletAddress && walletAddress.type === 'stealth';}); | ||
} | ||
|
||
HistoryRow.prototype.getTransferLabel = function() { | ||
var identity = this.identity; | ||
var pocketImpact = this.impact; | ||
var keys = Object.keys(pocketImpact); | ||
|
||
// Input pockets | ||
var inKeys = keys.filter(function(key) { return pocketImpact[key].ins!==0; } ); | ||
inKeys = inKeys.map(function(key) { return identity.wallet.pockets.getPocket(key, pocketImpact[key].type).name; }); | ||
|
||
// Output pockets (minus change pockets) | ||
var outKeys = keys.filter(function(key) { return pocketImpact[key].outs!==0 && pocketImpact[key].ins===0; } ); | ||
outKeys = outKeys.map(function(key) { return identity.wallet.pockets.getPocket(key, pocketImpact[key].type).name; }); | ||
|
||
// Compose the final label | ||
var label = inKeys.join(' ,'); | ||
if (outKeys.length) { | ||
return label + " to " + outKeys.join(' ,'); | ||
} else { | ||
return 'internal on ' + label; | ||
} | ||
}; | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'tx', { | ||
get: function() { | ||
if (!this._tx) { | ||
var txBody = this.identity.txdb.getBody(this.hash); | ||
this._tx = Bitcoin.Transaction.fromHex(txBody); | ||
} | ||
return this._tx; | ||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'inMine', { | ||
get: function() { return this.myInValue>0; } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'address', { | ||
// TODO: Probably don't want this here any more! | ||
get: function() { | ||
var addressLabel = this.identity.txdb.getAddress(this.hash); | ||
if (addressLabel) { | ||
return addressLabel; | ||
} else { | ||
return this.getTransferLabel(); | ||
} | ||
}, | ||
set: function(val) { this.identity.txdb.setAddress(this.hash, val); } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'total', { | ||
get: function() { return this.myOutValue-this.myInValue; } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'outPocket', { | ||
get: function() { | ||
var impactkeys = Object.keys(this.impact); | ||
for(var i=0; i<impactkeys.length; i++) { | ||
if (this.impact[impactkeys[i]].outs && this.impact[impactkeys[i]].outs > this.impact[impactkeys[i]].ins) { | ||
return impactkeys[i]; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'inPocket', { | ||
get: function() { | ||
var impactkeys = Object.keys(this.impact); | ||
for(var i=0; i<impactkeys.length; i++) { | ||
// TODO: should think about change in this comparison | ||
if (this.impact[impactkeys[i]].ins && this.impact[impactkeys[i]].ins > this.impact[impactkeys[i]].outs) { | ||
return impactkeys[i]; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'label', { | ||
get: function() { return this.identity.txdb.getLabel(this.hash); } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'impact', { | ||
get: function() { return this.identity.txdb.getImpact(this.hash); } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'internal', { | ||
get: function() { return (this.myInValue === this.myOutValue); } | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'bareid', { | ||
get: function() { | ||
if (!this._bareid) { | ||
this._bareid = BtcUtils.getBareTxId(this.tx); | ||
} | ||
return this._bareid; | ||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'myInValue', { | ||
get: function() { | ||
var res = 0; | ||
var impactkeys = Object.keys(this.impact); | ||
for(var i=0; i<impactkeys.length; i++) { | ||
res += this.impact[impactkeys[i]].ins; | ||
} | ||
return res; | ||
|
||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'myOutValue', { | ||
get: function() { | ||
var res = 0; | ||
var impactkeys = Object.keys(this.impact); | ||
for(var i=0; i<impactkeys.length; i++) { | ||
res += this.impact[impactkeys[i]].outs; | ||
} | ||
return res; | ||
|
||
} | ||
}); | ||
|
||
Object.defineProperty(HistoryRow.prototype, 'height', { | ||
// TODO: getHeight not implemented yet... | ||
get: function() { return this.identity.txdb.getHeight(this.hash); }, | ||
set: function(val) { return this.identity.txdb.setHeight(this.hash, val); } | ||
}); | ||
|
||
return HistoryRow; | ||
}); |
Oops, something went wrong.