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