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

View File

@ -17,7 +17,14 @@
/**
* Imports.
*/
import { Duration, j2s, NotificationType } from "@gnu-taler/taler-util";
import {
Duration,
j2s,
NotificationType,
TransactionMajorState,
TransactionMinorState,
TransactionType,
} from "@gnu-taler/taler-util";
import {
BankAccessApi,
BankApi,
@ -310,18 +317,7 @@ export async function runKycTest(t: GlobalTestState) {
// Withdraw
const kycNotificationCond = walletClient.waitForNotificationCond((x) => {
if (x.type === NotificationType.KycRequested) {
return x;
}
return false;
});
const withdrawalDoneCond = walletClient.waitForNotificationCond(
(x) => x.type === NotificationType.WithdrawGroupFinished,
);
await walletClient.client.call(
const acceptResp = await walletClient.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal,
{
exchangeBaseUrl: exchange.baseUrl,
@ -329,14 +325,47 @@ export async function runKycTest(t: GlobalTestState) {
},
);
const withdrawalTxId = acceptResp.transactionId;
// Confirm it
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;
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,
// which would usually done in the browser.
@ -344,11 +373,11 @@ export async function runKycTest(t: GlobalTestState) {
allowHttp: true,
enableThrottling: false,
});
const kycServerResp = await httpLib.get(kycNotif.kycUrl);
const kycServerResp = await httpLib.fetch(kycUrl);
const kycLoginResp = await kycServerResp.json();
console.log("kyc server resp:", j2s(kycLoginResp));
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("resp headers", proofHttpResp.headers.toJSON());

View File

@ -61,7 +61,9 @@ export async function runPeerRepairTest(t: GlobalTestState) {
const wallet2 = w2.walletClient;
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, {

View File

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

View File

@ -22,6 +22,7 @@ import {
Duration,
NotificationType,
PreparePayResultType,
TransactionMajorState,
} from "@gnu-taler/taler-util";
import {
BankAccessApi,
@ -143,12 +144,7 @@ export async function runWalletNotificationsTest(t: GlobalTestState) {
// Withdraw (AKA select)
const withdrawalFinishedReceivedPromise =
walletClient.waitForNotificationCond((x) => {
return x.type === NotificationType.WithdrawGroupFinished;
});
await walletClient.client.call(
const acceptRes = await walletClient.client.call(
WalletApiOperation.AcceptBankIntegratedWithdrawal,
{
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
await BankApi.confirmWithdrawalOperation(bank, user, wop);

View File

@ -82,7 +82,11 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
);
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(

View File

@ -27,7 +27,7 @@ import {
} from "../harness/harness.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
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.
@ -83,7 +83,11 @@ export async function runWithdrawalHugeTest(t: GlobalTestState) {
});
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, {
exchangeBaseUrl: exchange.baseUrl,

View File

@ -1,6 +1,6 @@
/*
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
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 {
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",
ExchangeAdded = "exchange-added",
BackupOperationError = "backup-error",
InternalError = "internal-error",
PendingOperationProcessed = "pending-operation-processed",
KycRequested = "kyc-requested",
TransactionStateTransition = "transaction-state-transition",
}
@ -63,85 +48,12 @@ export interface TransactionStateTransitionNotification {
errorInfo?: ErrorInfoSummary;
}
export interface ProposalAcceptedNotification {
type: NotificationType.ProposalAccepted;
proposalId: string;
}
export interface InternalErrorNotification {
type: NotificationType.InternalError;
message: string;
exception: any;
}
export interface CoinWithdrawnNotification {
type: NotificationType.CoinWithdrawn;
numWithdrawn: 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 {
type: NotificationType.ExchangeAdded;
}
@ -167,21 +79,6 @@ export type WalletNotification =
| BackupOperationErrorNotification
| ExchangeAddedNotification
| ExchangeOperationErrorNotification
| ProposalAcceptedNotification
| ProposalDownloadedNotification
| RefundsSubmittedNotification
| RecoupStartedNotification
| RecoupFinishedNotification
| RefreshMeltedNotification
| RefreshRevealedNotification
| RefreshStartedNotification
| RefreshRefusedNotification
| WithdrawalGroupFinishedNotification
| RefundStartedNotification
| RefundQueriedNotification
| WithdrawalGroupCreatedNotification
| CoinWithdrawnNotification
| InternalErrorNotification
| PendingOperationProcessedNotification
| KycRequestedNotification
| TransactionStateTransitionNotification;

View File

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

View File

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

View File

@ -266,7 +266,6 @@ async function refreshCreateSession(
await tx.refreshGroups.put(rg);
});
ws.notify({ type: NotificationType.RefreshUnwarranted });
return;
}
@ -297,7 +296,6 @@ async function refreshCreateSession(
logger.info(
`created refresh session for coin #${coinIndex} in ${refreshGroupId}`,
);
ws.notify({ type: NotificationType.RefreshStarted });
}
function getRefreshRequestTimeout(rg: RefreshGroupRecord): Duration {
@ -482,10 +480,6 @@ async function refreshMelt(
rs.norevealIndex = norevealIndex;
await tx.refreshGroups.put(rg);
});
ws.notify({
type: NotificationType.RefreshMelted,
});
}
export async function assembleRefreshRevealRequest(args: {
@ -742,9 +736,6 @@ async function refreshReveal(
await tx.refreshGroups.put(rg);
});
logger.trace("refresh finished (end of reveal)");
ws.notify({
type: NotificationType.RefreshRevealed,
});
}
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 {
type: OperationAttemptResultType.Finished,
result: undefined,
@ -1634,11 +1626,6 @@ export async function checkWithdrawalKycStatus(
} else if (kycStatusRes.status === HttpStatusCode.Accepted) {
const kycStatus = await kycStatusRes.json();
logger.info(`kyc status: ${j2s(kycStatus)}`);
ws.notify({
type: NotificationType.KycRequested,
kycUrl: kycStatus.kyc_url,
transactionId: txId,
});
throw TalerError.fromDetail(
TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, //FIXME: another error code or rename for merge
{