node: automatically bind to errors for plugins.
This commit is contained in:
parent
8c7279518f
commit
074c065262
@ -45,9 +45,10 @@ function Node(options) {
|
||||
this.plugins = {};
|
||||
this.stack = [];
|
||||
|
||||
this.spv = false;
|
||||
this.logger = null;
|
||||
this.workers = null;
|
||||
|
||||
this.spv = false;
|
||||
this.chain = null;
|
||||
this.fees = null;
|
||||
this.mempool = null;
|
||||
@ -212,6 +213,7 @@ Node.prototype.handleOpen = async function handleOpen() {
|
||||
*/
|
||||
|
||||
Node.prototype.handlePreclose = async function handlePreclose() {
|
||||
;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -291,7 +293,6 @@ Node.prototype.use = function use(plugin) {
|
||||
|
||||
// Reserved names
|
||||
switch (plugin.id) {
|
||||
case 'logger':
|
||||
case 'chain':
|
||||
case 'fees':
|
||||
case 'mempool':
|
||||
@ -308,6 +309,9 @@ Node.prototype.use = function use(plugin) {
|
||||
|
||||
this.stack.push(instance);
|
||||
|
||||
if (typeof instance.on === 'function')
|
||||
instance.on('error', err => this.error(err));
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
@ -333,9 +337,6 @@ Node.prototype.require = function require(name) {
|
||||
assert(typeof name === 'string', 'Plugin name must be a string.');
|
||||
|
||||
switch (name) {
|
||||
case 'logger':
|
||||
assert(this.logger, 'logger is not loaded.');
|
||||
return this.logger;
|
||||
case 'chain':
|
||||
assert(this.chain, 'chain is not loaded.');
|
||||
return this.chain;
|
||||
@ -372,8 +373,6 @@ Node.prototype.loadPlugins = function loadPlugins() {
|
||||
return;
|
||||
|
||||
for (let plugin of plugins) {
|
||||
assert(plugin);
|
||||
|
||||
if (typeof plugin === 'string')
|
||||
plugin = loader(plugin);
|
||||
|
||||
|
||||
@ -62,9 +62,5 @@ plugin.init = function init(node) {
|
||||
|
||||
wdb.rpc.attach(node.rpc);
|
||||
|
||||
wdb.on('error', (err) => {
|
||||
wdb.logger.error(err);
|
||||
});
|
||||
|
||||
return wdb;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user