-
Notifications
You must be signed in to change notification settings - Fork 3
feat: new proxy api #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,19 +20,14 @@ function createConnectionsManager(config, eventBus) { | |
|
|
||
| let interval | ||
|
|
||
| const getConnections = async (sellerUrl, buyerUrl) => { | ||
| const getConnections = async (proxyUrl) => { | ||
| const getMiners = async (url) => { | ||
| return (await createAxios({ baseURL: url })('/miners')).data?.Miners | ||
| } | ||
|
|
||
| if (sellerUrl && buyerUrl) { | ||
| const sellerMiners = await getMiners(sellerUrl) | ||
| const buyerMiners = (await getMiners(buyerUrl)).map((x) => ({ | ||
| ...x, | ||
| Status: 'busy', | ||
| })) | ||
|
|
||
| return [...sellerMiners, ...buyerMiners] | ||
| if (proxyUrl) { | ||
| const sellerMiners = await getMiners(proxyUrl); | ||
| return [...sellerMiners]; | ||
| } | ||
|
|
||
| return await getMiners(proxyRouterUrl) | ||
|
|
@@ -57,15 +52,15 @@ function createConnectionsManager(config, eventBus) { | |
| * | ||
| * @returns {object} The event emitter. | ||
| */ | ||
| function getConnectionsStream(sellerUrl, buyerUrl) { | ||
| function getConnectionsStream(proxyUrl) { | ||
| const stream = new EventEmitter() | ||
|
|
||
| let isConnected = false | ||
|
|
||
| disconnect() | ||
| interval = setInterval(async () => { | ||
| try { | ||
| const connections = await getConnections(sellerUrl, buyerUrl) | ||
| const connections = await getConnections(proxyUrl) | ||
|
|
||
| if (!isConnected) { | ||
| isConnected = true | ||
|
Comment on lines
+55
to
66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function Also, the function |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ function createPlugin() { | |
|
|
||
| const refreshConnectionsStream = (data) => | ||
| connectionManager | ||
| .getConnectionsStream(data.sellerNodeUrl, data.buyerNodeUrl) | ||
| .getConnectionsStream(data.proxyNodeUrl) | ||
| .on('data', (data) => { | ||
| eventBus.emit('proxy-router-connections-changed', { | ||
| connections: data.connections, | ||
|
Comment on lines
16
to
21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function To improve this, you should add an error event listener to the stream returned by |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
getConnectionsis not handling any potential errors that might occur during the execution of thegetMinersfunction. IfcreateAxiosor the subsequent call to/minersfails for any reason (e.g., network issues, server error, etc.), it will throw an error that is not being caught. This could lead to unexpected behavior or crashes in your application. To improve error handling, you should wrap the contents ofgetConnectionsin a try-catch block and handle any errors appropriately, such as logging the error and returning a default value or rethrowing the error to be handled by the caller.