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