refactor.
This commit is contained in:
parent
f5a0b9e284
commit
6a6cae51c6
@ -44,7 +44,7 @@ function Wallet(options) {
|
||||
options.master = bcoin.hd.fromSeed();
|
||||
|
||||
this.options = options;
|
||||
this.db = options.db;
|
||||
this.provider = options.provider || null;
|
||||
this.addresses = [];
|
||||
this.master = options.master || null;
|
||||
this.addressMap = options.addressMap || {};
|
||||
@ -460,10 +460,10 @@ Wallet.prototype.fill = function fill(tx, options, callback) {
|
||||
};
|
||||
|
||||
Wallet.prototype.fillPrevout = function fillPrevout(tx, callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.fillCoin(tx, callback);
|
||||
return this.provider.fillCoin(tx, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.sync = function sync(callback) {
|
||||
@ -760,45 +760,45 @@ Wallet.prototype.sign = function sign(tx, type, index) {
|
||||
Wallet.prototype.addTX = function addTX(tx, callback) {
|
||||
this.syncOutputDepth(tx);
|
||||
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.addTX(tx, callback);
|
||||
return this.provider.addTX(tx, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getAll = function getAll(callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.getAll(this, callback);
|
||||
return this.provider.getAll(this, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getUnspent = function getUnspent(callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.getUnspent(this, callback);
|
||||
return this.provider.getUnspent(this, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getPending = function getPending(callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.getPending(this, callback);
|
||||
return this.provider.getPending(this, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getBalance = function getBalance(callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.getBalance(this, callback);
|
||||
return this.provider.getBalance(this, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getLast = function getLast(callback) {
|
||||
if (!this.db)
|
||||
return callback(new Error('No wallet db available.'));
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.db.getLast(this, callback);
|
||||
return this.provider.getLast(this, callback);
|
||||
};
|
||||
|
||||
Wallet.prototype.getPrivateKey = function getPrivateKey(enc) {
|
||||
|
||||
@ -272,8 +272,7 @@ WalletDB.prototype.get = function get(id, passphrase, callback) {
|
||||
|
||||
try {
|
||||
wallet = bcoin.wallet.fromJSON(options, passphrase);
|
||||
wallet.store = true;
|
||||
wallet.db = self;
|
||||
wallet.provider = self;
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
@ -299,8 +298,7 @@ WalletDB.prototype.remove = function remove(id, callback) {
|
||||
callback = utils.ensure(callback);
|
||||
|
||||
if (id instanceof bcoin.wallet) {
|
||||
id.store = false;
|
||||
id.db = null;
|
||||
id.provider = null;
|
||||
id = id.id;
|
||||
}
|
||||
|
||||
@ -334,15 +332,13 @@ WalletDB.prototype.create = function create(options, callback) {
|
||||
if (json) {
|
||||
try {
|
||||
wallet = bcoin.wallet.fromJSON(json, options.passphrase);
|
||||
wallet.store = true;
|
||||
wallet.db = self;
|
||||
wallet.provider = self;
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
done();
|
||||
} else {
|
||||
options.store = true;
|
||||
options.db = self;
|
||||
options.provider = self;
|
||||
wallet = new bcoin.wallet(options);
|
||||
self.saveJSON(wallet.id, wallet.toJSON(), done);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user