From 2df790e2ab9a13a46a84c6c9701803d6c92375bb Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 21 May 2014 13:18:33 +1000 Subject: [PATCH] Wallet: remove use of hashLittleEndian --- src/wallet.js | 15 +++++++-------- test/wallet.js | 28 ++-------------------------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index b7fe55e..206bf44 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -1,5 +1,4 @@ var Address = require('./address') -var convert = require('./convert') var HDNode = require('./hdwallet.js') var networks = require('./networks') var rng = require('secure-random') @@ -92,7 +91,6 @@ function Wallet(seed, options) { return { hash: hashAndIndex[0], - hashLittleEndian: convert.reverseEndian(hashAndIndex[0]), outputIndex: parseInt(hashAndIndex[1]), address: output.address, value: output.value @@ -100,7 +98,7 @@ function Wallet(seed, options) { } function unspentOutputToOutput(o) { - var hash = o.hash || convert.reverseEndian(o.hashLittleEndian) + var hash = o.hash var key = hash + ":" + o.outputIndex return { receive: key, @@ -112,8 +110,8 @@ function Wallet(seed, options) { function validateUnspentOutput(uo) { var missingField - if (isNullOrUndefined(uo.hash) && isNullOrUndefined(uo.hashLittleEndian)) { - missingField = "hash(or hashLittleEndian)" + if (isNullOrUndefined(uo.hash)) { + missingField = "hash" } var requiredKeys = ['outputIndex', 'address', 'value'] @@ -129,7 +127,7 @@ function Wallet(seed, options) { 'A valid unspent output must contain' ] message.push(requiredKeys.join(', ')) - message.push("and hash(or hashLittleEndian)") + message.push("and hash") throw new Error(message.join(' ')) } } @@ -163,9 +161,10 @@ function Wallet(seed, options) { tx.ins.forEach(function(txIn, i){ var op = txIn.outpoint - var o = me.outputs[op.hash+':'+op.index] + + var o = me.outputs[op.hash + ':' + op.index] if (o) { - o.spend = txhash + ':' +i + o.spend = txhash + ':' + i } }) } diff --git a/test/wallet.js b/test/wallet.js index 64ddb8f..b5187d1 100644 --- a/test/wallet.js +++ b/test/wallet.js @@ -168,7 +168,6 @@ describe('Wallet', function() { beforeEach(function(){ expectedUtxo = { "hash":"6a4062273ac4f9ea4ffca52d9fd102b08f6c32faa0a4d1318e3a7b2e437bb9c7", - "hashLittleEndian":"c7b97b432e7b3a8e31d1a4a0fa326c8fb002d19f2da5fc4feaf9c43a2762406a", "outputIndex": 0, "address" : "1AZpKpcfCzKDUeTFBQUL4MokQai3m3HMXv", "value": 20000 @@ -230,36 +229,13 @@ describe('Wallet', function() { utxo = cloneObject([expectedUtxo]) }) - it('uses hashLittleEndian when hash is not present', function(){ - delete utxo[0]['hash'] - - wallet.setUnspentOutputs(utxo) - verifyOutputs() - }) - - it('uses hash when hashLittleEndian is not present', function(){ - delete utxo[0]['hashLittleEndian'] - - wallet.setUnspentOutputs(utxo) - verifyOutputs() - }) - - it('uses hash when both hash and hashLittleEndian are present', function(){ + it('matches the expected behaviour', function(){ wallet.setUnspentOutputs(utxo) verifyOutputs() }) describe('required fields', function(){ - it("throws an error when hash and hashLittleEndian are both missing", function(){ - delete utxo[0]['hash'] - delete utxo[0]['hashLittleEndian'] - - assert.throws(function() { - wallet.setUnspentOutputs(utxo) - }, /Invalid unspent output: key hash\(or hashLittleEndian\) is missing/) - }); - - ['outputIndex', 'address', 'value'].forEach(function(field){ + ['outputIndex', 'address', 'hash', 'value'].forEach(function(field){ it("throws an error when " + field + " is missing", function(){ delete utxo[0][field]