Fix unconsistent async patterns + add a few missing try/catch
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 1m53s
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 1m53s
This commit is contained in:
parent
8449083237
commit
83b21cb815
@ -309,7 +309,7 @@ export class RelayManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Relay Message Handling
|
// Relay Message Handling
|
||||||
private handleRelayMessage(relayId: string, message: any): void {
|
private async handleRelayMessage(relayId: string, message: any): Promise<void> {
|
||||||
console.log(`📨 Received message from relay ${relayId}:`);
|
console.log(`📨 Received message from relay ${relayId}:`);
|
||||||
|
|
||||||
if (message.flag === 'Handshake') {
|
if (message.flag === 'Handshake') {
|
||||||
@ -321,7 +321,7 @@ export class RelayManager {
|
|||||||
// Handle different types of relay responses
|
// Handle different types of relay responses
|
||||||
if (message.flag) {
|
if (message.flag) {
|
||||||
// Handle protocol-specific responses
|
// Handle protocol-specific responses
|
||||||
this.handleProtocolMessage(relayId, message);
|
await this.handleProtocolMessage(relayId, message);
|
||||||
} else if (message.type === 'heartbeat') {
|
} else if (message.type === 'heartbeat') {
|
||||||
// Update heartbeat
|
// Update heartbeat
|
||||||
const relay = this.relays.get(relayId);
|
const relay = this.relays.get(relayId);
|
||||||
@ -337,14 +337,16 @@ export class RelayManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleProtocolMessage(relayId: string, message: any): void {
|
private async handleProtocolMessage(relayId: string, message: any): Promise<void> {
|
||||||
// Handle different AnkFlag responses
|
// Handle different AnkFlag responses
|
||||||
switch (message.flag) {
|
switch (message.flag) {
|
||||||
case "NewTx":
|
case "NewTx":
|
||||||
console.log(`📨 NewTx response from relay ${relayId}`);
|
console.log(`📨 NewTx response from relay ${relayId}`);
|
||||||
setImmediate(() => {
|
try {
|
||||||
Service.getInstance().parseNewTx(message.content);
|
await Service.getInstance().parseNewTx(message.content);
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error(`❌ Error parsing NewTx from relay ${relayId}:`, error);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Commit":
|
case "Commit":
|
||||||
console.log(`📨 Commit response from relay ${relayId}`);
|
console.log(`📨 Commit response from relay ${relayId}`);
|
||||||
@ -353,9 +355,11 @@ export class RelayManager {
|
|||||||
break;
|
break;
|
||||||
case "Cipher":
|
case "Cipher":
|
||||||
console.log(`📨 Cipher response from relay ${relayId}`);
|
console.log(`📨 Cipher response from relay ${relayId}`);
|
||||||
setImmediate(() => {
|
try {
|
||||||
Service.getInstance().parseCipher(message.content);
|
await Service.getInstance().parseCipher(message.content);
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error(`❌ Error parsing Cipher from relay ${relayId}:`, error);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Handshake":
|
case "Handshake":
|
||||||
console.log(`📨 Handshake response from relay ${relayId}`);
|
console.log(`📨 Handshake response from relay ${relayId}`);
|
||||||
|
@ -1159,8 +1159,12 @@ export class Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
|
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
|
||||||
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send));
|
try {
|
||||||
await new Promise(r => setTimeout(r, 500));
|
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send));
|
||||||
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error sending NewTx message:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiReturn.secrets) {
|
if (apiReturn.secrets) {
|
||||||
@ -1245,11 +1249,19 @@ export class Service {
|
|||||||
|
|
||||||
if (apiReturn.commit_to_send) {
|
if (apiReturn.commit_to_send) {
|
||||||
const commit = apiReturn.commit_to_send;
|
const commit = apiReturn.commit_to_send;
|
||||||
await this.sendCommitMessage(JSON.stringify(commit));
|
try {
|
||||||
|
await this.sendCommitMessage(JSON.stringify(commit));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error sending Commit message:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) {
|
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) {
|
||||||
await this.sendCipherMessages(apiReturn.ciphers_to_send);
|
try {
|
||||||
|
await this.sendCipherMessages(apiReturn.ciphers_to_send);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error sending Cipher messages:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user