summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-cli/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-cli/src/index.ts')
-rw-r--r--packages/taler-wallet-cli/src/index.ts30
1 files changed, 27 insertions, 3 deletions
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
index e676f3950..68919615c 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -31,6 +31,7 @@ import {
getRandomBytes,
j2s,
Logger,
+ NotificationType,
parsePaytoUri,
parseTalerUri,
PreparePayResultType,
@@ -66,6 +67,8 @@ import {
makeNotificationWaiter,
} from "@gnu-taler/taler-wallet-core/remote";
+import * as fs from "node:fs";
+
// This module also serves as the entry point for the crypto
// thread worker, and thus must expose these two handlers.
export {
@@ -75,9 +78,10 @@ export {
const logger = new Logger("taler-wallet-cli.ts");
+let observabilityEventFile: string | undefined = undefined;
+
const EXIT_EXCEPTION = 4;
const EXIT_API_ERROR = 5;
-const EXIT_RETRIES_EXCEEDED = 6;
setUnhandledRejectionHandler((error: any) => {
logger.error("unhandledRejection", error.message);
@@ -270,6 +274,7 @@ async function createLocalWallet(
denomselAllowLate: checkEnvFlag(
"TALER_WALLET_DEBUG_DENOMSEL_ALLOW_LATE",
),
+ emitObservabilityEvents: observabilityEventFile != null,
skipDefaults: walletCliArgs.wallet.skipDefaults,
},
},
@@ -293,11 +298,26 @@ async function withWallet<T>(
): Promise<T> {
const waiter = makeNotificationWaiter();
+ const onNotif = (notif: WalletNotification) => {
+ waiter.notify(notif);
+ if (observabilityEventFile) {
+ switch (notif.type) {
+ case NotificationType.RequestObservabilityEvent:
+ case NotificationType.TaskObservabilityEvent:
+ fs.appendFileSync(
+ observabilityEventFile,
+ JSON.stringify(notif) + "\n",
+ );
+ break;
+ }
+ }
+ };
+
if (walletCliArgs.wallet.walletConnection) {
logger.info("creating remote wallet");
const w = await createRemoteWallet({
name: "wallet",
- notificationHandler: waiter.notify,
+ notificationHandler: onNotif,
socketFilename: walletCliArgs.wallet.walletConnection,
});
const ctx: WalletContext = {
@@ -311,7 +331,7 @@ async function withWallet<T>(
w.close();
return res;
} else {
- const wh = await createLocalWallet(walletCliArgs, waiter.notify);
+ const wh = await createLocalWallet(walletCliArgs, onNotif);
const ctx: WalletContext = {
client: wh.wallet.client,
waitForNotificationCond: waiter.waitForNotificationCond,
@@ -1719,5 +1739,9 @@ async function read(stream: NodeJS.ReadStream) {
}
export function main() {
+ const maybeFilename = getenv("TALER_WALLET_DEBUG_OBSERVE");
+ if (!!maybeFilename) {
+ observabilityEventFile = maybeFilename;
+ }
walletCli.run();
}