wallet.outputs[0].output -> wallet.outputs[0].receive

output is overloaded. Considering we have output.spend, output.receive makes sense to me
This commit is contained in:
Wei Lu 2014-03-22 21:19:50 +08:00
parent dbb5681366
commit e574693594
2 changed files with 8 additions and 8 deletions

View file

@ -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)

View file

@ -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))