From 2447f788e5f0757949a72ef7003123ab3dfb94bd Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sat, 26 Oct 2024 21:26:47 -0400 Subject: [PATCH 01/17] 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); From 60ea0eef669787e83474b4a659c4d306b2215006 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:08:28 -0400 Subject: [PATCH 02/17] ADD: content-available, category and interrupt level --- openapi.yaml | 64 ++++- src/openapi/api.ts | 663 ++++++++++++++++++++++++++++++--------------- 2 files changed, 499 insertions(+), 228 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index f17a8c0..cc77ae4 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.0.0 info: title: GroundControl push server API description: Push notifications server for BlueWallet - version: 0.0.13 + version: 0.0.14 servers: - url: http://localhost:3001 - url: https://groundcontrol-bluewallet-stg.herokuapp.com @@ -250,6 +250,13 @@ components: type: "integer" level: $ref: "#/components/schemas/NotificationLevel" + aps: + type: object + properties: + content-available: + type: integer + enum: [1] + description: "To send a background notification, include only this key in the aps dictionary for types 1, 2, 3, and 4. Custom keys may also be added outside the aps dictionary." PushNotificationLightningInvoicePaid: allOf: # Combines PushNotificationBase and the inline model @@ -275,6 +282,17 @@ components: memo: type: "string" description: text attached to bolt11 + aps: + type: object + properties: + content-available: + type: integer + enum: [1] + interruption-level: + type: "string" + enum: + - "time-sensitive" + default: "time-sensitive" PushNotificationOnchainAddressGotPaid: allOf: # Combines PushNotificationBase and the inline model @@ -300,6 +318,20 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs + aps: + type: object + properties: + content-available: + type: integer + enum: [1] + category: + type: "string" + default: "TRANSACTION_CATEGORY" + interruption-level: + type: "string" + enum: + - "active" + default: "active" PushNotificationOnchainAddressGotUnconfirmedTransaction: allOf: # Combines PushNotificationBase and the inline model @@ -325,6 +357,20 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs + aps: + type: object + properties: + content-available: + type: integer + enum: [1] + category: + type: "string" + default: "TRANSACTION_CATEGORY" + interruption-level: + type: "string" + enum: + - "active" + default: "active" PushNotificationTxidGotConfirmed: allOf: # Combines PushNotificationBase and the inline model @@ -342,6 +388,20 @@ components: txid: type: "string" description: txid of the transaction that got confirmed + aps: + type: object + properties: + content-available: + type: integer + enum: [1] + category: + type: "string" + default: "TRANSACTION_CATEGORY" + interruption-level: + type: "string" + enum: + - "time-sensitive" + default: "time-sensitive" PushNotificationMessage: allOf: # Combines PushNotificationBase and the inline model @@ -355,4 +415,4 @@ components: enum: [5] text: type: "string" - description: custom text thats displayed on push notification buble + description: custom text thats displayed on push notification bubble \ No newline at end of file diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 9596e83..01d52a2 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -3,237 +3,448 @@ * Do not make direct changes to the file. */ -export type paths = { - "/lightningInvoiceGotSettled": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; - }; - }; +export interface paths { + "/lightningInvoiceGotSettled": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/majorTomToGroundControl": { - post: { - responses: { - /** Created */ - 201: unknown; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; - } & { [key: string]: unknown }; - }; - }; + "/majorTomToGroundControl": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** Associate bitcoin addressess / ln preimage hashes / txids that you wish to be notified about to specific push token. Token serves as unique identifier of a device/user. Also, OS of the token */ + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + }; + }; + }; + responses: { + /** @description Created */ + 201: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/unsubscribe": { - post: { - responses: { - /** Created */ - 201: unknown; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; - } & { [key: string]: unknown }; - }; - }; + "/unsubscribe": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** This call is a reverse call for /majorTomToGroundControl. In case user doesnt want to track addresses/txids/ln invoice hashes, he makes this call along with his token/os so GroundControl can remove them from the database */ + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + }; + }; + }; + responses: { + /** @description Created */ + 201: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/ping": { - get: { - responses: { - /** OK */ - 200: { - content: { - "application/json": components["schemas"]["ServerInfo"]; - }; - }; - }; + "/ping": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["ServerInfo"]; + }; + }; + }; + }; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/getTokenConfiguration": { - post: { - responses: { - /** OK */ - 200: { - content: { - "application/json": components["schemas"]["TokenConfiguration"]; - }; - }; - }; - requestBody: { - content: { - "application/json": { - token?: string; - os?: string; - } & { [key: string]: unknown }; - }; - }; + "/getTokenConfiguration": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** Returns levels of notifications user currently subscribed to */ + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + token?: string; + os?: string; + }; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["TokenConfiguration"]; + }; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/setTokenConfiguration": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": components["schemas"]["TokenConfiguration"] & - ({ - token: string; - os: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - }; - }; + "/setTokenConfiguration": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** Sets levels of notifications user is subscribed to; also saves some user info, like lang or app version */ + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": components["schemas"]["TokenConfiguration"] & { + token: string; + os: string; + }; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; - "/enqueue": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": ( - | components["schemas"]["PushNotificationLightningInvoicePaid"] - | components["schemas"]["PushNotificationOnchainAddressGotPaid"] - | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] - | components["schemas"]["PushNotificationTxidGotConfirmed"] - ) & { [key: string]: unknown }; - }; - }; + "/enqueue": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** Puts push in send queue. Push body should be any descendant of `/components/schemas/PushNotificationBase` */ + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody: { + content: { + "application/json": components["schemas"]["PushNotificationLightningInvoicePaid"] | components["schemas"]["PushNotificationOnchainAddressGotPaid"] | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] | components["schemas"]["PushNotificationTxidGotConfirmed"]; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; }; - }; -}; - -export type components = { - schemas: { - ServerInfo: { - name?: string; - description?: string; - version?: string; - uptime?: number; - last_processed_block?: number; - send_queue_size?: number; - sent_24h?: number; - } & { [key: string]: unknown }; - /** @enum {string} */ - NotificationLevel: "transactions" | "news" | "price" | "tips"; - TokenConfiguration: { - level_all?: boolean; - level_transactions?: boolean; - level_news?: boolean; - level_price?: boolean; - level_tips?: boolean; - lang?: string; - app_version?: string; - } & { [key: string]: unknown }; - /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ - LightningInvoiceSettledNotification: { - /** @description text that was embedded in invoice paid */ - memo?: string; - /** @description hex string preimage */ - preimage?: string; - /** @description hex string preimage hash */ - hash?: string; - /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ - amt_paid_sat?: number; - } & { [key: string]: unknown }; - /** @description payload for push notification delivered to phone */ - PushNotificationBase: { - /** - * @description type: - * * `1` - Your lightning invoice was paid - * * `2` - New transaction to one of your addresses - * * `3` - New unconfirmed transaction to one of your addresses - * * `4` - Transaction confirmed - * * `5` - Arbitrary text message - * - * @enum {integer} - */ - type: 1 | 2 | 3 | 4 | 5; - token: string; - /** @enum {string} */ - os: "android" | "ios"; - badge?: number; - level: components["schemas"]["NotificationLevel"]; - } & { [key: string]: unknown }; - PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & - ({ - /** @enum {integer} */ - type?: 1; - /** @enum {string} */ - level?: "transactions"; - /** @description amount of satoshis */ - sat: number; - /** @description hash of specific ln invoice preimage */ - hash: string; - /** @description text attached to bolt11 */ - memo: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & - ({ - /** @enum {integer} */ - type?: 2; - /** @enum {string} */ - level?: "transactions"; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & - ({ - /** @enum {integer} */ - type?: 3; - /** @enum {string} */ - level?: "transactions"; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & - ({ - /** @enum {integer} */ - type?: 4; +} +export type webhooks = Record; +export interface components { + schemas: { + ServerInfo: { + name?: string; + description?: string; + version?: string; + uptime?: number; + last_processed_block?: number; + send_queue_size?: number; + sent_24h?: number; + }; /** @enum {string} */ - level?: "transactions"; - /** @description txid of the transaction that got confirmed */ - txid: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - PushNotificationMessage: components["schemas"]["PushNotificationBase"] & - ({ - /** @enum {integer} */ - type?: 5; - /** @description custom text thats displayed on push notification buble */ - text: string; - } & { [key: string]: unknown }) & { [key: string]: unknown }; - }; -}; - -export type operations = {}; - -export type external = {}; + NotificationLevel: "transactions" | "news" | "price" | "tips"; + TokenConfiguration: { + level_all?: boolean; + level_transactions?: boolean; + level_news?: boolean; + level_price?: boolean; + level_tips?: boolean; + lang?: string; + app_version?: string; + }; + /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ + LightningInvoiceSettledNotification: { + /** @description text that was embedded in invoice paid */ + memo?: string; + /** @description hex string preimage */ + preimage?: string; + /** @description hex string preimage hash */ + hash?: string; + /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ + amt_paid_sat?: number; + }; + /** @description payload for push notification delivered to phone */ + PushNotificationBase: { + /** + * @description type: + * * `1` - Your lightning invoice was paid + * * `2` - New transaction to one of your addresses + * * `3` - New unconfirmed transaction to one of your addresses + * * `4` - Transaction confirmed + * * `5` - Arbitrary text message + * + * @enum {integer} + */ + type: 1 | 2 | 3 | 4 | 5; + token: string; + /** @enum {string} */ + os: "android" | "ios"; + badge?: number; + level: components["schemas"]["NotificationLevel"]; + aps?: { + /** + * @description To send a background notification, include only this key in the aps dictionary for types 1, 2, 3, and 4. Custom keys may also be added outside the aps dictionary. + * @enum {integer} + */ + "content-available"?: 1; + }; + }; + PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 1; + /** @enum {string} */ + level?: "transactions"; + /** @description amount of satoshis */ + sat: number; + /** @description hash of specific ln invoice preimage */ + hash: string; + /** @description text attached to bolt11 */ + memo: string; + aps?: { + /** @enum {integer} */ + "content-available"?: 1; + }; + /** + * @default time-sensitive + * @enum {string} + */ + "interruption-level": "time-sensitive"; + }; + PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 2; + /** @enum {string} */ + level?: "transactions"; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + aps?: { + /** @enum {integer} */ + "content-available"?: 1; + }; + /** @default TRANSACTION_CATEGORY */ + category: string; + /** + * @default active + * @enum {string} + */ + "interruption-level": "active"; + }; + PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 3; + /** @enum {string} */ + level?: "transactions"; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + aps?: { + /** @enum {integer} */ + "content-available"?: 1; + }; + /** @default TRANSACTION_CATEGORY */ + category: string; + /** + * @default active + * @enum {string} + */ + "interruption-level": "active"; + }; + PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 4; + /** @enum {string} */ + level?: "transactions"; + /** @description txid of the transaction that got confirmed */ + txid: string; + aps?: { + /** @enum {integer} */ + "content-available"?: 1; + }; + /** @default TRANSACTION_CATEGORY */ + category: string; + /** + * @default time-sensitive + * @enum {string} + */ + "interruption-level": "time-sensitive"; + }; + PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 5; + /** @description custom text thats displayed on push notification bubble */ + text: string; + }; + }; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; +} +export type $defs = Record; +export type operations = Record; From 006078b2eff3ac83601df0151c199761a67e125c Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:38:23 -0400 Subject: [PATCH 03/17] FIX: category added in yml --- openapi.yaml | 33 --------------------------------- src/openapi/api.ts | 27 --------------------------- 2 files changed, 60 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index cc77ae4..be1067f 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -318,20 +318,9 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs - aps: - type: object - properties: - content-available: - type: integer - enum: [1] category: type: "string" default: "TRANSACTION_CATEGORY" - interruption-level: - type: "string" - enum: - - "active" - default: "active" PushNotificationOnchainAddressGotUnconfirmedTransaction: allOf: # Combines PushNotificationBase and the inline model @@ -357,20 +346,9 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs - aps: - type: object - properties: - content-available: - type: integer - enum: [1] category: type: "string" default: "TRANSACTION_CATEGORY" - interruption-level: - type: "string" - enum: - - "active" - default: "active" PushNotificationTxidGotConfirmed: allOf: # Combines PushNotificationBase and the inline model @@ -388,20 +366,9 @@ components: txid: type: "string" description: txid of the transaction that got confirmed - aps: - type: object - properties: - content-available: - type: integer - enum: [1] category: type: "string" default: "TRANSACTION_CATEGORY" - interruption-level: - type: "string" - enum: - - "time-sensitive" - default: "time-sensitive" PushNotificationMessage: allOf: # Combines PushNotificationBase and the inline model diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 01d52a2..9d89b4e 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -379,17 +379,8 @@ export interface components { address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - aps?: { - /** @enum {integer} */ - "content-available"?: 1; - }; /** @default TRANSACTION_CATEGORY */ category: string; - /** - * @default active - * @enum {string} - */ - "interruption-level": "active"; }; PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ @@ -402,17 +393,8 @@ export interface components { address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - aps?: { - /** @enum {integer} */ - "content-available"?: 1; - }; /** @default TRANSACTION_CATEGORY */ category: string; - /** - * @default active - * @enum {string} - */ - "interruption-level": "active"; }; PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ @@ -421,17 +403,8 @@ export interface components { level?: "transactions"; /** @description txid of the transaction that got confirmed */ txid: string; - aps?: { - /** @enum {integer} */ - "content-available"?: 1; - }; /** @default TRANSACTION_CATEGORY */ category: string; - /** - * @default time-sensitive - * @enum {string} - */ - "interruption-level": "time-sensitive"; }; PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ From 51813d9bf87b27141e6ee8a2697f7779aeb78d0c Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:42:49 -0400 Subject: [PATCH 04/17] wip --- src/class/GroundControlToMajorTom.ts | 2 ++ src/worker-blockprocessor.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index 9b91025..d451229 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -73,6 +73,7 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, + category: "TRANSACTION_CATEGORY", }; const apnsPayload = { @@ -100,6 +101,7 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, + category: "TRANSACTION_CATEGORY", }; const apnsPayload = { diff --git a/src/worker-blockprocessor.ts b/src/worker-blockprocessor.ts index 6b61aa4..994b9c6 100644 --- a/src/worker-blockprocessor.ts +++ b/src/worker-blockprocessor.ts @@ -52,6 +52,7 @@ async function processBlock(blockNum, sendQueueRepository: Repository level: "transactions", token: "", os: "ios", + category: "TRANSACTION_CATEGORY", }; allPotentialPushPayloadsArray.push(payload); } From 14b1b1d27a0f2a41dcac863e76934d8643edd686 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:43:58 -0400 Subject: [PATCH 05/17] wip --- src/openapi/constants.ts | 3 +-- src/worker-processmempool.ts | 5 ----- src/worker-sender.ts | 5 +---- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/openapi/constants.ts b/src/openapi/constants.ts index a273821..7797c35 100644 --- a/src/openapi/constants.ts +++ b/src/openapi/constants.ts @@ -3,5 +3,4 @@ import { components } from "./api"; export const NOTIFICATION_LEVEL_TRANSACTIONS: components["schemas"]["NotificationLevel"] = "transactions"; 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 +export const NOTIFICATION_LEVEL_TIPS: components["schemas"]["NotificationLevel"] = "tips"; \ No newline at end of file diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index 3ca25c3..d821b42 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -70,11 +70,6 @@ async function processMempool() { 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); } } diff --git a/src/worker-sender.ts b/src/worker-sender.ts index 2db5845..663c83d 100644 --- a/src/worker-sender.ts +++ b/src/worker-sender.ts @@ -2,7 +2,7 @@ import "reflect-metadata"; import { SendQueue } from "./entity/SendQueue"; import { GroundControlToMajorTom } from "./class/GroundControlToMajorTom"; import { TokenConfiguration } from "./entity/TokenConfiguration"; -import { NOTIFICATION_CATEGORY_TRANSACTION, NOTIFICATION_LEVEL_NEWS, NOTIFICATION_LEVEL_PRICE, NOTIFICATION_LEVEL_TIPS, NOTIFICATION_LEVEL_TRANSACTIONS } from "./openapi/constants"; +import { 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(); @@ -107,14 +107,12 @@ 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); @@ -127,7 +125,6 @@ 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); From fd86188ee3577442db5e3146ea9ca165338c7760 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:46:06 -0400 Subject: [PATCH 06/17] wip --- openapi.yaml | 18 ------------------ src/openapi/api.ts | 16 ---------------- 2 files changed, 34 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index be1067f..63716f0 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -250,13 +250,6 @@ components: type: "integer" level: $ref: "#/components/schemas/NotificationLevel" - aps: - type: object - properties: - content-available: - type: integer - enum: [1] - description: "To send a background notification, include only this key in the aps dictionary for types 1, 2, 3, and 4. Custom keys may also be added outside the aps dictionary." PushNotificationLightningInvoicePaid: allOf: # Combines PushNotificationBase and the inline model @@ -282,17 +275,6 @@ components: memo: type: "string" description: text attached to bolt11 - aps: - type: object - properties: - content-available: - type: integer - enum: [1] - interruption-level: - type: "string" - enum: - - "time-sensitive" - default: "time-sensitive" PushNotificationOnchainAddressGotPaid: allOf: # Combines PushNotificationBase and the inline model diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 9d89b4e..e26dbdc 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -339,13 +339,6 @@ export interface components { os: "android" | "ios"; badge?: number; level: components["schemas"]["NotificationLevel"]; - aps?: { - /** - * @description To send a background notification, include only this key in the aps dictionary for types 1, 2, 3, and 4. Custom keys may also be added outside the aps dictionary. - * @enum {integer} - */ - "content-available"?: 1; - }; }; PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ @@ -358,15 +351,6 @@ export interface components { hash: string; /** @description text attached to bolt11 */ memo: string; - aps?: { - /** @enum {integer} */ - "content-available"?: 1; - }; - /** - * @default time-sensitive - * @enum {string} - */ - "interruption-level": "time-sensitive"; }; PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ From ab23b49fd97797aa5419d01262ac0dca03851cfd Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:47:11 -0400 Subject: [PATCH 07/17] Update worker-processmempool.ts --- src/worker-processmempool.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index d821b42..da82b63 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -4,7 +4,6 @@ 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(); @@ -59,7 +58,6 @@ async function processMempool() { addresses.push(address); processedTxids[response.result.txid] = true; - // Define the payload object const payload: components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] = { address, txid: response.result.txid, From 8c3b6b6492cab3223ded6459338367891f93a00a Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:49:28 -0400 Subject: [PATCH 08/17] Update GroundControlToMajorTom.ts --- src/class/GroundControlToMajorTom.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index d451229..d7c8c81 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -86,6 +86,7 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, + category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); @@ -114,6 +115,7 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, + category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); @@ -154,6 +156,7 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, + category: "TRANSACTION_CATEGORY", }; const apnsPayload = { @@ -166,6 +169,7 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, + category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); From 98851ff0b3a0816f3603ccc9514b8055a9460abc Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:49:29 -0400 Subject: [PATCH 09/17] Update worker-blockprocessor.ts --- src/worker-blockprocessor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/worker-blockprocessor.ts b/src/worker-blockprocessor.ts index 994b9c6..010d1c0 100644 --- a/src/worker-blockprocessor.ts +++ b/src/worker-blockprocessor.ts @@ -107,6 +107,7 @@ async function processBlock(blockNum, sendQueueRepository: Repository token: t2txid.token, os: t2txid.os === "ios" ? "ios" : "android", badge: 1, + category: "TRANSACTION_CATEGORY", }; process.env.VERBOSE && console.log("enqueueing", payload); From 5b93544d798763af3351bfd660641fa1e5771ede Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 12:50:36 -0400 Subject: [PATCH 10/17] Update worker-processmempool.ts --- src/worker-processmempool.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index da82b63..a9b662c 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -66,6 +66,7 @@ async function processMempool() { level: "transactions", token: "", os: "ios", + category: "TRANSACTION_CATEGORY", }; allPotentialPushPayloadsArray.push(payload); From 124d1b7192cccaa6a0f0f7b1540a29cec8704efe Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:01:20 -0400 Subject: [PATCH 11/17] wip --- openapi.yaml | 3 +++ src/openapi/api.ts | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 63716f0..9492a47 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -303,6 +303,7 @@ components: category: type: "string" default: "TRANSACTION_CATEGORY" + description: "Only included if type is 2, 3, or 4" PushNotificationOnchainAddressGotUnconfirmedTransaction: allOf: # Combines PushNotificationBase and the inline model @@ -331,6 +332,7 @@ components: category: type: "string" default: "TRANSACTION_CATEGORY" + description: "Only included if type is 2, 3, or 4" PushNotificationTxidGotConfirmed: allOf: # Combines PushNotificationBase and the inline model @@ -351,6 +353,7 @@ components: category: type: "string" default: "TRANSACTION_CATEGORY" + description: "Only included if type is 2, 3, or 4" PushNotificationMessage: allOf: # Combines PushNotificationBase and the inline model diff --git a/src/openapi/api.ts b/src/openapi/api.ts index e26dbdc..0946894 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -363,7 +363,10 @@ export interface components { address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - /** @default TRANSACTION_CATEGORY */ + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ category: string; }; PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { @@ -377,7 +380,10 @@ export interface components { address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - /** @default TRANSACTION_CATEGORY */ + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ category: string; }; PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { @@ -387,7 +393,10 @@ export interface components { level?: "transactions"; /** @description txid of the transaction that got confirmed */ txid: string; - /** @default TRANSACTION_CATEGORY */ + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ category: string; }; PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { From 21eb51e0f8cd10271ebb3530c53e7cf39ef37d7c Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:02:20 -0400 Subject: [PATCH 12/17] wip --- src/class/GroundControlToMajorTom.ts | 6 ------ src/worker-processmempool.ts | 1 - 2 files changed, 7 deletions(-) diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index d7c8c81..9b91025 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -73,7 +73,6 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, - category: "TRANSACTION_CATEGORY", }; const apnsPayload = { @@ -86,7 +85,6 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, - category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); @@ -102,7 +100,6 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, - category: "TRANSACTION_CATEGORY", }; const apnsPayload = { @@ -115,7 +112,6 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, - category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); @@ -156,7 +152,6 @@ export class GroundControlToMajorTom { badge: pushNotification.badge, tag: pushNotification.txid, }, - category: "TRANSACTION_CATEGORY", }; const apnsPayload = { @@ -169,7 +164,6 @@ export class GroundControlToMajorTom { sound: "default", }, data: {}, - category: "TRANSACTION_CATEGORY", }; if (pushNotification.os === "android") return GroundControlToMajorTom._pushToFcm(dataSource, serverKey, pushNotification.token, fcmPayload, pushNotification); diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index a9b662c..da82b63 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -66,7 +66,6 @@ async function processMempool() { level: "transactions", token: "", os: "ios", - category: "TRANSACTION_CATEGORY", }; allPotentialPushPayloadsArray.push(payload); From 74858d3cc1c23a95b35aa107b29169f507f4a454 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:04:33 -0400 Subject: [PATCH 13/17] Update worker-processmempool.ts --- src/worker-processmempool.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index da82b63..a9b662c 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -66,6 +66,7 @@ async function processMempool() { level: "transactions", token: "", os: "ios", + category: "TRANSACTION_CATEGORY", }; allPotentialPushPayloadsArray.push(payload); From 9d33b026eea57f763128ae33673e3b03e7785cca Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:06:43 -0400 Subject: [PATCH 14/17] Update openapi.yaml --- openapi.yaml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 9492a47..c82f32b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -291,6 +291,10 @@ components: level: type: "string" enum: ["transactions"] + category: + type: "string" + default: "TRANSACTION_CATEGORY" + description: "Only included if type is 2, 3, or 4" sat: type: "integer" description: amount of satoshis @@ -300,10 +304,7 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs - category: - type: "string" - default: "TRANSACTION_CATEGORY" - description: "Only included if type is 2, 3, or 4" + PushNotificationOnchainAddressGotUnconfirmedTransaction: allOf: # Combines PushNotificationBase and the inline model @@ -320,6 +321,10 @@ components: level: type: "string" enum: ["transactions"] + category: + type: "string" + default: "TRANSACTION_CATEGORY" + description: "Only included if type is 2, 3, or 4" sat: type: "integer" description: amount of satoshis @@ -329,10 +334,6 @@ components: txid: type: "string" description: txid of the transaction where this address is one of the outputs - category: - type: "string" - default: "TRANSACTION_CATEGORY" - description: "Only included if type is 2, 3, or 4" PushNotificationTxidGotConfirmed: allOf: # Combines PushNotificationBase and the inline model @@ -347,14 +348,14 @@ components: level: type: "string" enum: ["transactions"] - txid: - type: "string" - description: txid of the transaction that got confirmed category: type: "string" default: "TRANSACTION_CATEGORY" description: "Only included if type is 2, 3, or 4" - + txid: + type: "string" + description: txid of the transaction that got confirmed + PushNotificationMessage: allOf: # Combines PushNotificationBase and the inline model - $ref: "#/components/schemas/PushNotificationBase" From 126f919c3a68c4f072d17552548b76064f2920b7 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:06:48 -0400 Subject: [PATCH 15/17] Update api.ts --- src/openapi/api.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 0946894..48bb285 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -357,47 +357,47 @@ export interface components { type?: 2; /** @enum {string} */ level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category: string; /** @description amount of satoshis */ sat: number; /** @description user's onchain address that has incoming transaction */ address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category: string; }; PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ type?: 3; /** @enum {string} */ level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category: string; /** @description amount of satoshis */ sat: number; /** @description user's onchain address that has incoming transaction */ address: string; /** @description txid of the transaction where this address is one of the outputs */ txid: string; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category: string; }; PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ type?: 4; /** @enum {string} */ level?: "transactions"; - /** @description txid of the transaction that got confirmed */ - txid: string; /** * @description Only included if type is 2, 3, or 4 * @default TRANSACTION_CATEGORY */ category: string; + /** @description txid of the transaction that got confirmed */ + txid: string; }; PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { /** @enum {integer} */ From c2013b36996d7ad89863005d7755a326a3211fa2 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 13:25:50 -0400 Subject: [PATCH 16/17] wip --- openapi.yaml | 5 +- scripts/mass_send.js | 5 +- src/class/GroundControlToMajorTom.ts | 14 +- src/openapi/api.ts | 627 ++++++++++----------------- src/openapi/constants.ts | 2 +- src/worker-blockprocessor.ts | 15 +- src/worker-processmempool.ts | 4 +- src/worker-sender.ts | 11 +- 8 files changed, 257 insertions(+), 426 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index c82f32b..a9c41af 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -305,7 +305,6 @@ components: type: "string" description: txid of the transaction where this address is one of the outputs - PushNotificationOnchainAddressGotUnconfirmedTransaction: allOf: # Combines PushNotificationBase and the inline model - $ref: "#/components/schemas/PushNotificationBase" @@ -355,7 +354,7 @@ components: txid: type: "string" description: txid of the transaction that got confirmed - + PushNotificationMessage: allOf: # Combines PushNotificationBase and the inline model - $ref: "#/components/schemas/PushNotificationBase" @@ -368,4 +367,4 @@ components: enum: [5] text: type: "string" - description: custom text thats displayed on push notification bubble \ No newline at end of file + description: custom text thats displayed on push notification bubble diff --git a/scripts/mass_send.js b/scripts/mass_send.js index f9f023c..5d4e27c 100644 --- a/scripts/mass_send.js +++ b/scripts/mass_send.js @@ -3,14 +3,15 @@ const fs = require("fs"); const text = fs.readFileSync("all_tokens_unique.csv", { encoding: "utf8" }); const lines = text.split("\n"); -console.log('# got', lines.length, 'tokens'); +console.log("# got", lines.length, "tokens"); console.log("INSERT INTO send_queue_2 VALUES "); let fisrt = true; for (const line of lines.slice(0, 1000000)) { const [token, os] = line.split("\t"); - const sql = (fisrt ? '' : ', ') + `(null, '{"type":5,"token":"${token}","os":"${os}","text":"If you are using Lightning, please read our blog post. The service is sunsetting. Balances should be moved to another service"}', null)`; + const sql = + (fisrt ? "" : ", ") + `(null, '{"type":5,"token":"${token}","os":"${os}","text":"If you are using Lightning, please read our blog post. The service is sunsetting. Balances should be moved to another service"}', null)`; console.log(sql); fisrt = false; } diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index 9b91025..ce0f91b 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -91,7 +91,12 @@ export class GroundControlToMajorTom { if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); } - static async pushOnchainTxidGotConfirmed(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationTxidGotConfirmed"]): Promise<[object, object]> { + static async pushOnchainTxidGotConfirmed( + dataSource: DataSource, + serverKey: string, + apnsP8: string, + pushNotification: components["schemas"]["PushNotificationTxidGotConfirmed"] + ): Promise<[object, object]> { const fcmPayload = { data: {}, notification: { @@ -143,7 +148,12 @@ export class GroundControlToMajorTom { if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); } - static async pushOnchainAddressWasPaid(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationOnchainAddressGotPaid"]): Promise<[object, object]> { + static async pushOnchainAddressWasPaid( + dataSource: DataSource, + serverKey: string, + apnsP8: string, + pushNotification: components["schemas"]["PushNotificationOnchainAddressGotPaid"] + ): Promise<[object, object]> { const fcmPayload = { data: {}, notification: { diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 48bb285..147be89 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -4,413 +4,244 @@ */ export interface paths { - "/lightningInvoiceGotSettled": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; - }; - }; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - }; - }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + "/lightningInvoiceGotSettled": { + post: { + responses: { + /** OK */ + 200: unknown; + }; + requestBody: { + content: { + "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; + }; + }; }; - "/majorTomToGroundControl": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - /** Associate bitcoin addressess / ln preimage hashes / txids that you wish to be notified about to specific push token. Token serves as unique identifier of a device/user. Also, OS of the token */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; - }; - }; - }; - responses: { - /** @description Created */ - 201: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - }; - }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; + "/majorTomToGroundControl": { + post: { + responses: { + /** Created */ + 201: unknown; + }; + requestBody: { + content: { + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + }; + }; + }; }; - "/unsubscribe": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - /** This call is a reverse call for /majorTomToGroundControl. In case user doesnt want to track addresses/txids/ln invoice hashes, he makes this call along with his token/os so GroundControl can remove them from the database */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; - }; - }; - }; - responses: { - /** @description Created */ - 201: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - }; - }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; + "/unsubscribe": { + post: { + responses: { + /** Created */ + 201: unknown; + }; + requestBody: { + content: { + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + }; + }; + }; }; - "/ping": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": components["schemas"]["ServerInfo"]; - }; - }; - }; - }; - put?: never; - post?: never; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; + "/ping": { + get: { + responses: { + /** OK */ + 200: { + content: { + "application/json": components["schemas"]["ServerInfo"]; + }; + }; + }; }; - "/getTokenConfiguration": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - /** Returns levels of notifications user currently subscribed to */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - token?: string; - os?: string; - }; - }; - }; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": components["schemas"]["TokenConfiguration"]; - }; - }; - }; - }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; + "/getTokenConfiguration": { + post: { + responses: { + /** OK */ + 200: { + content: { + "application/json": components["schemas"]["TokenConfiguration"]; + }; + }; + }; + requestBody: { + content: { + "application/json": { + token?: string; + os?: string; + }; + }; + }; }; - "/setTokenConfiguration": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - /** Sets levels of notifications user is subscribed to; also saves some user info, like lang or app version */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": components["schemas"]["TokenConfiguration"] & { - token: string; - os: string; - }; - }; - }; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - }; + }; + "/setTokenConfiguration": { + post: { + responses: { + /** OK */ + 200: unknown; + }; + requestBody: { + content: { + "application/json": components["schemas"]["TokenConfiguration"] & { + token: string; + os: string; + }; }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; }; - "/enqueue": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - get?: never; - put?: never; - /** Puts push in send queue. Push body should be any descendant of `/components/schemas/PushNotificationBase` */ - post: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - requestBody: { - content: { - "application/json": components["schemas"]["PushNotificationLightningInvoicePaid"] | components["schemas"]["PushNotificationOnchainAddressGotPaid"] | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] | components["schemas"]["PushNotificationTxidGotConfirmed"]; - }; - }; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content?: never; - }; - }; - }; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + }; + "/enqueue": { + post: { + responses: { + /** OK */ + 200: unknown; + }; + requestBody: { + content: { + "application/json": + | components["schemas"]["PushNotificationLightningInvoicePaid"] + | components["schemas"]["PushNotificationOnchainAddressGotPaid"] + | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] + | components["schemas"]["PushNotificationTxidGotConfirmed"]; + }; + }; }; + }; } -export type webhooks = Record; + export interface components { - schemas: { - ServerInfo: { - name?: string; - description?: string; - version?: string; - uptime?: number; - last_processed_block?: number; - send_queue_size?: number; - sent_24h?: number; - }; - /** @enum {string} */ - NotificationLevel: "transactions" | "news" | "price" | "tips"; - TokenConfiguration: { - level_all?: boolean; - level_transactions?: boolean; - level_news?: boolean; - level_price?: boolean; - level_tips?: boolean; - lang?: string; - app_version?: string; - }; - /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ - LightningInvoiceSettledNotification: { - /** @description text that was embedded in invoice paid */ - memo?: string; - /** @description hex string preimage */ - preimage?: string; - /** @description hex string preimage hash */ - hash?: string; - /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ - amt_paid_sat?: number; - }; - /** @description payload for push notification delivered to phone */ - PushNotificationBase: { - /** - * @description type: - * * `1` - Your lightning invoice was paid - * * `2` - New transaction to one of your addresses - * * `3` - New unconfirmed transaction to one of your addresses - * * `4` - Transaction confirmed - * * `5` - Arbitrary text message - * - * @enum {integer} - */ - type: 1 | 2 | 3 | 4 | 5; - token: string; - /** @enum {string} */ - os: "android" | "ios"; - badge?: number; - level: components["schemas"]["NotificationLevel"]; - }; - PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 1; - /** @enum {string} */ - level?: "transactions"; - /** @description amount of satoshis */ - sat: number; - /** @description hash of specific ln invoice preimage */ - hash: string; - /** @description text attached to bolt11 */ - memo: string; - }; - PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 2; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category: string; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - }; - PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 3; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category: string; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - }; - PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 4; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category: string; - /** @description txid of the transaction that got confirmed */ - txid: string; - }; - PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 5; - /** @description custom text thats displayed on push notification bubble */ - text: string; - }; + schemas: { + ServerInfo: { + name?: string; + description?: string; + version?: string; + uptime?: number; + last_processed_block?: number; + send_queue_size?: number; + sent_24h?: number; + }; + /** @enum {string} */ + NotificationLevel: "transactions" | "news" | "price" | "tips"; + TokenConfiguration: { + level_all?: boolean; + level_transactions?: boolean; + level_news?: boolean; + level_price?: boolean; + level_tips?: boolean; + lang?: string; + app_version?: string; + }; + /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ + LightningInvoiceSettledNotification: { + /** @description text that was embedded in invoice paid */ + memo?: string; + /** @description hex string preimage */ + preimage?: string; + /** @description hex string preimage hash */ + hash?: string; + /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ + amt_paid_sat?: number; }; - responses: never; - parameters: never; - requestBodies: never; - headers: never; - pathItems: never; + /** @description payload for push notification delivered to phone */ + PushNotificationBase: { + /** + * @description type: + * * `1` - Your lightning invoice was paid + * * `2` - New transaction to one of your addresses + * * `3` - New unconfirmed transaction to one of your addresses + * * `4` - Transaction confirmed + * * `5` - Arbitrary text message + * + * @enum {integer} + */ + type: 1 | 2 | 3 | 4 | 5; + token: string; + /** @enum {string} */ + os: "android" | "ios"; + badge?: number; + level: components["schemas"]["NotificationLevel"]; + }; + PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 1; + /** @enum {string} */ + level?: "transactions"; + /** @description amount of satoshis */ + sat: number; + /** @description hash of specific ln invoice preimage */ + hash: string; + /** @description text attached to bolt11 */ + memo: string; + }; + PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 2; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + }; + PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 3; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + }; + PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 4; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description txid of the transaction that got confirmed */ + txid: string; + }; + PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { + /** @enum {integer} */ + type?: 5; + /** @description custom text thats displayed on push notification bubble */ + text: string; + }; + }; } -export type $defs = Record; -export type operations = Record; + +export interface operations {} + +export interface external {} diff --git a/src/openapi/constants.ts b/src/openapi/constants.ts index 7797c35..c78c261 100644 --- a/src/openapi/constants.ts +++ b/src/openapi/constants.ts @@ -3,4 +3,4 @@ import { components } from "./api"; export const NOTIFICATION_LEVEL_TRANSACTIONS: components["schemas"]["NotificationLevel"] = "transactions"; 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"; \ No newline at end of file +export const NOTIFICATION_LEVEL_TIPS: components["schemas"]["NotificationLevel"] = "tips"; diff --git a/src/worker-blockprocessor.ts b/src/worker-blockprocessor.ts index 010d1c0..d6b8cc1 100644 --- a/src/worker-blockprocessor.ts +++ b/src/worker-blockprocessor.ts @@ -89,12 +89,7 @@ async function processBlock(blockNum, sendQueueRepository: Repository } // batch insert via a raw query as its faster - await sendQueueRepository - .createQueryBuilder() - .insert() - .into(SendQueue) - .values(entities2save) - .execute(); + await sendQueueRepository.createQueryBuilder().insert().into(SendQueue).values(entities2save).execute(); // now, checking if there is a subscription to one of the mined txids: const query2 = dataSource.getRepository(TokenToTxid).createQueryBuilder().where("txid IN (:...txids)", { txids }); @@ -116,14 +111,8 @@ async function processBlock(blockNum, sendQueueRepository: Repository }); } - // batch insert via a raw query as its faster - await sendQueueRepository - .createQueryBuilder() - .insert() - .into(SendQueue) - .values(entities2save) - .execute(); + await sendQueueRepository.createQueryBuilder().insert().into(SendQueue).values(entities2save).execute(); } dataSource diff --git a/src/worker-processmempool.ts b/src/worker-processmempool.ts index a9b662c..8c26f87 100644 --- a/src/worker-processmempool.ts +++ b/src/worker-processmempool.ts @@ -131,7 +131,7 @@ dataSource try { await processMempool(); } catch (error) { - console.warn('Exception in processMempool():', error); + console.warn("Exception in processMempool():", error); } const end = +new Date(); process.env.VERBOSE && console.log("processing mempool took", (end - start) / 1000, "sec"); @@ -142,4 +142,4 @@ dataSource .catch((error) => { 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 663c83d..843772e 100644 --- a/src/worker-sender.ts +++ b/src/worker-sender.ts @@ -34,10 +34,11 @@ dataSource while (1) { // getting random record so multiple workers wont fight for the same record to send - const [record] = await sendQueueRepository .createQueryBuilder() - .orderBy('RAND()') // mysql-specific - .limit(1) - .getMany(); + const [record] = await sendQueueRepository + .createQueryBuilder() + .orderBy("RAND()") // mysql-specific + .limit(1) + .getMany(); // ^^^ 'order by rand' is suboptimal, but will have to do for now, especially if we are aiming to keep // queue table near-empty @@ -51,7 +52,7 @@ dataSource const query = `SELECT GET_LOCK(?, ?) as result`; const result = await sendQueueRepository.query(query, [`send${record.id}`, 0]); if (result[0].result !== 1) { - process.env.VERBOSE && console.log('could not acquire lock, skipping record'); + process.env.VERBOSE && console.log("could not acquire lock, skipping record"); continue; } From 8fef5e10db435de2784f0c33b751f1e640e870cc Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 27 Oct 2024 14:36:25 -0400 Subject: [PATCH 17/17] wip --- src/class/GroundControlToMajorTom.ts | 14 +- src/openapi/api.ts | 421 ++++++++++++++------------- 2 files changed, 217 insertions(+), 218 deletions(-) diff --git a/src/class/GroundControlToMajorTom.ts b/src/class/GroundControlToMajorTom.ts index ce0f91b..9b91025 100644 --- a/src/class/GroundControlToMajorTom.ts +++ b/src/class/GroundControlToMajorTom.ts @@ -91,12 +91,7 @@ export class GroundControlToMajorTom { if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); } - static async pushOnchainTxidGotConfirmed( - dataSource: DataSource, - serverKey: string, - apnsP8: string, - pushNotification: components["schemas"]["PushNotificationTxidGotConfirmed"] - ): Promise<[object, object]> { + static async pushOnchainTxidGotConfirmed(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationTxidGotConfirmed"]): Promise<[object, object]> { const fcmPayload = { data: {}, notification: { @@ -148,12 +143,7 @@ export class GroundControlToMajorTom { if (pushNotification.os === "ios") return GroundControlToMajorTom._pushToApns(dataSource, apnsP8, pushNotification.token, apnsPayload, pushNotification, pushNotification.txid); } - static async pushOnchainAddressWasPaid( - dataSource: DataSource, - serverKey: string, - apnsP8: string, - pushNotification: components["schemas"]["PushNotificationOnchainAddressGotPaid"] - ): Promise<[object, object]> { + static async pushOnchainAddressWasPaid(dataSource: DataSource, serverKey: string, apnsP8: string, pushNotification: components["schemas"]["PushNotificationOnchainAddressGotPaid"]): Promise<[object, object]> { const fcmPayload = { data: {}, notification: { diff --git a/src/openapi/api.ts b/src/openapi/api.ts index 147be89..008e469 100644 --- a/src/openapi/api.ts +++ b/src/openapi/api.ts @@ -3,245 +3,254 @@ * Do not make direct changes to the file. */ -export interface paths { - "/lightningInvoiceGotSettled": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; +export type paths ={ + "/lightningInvoiceGotSettled": { + post: { + responses: { + /** OK */ + 200: unknown; }; - }; - }; - }; - "/majorTomToGroundControl": { - post: { - responses: { - /** Created */ - 201: unknown; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; + requestBody: { + content: { + "application/json": components["schemas"]["LightningInvoiceSettledNotification"]; }; }; }; }; - }; - "/unsubscribe": { - post: { - responses: { - /** Created */ - 201: unknown; - }; - requestBody: { - content: { - "application/json": { - addresses?: string[]; - hashes?: string[]; - txids?: string[]; - token?: string; - os?: string; + "/majorTomToGroundControl": { + post: { + responses: { + /** Created */ + 201: unknown; + }; + requestBody: { + content: { + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + } & { [key: string]: unknown } }; }; }; }; - }; - "/ping": { - get: { - responses: { - /** OK */ - 200: { + "/unsubscribe": { + post: { + responses: { + /** Created */ + 201: unknown; + }; + requestBody: { content: { - "application/json": components["schemas"]["ServerInfo"]; + "application/json": { + addresses?: string[]; + hashes?: string[]; + txids?: string[]; + token?: string; + os?: string; + } & { [key: string]: unknown } }; }; }; }; - }; - "/getTokenConfiguration": { - post: { - responses: { - /** OK */ - 200: { - content: { - "application/json": components["schemas"]["TokenConfiguration"]; + "/ping": { + get: { + responses: { + /** OK */ + 200: { + content: { + "application/json": components["schemas"]["ServerInfo"]; + }; }; }; }; - requestBody: { - content: { - "application/json": { - token?: string; - os?: string; + }; + "/getTokenConfiguration": { + post: { + responses: { + /** OK */ + 200: { + content: { + "application/json": components["schemas"]["TokenConfiguration"]; + }; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["TokenConfiguration"] & + ({ + token: string; + os: string; + } & { [key: string]: unknown }) & { [key: string]: unknown }; }; }; }; }; - }; - "/setTokenConfiguration": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": components["schemas"]["TokenConfiguration"] & { - token: string; - os: string; + "/setTokenConfiguration": { + post: { + responses: { + /** OK */ + 200: unknown; + }; + requestBody: { + content: { + "application/json": components["schemas"]["TokenConfiguration"] & { + token: string; + os: string; + } & { [key: string]: unknown } + }; }; }; }; - }; - "/enqueue": { - post: { - responses: { - /** OK */ - 200: unknown; - }; - requestBody: { - content: { - "application/json": - | components["schemas"]["PushNotificationLightningInvoicePaid"] - | components["schemas"]["PushNotificationOnchainAddressGotPaid"] - | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] - | components["schemas"]["PushNotificationTxidGotConfirmed"]; + "/enqueue": { + post: { + responses: { + /** OK */ + 200: unknown; + }; + requestBody: { + content: { + "application/json": ( + + | components["schemas"]["PushNotificationLightningInvoicePaid"] + | components["schemas"]["PushNotificationOnchainAddressGotPaid"] + | components["schemas"]["PushNotificationOnchainAddressGotUnconfirmedTransaction"] + | components["schemas"]["PushNotificationTxidGotConfirmed"] + ) & { [key: string]: unknown }; }; }; }; }; - }; -} - -export interface components { - schemas: { - ServerInfo: { - name?: string; - description?: string; - version?: string; - uptime?: number; - last_processed_block?: number; - send_queue_size?: number; - sent_24h?: number; - }; - /** @enum {string} */ - NotificationLevel: "transactions" | "news" | "price" | "tips"; - TokenConfiguration: { - level_all?: boolean; - level_transactions?: boolean; - level_news?: boolean; - level_price?: boolean; - level_tips?: boolean; - lang?: string; - app_version?: string; - }; - /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ + } + + export type components = { + schemas: { + ServerInfo: { + name?: string; + description?: string; + version?: string; + uptime?: number; + last_processed_block?: number; + send_queue_size?: number; + sent_24h?: number; + }; + /** @enum {string} */ + NotificationLevel: "transactions" | "news" | "price" | "tips"; + TokenConfiguration: { + level_all?: boolean; + level_transactions?: boolean; + level_news?: boolean; + level_price?: boolean; + level_tips?: boolean; + lang?: string; + app_version?: string; + } & { [key: string]: unknown }; + /** @description object thats posted to GroundControl to notify end-user that his specific invoice was paid by someone */ LightningInvoiceSettledNotification: { - /** @description text that was embedded in invoice paid */ - memo?: string; - /** @description hex string preimage */ - preimage?: string; - /** @description hex string preimage hash */ - hash?: string; - /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ - amt_paid_sat?: number; - }; - /** @description payload for push notification delivered to phone */ + /** @description text that was embedded in invoice paid */ + memo?: string; + /** @description hex string preimage */ + preimage?: string; + /** @description hex string preimage hash */ + hash?: string; + /** @description exactly how much satoshis was paid to make this invoice settked (>= invoice amount) */ + amt_paid_sat?: number; + } & { [key: string]: unknown }; + + /** @description payload for push notification delivered to phone */ PushNotificationBase: { - /** - * @description type: - * * `1` - Your lightning invoice was paid - * * `2` - New transaction to one of your addresses - * * `3` - New unconfirmed transaction to one of your addresses - * * `4` - Transaction confirmed - * * `5` - Arbitrary text message - * - * @enum {integer} - */ - type: 1 | 2 | 3 | 4 | 5; - token: string; - /** @enum {string} */ - os: "android" | "ios"; - badge?: number; - level: components["schemas"]["NotificationLevel"]; - }; - PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 1; - /** @enum {string} */ - level?: "transactions"; - /** @description amount of satoshis */ - sat: number; - /** @description hash of specific ln invoice preimage */ - hash: string; - /** @description text attached to bolt11 */ - memo: string; - }; - PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 2; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category?: string; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - }; + /** + * @description type: + * * `1` - Your lightning invoice was paid + * * `2` - New transaction to one of your addresses + * * `3` - New unconfirmed transaction to one of your addresses + * * `4` - Transaction confirmed + * * `5` - Arbitrary text message + * + * @enum {integer} + */ + type: 1 | 2 | 3 | 4 | 5; + token: string; + /** @enum {string} */ + os: "android" | "ios"; + badge?: number; + level: components["schemas"]["NotificationLevel"]; + } & { [key: string]: unknown }; + PushNotificationLightningInvoicePaid: components["schemas"]["PushNotificationBase"] & + ({ + /** @enum {integer} */ + type?: 1; + /** @enum {string} */ + level?: "transactions"; + /** @description amount of satoshis */ + sat: number; + /** @description hash of specific ln invoice preimage */ + hash: string; + /** @description text attached to bolt11 */ + memo: string; + } & { [key: string]: unknown }) & { [key: string]: unknown }; + PushNotificationOnchainAddressGotPaid: components["schemas"]["PushNotificationBase"] & + ({ + /** @enum {integer} */ + type?: 2; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + } & { [key: string]: unknown }) & { [key: string]: unknown }; + + PushNotificationOnchainAddressGotUnconfirmedTransaction: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 3; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category?: string; - /** @description amount of satoshis */ - sat: number; - /** @description user's onchain address that has incoming transaction */ - address: string; - /** @description txid of the transaction where this address is one of the outputs */ - txid: string; - }; - PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 4; - /** @enum {string} */ - level?: "transactions"; - /** - * @description Only included if type is 2, 3, or 4 - * @default TRANSACTION_CATEGORY - */ - category?: string; - /** @description txid of the transaction that got confirmed */ - txid: string; - }; + /** @enum {integer} */ + type?: 3; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description amount of satoshis */ + sat: number; + /** @description user's onchain address that has incoming transaction */ + address: string; + /** @description txid of the transaction where this address is one of the outputs */ + txid: string; + }; + PushNotificationTxidGotConfirmed: components["schemas"]["PushNotificationBase"] & ({ + /** @enum {integer} */ + type?: 4; + /** @enum {string} */ + level?: "transactions"; + /** + * @description Only included if type is 2, 3, or 4 + * @default TRANSACTION_CATEGORY + */ + category?: string; + /** @description txid of the transaction that got confirmed */ + /** @description txid of the transaction that got confirmed */ + txid: string; + } & { [key: string]: unknown }) & { [key: string]: unknown }; PushNotificationMessage: components["schemas"]["PushNotificationBase"] & { - /** @enum {integer} */ - type?: 5; - /** @description custom text thats displayed on push notification bubble */ - text: string; + /** @enum {integer} */ + type?: 5; + /** @description custom text thats displayed on push notification bubble */ + text: string; + }; }; - }; -} - +}; + export interface operations {} export interface external {}