wallet-core: rename ops with support for old names

This commit is contained in:
Florian Dold 2023-02-20 01:44:28 +01:00
parent fddc6eb4f2
commit 803d1bf7a7
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 53 additions and 37 deletions

View File

@ -2044,7 +2044,7 @@ export interface CheckPeerPushDebitRequest {
amount: AmountString; amount: AmountString;
} }
export const codecForPreparePeerPushPaymentRequest = export const codecForCheckPeerPushDebitRequest =
(): Codec<CheckPeerPushDebitRequest> => (): Codec<CheckPeerPushDebitRequest> =>
buildCodecForObject<CheckPeerPushDebitRequest>() buildCodecForObject<CheckPeerPushDebitRequest>()
.property("exchangeBaseUrl", codecOptional(codecForString())) .property("exchangeBaseUrl", codecOptional(codecForString()))
@ -2076,7 +2076,7 @@ export const codecForInitiatePeerPushPaymentRequest =
.property("partialContractTerms", codecForPeerContractTerms()) .property("partialContractTerms", codecForPeerContractTerms())
.build("InitiatePeerPushPaymentRequest"); .build("InitiatePeerPushPaymentRequest");
export interface CheckPeerPushPaymentRequest { export interface PreparePeerPushCredit {
talerUri: string; talerUri: string;
} }
@ -2103,9 +2103,9 @@ export interface PreparePeerPullDebitResponse {
peerPullPaymentIncomingId: string; peerPullPaymentIncomingId: string;
} }
export const codecForCheckPeerPushPaymentRequest = export const codecForPreparePeerPushCreditRequest =
(): Codec<CheckPeerPushPaymentRequest> => (): Codec<PreparePeerPushCredit> =>
buildCodecForObject<CheckPeerPushPaymentRequest>() buildCodecForObject<PreparePeerPushCredit>()
.property("talerUri", codecForString()) .property("talerUri", codecForString())
.build("CheckPeerPushPaymentRequest"); .build("CheckPeerPushPaymentRequest");

View File

@ -30,7 +30,7 @@ import {
buildCodecForObject, buildCodecForObject,
PreparePeerPullDebitRequest, PreparePeerPullDebitRequest,
PreparePeerPullDebitResponse, PreparePeerPullDebitResponse,
CheckPeerPushPaymentRequest, PreparePeerPushCredit,
CheckPeerPushPaymentResponse, CheckPeerPushPaymentResponse,
Codec, Codec,
codecForAmountString, codecForAmountString,
@ -387,7 +387,7 @@ export async function getTotalPeerPaymentCost(
}); });
} }
export async function preparePeerPushPayment( export async function checkPeerPushDebit(
ws: InternalWalletState, ws: InternalWalletState,
req: CheckPeerPushDebitRequest, req: CheckPeerPushDebitRequest,
): Promise<CheckPeerPushDebitResponse> { ): Promise<CheckPeerPushDebitResponse> {
@ -622,7 +622,7 @@ export const codecForExchangePurseStatus = (): Codec<ExchangePurseStatus> =>
export async function preparePeerPushCredit( export async function preparePeerPushCredit(
ws: InternalWalletState, ws: InternalWalletState,
req: CheckPeerPushPaymentRequest, req: PreparePeerPushCredit,
): Promise<CheckPeerPushPaymentResponse> { ): Promise<CheckPeerPushPaymentResponse> {
const uri = parsePayPushUri(req.talerUri); const uri = parsePayPushUri(req.talerUri);
@ -898,7 +898,7 @@ export async function processPeerPushCredit(
}; };
} }
export async function acceptPeerPushPayment( export async function confirmPeerPushPayment(
ws: InternalWalletState, ws: InternalWalletState,
req: ConfirmPeerPushCreditRequest, req: ConfirmPeerPushCreditRequest,
): Promise<AcceptPeerPushPaymentResponse> { ): Promise<AcceptPeerPushPaymentResponse> {

View File

@ -44,7 +44,7 @@ import {
BalancesResponse, BalancesResponse,
PreparePeerPullDebitRequest, PreparePeerPullDebitRequest,
PreparePeerPullDebitResponse, PreparePeerPullDebitResponse,
CheckPeerPushPaymentRequest, PreparePeerPushCredit,
CheckPeerPushPaymentResponse, CheckPeerPushPaymentResponse,
CoinDumpJson, CoinDumpJson,
ConfirmPayRequest, ConfirmPayRequest,
@ -183,22 +183,14 @@ export enum WalletApiOperation {
WithdrawFakebank = "withdrawFakebank", WithdrawFakebank = "withdrawFakebank",
ImportDb = "importDb", ImportDb = "importDb",
ExportDb = "exportDb", ExportDb = "exportDb",
// FIXME: Also rename enum value PreparePeerPushCredit = "preparePeerPushCredit",
CheckPeerPushDebit = "preparePeerPushPayment", CheckPeerPushDebit = "checkPeerPushDebit",
// FIXME: Also rename enum value InitiatePeerPushDebit = "initiatePeerPushDebit",
InitiatePeerPushDebit = "initiatePeerPushPayment", ConfirmPeerPushCredit = "confirmPeerPushCredit",
// FIXME: Also rename enum value CheckPeerPullCredit = "checkPeerPullCredit",
PreparePeerPushCredit = "checkPeerPushPayment", InitiatePeerPullCredit = "initiatePeerPullCredit",
// FIXME: Also rename enum value PreparePeerPullDebit = "preparePeerPullDebit",
ConfirmPeerPushCredit = "acceptPeerPushPayment", ConfirmPeerPullDebit = "confirmPeerPullDebit",
// FIXME: Also rename enum value
CheckPeerPullCredit = "preparePeerPullPayment",
// FIXME: Also rename enum value
InitiatePeerPullCredit = "initiatePeerPullPayment",
// FIXME: Also rename enum value
PreparePeerPullDebit = "checkPeerPullPayment",
// FIXME: Also rename enum value
ConfirmPeerPullDebit = "acceptPeerPullPayment",
ClearDb = "clearDb", ClearDb = "clearDb",
Recycle = "recycle", Recycle = "recycle",
SetDevMode = "setDevMode", SetDevMode = "setDevMode",
@ -622,7 +614,7 @@ export type InitiatePeerPushDebitOp = {
*/ */
export type PreparePeerPushCreditOp = { export type PreparePeerPushCreditOp = {
op: WalletApiOperation.PreparePeerPushCredit; op: WalletApiOperation.PreparePeerPushCredit;
request: CheckPeerPushPaymentRequest; request: PreparePeerPushCredit;
response: CheckPeerPushPaymentResponse; response: CheckPeerPushPaymentResponse;
}; };

View File

@ -30,7 +30,7 @@ import {
codecForAcceptExchangeTosRequest, codecForAcceptExchangeTosRequest,
codecForAcceptManualWithdrawalRequet, codecForAcceptManualWithdrawalRequet,
codecForAcceptPeerPullPaymentRequest, codecForAcceptPeerPullPaymentRequest,
codecForAcceptPeerPushPaymentRequest, codecForAcceptPeerPushPaymentRequest as codecForConfirmPeerPushPaymentRequest,
codecForAcceptTipRequest, codecForAcceptTipRequest,
codecForAddExchangeRequest, codecForAddExchangeRequest,
codecForAddKnownBankAccounts, codecForAddKnownBankAccounts,
@ -39,7 +39,7 @@ import {
codecForApplyRefundFromPurchaseIdRequest, codecForApplyRefundFromPurchaseIdRequest,
codecForApplyRefundRequest, codecForApplyRefundRequest,
codecForCheckPeerPullPaymentRequest, codecForCheckPeerPullPaymentRequest,
codecForCheckPeerPushPaymentRequest, codecForPreparePeerPushCreditRequest,
codecForConfirmPayRequest, codecForConfirmPayRequest,
codecForCreateDepositGroupRequest, codecForCreateDepositGroupRequest,
codecForDeleteTransactionRequest, codecForDeleteTransactionRequest,
@ -61,7 +61,7 @@ import {
codecForPreparePayRequest, codecForPreparePayRequest,
codecForPreparePayTemplateRequest, codecForPreparePayTemplateRequest,
codecForPreparePeerPullPaymentRequest, codecForPreparePeerPullPaymentRequest,
codecForPreparePeerPushPaymentRequest, codecForCheckPeerPushDebitRequest,
codecForPrepareRefundRequest, codecForPrepareRefundRequest,
codecForPrepareTipRequest, codecForPrepareTipRequest,
codecForRetryTransactionRequest, codecForRetryTransactionRequest,
@ -196,13 +196,13 @@ import {
} from "./operations/pay-merchant.js"; } from "./operations/pay-merchant.js";
import { import {
acceptIncomingPeerPullPayment, acceptIncomingPeerPullPayment,
acceptPeerPushPayment, confirmPeerPushPayment,
preparePeerPullCredit, preparePeerPullCredit,
preparePeerPushCredit, preparePeerPushCredit,
initiatePeerPullPayment, initiatePeerPullPayment,
initiatePeerPushPayment, initiatePeerPushPayment,
checkPeerPullPaymentInitiation, checkPeerPullPaymentInitiation,
preparePeerPushPayment, checkPeerPushDebit,
processPeerPullCredit, processPeerPullCredit,
processPeerPushInitiation, processPeerPushInitiation,
processPeerPullDebit, processPeerPullDebit,
@ -1428,21 +1428,25 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
await importDb(ws.db.idbHandle(), req.dump); await importDb(ws.db.idbHandle(), req.dump);
return []; return [];
} }
case WalletApiOperation.CheckPeerPushDebit: {
const req = codecForCheckPeerPushDebitRequest().decode(payload);
return await checkPeerPushDebit(ws, req);
}
case WalletApiOperation.PreparePeerPushCredit: { case WalletApiOperation.PreparePeerPushCredit: {
const req = codecForPreparePeerPushPaymentRequest().decode(payload); const req = codecForPreparePeerPushCreditRequest().decode(payload);
return await preparePeerPushPayment(ws, req); return await preparePeerPushCredit(ws, req);
} }
case WalletApiOperation.InitiatePeerPushDebit: { case WalletApiOperation.InitiatePeerPushDebit: {
const req = codecForInitiatePeerPushPaymentRequest().decode(payload); const req = codecForInitiatePeerPushPaymentRequest().decode(payload);
return await initiatePeerPushPayment(ws, req); return await initiatePeerPushPayment(ws, req);
} }
case WalletApiOperation.PreparePeerPushCredit: { case WalletApiOperation.PreparePeerPushCredit: {
const req = codecForCheckPeerPushPaymentRequest().decode(payload); const req = codecForPreparePeerPushCreditRequest().decode(payload);
return await preparePeerPushCredit(ws, req); return await preparePeerPushCredit(ws, req);
} }
case WalletApiOperation.ConfirmPeerPushCredit: { case WalletApiOperation.ConfirmPeerPushCredit: {
const req = codecForAcceptPeerPushPaymentRequest().decode(payload); const req = codecForConfirmPeerPushPaymentRequest().decode(payload);
return await acceptPeerPushPayment(ws, req); return await confirmPeerPushPayment(ws, req);
} }
case WalletApiOperation.CheckPeerPullCredit: { case WalletApiOperation.CheckPeerPullCredit: {
const req = codecForPreparePeerPullPaymentRequest().decode(payload); const req = codecForPreparePeerPullPaymentRequest().decode(payload);
@ -1497,6 +1501,24 @@ export function getVersion(ws: InternalWalletState): WalletCoreVersion {
return version; return version;
} }
function translateLegacyOperationNames(operation: string): string {
switch (operation) {
case "initiatePeerPullPayment":
return WalletApiOperation.InitiatePeerPullCredit.toString();
case "initiatePeerPushPayment":
return WalletApiOperation.InitiatePeerPushDebit.toString();
case "checkPeerPullPayment":
return WalletApiOperation.PreparePeerPullDebit.toString();
case "acceptPeerPullPayment":
return WalletApiOperation.ConfirmPeerPullDebit.toString();
case "checkPeerPushPayment":
return WalletApiOperation.PreparePeerPushCredit.toString();
case "acceptPeerPushPayment":
return WalletApiOperation.ConfirmPeerPushCredit.toString();
}
return operation;
}
/** /**
* Handle a request to the wallet-core API. * Handle a request to the wallet-core API.
*/ */
@ -1506,6 +1528,8 @@ export async function handleCoreApiRequest(
id: string, id: string,
payload: unknown, payload: unknown,
): Promise<CoreApiResponse> { ): Promise<CoreApiResponse> {
operation = translateLegacyOperationNames(operation);
try { try {
const result = await dispatchRequestInternal(ws, operation as any, payload); const result = await dispatchRequestInternal(ws, operation as any, payload);
return { return {