Browse Source

remove scriptPubKey from wallet.outputs, set/get unspent outputs as it is unused

hk-custom-address
Wei Lu 11 years ago
parent
commit
7bfa6ab9d2
  1. 5
      src/wallet.js
  2. 23
      test/wallet.js

5
src/wallet.js

@ -96,7 +96,6 @@ var Wallet = function (seed, options) {
hash: hashAndIndex[0],
hashLittleEndian: convert.reverseEndian(hashAndIndex[0]),
outputIndex: parseInt(hashAndIndex[1]),
scriptPubKey: output.scriptPubKey,
address: output.address,
value: output.value
}
@ -107,7 +106,6 @@ var Wallet = function (seed, options) {
var key = hash + ":" + o.outputIndex
return {
receive: key,
scriptPubKey: o.scriptPubKey,
address: o.address,
value: o.value
}
@ -120,7 +118,7 @@ var Wallet = function (seed, options) {
missingField = "hash(or hashLittleEndian)"
}
var requiredKeys = ['outputIndex', 'scriptPubKey', 'address', 'value']
var requiredKeys = ['outputIndex', 'address', 'value']
requiredKeys.forEach(function(key){
if(isNullOrUndefined(uo[key])){
missingField = key
@ -153,7 +151,6 @@ var Wallet = function (seed, options) {
receive: output,
value: txOut.value,
address: address,
scriptPubKey: txOut.scriptPubKey()
}
}
})

23
test/wallet.js

@ -161,7 +161,6 @@ describe('Wallet', function() {
"hash":"6a4062273ac4f9ea4ffca52d9fd102b08f6c32faa0a4d1318e3a7b2e437bb9c7",
"hashLittleEndian":"c7b97b432e7b3a8e31d1a4a0fa326c8fb002d19f2da5fc4feaf9c43a2762406a",
"outputIndex": 0,
"scriptPubKey":"76a91468edf28474ee22f68dfe7e56e76c017c1701b84f88ac",
"address" : "1AZpKpcfCzKDUeTFBQUL4MokQai3m3HMXv",
"value": 20000
}
@ -172,7 +171,6 @@ describe('Wallet', function() {
var key = utxo.hash + ":" + utxo.outputIndex
wallet.outputs[key] = {
receive: key,
scriptPubKey: utxo.scriptPubKey,
address: utxo.address,
value: utxo.value
}
@ -248,18 +246,18 @@ describe('Wallet', function() {
delete utxo[0]['hashLittleEndian']
var errorMessage = 'Invalid unspent output: key hash(or hashLittleEndian) is missing. ' +
'A valid unspent output must contain outputIndex, scriptPubKey, address, value and hash(or hashLittleEndian)'
'A valid unspent output must contain outputIndex, address, value and hash(or hashLittleEndian)'
assert.throws(function() {
wallet.setUnspentOutputs(utxo)
}, Error, errorMessage)
});
['outputIndex', 'scriptPubKey', 'address', 'value'].forEach(function(field){
['outputIndex', 'address', 'value'].forEach(function(field){
it("throws an error when " + field + " is missing", function(){
delete utxo[0][field]
var errorMessage = 'Invalid unspent output: key ' + field +
' is missing. A valid unspent output must contain outputIndex, scriptPubKey, address, value and hash(or hashLittleEndian)'
' is missing. A valid unspent output must contain outputIndex, address, value and hash(or hashLittleEndian)'
assert.throws(function() {
wallet.setUnspentOutputs(utxo)
@ -273,7 +271,6 @@ describe('Wallet', function() {
assert(output)
assert.equal(output.value, utxo[0].value)
assert.equal(output.address, utxo[0].address)
assert.equal(output.scriptPubKey, utxo[0].scriptPubKey)
}
})
})
@ -317,7 +314,6 @@ describe('Wallet', function() {
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))
}
})
@ -370,21 +366,18 @@ describe('Wallet', function() {
{
"hash": fakeTxHash(1),
"outputIndex": 0,
"scriptPubKey": scriptPubKeyFor(address1, 300000),
"address" : address1,
"value": 400000 // not enough for value
},
{
"hash": fakeTxHash(2),
"outputIndex": 1,
"scriptPubKey": scriptPubKeyFor(address1, 500000),
"address" : address1,
"value": 500000 // enough for only value
},
{
"hash": fakeTxHash(3),
"outputIndex": 0,
"scriptPubKey": scriptPubKeyFor(address2, 520000),
"address" : address2,
"value": 520000 // enough for value and fee
}
@ -414,7 +407,6 @@ describe('Wallet', function() {
{
"hash": fakeTxHash(4),
"outputIndex": 0,
"scriptPubKey": scriptPubKeyFor(address2, 520000),
"address" : address2,
"value": 530000 // enough but spent before createTx
}
@ -511,15 +503,6 @@ describe('Wallet', function() {
function fakeTxHash(i) {
return "txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtx" + i
}
function scriptPubKeyFor(address, value){
var txOut = new TransactionOut({
value: value,
script: Script.createOutputScript(address)
})
return txOut.scriptPubKey()
}
})
function assertEqual(obj1, obj2){

Loading…
Cancel
Save