Browse Source

Wallet: move getPrivateKeyForAddress to prototype

also, move the assert to the end to simplify the logic
hk-custom-address
Wei Lu 10 years ago
parent
commit
00d58604a4
  1. 34
      src/wallet.js

34
src/wallet.js

@ -53,24 +53,6 @@ function Wallet(seed, network, unspents) {
this.getAccountZero = function() { return accountZero }
this.getExternalAccount = function() { return externalAccount }
this.getInternalAccount = function() { return internalAccount }
this.getPrivateKeyForAddress = function(address) {
var myAddresses = this.addresses.concat(this.changeAddresses)
assert(includeAddress(myAddresses, address),
'Unknown address. Make sure the address is from the keychain and has been generated')
if (includeAddress(this.addresses, address)) {
var index = this.addresses.indexOf(address)
return this.getPrivateKey(index)
}
if (includeAddress(this.changeAddresses, address)) {
var index = this.changeAddresses.indexOf(address)
return this.getInternalPrivateKey(index)
}
}
}
Wallet.prototype.createTx = function(to, value, fixedFee, changeAddress) {
@ -160,6 +142,22 @@ Wallet.prototype.getPrivateKey = function(index) {
return this.getExternalAccount().derive(index).privKey
}
Wallet.prototype.getPrivateKeyForAddress = function(address) {
if (includeAddress(this.addresses, address)) {
var index = this.addresses.indexOf(address)
return this.getPrivateKey(index)
}
if (includeAddress(this.changeAddresses, address)) {
var index = this.changeAddresses.indexOf(address)
return this.getInternalPrivateKey(index)
}
assert(false, 'Unknown address. Make sure the address is from the keychain and has been generated')
}
Wallet.prototype.getReceiveAddress = function() {
if (this.addresses.length === 0) {
this.generateAddress()

Loading…
Cancel
Save