Skip to content
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

ADD: Payload category to support Actions #289

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/openapi/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 15 additions & 3 deletions src/worker-processmempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
});
});
6 changes: 5 additions & 1 deletion src/worker-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -106,12 +107,14 @@ dataSource
switch (payload.type) {
case 2:
payload = <components["schemas"]["PushNotificationOnchainAddressGotPaid"]>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 = <components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"]>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);
Expand All @@ -124,6 +127,7 @@ dataSource
break;
case 4:
payload = <components["schemas"]["PushNotificationTxidGotConfirmed"]>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);
Expand Down
Loading