Wallet: clarify getPrivateKeyForAddress method structure
This does repeat the O(n) lookup several times, but that can be fixed by using an O(1) lookup instead (and will be later). Clarity first.
This commit is contained in:
parent
abc3e6c715
commit
7c22067f69
2 changed files with 11 additions and 6 deletions
|
@ -208,13 +208,18 @@ function Wallet(seed, network) {
|
|||
}
|
||||
|
||||
this.getPrivateKeyForAddress = function(address) {
|
||||
var index
|
||||
if((index = this.addresses.indexOf(address)) > -1) {
|
||||
assert(isMyAddress(address), 'Unknown address. Make sure the address is from the keychain and has been generated')
|
||||
|
||||
if (isReceiveAddress(address)) {
|
||||
var index = this.addresses.indexOf(address)
|
||||
|
||||
return this.getPrivateKey(index)
|
||||
} else if((index = this.changeAddresses.indexOf(address)) > -1) {
|
||||
}
|
||||
|
||||
if (isChangeAddress(address)) {
|
||||
var index = this.changeAddresses.indexOf(address)
|
||||
|
||||
return this.getInternalPrivateKey(index)
|
||||
} else {
|
||||
throw new Error('Unknown address. Make sure the address is from the keychain and has been generated.')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ describe('Wallet', function() {
|
|||
var wallet = new Wallet(seed, networks.testnet)
|
||||
assert.throws(function() {
|
||||
wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X")
|
||||
}, /Unknown address. Make sure the address is from the keychain and has been generated./)
|
||||
}, /Unknown address. Make sure the address is from the keychain and has been generated/)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue