From 2447f788e5f0757949a72ef7003123ab3dfb94bd Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sat, 26 Oct 2024 21:26:47 -0400 Subject: [PATCH] ADD: Payload category to support Actions --- src/openapi/constants.ts | 1 + src/worker-processmempool.ts | 18 +++++++++++++++--- src/worker-sender.ts | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/openapi/constants.ts b/src/openapi/constants.ts index c78c261..a273821 100644 --- a/src/openapi/constants.ts +++ b/src/openapi/constants.ts @@ -4,3 +4,4 @@ export const NOTIFICATION_LEVEL_TRANSACTIONS: components["schemas"]["Notificatio export const NOTIFICATION_LEVEL_NEWS: components["schemas"]["NotificationLevel"] = "news"; export const NOTIFICATION_LEVEL_PRICE: components["schemas"]["NotificationLevel"] = "price"; export const NOTIFICATION_LEVEL_TIPS: components["schemas"]["NotificationLevel"] = "tips"; +export const NOTIFICATION_CATEGORY_TRANSACTION = "TRANSACTION_CATEGORY"; // Add category only for type 2, 3 and 4 diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index b6db949..3ca25c3 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -4,13 +4,17 @@ import { TokenToAddress } from "./entity/TokenToAddress"; import { SendQueue } from "./entity/SendQueue"; import dataSource from "./data-source"; import { components } from "./openapi/api"; +import { NOTIFICATION_CATEGORY_TRANSACTION } from "./openapi/constants"; + require("dotenv").config(); + const url = require("url"); let jayson = require("jayson/promise"); let rpc = url.parse(process.env.BITCOIN_RPC); let client = jayson.client.http(rpc); let processedTxids = {}; + if (!process.env.BITCOIN_RPC) { console.error("not all env variables set"); process.exit(); @@ -51,9 +55,11 @@ async function processMempool() { if (response.result && response.result.vout) { for (const output of response.result.vout) { if (output.scriptPubKey && (output.scriptPubKey.addresses || output.scriptPubKey.address)) { - for (const address of output.scriptPubKey?.addresses ?? (output.scriptPubKey?.address ? [output.scriptPubKey?.address] : []) ) { + for (const address of output.scriptPubKey?.addresses ?? (output.scriptPubKey?.address ? [output.scriptPubKey?.address] : [])) { addresses.push(address); processedTxids[response.result.txid] = true; + + // Define the payload object const payload: components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] = { address, txid: response.result.txid, @@ -63,6 +69,12 @@ async function processMempool() { token: "", os: "ios", }; + + // Add category only if type is 2, 3, or 4 + if ([2, 3, 4].includes(payload.type)) { + payload.category = NOTIFICATION_CATEGORY_TRANSACTION; + } + allPotentialPushPayloadsArray.push(payload); } } @@ -134,6 +146,6 @@ dataSource } }) .catch((error) => { - console.error("exception in mempool processor:", error, "comitting suicide"); + console.error("exception in mempool processor:", error, "committing suicide"); process.exit(1); - }); + }); \ No newline at end of file diff --git a/src/worker-sender.ts b/src/worker-sender.ts index 20573f4..2db5845 100644 --- a/src/worker-sender.ts +++ b/src/worker-sender.ts @@ -2,10 +2,11 @@ import "reflect-metadata"; import { SendQueue } from "./entity/SendQueue"; import { GroundControlToMajorTom } from "./class/GroundControlToMajorTom"; import { TokenConfiguration } from "./entity/TokenConfiguration"; -import { NOTIFICATION_LEVEL_NEWS, NOTIFICATION_LEVEL_PRICE, NOTIFICATION_LEVEL_TIPS, NOTIFICATION_LEVEL_TRANSACTIONS } from "./openapi/constants"; +import { NOTIFICATION_CATEGORY_TRANSACTION, NOTIFICATION_LEVEL_NEWS, NOTIFICATION_LEVEL_PRICE, NOTIFICATION_LEVEL_TIPS, NOTIFICATION_LEVEL_TRANSACTIONS } from "./openapi/constants"; import dataSource from "./data-source"; import { components } from "./openapi/api"; require("dotenv").config(); + if (!process.env.FCM_SERVER_KEY || !process.env.APNS_P8 || !process.env.APNS_TOPIC || !process.env.APPLE_TEAM_ID || !process.env.APNS_P8_KID) { console.error("not all env variables set"); process.exit(); @@ -106,12 +107,14 @@ dataSource switch (payload.type) { case 2: payload = payload; + payload.category = NOTIFICATION_CATEGORY_TRANSACTION; process.env.VERBOSE && console.log("pushing to token", payload.token, payload.os); await GroundControlToMajorTom.pushOnchainAddressWasPaid(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload); await sendQueueRepository.remove(record); break; case 3: payload = payload; + payload.category = NOTIFICATION_CATEGORY_TRANSACTION; process.env.VERBOSE && console.log("pushing to token", payload.token, payload.os); await GroundControlToMajorTom.pushOnchainAddressGotUnconfirmedTransaction(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload); await sendQueueRepository.remove(record); @@ -124,6 +127,7 @@ dataSource break; case 4: payload = payload; + payload.category = NOTIFICATION_CATEGORY_TRANSACTION; process.env.VERBOSE && console.log("pushing to token", payload.token, payload.os); await GroundControlToMajorTom.pushOnchainTxidGotConfirmed(connection, GroundControlToMajorTom.getGoogleServerKey(), GroundControlToMajorTom.getApnsJwtToken(), payload); await sendQueueRepository.remove(record);