mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-19 11:15:50 +00:00
More robust websocket connection
This commit is contained in:
27
index.mjs
27
index.mjs
@@ -15,7 +15,11 @@ await createDirectory('store')
|
|||||||
await createDirectory('store/xpop')
|
await createDirectory('store/xpop')
|
||||||
|
|
||||||
const connections = process.env.NODES.split(',').map(h => h.trim())
|
const connections = process.env.NODES.split(',').map(h => h.trim())
|
||||||
.map(h => new XrplClient(h))
|
.map(h => new XrplClient(h, {
|
||||||
|
assumeOfflineAfterSeconds: 10,
|
||||||
|
connectAttemptTimeoutSeconds: 10,
|
||||||
|
maxConnectionAttempts: null,
|
||||||
|
}))
|
||||||
|
|
||||||
connections
|
connections
|
||||||
.map(async c => {
|
.map(async c => {
|
||||||
@@ -28,13 +32,17 @@ connections
|
|||||||
* TODO: Generate xPOPs for matching transactions
|
* TODO: Generate xPOPs for matching transactions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
c.send({ command: "subscribe", streams: [
|
try {
|
||||||
"validations",
|
c.send({ command: "subscribe", streams: [
|
||||||
"ledger",
|
"validations",
|
||||||
// No transactions, to make it easier for clients transactions are
|
"ledger",
|
||||||
// processed in order (sorted on sequence) and emitted in order
|
// No transactions, to make it easier for clients transactions are
|
||||||
// to clients to prevent async tx sequence problems.
|
// processed in order (sorted on sequence) and emitted in order
|
||||||
] })
|
// to clients to prevent async tx sequence problems.
|
||||||
|
] })
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.on("validation", validation => onValidation({
|
c.on("validation", validation => onValidation({
|
||||||
@@ -51,6 +59,9 @@ connections
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
c.on('online', () => subscribe())
|
c.on('online', () => subscribe())
|
||||||
|
c.on('state', () => subscribe())
|
||||||
|
// c.on('retry', () => subscribe())
|
||||||
|
// c.on('round', () => subscribe())
|
||||||
|
|
||||||
c.on('error', e => console.error(e?.message || e))
|
c.on('error', e => console.error(e?.message || e))
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user