From e51dde138627447429ef1b083b3ee0feff0b0709 Mon Sep 17 00:00:00 2001 From: Wietse Wind Date: Fri, 6 Oct 2023 01:42:30 +0200 Subject: [PATCH] Resubscribe on reconnect --- index.mjs | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/index.mjs b/index.mjs index 7bfebfa..f9e1473 100644 --- a/index.mjs +++ b/index.mjs @@ -13,31 +13,36 @@ await createDirectory('store/xpop') process.env.NODES.split(',').map(h => h.trim()) .map(h => new XrplClient(h)).map(async c => { - await c.ready() + + const subscribe = async () => { + await c.ready() + + /** + * TODO: Auto disconnect if no messages for X + * TODO: Generate xPOPs for matching transactions + */ - /** - * TODO: Auto disconnect if no messages for X - * TODO: Generate xPOPs for matching transactions - */ + c.send({ command: "subscribe", streams: [ + "validations", + "ledger", + // No transactions, to make it easier for clients transactions are + // processed in order (sorted on sequence) and emitted in order + // to clients to prevent async tx sequence problems. + ] }) - c.send({ command: "subscribe", streams: [ - "validations", - "ledger", - // No transactions, to make it easier for clients transactions are - // processed in order (sorted on sequence) and emitted in order - // to clients to prevent async tx sequence problems. - ] }) + c.on("validation", validation => onValidation({ + connectionUrl: c.getState()?.server?.uri, + networkId: c.getState()?.server?.networkId, + validation, + })) - c.on("validation", validation => onValidation({ - connectionUrl: c.getState()?.server?.uri, - networkId: c.getState()?.server?.networkId, - validation, - })) + c.on("ledger", ledger => onLedger({ + connectionUrl: c.getState()?.server?.uri, + networkId: c.getState()?.server?.networkId, + ledger, + connection: c, + })) + } - c.on("ledger", ledger => onLedger({ - connectionUrl: c.getState()?.server?.uri, - networkId: c.getState()?.server?.networkId, - ledger, - connection: c, - })) + c.on('online', () => subscribe()) })