minor refactoring

This commit is contained in:
Wei Lu 2014-03-22 15:43:55 +08:00
parent 01dc34d720
commit c39aa6cb07

View file

@ -64,17 +64,7 @@ var Wallet = function (seed, options) {
var utxo = [] var utxo = []
for(var key in this.outputs){ for(var key in this.outputs){
var hashAndIndex = key.split(":") utxo.push(outputToUnspentOutput(this.outputs[key]))
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 return utxo
@ -92,6 +82,19 @@ var Wallet = function (seed, options) {
this.outputs = outputs this.outputs = outputs
} }
function outputToUnspentOutput(output){
var hashAndIndex = output.output.split(":")
return {
hash: hashAndIndex[0],
hashLittleEndian: convert.reverseEndian(hashAndIndex[0]),
outputIndex: parseInt(hashAndIndex[1]),
scriptPubKey: output.scriptPubKey,
address: output.address,
value: output.value
}
}
function unspentOutputToOutput(o) { function unspentOutputToOutput(o) {
var hash = o.hash || convert.reverseEndian(o.hashLittleEndian) var hash = o.hash || convert.reverseEndian(o.hashLittleEndian)
var key = hash + ":" + o.outputIndex var key = hash + ":" + o.outputIndex