gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/02: -validation


From: gnunet
Subject: [taler-wallet-core] 02/02: -validation
Date: Sat, 05 Aug 2023 23:34:43 +0200

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

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

commit 6286699f26f486a9406827ef7359f62896a2dada
Author: Florian Dold <florian@dold.me>
AuthorDate: Sat Aug 5 23:34:25 2023 +0200

    -validation
---
 packages/taler-util/src/wallet-types.ts            | 52 +++++++++++++++++++---
 packages/taler-wallet-core/src/wallet-api-types.ts |  8 ++--
 packages/taler-wallet-core/src/wallet.ts           |  6 ++-
 3 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/packages/taler-util/src/wallet-types.ts 
b/packages/taler-util/src/wallet-types.ts
index 922b20862..42d54752a 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -379,11 +379,44 @@ export interface Balance {
   requiresUserInput: boolean;
 }
 
+export const codecForScopeInfoGlobal = (): Codec<ScopeInfoGlobal> =>
+  buildCodecForObject<ScopeInfoGlobal>()
+    .property("currency", codecForString())
+    .property("type", codecForConstString(ScopeType.Global))
+    .build("ScopeInfoGlobal");
+
+export const codecForScopeInfoExchange = (): Codec<ScopeInfoExchange> =>
+  buildCodecForObject<ScopeInfoExchange>()
+    .property("currency", codecForString())
+    .property("type", codecForConstString(ScopeType.Exchange))
+    .property("url", codecForString())
+    .build("ScopeInfoExchange");
+
+export const codecForScopeInfoAuditor = (): Codec<ScopeInfoAuditor> =>
+  buildCodecForObject<ScopeInfoAuditor>()
+    .property("currency", codecForString())
+    .property("type", codecForConstString(ScopeType.Auditor))
+    .property("url", codecForString())
+    .build("ScopeInfoAuditor");
+
+export const codecForScopeInfo = (): Codec<ScopeInfo> =>
+  buildCodecForUnion<ScopeInfo>()
+    .discriminateOn("type")
+    .alternative(ScopeType.Global, codecForScopeInfoGlobal())
+    .alternative(ScopeType.Exchange, codecForScopeInfoExchange())
+    .alternative(ScopeType.Auditor, codecForScopeInfoAuditor())
+    .build("ScopeInfo");
+
 export interface GetCurrencyInfoRequest {
-  currency: string;
   scope: ScopeInfo;
 }
 
+export const codecForGetCurrencyInfoRequest =
+  (): Codec<GetCurrencyInfoRequest> =>
+    buildCodecForObject<GetCurrencyInfoRequest>()
+      .property("scope", codecForScopeInfo())
+      .build("GetCurrencyInfoRequest");
+
 export interface GetCurrencyInfoResponse {
   decimalSeparator: string;
   numFractionalDigits: number;
@@ -407,10 +440,19 @@ export enum ScopeType {
   Auditor = "auditor",
 }
 
-export type ScopeInfo =
-  | { type: ScopeType.Global; currency: string }
-  | { type: ScopeType.Exchange; currency: string; url: string }
-  | { type: ScopeType.Auditor; currency: string; url: string };
+export type ScopeInfoGlobal = { type: ScopeType.Global; currency: string };
+export type ScopeInfoExchange = {
+  type: ScopeType.Exchange;
+  currency: string;
+  url: string;
+};
+export type ScopeInfoAuditor = {
+  type: ScopeType.Auditor;
+  currency: string;
+  url: string;
+};
+
+export type ScopeInfo = ScopeInfoGlobal | ScopeInfoExchange | ScopeInfoAuditor;
 
 export interface BalancesResponse {
   balances: Balance[];
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts 
b/packages/taler-wallet-core/src/wallet-api-types.ts
index 0c9755a3a..36c4809af 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -212,7 +212,7 @@ export enum WalletApiOperation {
   ApplyDevExperiment = "applyDevExperiment",
   ValidateIban = "validateIban",
   TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
-  GetCurrencyInfo = "getCurrencyInfo",
+  GetScopedCurrencyInfo = "getScopedCurrencyInfo",
 }
 
 // group: Initialization
@@ -604,8 +604,8 @@ export type ListCurrenciesOp = {
   response: WalletCurrencyInfo;
 };
 
-export type GetCurrencyInfoOp = {
-  op: WalletApiOperation.GetCurrencyInfo;
+export type GetScopedCurrencyInfoOp = {
+  op: WalletApiOperation.GetScopedCurrencyInfo;
   request: GetCurrencyInfoRequest;
   response: GetCurrencyInfoResponse;
 };
@@ -1081,7 +1081,7 @@ export type WalletOperations = {
   [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
   [WalletApiOperation.ValidateIban]: ValidateIbanOp;
   [WalletApiOperation.TestingWaitTransactionsFinal]: 
TestingWaitTransactionsFinal;
-  [WalletApiOperation.GetCurrencyInfo]: GetCurrencyInfoOp;
+  [WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp;
 };
 
 export type WalletCoreRequestType<
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 81ea26260..dfa41d60e 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -119,6 +119,7 @@ import {
   validateIban,
   codecForSharePaymentRequest,
   GetCurrencyInfoResponse,
+  codecForGetCurrencyInfoRequest,
 } from "@gnu-taler/taler-util";
 import {
   HttpRequestLibrary,
@@ -1396,7 +1397,10 @@ async function dispatchRequestInternal<Op extends 
WalletApiOperation>(
       const resp = await getBackupRecovery(ws);
       return resp;
     }
-    case WalletApiOperation.GetCurrencyInfo: {
+    case WalletApiOperation.GetScopedCurrencyInfo: {
+      logger.info(`payload: ${j2s(payload)}`);
+      // Ignore result, just validate in this mock implementation
+      codecForGetCurrencyInfoRequest().decode(payload);
       const resp: GetCurrencyInfoResponse = {
         decimalSeparator: ",",
         isCurrencyNameLeading: false,

-- 
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]