forked from shopglobal/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peers-plugin.js
50 lines (36 loc) · 883 Bytes
/
peers-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const bcoin = require('../..');
function MyPlugin(node) {
this.node = node;
}
MyPlugin.id = 'my-plugin';
MyPlugin.init = function init(node) {
return new MyPlugin(node);
};
MyPlugin.prototype.open = function open() {
console.log('Opened my plugin.');
return Promise.resolve();
};
MyPlugin.prototype.close = function close() {
console.log('Closed my plugin.');
return Promise.resolve();
};
MyPlugin.prototype.sayPeers = function sayPeers() {
console.log('Number of peers: %d', this.node.pool.peers.size());
};
const node = new bcoin.FullNode({
memory: true,
network: 'testnet',
workers: true
});
node.use(MyPlugin);
(async () => {
const plugin = node.require('my-plugin');
await node.open();
await node.connect();
plugin.sayPeers();
await node.close();
})().catch((err) => {
console.error(err.stack);
process.exit(1);
});