gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-typescript-core] branch master updated: wallet-core: implement ch


From: gnunet
Subject: [taler-typescript-core] branch master updated: wallet-core: implement checkPeerPushDebitV2
Date: Tue, 14 Jan 2025 23:27:00 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository taler-typescript-core.

The following commit(s) were added to refs/heads/master by this push:
     new c47cdeea3 wallet-core: implement checkPeerPushDebitV2
c47cdeea3 is described below

commit c47cdeea31176532484c754a0897f02ffb64f28f
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Jan 14 23:26:56 2025 +0100

    wallet-core: implement checkPeerPushDebitV2
---
 packages/taler-util/src/types-taler-wallet.ts      | 14 ++++++++-
 .../taler-wallet-core/src/pay-peer-push-debit.ts   | 36 ++++++++++++++++++----
 packages/taler-wallet-core/src/wallet-api-types.ts | 13 ++++++++
 packages/taler-wallet-core/src/wallet.ts           |  8 +++--
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts 
b/packages/taler-util/src/types-taler-wallet.ts
index 0a3d49a49..55611e00f 100644
--- a/packages/taler-util/src/types-taler-wallet.ts
+++ b/packages/taler-util/src/types-taler-wallet.ts
@@ -2938,7 +2938,19 @@ export const codecForCheckPeerPushDebitRequest =
       .property("clientCancellationId", codecOptional(codecForString()))
       .build("CheckPeerPushDebitRequest");
 
-export interface CheckPeerPushDebitResponse {
+export type CheckPeerPushDebitResponse =
+  | CheckPeerPushDebitOkResponse
+  | CheckPeerPushDebitInsufficientBalanceResponse;
+
+export interface CheckPeerPushDebitInsufficientBalanceResponse {
+  type: "insufficient-balance";
+
+  insufficientBalanceDetails: PaymentInsufficientBalanceDetails;
+}
+
+export interface CheckPeerPushDebitOkResponse {
+  type: "ok";
+
   amountRaw: AmountString;
 
   amountEffective: AmountString;
diff --git a/packages/taler-wallet-core/src/pay-peer-push-debit.ts 
b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
index 9a8195cf5..c58564530 100644
--- a/packages/taler-wallet-core/src/pay-peer-push-debit.ts
+++ b/packages/taler-wallet-core/src/pay-peer-push-debit.ts
@@ -16,6 +16,7 @@
 
 import {
   Amounts,
+  CheckPeerPushDebitOkResponse,
   CheckPeerPushDebitRequest,
   CheckPeerPushDebitResponse,
   CoinRefreshRequest,
@@ -416,9 +417,32 @@ export class PeerPushDebitTransactionContext implements 
TransactionContext {
   }
 }
 
+/**
+ * @deprecated use V2 instead
+ */
 export async function checkPeerPushDebit(
   wex: WalletExecutionContext,
   req: CheckPeerPushDebitRequest,
+): Promise<CheckPeerPushDebitOkResponse> {
+  const res = await checkPeerPushDebitV2(wex, req);
+  switch (res.type) {
+    case "ok":
+      return res;
+    case "insufficient-balance":
+      throw TalerError.fromDetail(
+        TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE,
+        {
+          insufficientBalanceDetails: res.insufficientBalanceDetails,
+        },
+      );
+    default:
+      assertUnreachable(res);
+  }
+}
+
+export async function checkPeerPushDebitV2(
+  wex: WalletExecutionContext,
+  req: CheckPeerPushDebitRequest,
 ): Promise<CheckPeerPushDebitResponse> {
   return runWithClientCancellation(
     wex,
@@ -457,6 +481,7 @@ async function internalCheckPeerPushDebit(
       throw Error("no exchange found for payment");
     }
     return {
+      type: "ok",
       amountEffective: req.amount,
       amountRaw: req.amount,
       exchangeBaseUrl,
@@ -471,12 +496,10 @@ async function internalCheckPeerPushDebit(
   let coins: SelectedProspectiveCoin[] | undefined = undefined;
   switch (coinSelRes.type) {
     case "failure":
-      throw TalerError.fromDetail(
-        TalerErrorCode.WALLET_PEER_PUSH_PAYMENT_INSUFFICIENT_BALANCE,
-        {
-          insufficientBalanceDetails: coinSelRes.insufficientBalanceDetails,
-        },
-      );
+      return {
+        type: "insufficient-balance",
+        insufficientBalanceDetails: coinSelRes.insufficientBalanceDetails,
+      };
     case "prospective":
       coins = coinSelRes.result.prospectiveCoins;
       break;
@@ -490,6 +513,7 @@ async function internalCheckPeerPushDebit(
   const totalAmount = await getTotalPeerPaymentCost(wex, coins);
   logger.trace("computed total peer payment cost");
   return {
+    type: "ok",
     exchangeBaseUrl: coinSelRes.result.exchangeBaseUrl,
     amountEffective: Amounts.stringify(totalAmount),
     amountRaw: req.amount,
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts 
b/packages/taler-wallet-core/src/wallet-api-types.ts
index ba4644374..3fb806387 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -49,6 +49,7 @@ import {
   CheckPayTemplateRequest,
   CheckPeerPullCreditRequest,
   CheckPeerPullCreditResponse,
+  CheckPeerPushDebitOkResponse,
   CheckPeerPushDebitRequest,
   CheckPeerPushDebitResponse,
   CoinDumpJson,
@@ -251,6 +252,7 @@ export enum WalletApiOperation {
   ExportDbToFile = "exportDbToFile",
   PreparePeerPushCredit = "preparePeerPushCredit",
   CheckPeerPushDebit = "checkPeerPushDebit",
+  CheckPeerPushDebitV2 = "checkPeerPushDebitV2",
   InitiatePeerPushDebit = "initiatePeerPushDebit",
   ConfirmPeerPushCredit = "confirmPeerPushCredit",
   CheckPeerPullCredit = "checkPeerPullCredit",
@@ -981,6 +983,16 @@ export type DeleteStoredBackupOp = {
 export type CheckPeerPushDebitOp = {
   op: WalletApiOperation.CheckPeerPushDebit;
   request: CheckPeerPushDebitRequest;
+  response: CheckPeerPushDebitOkResponse;
+};
+
+/**
+ * Check if initiating a peer push payment is possible
+ * based on the funds in the wallet.
+ */
+export type CheckPeerPushDebitV2Op = {
+  op: WalletApiOperation.CheckPeerPushDebitV2;
+  request: CheckPeerPushDebitRequest;
   response: CheckPeerPushDebitResponse;
 };
 
@@ -1408,6 +1420,7 @@ export type WalletOperations = {
   [WalletApiOperation.ExportDb]: ExportDbOp;
   [WalletApiOperation.ImportDb]: ImportDbOp;
   [WalletApiOperation.CheckPeerPushDebit]: CheckPeerPushDebitOp;
+  [WalletApiOperation.CheckPeerPushDebitV2]: CheckPeerPushDebitV2Op;
   [WalletApiOperation.InitiatePeerPushDebit]: InitiatePeerPushDebitOp;
   [WalletApiOperation.PreparePeerPushCredit]: PreparePeerPushCreditOp;
   [WalletApiOperation.ConfirmPeerPushCredit]: ConfirmPeerPushCreditOp;
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 61ca33996..96a117dab 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -327,6 +327,7 @@ import {
 } from "./pay-peer-push-credit.js";
 import {
   checkPeerPushDebit,
+  checkPeerPushDebitV2,
   initiatePeerPushDebit,
 } from "./pay-peer-push-debit.js";
 import {
@@ -1278,8 +1279,7 @@ async function handleGetDepositWireTypes(
         if (!det) {
           continue;
         }
-        if (req.currency !== undefined
-          && det.currency !== req.currency) {
+        if (req.currency !== undefined && det.currency !== req.currency) {
           continue;
         }
         for (const acc of det.wireInfo.accounts) {
@@ -2151,6 +2151,10 @@ const handlers: { [T in WalletApiOperation]: 
HandlerWithValidator<T> } = {
     codec: codecForCheckPeerPushDebitRequest(),
     handler: checkPeerPushDebit,
   },
+  [WalletApiOperation.CheckPeerPushDebitV2]: {
+    codec: codecForCheckPeerPushDebitRequest(),
+    handler: checkPeerPushDebitV2,
+  },
   [WalletApiOperation.InitiatePeerPushDebit]: {
     codec: codecForInitiatePeerPushDebitRequest(),
     handler: initiatePeerPushDebit,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]