Wallet: remove use of hashLittleEndian
This commit is contained in:
parent
4afdbc9f68
commit
2df790e2ab
2 changed files with 9 additions and 34 deletions
|
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in a new issue