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

View File

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

View File

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

View File

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