Browse Source

Fix wallet.js so it does not crash with HDWallet.

hk-custom-address
Andreas Brekken 11 years ago
parent
commit
4edbaee96a
  1. 13
      src/wallet.js

13
src/wallet.js

@ -5,11 +5,10 @@ var util = require('./util');
var BigInteger = require('./jsbn/jsbn'); var BigInteger = require('./jsbn/jsbn');
var BIP32key = require('./bip32');
var Transaction = require('./transaction').Transaction; var Transaction = require('./transaction').Transaction;
var TransactionIn = require('./transaction').TransactionIn; var TransactionIn = require('./transaction').TransactionIn;
var TransactionOut = require('./transaction').TransactionOut; var TransactionOut = require('./transaction').TransactionOut;
var HDWallet = require('./hdwallet.js')
var SecureRandom = require('./jsbn/rng'); var SecureRandom = require('./jsbn/rng');
var rng = new SecureRandom(); var rng = new SecureRandom();
@ -26,7 +25,7 @@ var Wallet = function (seed) {
// Transaction output data // Transaction output data
this.outputs = {}; this.outputs = {};
// Make a new master key // Make a new master key
this.newMasterKey = function(seed) { this.newMasterKey = function(seed) {
if (!seed) { if (!seed) {
@ -34,7 +33,7 @@ var Wallet = function (seed) {
rng.nextBytes(seedBytes); rng.nextBytes(seedBytes);
seed = conv.bytesToString(seedBytes) seed = conv.bytesToString(seedBytes)
} }
masterkey = new BIP32key(seed); masterkey = new HDWallet(seed);
keys = [] keys = []
} }
this.newMasterKey(seed) this.newMasterKey(seed)
@ -45,7 +44,7 @@ var Wallet = function (seed) {
this.addresses.push(keys[keys.length-1].getBitcoinAddress().toString()) this.addresses.push(keys[keys.length-1].getBitcoinAddress().toString())
return this.addresses[this.addresses.length - 1] return this.addresses[this.addresses.length - 1]
} }
// Processes a transaction object // Processes a transaction object
// If "verified" is true, then we trust the transaction as "final" // If "verified" is true, then we trust the transaction as "final"
this.processTx = function(tx, verified) { this.processTx = function(tx, verified) {
@ -108,9 +107,9 @@ var Wallet = function (seed) {
if (totalval >= value) return utxo.slice(0,i+1); if (totalval >= value) return utxo.slice(0,i+1);
} }
throw ("Not enough money to send funds including transaction fee. Have: " throw ("Not enough money to send funds including transaction fee. Have: "
+ (totalval / 100000000) + ", needed: " + (value / 100000000)); + (totalval / 100000000) + ", needed: " + (value / 100000000));
} }
this.mkSend = function(to, value, fee) { this.mkSend = function(to, value, fee) {
var utxo = this.getUtxoToPay(value + fee) var utxo = this.getUtxoToPay(value + fee)
var sum = utxo.reduce(function(t,o) { return t + o.value },0), var sum = utxo.reduce(function(t,o) { return t + o.value },0),

Loading…
Cancel
Save