Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 71 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@hathor/wallet-lib": "^0.18.0",
"@hathor/wallet-lib": "^0.20.3",
"aws-sdk": "^2.878.0",
"axios": "^0.21.1",
"dotenv": "^8.2.0",
Expand Down
20 changes: 17 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@ const handleMessage = (message: any) => {
* the machine, triggering a download if new blocks were generated.
*/
if (message.state === Connection.CONNECTED) {
logger.info('Websocket connected.');
machine.send({ type: 'NEW_BLOCK' });
}
if (message.state === Connection.CONNECTING) {
logger.info(`Websocket is attempting to connect to ${process.env.DEFAULT_SERVER}`);
}
if (message.state === Connection.CLOSED) {
logger.error('Websocket connection was closed.');
Comment thread
andreabadesso marked this conversation as resolved.
}
break;
}
};

machine.start();

const DEFAULT_SERVER = process.env.DEFAULT_SERVER;
const conn = new Connection({ network: process.env.NETWORK, servers: [DEFAULT_SERVER] });
const conn = new Connection({
network: process.env.NETWORK,
servers: [DEFAULT_SERVER],
});

// @ts-ignore
conn.websocket.on('network', (message) => handleMessage(message));
Expand All @@ -63,4 +71,10 @@ conn.on('state', (state) => handleMessage({
type: 'state_update',
state,
}));
// @ts-ignore
conn.websocket.on('connection_error', (evt) => {
logger.error(`Websocket connection error: ${evt.message}`);
});

machine.start();
conn.start();