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
13 changes: 4 additions & 9 deletions packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
getFullnodeHttpUrl,
sendMessageSQS,
generateAddresses,
sendRealtimeTx,
} from '../utils';
import {
getDbConnection,
Expand Down Expand Up @@ -169,7 +170,6 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
NETWORK,
STAGE,
PUSH_NOTIFICATION_ENABLED,
NEW_TX_SQS,
} = getConfig();

try {
Expand Down Expand Up @@ -381,15 +381,10 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {

try {
if (seenWallets.length > 0) {
const queueUrl = NEW_TX_SQS;
Comment thread
pedroferreira1 marked this conversation as resolved.
if (!queueUrl) {
throw new Error('Queue URL is invalid');
}

await sendMessageSQS(JSON.stringify({
wallets: Array.from(seenWallets),
await sendRealtimeTx(
Array.from(seenWallets),
txData,
}), queueUrl);
);
}
} catch (e) {
logger.error('Failed to send transaction to SQS queue');
Expand Down
21 changes: 20 additions & 1 deletion packages/daemon/src/utils/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -56,6 +56,25 @@ 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<void> => {
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
*
Expand Down