-validation

This commit is contained in:
Florian Dold 2023-08-05 23:34:25 +02:00
parent 308a4282cb
commit 6286699f26
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 56 additions and 10 deletions

View File

@ -379,11 +379,44 @@ export interface Balance {
requiresUserInput: boolean; 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 { export interface GetCurrencyInfoRequest {
currency: string;
scope: ScopeInfo; scope: ScopeInfo;
} }
export const codecForGetCurrencyInfoRequest =
(): Codec<GetCurrencyInfoRequest> =>
buildCodecForObject<GetCurrencyInfoRequest>()
.property("scope", codecForScopeInfo())
.build("GetCurrencyInfoRequest");
export interface GetCurrencyInfoResponse { export interface GetCurrencyInfoResponse {
decimalSeparator: string; decimalSeparator: string;
numFractionalDigits: number; numFractionalDigits: number;
@ -407,10 +440,19 @@ export enum ScopeType {
Auditor = "auditor", Auditor = "auditor",
} }
export type ScopeInfo = export type ScopeInfoGlobal = { type: ScopeType.Global; currency: string };
| { type: ScopeType.Global; currency: string } export type ScopeInfoExchange = {
| { type: ScopeType.Exchange; currency: string; url: string } type: ScopeType.Exchange;
| { type: ScopeType.Auditor; currency: string; url: string }; currency: string;
url: string;
};
export type ScopeInfoAuditor = {
type: ScopeType.Auditor;
currency: string;
url: string;
};
export type ScopeInfo = ScopeInfoGlobal | ScopeInfoExchange | ScopeInfoAuditor;
export interface BalancesResponse { export interface BalancesResponse {
balances: Balance[]; balances: Balance[];

View File

@ -212,7 +212,7 @@ export enum WalletApiOperation {
ApplyDevExperiment = "applyDevExperiment", ApplyDevExperiment = "applyDevExperiment",
ValidateIban = "validateIban", ValidateIban = "validateIban",
TestingWaitTransactionsFinal = "testingWaitTransactionsFinal", TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
GetCurrencyInfo = "getCurrencyInfo", GetScopedCurrencyInfo = "getScopedCurrencyInfo",
} }
// group: Initialization // group: Initialization
@ -604,8 +604,8 @@ export type ListCurrenciesOp = {
response: WalletCurrencyInfo; response: WalletCurrencyInfo;
}; };
export type GetCurrencyInfoOp = { export type GetScopedCurrencyInfoOp = {
op: WalletApiOperation.GetCurrencyInfo; op: WalletApiOperation.GetScopedCurrencyInfo;
request: GetCurrencyInfoRequest; request: GetCurrencyInfoRequest;
response: GetCurrencyInfoResponse; response: GetCurrencyInfoResponse;
}; };
@ -1081,7 +1081,7 @@ export type WalletOperations = {
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
[WalletApiOperation.ValidateIban]: ValidateIbanOp; [WalletApiOperation.ValidateIban]: ValidateIbanOp;
[WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal; [WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal;
[WalletApiOperation.GetCurrencyInfo]: GetCurrencyInfoOp; [WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp;
}; };
export type WalletCoreRequestType< export type WalletCoreRequestType<

View File

@ -119,6 +119,7 @@ import {
validateIban, validateIban,
codecForSharePaymentRequest, codecForSharePaymentRequest,
GetCurrencyInfoResponse, GetCurrencyInfoResponse,
codecForGetCurrencyInfoRequest,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { import {
HttpRequestLibrary, HttpRequestLibrary,
@ -1396,7 +1397,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
const resp = await getBackupRecovery(ws); const resp = await getBackupRecovery(ws);
return resp; 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 = { const resp: GetCurrencyInfoResponse = {
decimalSeparator: ",", decimalSeparator: ",",
isCurrencyNameLeading: false, isCurrencyNameLeading: false,