more renaming.
This commit is contained in:
parent
d48d9d44ee
commit
06d6d74081
@ -233,8 +233,8 @@ Pool.prototype._init = function _init() {
|
|||||||
self.loadOrphan(self.peers.load, null, data.hash);
|
self.loadOrphan(self.peers.load, null, data.hash);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.options.wallets.forEach(function(w) {
|
this.options.wallets.forEach(function(wallet) {
|
||||||
self.addWallet(w);
|
self.addWallet(wallet);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Chain is full and up-to-date
|
// Chain is full and up-to-date
|
||||||
@ -1186,18 +1186,18 @@ Pool.prototype.isWatched = function(tx, bloom) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.addWallet = function addWallet(w) {
|
Pool.prototype.addWallet = function addWallet(wallet) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var e;
|
var e;
|
||||||
|
|
||||||
if (this.loading)
|
if (this.loading)
|
||||||
return this.once('load', this.addWallet.bind(this, w));
|
return this.once('load', this.addWallet.bind(this, wallet));
|
||||||
|
|
||||||
if (this.wallets.indexOf(w) !== -1)
|
if (this.wallets.indexOf(wallet) !== -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.watchWallet(w);
|
this.watchWallet(wallet);
|
||||||
this.wallets.push(w);
|
this.wallets.push(wallet);
|
||||||
|
|
||||||
e = new EventEmitter();
|
e = new EventEmitter();
|
||||||
|
|
||||||
@ -1205,7 +1205,7 @@ Pool.prototype.addWallet = function addWallet(w) {
|
|||||||
// Relay pending TXs
|
// Relay pending TXs
|
||||||
// NOTE: It is important to do it after search, because search could
|
// NOTE: It is important to do it after search, because search could
|
||||||
// add TS to pending TXs, thus making them confirmed
|
// add TS to pending TXs, thus making them confirmed
|
||||||
w.pending().forEach(function(tx) {
|
wallet.pending().forEach(function(tx) {
|
||||||
self.sendTX(tx);
|
self.sendTX(tx);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1223,21 +1223,21 @@ Pool.prototype.addWallet = function addWallet(w) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w.loading)
|
if (wallet.loading)
|
||||||
w.once('load', search);
|
wallet.once('load', search);
|
||||||
else
|
else
|
||||||
search();
|
search();
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.removeWallet = function removeWallet(w) {
|
Pool.prototype.removeWallet = function removeWallet(wallet) {
|
||||||
var i = this.wallets.indexOf(w);
|
var i = this.wallets.indexOf(wallet);
|
||||||
assert(!this.loading);
|
assert(!this.loading);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
return;
|
return;
|
||||||
this.wallets.splice(i, 1);
|
this.wallets.splice(i, 1);
|
||||||
this.unwatchWallet(w);
|
this.unwatchWallet(wallet);
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.watchAddress = function watchAddress(address) {
|
Pool.prototype.watchAddress = function watchAddress(address) {
|
||||||
@ -1268,66 +1268,64 @@ Pool.prototype.unwatchAddress = function unwatchAddress(address) {
|
|||||||
this.unwatch(address.getPublicKey());
|
this.unwatch(address.getPublicKey());
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.watchWallet = function watchWallet(w) {
|
Pool.prototype.watchWallet = function watchWallet(wallet) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
w.addresses.forEach(function(address) {
|
wallet.addresses.forEach(function(address) {
|
||||||
this.watchAddress(address);
|
this.watchAddress(address);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
w.on('add address', w._poolOnAdd = function(address) {
|
wallet.on('add address', wallet._poolOnAdd = function(address) {
|
||||||
self.watchAddress(address);
|
self.watchAddress(address);
|
||||||
});
|
});
|
||||||
|
|
||||||
w.on('remove address', w._poolOnRemove = function(address) {
|
wallet.on('remove address', wallet._poolOnRemove = function(address) {
|
||||||
self.unwatchAddress(address);
|
self.unwatchAddress(address);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.unwatchWallet = function unwatchWallet(w) {
|
Pool.prototype.unwatchWallet = function unwatchWallet(wallet) {
|
||||||
w.addresses.forEach(function(address) {
|
wallet.addresses.forEach(function(address) {
|
||||||
this.unwatchAddress(address);
|
this.unwatchAddress(address);
|
||||||
}, this);
|
}, this);
|
||||||
w.removeListener('add address', w._poolOnAdd);
|
wallet.removeListener('add address', wallet._poolOnAdd);
|
||||||
w.removeListener('remove address', w._poolOnRemove);
|
wallet.removeListener('remove address', wallet._poolOnRemove);
|
||||||
delete w._poolOnAdd;
|
delete wallet._poolOnAdd;
|
||||||
delete w._poolOnRemove;
|
delete wallet._poolOnRemove;
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.searchWallet = function(w, h) {
|
Pool.prototype.searchWallet = function(ts, height) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var ts, height;
|
var wallet;
|
||||||
|
|
||||||
assert(!this.loading);
|
assert(!this.loading);
|
||||||
|
|
||||||
if (!this.options.spv)
|
if (!this.options.spv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (w == null) {
|
if (ts == null) {
|
||||||
height = this.wallets.reduce(function(height, w) {
|
height = this.wallets.reduce(function(height, wallet) {
|
||||||
if (w.lastHeight < height)
|
if (wallet.lastHeight < height)
|
||||||
return w.lastHeight;
|
return wallet.lastHeight;
|
||||||
return height;
|
return height;
|
||||||
}, Infinity);
|
}, Infinity);
|
||||||
assert(height !== Infinity);
|
assert(height !== Infinity);
|
||||||
ts = this.wallets.reduce(function(ts, w) {
|
ts = this.wallets.reduce(function(ts, wallet) {
|
||||||
if (w.lastTs < ts)
|
if (wallet.lastTs < ts)
|
||||||
return w.lastTs;
|
return wallet.lastTs;
|
||||||
return ts;
|
return ts;
|
||||||
}, Infinity);
|
}, Infinity);
|
||||||
assert(ts !== Infinity);
|
assert(ts !== Infinity);
|
||||||
} else if (typeof w === 'number') {
|
} else if (typeof ts !== 'number') {
|
||||||
ts = w;
|
wallet = ts;
|
||||||
height = h;
|
if (wallet.loading) {
|
||||||
} else {
|
wallet.once('load', function() {
|
||||||
if (w.loading) {
|
self.searchWallet(wallet);
|
||||||
w.once('load', function() {
|
|
||||||
self.searchWallet(w);
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ts = w.lastTs;
|
ts = wallet.lastTs;
|
||||||
height = w.lastHeight;
|
height = wallet.lastHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always prefer height
|
// Always prefer height
|
||||||
@ -1342,8 +1340,9 @@ Pool.prototype.searchWallet = function(w, h) {
|
|||||||
|
|
||||||
utils.debug('Wallet height: %s', height);
|
utils.debug('Wallet height: %s', height);
|
||||||
utils.debug(
|
utils.debug(
|
||||||
'Reverted chain to height=%d',
|
'Reverted chain to height=%d (%s)',
|
||||||
self.chain.height
|
self.chain.height,
|
||||||
|
new Date(self.chain.tip.ts * 1000)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user