wallet: refactor.
This commit is contained in:
parent
8ef70978d0
commit
c4f16f8d72
@ -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) {
|
LowlevelUp.prototype.each = function each(options, handler, callback) {
|
||||||
|
var i = 0;
|
||||||
var opt, iter;
|
var opt, iter;
|
||||||
|
|
||||||
opt = {
|
opt = {
|
||||||
@ -284,7 +292,7 @@ LowlevelUp.prototype.each = function each(options, handler, callback) {
|
|||||||
if (key === undefined)
|
if (key === undefined)
|
||||||
return iter.end(callback);
|
return iter.end(callback);
|
||||||
|
|
||||||
handler(key, value, next);
|
handler(key, value, next, i++);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -517,8 +517,8 @@ TXDB.prototype.add = function add(tx, info, callback) {
|
|||||||
return self._addOrphan(key, outpoint, next);
|
return self._addOrphan(key, outpoint, next);
|
||||||
|
|
||||||
self.del('c/' + key);
|
self.del('c/' + key);
|
||||||
self.put('d/' + hash + '/' + i, input.coin.toRaw());
|
|
||||||
self.del('C/' + path.account + '/' + key);
|
self.del('C/' + path.account + '/' + key);
|
||||||
|
self.put('d/' + hash + '/' + i, input.coin.toRaw());
|
||||||
|
|
||||||
self.coinCache.remove(key);
|
self.coinCache.remove(key);
|
||||||
|
|
||||||
|
|||||||
@ -881,6 +881,7 @@ Wallet.prototype.send = function send(options, callback) {
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
self.logger.debug('Sending wallet tx (%s): %s', self.id, tx.rhash);
|
||||||
self.db.emit('send', tx);
|
self.db.emit('send', tx);
|
||||||
|
|
||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
@ -899,6 +900,7 @@ Wallet.prototype.send = function send(options, callback) {
|
|||||||
Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
|
Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var addresses = [];
|
var addresses = [];
|
||||||
|
var address;
|
||||||
|
|
||||||
this.getInputPaths(tx, function(err, paths) {
|
this.getInputPaths(tx, function(err, paths) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -912,7 +914,8 @@ Wallet.prototype.deriveInputs = function deriveInputs(tx, callback) {
|
|||||||
if (!account)
|
if (!account)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
addresses.push(account.deriveAddress(path.change, path.index));
|
address = account.deriveAddress(path.change, path.index);
|
||||||
|
addresses.push(address);
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
@ -2317,8 +2320,7 @@ Account.prototype.createChange = function createChange(callback) {
|
|||||||
|
|
||||||
Account.prototype.createAddress = function createAddress(change, callback) {
|
Account.prototype.createAddress = function createAddress(change, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var addresses = [];
|
var address, lookahead;
|
||||||
var address;
|
|
||||||
|
|
||||||
if (typeof change === 'function') {
|
if (typeof change === 'function') {
|
||||||
callback = change;
|
callback = change;
|
||||||
@ -2327,19 +2329,17 @@ Account.prototype.createAddress = function createAddress(change, callback) {
|
|||||||
|
|
||||||
if (change) {
|
if (change) {
|
||||||
address = this.deriveChange(this.changeDepth);
|
address = this.deriveChange(this.changeDepth);
|
||||||
addresses.push(address);
|
lookahead = this.deriveChange(this.changeDepth + this.lookahead);
|
||||||
addresses.push(this.deriveChange(this.changeDepth + this.lookahead));
|
|
||||||
this.changeDepth++;
|
this.changeDepth++;
|
||||||
this.changeAddress = address;
|
this.changeAddress = address;
|
||||||
} else {
|
} else {
|
||||||
address = this.deriveReceive(this.receiveDepth);
|
address = this.deriveReceive(this.receiveDepth);
|
||||||
addresses.push(address);
|
lookahead = this.deriveReceive(this.receiveDepth + this.lookahead);
|
||||||
addresses.push(this.deriveReceive(this.receiveDepth + this.lookahead));
|
|
||||||
this.receiveDepth++;
|
this.receiveDepth++;
|
||||||
this.receiveAddress = address;
|
this.receiveAddress = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveAddress(addresses, function(err) {
|
this.saveAddress([address, lookahead], function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user