From c39aa6cb0793f704a153a3a7c71e60a38e2abaf1 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sat, 22 Mar 2014 15:43:55 +0800 Subject: [PATCH] minor refactoring --- src/wallet.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index dcc8801..8c7ab56 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -64,17 +64,7 @@ var Wallet = function (seed, options) { 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 - }) + utxo.push(outputToUnspentOutput(this.outputs[key])) } return utxo @@ -92,6 +82,19 @@ var Wallet = function (seed, options) { 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) { var hash = o.hash || convert.reverseEndian(o.hashLittleEndian) var key = hash + ":" + o.outputIndex