wallet-core: remove redundant/unused notifications

This commit is contained in:
Florian Dold 2023-06-20 16:07:15 +02:00
parent a86c948fc9
commit e5a8ae7d60
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
12 changed files with 89 additions and 192 deletions

View File

@ -30,8 +30,8 @@ import {
Duration, Duration,
PreparePayResultType, PreparePayResultType,
NotificationType, NotificationType,
WithdrawalGroupFinishedNotification,
WalletNotification, WalletNotification,
TransactionMajorState,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { import {
BankAccessApi, BankAccessApi,
@ -505,7 +505,7 @@ export async function startWithdrawViaBank(
} }
export interface WithdrawViaBankResult { export interface WithdrawViaBankResult {
withdrawalFinishedCond: Promise<WithdrawalGroupFinishedNotification>; withdrawalFinishedCond: Promise<true>;
} }
/** /**
@ -535,17 +535,22 @@ export async function withdrawViaBankV2(
restrictAge: p.restrictAge, restrictAge: p.restrictAge,
}); });
const withdrawalFinishedCond = wallet.waitForNotificationCond((x) =>
x.type === NotificationType.WithdrawGroupFinished ? x : false,
);
// Withdraw (AKA select) // Withdraw (AKA select)
await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { const acceptRes = await wallet.client.call(
exchangeBaseUrl: exchange.baseUrl, WalletApiOperation.AcceptBankIntegratedWithdrawal,
talerWithdrawUri: wop.taler_withdraw_uri, {
restrictAge: p.restrictAge, exchangeBaseUrl: exchange.baseUrl,
}); talerWithdrawUri: wop.taler_withdraw_uri,
restrictAge: p.restrictAge,
},
);
const withdrawalFinishedCond = wallet.waitForNotificationCond((x) =>
x.type === NotificationType.TransactionStateTransition &&
x.newTxState.major === TransactionMajorState.Done &&
x.transactionId === acceptRes.transactionId,
);
// Confirm it // Confirm it

View File

@ -17,7 +17,14 @@
/** /**
* Imports. * Imports.
*/ */
import { Duration, j2s, NotificationType } from "@gnu-taler/taler-util"; import {
Duration,
j2s,
NotificationType,
TransactionMajorState,
TransactionMinorState,
TransactionType,
} from "@gnu-taler/taler-util";
import { import {
BankAccessApi, BankAccessApi,
BankApi, BankApi,
@ -310,18 +317,7 @@ export async function runKycTest(t: GlobalTestState) {
// Withdraw // Withdraw
const kycNotificationCond = walletClient.waitForNotificationCond((x) => { const acceptResp = await walletClient.client.call(
if (x.type === NotificationType.KycRequested) {
return x;
}
return false;
});
const withdrawalDoneCond = walletClient.waitForNotificationCond(
(x) => x.type === NotificationType.WithdrawGroupFinished,
);
await walletClient.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal, WalletApiOperation.AcceptBankIntegratedWithdrawal,
{ {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
@ -329,14 +325,47 @@ export async function runKycTest(t: GlobalTestState) {
}, },
); );
const withdrawalTxId = acceptResp.transactionId;
// Confirm it // Confirm it
await BankApi.confirmWithdrawalOperation(bank, user, wop); await BankApi.confirmWithdrawalOperation(bank, user, wop);
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
if (
x.type === NotificationType.TransactionStateTransition &&
x.transactionId === withdrawalTxId &&
x.newTxState.major === TransactionMajorState.Pending &&
x.newTxState.minor === TransactionMinorState.KycRequired
) {
return x;
}
return false;
});
const withdrawalDoneCond = walletClient.waitForNotificationCond(
(x) =>
x.type === NotificationType.TransactionStateTransition &&
x.transactionId === withdrawalTxId &&
x.newTxState.major === TransactionMajorState.Done,
);
const kycNotif = await kycNotificationCond; const kycNotif = await kycNotificationCond;
console.log("got kyc notification:", j2s(kycNotif)); console.log("got kyc notification:", j2s(kycNotif));
const txState = await walletClient.client.call(WalletApiOperation.GetTransactionById, {
transactionId: withdrawalTxId
});
t.assertDeepEqual(txState.type, TransactionType.Withdrawal);
const kycUrl = txState.kycUrl;
t.assertTrue(!!kycUrl);
console.log(`kyc URL is ${kycUrl}`);
// We now simulate the user interacting with the KYC service, // We now simulate the user interacting with the KYC service,
// which would usually done in the browser. // which would usually done in the browser.
@ -344,11 +373,11 @@ export async function runKycTest(t: GlobalTestState) {
allowHttp: true, allowHttp: true,
enableThrottling: false, enableThrottling: false,
}); });
const kycServerResp = await httpLib.get(kycNotif.kycUrl); const kycServerResp = await httpLib.fetch(kycUrl);
const kycLoginResp = await kycServerResp.json(); const kycLoginResp = await kycServerResp.json();
console.log("kyc server resp:", j2s(kycLoginResp)); console.log("kyc server resp:", j2s(kycLoginResp));
const kycProofUrl = kycLoginResp.redirect_uri; const kycProofUrl = kycLoginResp.redirect_uri;
const proofHttpResp = await httpLib.get(kycProofUrl); const proofHttpResp = await httpLib.fetch(kycProofUrl);
console.log("proof resp status", proofHttpResp.status); console.log("proof resp status", proofHttpResp.status);
console.log("resp headers", proofHttpResp.headers.toJSON()); console.log("resp headers", proofHttpResp.headers.toJSON());

View File

@ -61,7 +61,9 @@ export async function runPeerRepairTest(t: GlobalTestState) {
const wallet2 = w2.walletClient; const wallet2 = w2.walletClient;
const withdrawalDoneCond = wallet1.waitForNotificationCond( const withdrawalDoneCond = wallet1.waitForNotificationCond(
(x) => x.type === NotificationType.WithdrawGroupFinished, (x) => x.type === NotificationType.TransactionStateTransition &&
x.newTxState.major === TransactionMajorState.Done &&
x.transactionId.startsWith("txn:withdrawal:"),
); );
await withdrawViaBankV2(t, { await withdrawViaBankV2(t, {

View File

@ -61,18 +61,14 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) {
const wallet1 = w1.walletClient; const wallet1 = w1.walletClient;
const wallet2 = w2.walletClient; const wallet2 = w2.walletClient;
const withdrawalDoneCond = wallet2.waitForNotificationCond( const withdrawRes = await withdrawViaBankV2(t, {
(x) => x.type === NotificationType.WithdrawGroupFinished,
);
await withdrawViaBankV2(t, {
walletClient: wallet2, walletClient: wallet2,
bank, bank,
exchange, exchange,
amount: "TESTKUDOS:20", amount: "TESTKUDOS:20",
}); });
await withdrawalDoneCond; await withdrawRes.withdrawalFinishedCond;
const purse_expiration = AbsoluteTime.toProtocolTimestamp( const purse_expiration = AbsoluteTime.toProtocolTimestamp(
AbsoluteTime.addDuration( AbsoluteTime.addDuration(

View File

@ -22,6 +22,7 @@ import {
Duration, Duration,
NotificationType, NotificationType,
PreparePayResultType, PreparePayResultType,
TransactionMajorState,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { import {
BankAccessApi, BankAccessApi,
@ -143,12 +144,7 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
// Withdraw (AKA select) // Withdraw (AKA select)
const withdrawalFinishedReceivedPromise = const acceptRes = await walletClient.client.call(
walletClient.waitForNotificationCond((x) => {
return x.type === NotificationType.WithdrawGroupFinished;
});
await walletClient.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal, WalletApiOperation.AcceptBankIntegratedWithdrawal,
{ {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,
@ -156,6 +152,15 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
}, },
); );
const withdrawalFinishedReceivedPromise =
walletClient.waitForNotificationCond((x) => {
return (
x.type === NotificationType.TransactionStateTransition &&
x.newTxState.major === TransactionMajorState.Done &&
x.transactionId === acceptRes.transactionId
);
});
// Confirm it // Confirm it
await BankApi.confirmWithdrawalOperation(bank, user, wop); await BankApi.confirmWithdrawalOperation(bank, user, wop);

View File

@ -82,7 +82,11 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
); );
const withdrawalFinishedCond = walletClient.waitForNotificationCond((x) => { const withdrawalFinishedCond = walletClient.waitForNotificationCond((x) => {
return x.type === NotificationType.WithdrawGroupFinished; return (
x.type === NotificationType.TransactionStateTransition &&
x.transactionId === r2.transactionId &&
x.newTxState.major === TransactionMajorState.Done
);
}); });
const withdrawalReserveReadyCond = walletClient.waitForNotificationCond( const withdrawalReserveReadyCond = walletClient.waitForNotificationCond(

View File

@ -27,7 +27,7 @@ import {
} from "../harness/harness.js"; } from "../harness/harness.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js";
import { NotificationType, URL } from "@gnu-taler/taler-util"; import { NotificationType, TransactionMajorState, URL } from "@gnu-taler/taler-util";
/** /**
* Withdraw a high amount. Mostly intended as a perf test. * Withdraw a high amount. Mostly intended as a perf test.
@ -83,7 +83,11 @@ export async function runWithdrawalHugeTest(t: GlobalTestState) {
}); });
await wallet.connect(); await wallet.connect();
const withdrawalFinishedCond = wallet.waitForNotificationCond((wn) => wn.type === NotificationType.WithdrawGroupFinished); const withdrawalFinishedCond = wallet.waitForNotificationCond(
(wn) => wn.type === NotificationType.TransactionStateTransition &&
wn.transactionId.startsWith("txn:withdrawal:") &&
wn.newTxState.major === TransactionMajorState.Done,
);
await wallet.client.call(WalletApiOperation.AddExchange, { await wallet.client.call(WalletApiOperation.AddExchange, {
exchangeBaseUrl: exchange.baseUrl, exchangeBaseUrl: exchange.baseUrl,

View File

@ -1,6 +1,6 @@
/* /*
This file is part of GNU Taler This file is part of GNU Taler
(C) 2019 GNUnet e.V. (C) 2019-2023 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -27,25 +27,10 @@ import { TalerErrorDetail } from "./wallet-types.js";
export enum NotificationType { export enum NotificationType {
CoinWithdrawn = "coin-withdrawn", CoinWithdrawn = "coin-withdrawn",
ProposalAccepted = "proposal-accepted",
ProposalDownloaded = "proposal-downloaded",
RefundsSubmitted = "refunds-submitted",
RecoupStarted = "recoup-started",
RecoupFinished = "recoup-finished",
RefreshRevealed = "refresh-revealed",
RefreshMelted = "refresh-melted",
RefreshStarted = "refresh-started",
RefreshUnwarranted = "refresh-unwarranted",
WithdrawGroupCreated = "withdraw-group-created",
WithdrawGroupFinished = "withdraw-group-finished",
RefundStarted = "refund-started",
RefundQueried = "refund-queried",
ExchangeOperationError = "exchange-operation-error", ExchangeOperationError = "exchange-operation-error",
ExchangeAdded = "exchange-added", ExchangeAdded = "exchange-added",
BackupOperationError = "backup-error", BackupOperationError = "backup-error",
InternalError = "internal-error",
PendingOperationProcessed = "pending-operation-processed", PendingOperationProcessed = "pending-operation-processed",
KycRequested = "kyc-requested",
TransactionStateTransition = "transaction-state-transition", TransactionStateTransition = "transaction-state-transition",
} }
@ -63,85 +48,12 @@ export interface TransactionStateTransitionNotification {
errorInfo?: ErrorInfoSummary; errorInfo?: ErrorInfoSummary;
} }
export interface ProposalAcceptedNotification {
type: NotificationType.ProposalAccepted;
proposalId: string;
}
export interface InternalErrorNotification {
type: NotificationType.InternalError;
message: string;
exception: any;
}
export interface CoinWithdrawnNotification { export interface CoinWithdrawnNotification {
type: NotificationType.CoinWithdrawn; type: NotificationType.CoinWithdrawn;
numWithdrawn: number; numWithdrawn: number;
numTotal: number; numTotal: number;
} }
export interface RefundStartedNotification {
type: NotificationType.RefundStarted;
}
export interface RefundQueriedNotification {
type: NotificationType.RefundQueried;
/**
* Transaction ID of the purchase (NOT the refund transaction).
*/
transactionId: string;
}
export interface ProposalDownloadedNotification {
type: NotificationType.ProposalDownloaded;
proposalId: string;
}
export interface RefundsSubmittedNotification {
type: NotificationType.RefundsSubmitted;
proposalId: string;
}
export interface RecoupStartedNotification {
type: NotificationType.RecoupStarted;
}
export interface RecoupFinishedNotification {
type: NotificationType.RecoupFinished;
}
export interface RefreshMeltedNotification {
type: NotificationType.RefreshMelted;
}
export interface KycRequestedNotification {
type: NotificationType.KycRequested;
transactionId: string;
kycUrl: string;
}
export interface RefreshRevealedNotification {
type: NotificationType.RefreshRevealed;
}
export interface RefreshStartedNotification {
type: NotificationType.RefreshStarted;
}
export interface RefreshRefusedNotification {
type: NotificationType.RefreshUnwarranted;
}
export interface WithdrawalGroupCreatedNotification {
type: NotificationType.WithdrawGroupCreated;
withdrawalGroupId: string;
}
export interface WithdrawalGroupFinishedNotification {
type: NotificationType.WithdrawGroupFinished;
reservePub: string;
}
export interface ExchangeAddedNotification { export interface ExchangeAddedNotification {
type: NotificationType.ExchangeAdded; type: NotificationType.ExchangeAdded;
} }
@ -167,21 +79,6 @@ export type WalletNotification =
| BackupOperationErrorNotification | BackupOperationErrorNotification
| ExchangeAddedNotification | ExchangeAddedNotification
| ExchangeOperationErrorNotification | ExchangeOperationErrorNotification
| ProposalAcceptedNotification
| ProposalDownloadedNotification
| RefundsSubmittedNotification
| RecoupStartedNotification
| RecoupFinishedNotification
| RefreshMeltedNotification
| RefreshRevealedNotification
| RefreshStartedNotification
| RefreshRefusedNotification
| WithdrawalGroupFinishedNotification
| RefundStartedNotification
| RefundQueriedNotification
| WithdrawalGroupCreatedNotification
| CoinWithdrawnNotification | CoinWithdrawnNotification
| InternalErrorNotification
| PendingOperationProcessedNotification | PendingOperationProcessedNotification
| KycRequestedNotification
| TransactionStateTransitionNotification; | TransactionStateTransitionNotification;

View File

@ -560,12 +560,6 @@ async function processDownloadProposal(
notifyTransition(ws, transactionId, transitionInfo); notifyTransition(ws, transactionId, transitionInfo);
// FIXME: Deprecated pre-DD37 notification, remove eventually
ws.notify({
type: NotificationType.ProposalDownloaded,
proposalId: proposal.proposalId,
});
return { return {
type: OperationAttemptResultType.Finished, type: OperationAttemptResultType.Finished,
result: undefined, result: undefined,
@ -1453,11 +1447,6 @@ export async function confirmPay(
notifyTransition(ws, transactionId, transitionInfo); notifyTransition(ws, transactionId, transitionInfo);
ws.notify({
type: NotificationType.ProposalAccepted,
proposalId: proposal.proposalId,
});
return runPayForConfirmPay(ws, proposalId); return runPayForConfirmPay(ws, proposalId);
} }

View File

@ -136,10 +136,6 @@ async function recoupWithdrawCoin(
return; return;
} }
ws.notify({
type: NotificationType.RecoupStarted,
});
const recoupRequest = await ws.cryptoApi.createRecoupRequest({ const recoupRequest = await ws.cryptoApi.createRecoupRequest({
blindingKey: coin.blindingKey, blindingKey: coin.blindingKey,
coinPriv: coin.coinPriv, coinPriv: coin.coinPriv,
@ -182,10 +178,6 @@ async function recoupWithdrawCoin(
await tx.coins.put(updatedCoin); await tx.coins.put(updatedCoin);
await putGroupAsFinished(ws, tx, recoupGroup, coinIdx); await putGroupAsFinished(ws, tx, recoupGroup, coinIdx);
}); });
ws.notify({
type: NotificationType.RecoupFinished,
});
} }
async function recoupRefreshCoin( async function recoupRefreshCoin(
@ -214,10 +206,6 @@ async function recoupRefreshCoin(
return; return;
} }
ws.notify({
type: NotificationType.RecoupStarted,
});
const recoupRequest = await ws.cryptoApi.createRecoupRefreshRequest({ const recoupRequest = await ws.cryptoApi.createRecoupRefreshRequest({
blindingKey: coin.blindingKey, blindingKey: coin.blindingKey,
coinPriv: coin.coinPriv, coinPriv: coin.coinPriv,

View File

@ -266,7 +266,6 @@ async function refreshCreateSession(
await tx.refreshGroups.put(rg); await tx.refreshGroups.put(rg);
}); });
ws.notify({ type: NotificationType.RefreshUnwarranted });
return; return;
} }
@ -297,7 +296,6 @@ async function refreshCreateSession(
logger.info( logger.info(
`created refresh session for coin #${coinIndex} in ${refreshGroupId}`, `created refresh session for coin #${coinIndex} in ${refreshGroupId}`,
); );
ws.notify({ type: NotificationType.RefreshStarted });
} }
function getRefreshRequestTimeout(rg: RefreshGroupRecord): Duration { function getRefreshRequestTimeout(rg: RefreshGroupRecord): Duration {
@ -482,10 +480,6 @@ async function refreshMelt(
rs.norevealIndex = norevealIndex; rs.norevealIndex = norevealIndex;
await tx.refreshGroups.put(rg); await tx.refreshGroups.put(rg);
}); });
ws.notify({
type: NotificationType.RefreshMelted,
});
} }
export async function assembleRefreshRevealRequest(args: { export async function assembleRefreshRevealRequest(args: {
@ -742,9 +736,6 @@ async function refreshReveal(
await tx.refreshGroups.put(rg); await tx.refreshGroups.put(rg);
}); });
logger.trace("refresh finished (end of reveal)"); logger.trace("refresh finished (end of reveal)");
ws.notify({
type: NotificationType.RefreshRevealed,
});
} }
export async function processRefreshGroup( export async function processRefreshGroup(

View File

@ -1515,14 +1515,6 @@ async function processWithdrawalGroupPendingReady(
); );
} }
// FIXME: Deprecated with DD37
if (finishedForFirstTime) {
ws.notify({
type: NotificationType.WithdrawGroupFinished,
reservePub: withdrawalGroup.reservePub,
});
}
return { return {
type: OperationAttemptResultType.Finished, type: OperationAttemptResultType.Finished,
result: undefined, result: undefined,
@ -1634,11 +1626,6 @@ export async function checkWithdrawalKycStatus(
} else if (kycStatusRes.status === HttpStatusCode.Accepted) { } else if (kycStatusRes.status === HttpStatusCode.Accepted) {
const kycStatus = await kycStatusRes.json(); const kycStatus = await kycStatusRes.json();
logger.info(`kyc status: ${j2s(kycStatus)}`); logger.info(`kyc status: ${j2s(kycStatus)}`);
ws.notify({
type: NotificationType.KycRequested,
kycUrl: kycStatus.kyc_url,
transactionId: txId,
});
throw TalerError.fromDetail( throw TalerError.fromDetail(
TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, //FIXME: another error code or rename for merge TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, //FIXME: another error code or rename for merge
{ {