refactor account.
This commit is contained in:
parent
f382ca2a31
commit
c3ba9808b1
@ -375,7 +375,7 @@ Wallet.prototype.getAccount = function getAccount(account, callback) {
|
||||
if (account === 0 || account === 'default')
|
||||
return callback(null, this.account);
|
||||
}
|
||||
this.db.getAccount(this.id, account, callback);
|
||||
return this.db.getAccount(this.id, account, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1980,15 +1980,22 @@ Account.prototype.deriveChange = function deriveChange(index) {
|
||||
*/
|
||||
|
||||
Account.prototype.deriveAddress = function deriveAddress(change, index) {
|
||||
var i, key, options;
|
||||
var keys = [];
|
||||
var i, key, shared;
|
||||
|
||||
assert(this.initialized);
|
||||
assert(this.initialized, 'Account is not initialized.');
|
||||
|
||||
change = +change;
|
||||
|
||||
key = this.accountKey.derive(change).derive(index);
|
||||
|
||||
options = {
|
||||
for (i = 0; i < this.keys.length; i++) {
|
||||
shared = this.keys[i];
|
||||
shared = shared.derive(change).derive(index);
|
||||
keys.push(shared.publicKey);
|
||||
}
|
||||
|
||||
return new bcoin.keyring({
|
||||
network: this.network,
|
||||
key: key.publicKey,
|
||||
account: this.accountIndex,
|
||||
@ -1999,16 +2006,8 @@ Account.prototype.deriveAddress = function deriveAddress(change, index) {
|
||||
witness: this.witness,
|
||||
m: this.m,
|
||||
n: this.n,
|
||||
keys: []
|
||||
};
|
||||
|
||||
for (i = 0; i < this.keys.length; i++) {
|
||||
key = this.keys[i];
|
||||
key = key.derive(change).derive(index);
|
||||
options.keys.push(key.publicKey);
|
||||
}
|
||||
|
||||
return new bcoin.keyring(options);
|
||||
keys: keys
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2018,7 +2017,7 @@ Account.prototype.deriveAddress = function deriveAddress(change, index) {
|
||||
*/
|
||||
|
||||
Account.prototype.save = function save(callback) {
|
||||
this.db.saveAccount(this, callback);
|
||||
return this.db.saveAccount(this, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2028,7 +2027,7 @@ Account.prototype.save = function save(callback) {
|
||||
*/
|
||||
|
||||
Account.prototype.saveAddress = function saveAddress(address, callback) {
|
||||
this.db.saveAddress(this.id, address, callback);
|
||||
return this.db.saveAddress(this.id, address, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user