From 538c46a7431711be33f26c98199a3ec51092c5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Fri, 24 Jan 2025 12:43:04 -0300 Subject: [PATCH 1/4] fix: invalid parameter being sent to sendMessageSQS --- packages/daemon/src/services/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index 77e5fc69..bc0f6048 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -388,7 +388,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => { await sendMessageSQS(JSON.stringify({ wallets: Array.from(seenWallets), - txData, + tx: txData, }), queueUrl); } } catch (e) { From 6aff08aa9fb00c0eb905d45d7ecb1e82029391d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Fri, 24 Jan 2025 12:52:45 -0300 Subject: [PATCH 2/4] refactor: added helper method to send realtime tx --- packages/daemon/src/services/index.ts | 14 +++++--------- packages/daemon/src/utils/aws.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index bc0f6048..44c9c76d 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -45,6 +45,7 @@ import { getFullnodeHttpUrl, sendMessageSQS, generateAddresses, + sendRealtimeTx, } from '../utils'; import { getDbConnection, @@ -381,15 +382,10 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => { try { if (seenWallets.length > 0) { - const queueUrl = NEW_TX_SQS; - if (!queueUrl) { - throw new Error('Queue URL is invalid'); - } - - await sendMessageSQS(JSON.stringify({ - wallets: Array.from(seenWallets), - tx: txData, - }), queueUrl); + await sendRealtimeTx( + Array.from(seenWallets), + txData, + ); } } catch (e) { logger.error('Failed to send transaction to SQS queue'); diff --git a/packages/daemon/src/utils/aws.ts b/packages/daemon/src/utils/aws.ts index 7c0a60b8..d3134240 100644 --- a/packages/daemon/src/utils/aws.ts +++ b/packages/daemon/src/utils/aws.ts @@ -4,7 +4,7 @@ import { SendMessageCommand, SendMessageCommandOutput, SQSClient, MessageAttribu import { StringMap } from '../types'; import getConfig from '../config'; import logger from '../logger'; -import { addAlert } from '@wallet-service/common'; +import { addAlert, Transaction } from '@wallet-service/common'; export function buildFunctionName(functionName: string): string { const { STAGE } = getConfig(); @@ -56,6 +56,19 @@ export const invokeOnTxPushNotificationRequestedLambda = async (walletBalanceVal } } +export const sendRealtimeTx = async (wallets: string[], tx: Transaction): Promise => { + const { NEW_TX_SQS } = getConfig(); + + if (!NEW_TX_SQS) { + throw new Error('Queue URL is invalid'); + } + + await sendMessageSQS(JSON.stringify({ + wallets, + tx, + }), NEW_TX_SQS); +} + /** * Sends a message to a specific SQS queue * From f03f1de6640a737805d9d79cf7e2a945977e04de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Fri, 24 Jan 2025 12:57:34 -0300 Subject: [PATCH 3/4] docs: added docstring to sendRealtimeTx --- packages/daemon/src/utils/aws.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/daemon/src/utils/aws.ts b/packages/daemon/src/utils/aws.ts index d3134240..7a35927b 100644 --- a/packages/daemon/src/utils/aws.ts +++ b/packages/daemon/src/utils/aws.ts @@ -56,6 +56,12 @@ export const invokeOnTxPushNotificationRequestedLambda = async (walletBalanceVal } } +/** + * Sends a message to the real-time wallet-service SQS queue. + * + * @param wallets - A list of wallets to notify + * @param tx - The transaction details to send to the clients + */ export const sendRealtimeTx = async (wallets: string[], tx: Transaction): Promise => { const { NEW_TX_SQS } = getConfig(); From 2b9fd51fb0bee3cd3af5a3e0b425336d8b4bc7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Abadesso?= Date: Fri, 24 Jan 2025 13:32:47 -0300 Subject: [PATCH 4/4] refactor: removed unused import --- packages/daemon/src/services/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index 44c9c76d..2a00280a 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -170,7 +170,6 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => { NETWORK, STAGE, PUSH_NOTIFICATION_ENABLED, - NEW_TX_SQS, } = getConfig(); try {