wallet: refactor.

This commit is contained in:
Christopher Jeffrey 2016-08-12 15:32:56 -07:00
parent 8ef70978d0
commit c4f16f8d72
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 18 additions and 10 deletions

View File

@ -251,7 +251,15 @@ LowlevelUp.prototype.fetch = function fetch(key, parse, callback) {
});
};
/**
* Iterate over each record.
* @param {Object} options
* @param {Function} handler
* @param {Function} callback - Returns [Error, Object].
*/
LowlevelUp.prototype.each = function each(options, handler, callback) {
var i = 0;
var opt, iter;
opt = {
@ -284,7 +292,7 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
if (key === undefined)
return iter.end(callback);
handler(key, value, next);
handler(key, value, next, i++);
});
})();
};

View File

@ -517,8 +517,8 @@ TXDB.prototype.add = function add(tx, info, callback) {
return self._addOrphan(key, outpoint, next);
self.del('c/' + key);
self.put('d/' + hash + '/' + i, input.coin.toRaw());
self.del('C/' + path.account + '/' + key);
self.put('d/' + hash + '/' + i, input.coin.toRaw());
self.coinCache.remove(key);

View File

@ -881,6 +881,7 @@ Wallet.prototype.send = function send(options, callback) {
if (err)
return callback(err);
self.logger.debug('Sending wallet tx (%s): %s', self.id, tx.rhash);
self.db.emit('send', tx);
return callback(null, tx);
@ -899,6 +900,7 @@ Wallet.prototype.send = function send(options, callback) {
Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
var self = this;
var addresses = [];
var address;
this.getInputPaths(tx, function(err, paths) {
if (err)
@ -912,7 +914,8 @@ Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
if (!account)
return next();
addresses.push(account.deriveAddress(path.change, path.index));
address = account.deriveAddress(path.change, path.index);
addresses.push(address);
return next();
});
@ -2317,8 +2320,7 @@ Account.prototype.createChange = function createChange(callback) {
Account.prototype.createAddress = function createAddress(change, callback) {
var self = this;
var addresses = [];
var address;
var address, lookahead;
if (typeof change === 'function') {
callback = change;
@ -2327,19 +2329,17 @@ Account.prototype.createAddress = function createAddress(change, callback) {
if (change) {
address = this.deriveChange(this.changeDepth);
addresses.push(address);
addresses.push(this.deriveChange(this.changeDepth + this.lookahead));
lookahead = this.deriveChange(this.changeDepth + this.lookahead);
this.changeDepth++;
this.changeAddress = address;
} else {
address = this.deriveReceive(this.receiveDepth);
addresses.push(address);
addresses.push(this.deriveReceive(this.receiveDepth + this.lookahead));
lookahead = this.deriveReceive(this.receiveDepth + this.lookahead);
this.receiveDepth++;
this.receiveAddress = address;
}
this.saveAddress(addresses, function(err) {
this.saveAddress([address, lookahead], function(err) {
if (err)
return callback(err);