From e574693594e78204506dd7ca4c88d633cf0405d5 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sat, 22 Mar 2014 21:19:50 +0800 Subject: [PATCH] wallet.outputs[0].output -> wallet.outputs[0].receive output is overloaded. Considering we have output.spend, output.receive makes sense to me --- src/wallet.js | 12 ++++++------ test/wallet.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index ec19147..484700f 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -76,14 +76,14 @@ var Wallet = function (seed, options) { utxo.forEach(function(uo){ validateUnspentOutput(uo) var o = unspentOutputToOutput(uo) - outputs[o.output] = o + outputs[o.receive] = o }) this.outputs = outputs } function outputToUnspentOutput(output){ - var hashAndIndex = output.output.split(":") + var hashAndIndex = output.receive.split(":") return { hash: hashAndIndex[0], @@ -99,7 +99,7 @@ var Wallet = function (seed, options) { var hash = o.hash || convert.reverseEndian(o.hashLittleEndian) var key = hash + ":" + o.outputIndex return { - output: key, + receive: key, scriptPubKey: o.scriptPubKey, address: o.address, value: o.value @@ -143,7 +143,7 @@ var Wallet = function (seed, options) { if (isMyAddress(address)) { var output = txhash+':'+i me.outputs[output] = { - output: output, + receive: output, value: txOut.value, address: address, scriptPubKey: convert.bytesToHex(txOut.script.buffer) //TODO: txOut.scriptPubKey() @@ -226,7 +226,7 @@ var Wallet = function (seed, options) { : [toOut, halfChangeOut, halfChangeOut] var tx = new Bitcoin.Transaction({ - ins: utxo.map(function(x) { return x.output }), + ins: utxo.map(function(x) { return x.receive }), outs: outs }) this.sign(tx) @@ -239,7 +239,7 @@ var Wallet = function (seed, options) { sum = utxo.reduce(function(t,p) { return t + o.value },0); utxo[changeIndex].value += sum - value - fee; var tx = new Bitcoin.Transaction({ - ins: utxo.map(function(x) { return x.output }), + ins: utxo.map(function(x) { return x.receive }), outs: outputs }) this.sign(tx) diff --git a/test/wallet.js b/test/wallet.js index a7161e2..6bd7a7a 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -168,7 +168,7 @@ describe('Wallet', function() { describe('getUnspentOutputs', function(){ it('parses wallet outputs to the expect format', function(){ wallet.outputs[expectedOutputKey] = { - output: expectedOutputKey, + receive: expectedOutputKey, scriptPubKey: expectedUtxo[0].scriptPubKey, address: expectedUtxo[0].address, value: expectedUtxo[0].value @@ -275,7 +275,7 @@ describe('Wallet', function() { var txOut = tx.outs[index] var key = convert.bytesToHex(tx.getHash()) + ":" + index var output = wallet.outputs[key] - assert.equal(output.output, key) + assert.equal(output.receive, key) assert.equal(output.value, txOut.value) assert.equal(output.address, txOut.address) assert.equal(output.scriptPubKey, convert.bytesToHex(txOut.script.buffer))