wallet-core: skeleton for dev-experiments
This commit is contained in:
parent
8bfa77200e
commit
3da1e82a24
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -21,7 +21,6 @@
|
|||||||
// Defines whether an open brace is put onto a new line for control blocks or not
|
// Defines whether an open brace is put onto a new line for control blocks or not
|
||||||
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
|
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
|
||||||
"typescript.preferences.autoImportFileExcludePatterns": [
|
"typescript.preferences.autoImportFileExcludePatterns": [
|
||||||
"index.js",
|
|
||||||
"index.*.js",
|
"index.*.js",
|
||||||
"index.ts",
|
"index.ts",
|
||||||
"index.*.ts"
|
"index.*.ts"
|
||||||
|
@ -50,6 +50,10 @@ export interface PayPullUriResult {
|
|||||||
contractPriv: string;
|
contractPriv: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DevExperimentUri {
|
||||||
|
devExperimentId: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a taler[+http]://withdraw URI.
|
* Parse a taler[+http]://withdraw URI.
|
||||||
* Return undefined if not passed a valid URI.
|
* Return undefined if not passed a valid URI.
|
||||||
@ -91,6 +95,7 @@ export enum TalerUriType {
|
|||||||
TalerNotifyReserve = "taler-notify-reserve",
|
TalerNotifyReserve = "taler-notify-reserve",
|
||||||
TalerPayPush = "taler-pay-push",
|
TalerPayPush = "taler-pay-push",
|
||||||
TalerPayPull = "taler-pay-pull",
|
TalerPayPull = "taler-pay-pull",
|
||||||
|
TalerDevExperiment = "taler-dev-experiment",
|
||||||
Unknown = "unknown",
|
Unknown = "unknown",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +146,9 @@ export function classifyTalerUri(s: string): TalerUriType {
|
|||||||
if (sl.startsWith("taler://notify-reserve/")) {
|
if (sl.startsWith("taler://notify-reserve/")) {
|
||||||
return TalerUriType.TalerNotifyReserve;
|
return TalerUriType.TalerNotifyReserve;
|
||||||
}
|
}
|
||||||
|
if (sl.startsWith("taler://dev-experiment/")) {
|
||||||
|
return TalerUriType.TalerDevExperiment;
|
||||||
|
}
|
||||||
return TalerUriType.Unknown;
|
return TalerUriType.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,6 +308,19 @@ export function parseRefundUri(s: string): RefundUriResult | undefined {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseDevExperimentUri(s: string): DevExperimentUri | undefined {
|
||||||
|
const pi = parseProtoInfo(s, "dev-experiment");
|
||||||
|
const c = pi?.rest.split("?");
|
||||||
|
if (!c) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
// const q = new URLSearchParams(c[1] ?? "");
|
||||||
|
const parts = c[0].split("/");
|
||||||
|
return {
|
||||||
|
devExperimentId: parts[0],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function constructPayPushUri(args: {
|
export function constructPayPushUri(args: {
|
||||||
exchangeBaseUrl: string;
|
exchangeBaseUrl: string;
|
||||||
contractPriv: string;
|
contractPriv: string;
|
||||||
|
@ -1683,6 +1683,16 @@ export interface AcceptPeerPullPaymentRequest {
|
|||||||
peerPullPaymentIncomingId: string;
|
peerPullPaymentIncomingId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApplyDevExperimentRequest {
|
||||||
|
devExperimentUri: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const codecForApplyDevExperiment =
|
||||||
|
(): Codec<ApplyDevExperimentRequest> =>
|
||||||
|
buildCodecForObject<ApplyDevExperimentRequest>()
|
||||||
|
.property("devExperimentUri", codecForString())
|
||||||
|
.build("ApplyDevExperimentRequest");
|
||||||
|
|
||||||
export const codecForAcceptPeerPullPaymentRequest =
|
export const codecForAcceptPeerPullPaymentRequest =
|
||||||
(): Codec<AcceptPeerPullPaymentRequest> =>
|
(): Codec<AcceptPeerPullPaymentRequest> =>
|
||||||
buildCodecForObject<AcceptPeerPullPaymentRequest>()
|
buildCodecForObject<AcceptPeerPullPaymentRequest>()
|
||||||
|
@ -43,6 +43,7 @@ import {
|
|||||||
setDangerousTimetravel,
|
setDangerousTimetravel,
|
||||||
setGlobalLogLevelFromString,
|
setGlobalLogLevelFromString,
|
||||||
TalerUriType,
|
TalerUriType,
|
||||||
|
parseDevExperimentUri,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
CryptoDispatcher,
|
CryptoDispatcher,
|
||||||
@ -67,6 +68,7 @@ import { runEnv1 } from "./env1.js";
|
|||||||
import { GlobalTestState, runTestWithState } from "./harness/harness.js";
|
import { GlobalTestState, runTestWithState } from "./harness/harness.js";
|
||||||
import { getTestInfo, runTests } from "./integrationtests/testrunner.js";
|
import { getTestInfo, runTests } from "./integrationtests/testrunner.js";
|
||||||
import { lintExchangeDeployment } from "./lint.js";
|
import { lintExchangeDeployment } from "./lint.js";
|
||||||
|
import { checkLogicInvariant } from "@gnu-taler/taler-wallet-core/src/util/invariants.js";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
global.TextEncoder = TextEncoder;
|
global.TextEncoder = TextEncoder;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -498,6 +500,12 @@ walletCli
|
|||||||
console.log("accept withdrawal response", res);
|
console.log("accept withdrawal response", res);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TalerUriType.TalerDevExperiment: {
|
||||||
|
await wallet.client.call(WalletApiOperation.ApplyDevExperiment, {
|
||||||
|
devExperimentUri: uri,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
console.log(`URI type (${uriType}) not handled`);
|
console.log(`URI type (${uriType}) not handled`);
|
||||||
break;
|
break;
|
||||||
|
38
packages/taler-wallet-core/src/dev-experiments.ts
Normal file
38
packages/taler-wallet-core/src/dev-experiments.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
This file is part of GNU Taler
|
||||||
|
(C) 2022 Taler Systems SA
|
||||||
|
|
||||||
|
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
|
||||||
|
Foundation; either version 3, or (at your option) any later version.
|
||||||
|
|
||||||
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of dev experiments, i.e. scenarios
|
||||||
|
* triggered by taler://dev-experiment URIs.
|
||||||
|
*
|
||||||
|
* @author Florian Dold <dold@taler.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Logger } from "@gnu-taler/taler-util";
|
||||||
|
import { InternalWalletState } from "./internal-wallet-state.js";
|
||||||
|
|
||||||
|
const logger = new Logger("dev-experiments.ts");
|
||||||
|
|
||||||
|
export async function applyDevExperiment(
|
||||||
|
ws: InternalWalletState,
|
||||||
|
uri: string,
|
||||||
|
): Promise<void> {
|
||||||
|
logger.info(`applying dev experiment ${uri}`);
|
||||||
|
}
|
@ -80,6 +80,7 @@ import {
|
|||||||
WithdrawTestBalanceRequest,
|
WithdrawTestBalanceRequest,
|
||||||
WithdrawUriInfoResponse,
|
WithdrawUriInfoResponse,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
|
import { ApplyDevExperimentRequest } from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
AddBackupProviderRequest,
|
AddBackupProviderRequest,
|
||||||
BackupInfo,
|
BackupInfo,
|
||||||
@ -139,6 +140,7 @@ export enum WalletApiOperation {
|
|||||||
AcceptPeerPullPayment = "acceptPeerPullPayment",
|
AcceptPeerPullPayment = "acceptPeerPullPayment",
|
||||||
ClearDb = "clearDb",
|
ClearDb = "clearDb",
|
||||||
Recycle = "recycle",
|
Recycle = "recycle",
|
||||||
|
ApplyDevExperiment = "applyDevExperiment",
|
||||||
}
|
}
|
||||||
|
|
||||||
// group: Initialization
|
// group: Initialization
|
||||||
@ -487,7 +489,7 @@ export type AcceptPeerPullPaymentOp = {
|
|||||||
// group: Database Management
|
// group: Database Management
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exoport the wallet database's contents to JSON.
|
* Export the wallet database's contents to JSON.
|
||||||
*/
|
*/
|
||||||
export type ExportDbOp = {
|
export type ExportDbOp = {
|
||||||
op: WalletApiOperation.ExportDb;
|
op: WalletApiOperation.ExportDb;
|
||||||
@ -515,6 +517,18 @@ export type RecycleOp = {
|
|||||||
|
|
||||||
// group: Testing and Debugging
|
// group: Testing and Debugging
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a developer experiment to the current wallet state.
|
||||||
|
*
|
||||||
|
* This allows UI developers / testers to play around without
|
||||||
|
* an elaborate test environment.
|
||||||
|
*/
|
||||||
|
export type ApplyDevExperimentOp = {
|
||||||
|
op: WalletApiOperation.ApplyDevExperiment;
|
||||||
|
request: ApplyDevExperimentRequest;
|
||||||
|
response: {};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a simple integration test on a test deployment
|
* Run a simple integration test on a test deployment
|
||||||
* of the exchange and merchant.
|
* of the exchange and merchant.
|
||||||
@ -661,6 +675,7 @@ export type WalletOperations = {
|
|||||||
[WalletApiOperation.AcceptPeerPullPayment]: AcceptPeerPullPaymentOp;
|
[WalletApiOperation.AcceptPeerPullPayment]: AcceptPeerPullPaymentOp;
|
||||||
[WalletApiOperation.ClearDb]: ClearDbOp;
|
[WalletApiOperation.ClearDb]: ClearDbOp;
|
||||||
[WalletApiOperation.Recycle]: RecycleOp;
|
[WalletApiOperation.Recycle]: RecycleOp;
|
||||||
|
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RequestType<
|
export type RequestType<
|
||||||
|
@ -90,6 +90,7 @@ import {
|
|||||||
parsePaytoUri,
|
parsePaytoUri,
|
||||||
RefreshReason,
|
RefreshReason,
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
|
codecForApplyDevExperiment,
|
||||||
URL,
|
URL,
|
||||||
WalletCoreVersion,
|
WalletCoreVersion,
|
||||||
WalletNotification,
|
WalletNotification,
|
||||||
@ -109,6 +110,7 @@ import {
|
|||||||
importDb,
|
importDb,
|
||||||
WalletStoresV1,
|
WalletStoresV1,
|
||||||
} from "./db.js";
|
} from "./db.js";
|
||||||
|
import { applyDevExperiment } from "./dev-experiments.js";
|
||||||
import { getErrorDetailFromException, TalerError } from "./errors.js";
|
import { getErrorDetailFromException, TalerError } from "./errors.js";
|
||||||
import {
|
import {
|
||||||
ActiveLongpollInfo,
|
ActiveLongpollInfo,
|
||||||
@ -1325,6 +1327,11 @@ async function dispatchRequestInternal(
|
|||||||
const req = codecForAcceptPeerPullPaymentRequest().decode(payload);
|
const req = codecForAcceptPeerPullPaymentRequest().decode(payload);
|
||||||
return await acceptPeerPullPayment(ws, req);
|
return await acceptPeerPullPayment(ws, req);
|
||||||
}
|
}
|
||||||
|
case "applyDevExperiment": {
|
||||||
|
const req = codecForApplyDevExperiment().decode(payload);
|
||||||
|
await applyDevExperiment(ws, req.devExperimentUri);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
case "getVersion": {
|
case "getVersion": {
|
||||||
const version: WalletCoreVersion = {
|
const version: WalletCoreVersion = {
|
||||||
hash: GIT_HASH,
|
hash: GIT_HASH,
|
||||||
|
Loading…
Reference in New Issue
Block a user