wallet/client: different parsing solution.
This commit is contained in:
parent
a313ac244c
commit
11ac46e051
@ -13,32 +13,42 @@ const TX = require('../primitives/tx');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const util = require('../utils/util');
|
||||
|
||||
const parsers = {
|
||||
'block connect': (entry, txs) => parseBlock(entry, txs),
|
||||
'block disconnect': entry => [parseEntry(entry)],
|
||||
'block rescan': (entry, txs) => parseBlock(entry, txs),
|
||||
'chain reset': entry => [parseEntry(entry)],
|
||||
'tx': tx => [TX.fromRaw(tx)],
|
||||
};
|
||||
|
||||
class WalletClient extends NodeClient {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
async open() {
|
||||
await super.open();
|
||||
listen(event, handler) {
|
||||
const parser = parsers[event];
|
||||
|
||||
this.parse('block connect', (entry, txs) => {
|
||||
return parseBlock(entry, txs);
|
||||
if (!parser) {
|
||||
super.listen(event, handler);
|
||||
return;
|
||||
}
|
||||
|
||||
super.listen(event, (...args) => {
|
||||
return handler(...parser(...args));
|
||||
});
|
||||
}
|
||||
|
||||
this.parse('block disconnect', (entry) => {
|
||||
return [parseEntry(entry)];
|
||||
});
|
||||
hook(event, handler) {
|
||||
const parser = parsers[event];
|
||||
|
||||
this.parse('block rescan', (entry, txs) => {
|
||||
return parseBlock(entry, txs);
|
||||
});
|
||||
if (!parser) {
|
||||
super.hook(event, handler);
|
||||
return;
|
||||
}
|
||||
|
||||
this.parse('chain reset', (tip) => {
|
||||
return [parseEntry(tip)];
|
||||
});
|
||||
|
||||
this.parse('tx', (tx) => {
|
||||
return [TX.fromRaw(tx)];
|
||||
super.hook(event, (...args) => {
|
||||
return handler(...parser(...args));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user