wallet exposes unspent outputs via a getter

also add reverseEndian method to convert
This commit is contained in:
Wei Lu 2014-03-22 14:37:09 +08:00
parent 68e8834c66
commit 16dc68cbaa
4 changed files with 67 additions and 8 deletions

View file

@ -158,6 +158,10 @@ function wordArrayToBytes(wordArray) {
return wordsToBytes(wordArray.words)
}
function reverseEndian (hex) {
return bytesToHex(hexToBytes(hex).reverse())
}
module.exports = {
lpad: lpad,
bytesToHex: bytesToHex,
@ -175,5 +179,6 @@ module.exports = {
bytesToWords: bytesToWords,
wordsToBytes: wordsToBytes,
bytesToWordArray: bytesToWordArray,
wordArrayToBytes: wordArrayToBytes
wordArrayToBytes: wordArrayToBytes,
reverseEndian: reverseEndian
}

View file

@ -60,6 +60,26 @@ var Wallet = function (seed, options) {
return this.changeAddresses[this.changeAddresses.length - 1]
}
this.getUnspentOutputs = function() {
var utxo = []
for(var key in this.outputs){
var hashAndIndex = key.split(":")
var output = this.outputs[key]
utxo.push({
hash: hashAndIndex[0],
hashLittleEndian: convert.reverseEndian(hashAndIndex[0]),
outputIndex: parseInt(hashAndIndex[1]),
scriptPubKey: output.scriptPubKey,
address: output.address,
value: output.value
})
}
return utxo
}
// Processes a transaction object
// If "verified" is true, then we trust the transaction as "final"
this.processTx = function(tx, verified) {