wallet-core: only allow enabling dev mode via separate request
This commit is contained in:
parent
83d4a1addc
commit
ca8da4ed38
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -20,11 +20,6 @@
|
||||
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
|
||||
// Defines whether an open brace is put onto a new line for control blocks or not
|
||||
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
|
||||
"typescript.preferences.autoImportFileExcludePatterns": [
|
||||
"index.*.js",
|
||||
"index.ts",
|
||||
"index.*.ts"
|
||||
],
|
||||
// Files hidden in the explorer
|
||||
"files.exclude": {
|
||||
// include the defaults from VS Code
|
||||
|
@ -1684,6 +1684,15 @@ export interface AcceptPeerPullPaymentRequest {
|
||||
peerPullPaymentIncomingId: string;
|
||||
}
|
||||
|
||||
export interface SetDevModeRequest {
|
||||
devModeEnabled: boolean;
|
||||
}
|
||||
|
||||
export const codecForSetDevModeRequest = (): Codec<SetDevModeRequest> =>
|
||||
buildCodecForObject<SetDevModeRequest>()
|
||||
.property("devModeEnabled", codecForBoolean())
|
||||
.build("SetDevModeRequest");
|
||||
|
||||
export interface ApplyDevExperimentRequest {
|
||||
devExperimentUri: string;
|
||||
}
|
||||
|
@ -1018,6 +1018,30 @@ advancedCli
|
||||
});
|
||||
});
|
||||
|
||||
advancedCli
|
||||
.subcommand("enableDevMode", "enable-dev-mode", {
|
||||
help: "Enable developer mode (dangerous!)",
|
||||
})
|
||||
.action(async (args) => {
|
||||
await withWallet(args, async (wallet) => {
|
||||
await wallet.client.call(WalletApiOperation.SetDevMode, {
|
||||
devModeEnabled: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
advancedCli
|
||||
.subcommand("disableDevMode", "disable-dev-mode", {
|
||||
help: "Disable developer mode",
|
||||
})
|
||||
.action(async (args) => {
|
||||
await withWallet(args, async (wallet) => {
|
||||
await wallet.client.call(WalletApiOperation.SetDevMode, {
|
||||
devModeEnabled: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const coinPubListCodec = codecForList(codecForString());
|
||||
|
||||
advancedCli
|
||||
|
@ -36,6 +36,35 @@ import {
|
||||
|
||||
const logger = new Logger("dev-experiments.ts");
|
||||
|
||||
export async function setDevMode(
|
||||
ws: InternalWalletState,
|
||||
enabled: boolean,
|
||||
): Promise<void> {
|
||||
if (enabled) {
|
||||
logger.info("enabling devmode");
|
||||
await ws.db
|
||||
.mktx((x) => [x.config])
|
||||
.runReadWrite(async (tx) => {
|
||||
tx.config.put({
|
||||
key: ConfigRecordKey.DevMode,
|
||||
value: true,
|
||||
});
|
||||
});
|
||||
await maybeInitDevMode(ws);
|
||||
} else {
|
||||
logger.info("disabling devmode");
|
||||
await ws.db
|
||||
.mktx((x) => [x.config])
|
||||
.runReadWrite(async (tx) => {
|
||||
tx.config.put({
|
||||
key: ConfigRecordKey.DevMode,
|
||||
value: false,
|
||||
});
|
||||
});
|
||||
await leaveDevMode(ws);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a dev experiment to the wallet database / state.
|
||||
*/
|
||||
@ -49,32 +78,6 @@ export async function applyDevExperiment(
|
||||
logger.info("unable to parse dev experiment URI");
|
||||
return;
|
||||
}
|
||||
if (parsedUri.devExperimentId == "enable-devmode") {
|
||||
logger.info("enabling devmode");
|
||||
await ws.db
|
||||
.mktx((x) => [x.config])
|
||||
.runReadWrite(async (tx) => {
|
||||
tx.config.put({
|
||||
key: ConfigRecordKey.DevMode,
|
||||
value: true,
|
||||
});
|
||||
});
|
||||
await maybeInitDevMode(ws);
|
||||
return;
|
||||
}
|
||||
if (parsedUri.devExperimentId === "disable-devmode") {
|
||||
logger.info("disabling devmode");
|
||||
await ws.db
|
||||
.mktx((x) => [x.config])
|
||||
.runReadWrite(async (tx) => {
|
||||
tx.config.put({
|
||||
key: ConfigRecordKey.DevMode,
|
||||
value: false,
|
||||
});
|
||||
});
|
||||
await leaveDevMode(ws);
|
||||
return;
|
||||
}
|
||||
if (!ws.devModeActive) {
|
||||
throw Error(
|
||||
"can't handle devmode URI (other than enable-devmode) unless devmode is active",
|
||||
|
@ -67,6 +67,7 @@ import {
|
||||
RecoveryLoadRequest,
|
||||
RetryTransactionRequest,
|
||||
SetCoinSuspendedRequest,
|
||||
SetDevModeRequest,
|
||||
SetWalletDeviceIdRequest,
|
||||
TestPayArgs,
|
||||
TestPayResult,
|
||||
@ -140,6 +141,7 @@ export enum WalletApiOperation {
|
||||
AcceptPeerPullPayment = "acceptPeerPullPayment",
|
||||
ClearDb = "clearDb",
|
||||
Recycle = "recycle",
|
||||
SetDevMode = "setDevMode",
|
||||
ApplyDevExperiment = "applyDevExperiment",
|
||||
}
|
||||
|
||||
@ -529,6 +531,12 @@ export type ApplyDevExperimentOp = {
|
||||
response: {};
|
||||
};
|
||||
|
||||
export type SetDevModeOp = {
|
||||
op: WalletApiOperation.SetDevMode;
|
||||
request: SetDevModeRequest;
|
||||
response: {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Run a simple integration test on a test deployment
|
||||
* of the exchange and merchant.
|
||||
@ -676,6 +684,7 @@ export type WalletOperations = {
|
||||
[WalletApiOperation.ClearDb]: ClearDbOp;
|
||||
[WalletApiOperation.Recycle]: RecycleOp;
|
||||
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
|
||||
[WalletApiOperation.SetDevMode]: SetDevModeOp;
|
||||
};
|
||||
|
||||
export type RequestType<
|
||||
|
@ -94,6 +94,7 @@ import {
|
||||
URL,
|
||||
WalletCoreVersion,
|
||||
WalletNotification,
|
||||
codecForSetDevModeRequest,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
|
||||
import {
|
||||
@ -111,7 +112,7 @@ import {
|
||||
importDb,
|
||||
WalletStoresV1,
|
||||
} from "./db.js";
|
||||
import { applyDevExperiment, maybeInitDevMode } from "./dev-experiments.js";
|
||||
import { applyDevExperiment, maybeInitDevMode, setDevMode } from "./dev-experiments.js";
|
||||
import { getErrorDetailFromException, TalerError } from "./errors.js";
|
||||
import {
|
||||
ActiveLongpollInfo,
|
||||
@ -1334,6 +1335,11 @@ async function dispatchRequestInternal(
|
||||
await applyDevExperiment(ws, req.devExperimentUri);
|
||||
return {};
|
||||
}
|
||||
case "setDevMode": {
|
||||
const req = codecForSetDevModeRequest().decode(payload);
|
||||
await setDevMode(ws, req.devModeEnabled);
|
||||
return {};
|
||||
}
|
||||
case "getVersion": {
|
||||
const version: WalletCoreVersion = {
|
||||
hash: GIT_HASH,
|
||||
|
@ -92,29 +92,21 @@ importers:
|
||||
|
||||
packages/idb-bridge:
|
||||
specifiers:
|
||||
'@rollup/plugin-commonjs': ^22.0.2
|
||||
'@rollup/plugin-json': ^4.1.0
|
||||
'@rollup/plugin-node-resolve': ^13.3.0
|
||||
'@types/node': ^18.8.5
|
||||
ava: ^4.3.3
|
||||
esm: ^3.2.25
|
||||
prettier: ^2.5.1
|
||||
rimraf: ^3.0.2
|
||||
rollup: ^2.79.0
|
||||
tslib: ^2.4.0
|
||||
typescript: ^4.8.4
|
||||
dependencies:
|
||||
tslib: 2.4.0
|
||||
devDependencies:
|
||||
'@rollup/plugin-commonjs': 22.0.2_rollup@2.79.0
|
||||
'@rollup/plugin-json': 4.1.0_rollup@2.79.0
|
||||
'@rollup/plugin-node-resolve': 13.3.0_rollup@2.79.0
|
||||
'@types/node': 18.8.5
|
||||
ava: 4.3.3
|
||||
esm: 3.2.25
|
||||
prettier: 2.5.1
|
||||
rimraf: 3.0.2
|
||||
rollup: 2.79.0
|
||||
typescript: 4.8.4
|
||||
|
||||
packages/pogen:
|
||||
@ -130,29 +122,6 @@ importers:
|
||||
po2json: 0.4.5
|
||||
typescript: 4.8.4
|
||||
|
||||
packages/taler-config-lib:
|
||||
specifiers:
|
||||
'@types/node': ^18.8.5
|
||||
ava: ^4.3.3
|
||||
big-integer: ^1.6.51
|
||||
esbuild: ^0.14.21
|
||||
jed: ^1.1.1
|
||||
prettier: ^2.5.1
|
||||
rimraf: ^3.0.2
|
||||
tslib: ^2.4.0
|
||||
typescript: ^4.8.4
|
||||
dependencies:
|
||||
big-integer: 1.6.51
|
||||
jed: 1.1.1
|
||||
tslib: 2.4.0
|
||||
devDependencies:
|
||||
'@types/node': 18.8.5
|
||||
ava: 4.3.3
|
||||
esbuild: 0.14.21
|
||||
prettier: 2.5.1
|
||||
rimraf: 3.0.2
|
||||
typescript: 4.8.4
|
||||
|
||||
packages/taler-util:
|
||||
specifiers:
|
||||
'@types/node': ^18.8.5
|
||||
@ -241,8 +210,6 @@ importers:
|
||||
po2json: ^0.4.5
|
||||
prettier: ^2.5.1
|
||||
rimraf: ^3.0.2
|
||||
rollup: ^2.79.0
|
||||
rollup-plugin-sourcemaps: ^0.6.3
|
||||
source-map-resolve: ^0.6.0
|
||||
source-map-support: ^0.5.21
|
||||
tslib: ^2.4.0
|
||||
@ -274,8 +241,6 @@ importers:
|
||||
po2json: 0.4.5
|
||||
prettier: 2.5.1
|
||||
rimraf: 3.0.2
|
||||
rollup: 2.79.0
|
||||
rollup-plugin-sourcemaps: 0.6.3_n3h7ooyjwm4phuvjpg4pqirc4i
|
||||
source-map-resolve: 0.6.0
|
||||
typedoc: 0.23.16_typescript@4.8.4
|
||||
typescript: 4.8.4
|
||||
|
Loading…
Reference in New Issue
Block a user