dynamic pay request timeout

This commit is contained in:
Florian Dold 2020-09-07 15:54:22 +05:30
parent d0088323ce
commit be77ee284a
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 36 additions and 3 deletions

View File

@ -1215,6 +1215,30 @@ export namespace MerchantPrivateApi {
talerRefundUri: resp.data.taler_refund_uri,
};
}
export async function createTippingReserve(merchantService: MerchantServiceInterface,
req: CreateMerchantTippingReserveRequest,
): Promise<CreateMerchantTippingReserveConfirmation> {}
}
export interface CreateMerchantTippingReserveRequest {
// Amount that the merchant promises to put into the reserve
initial_balance: AmountString;
// Exchange the merchant intends to use for tipping
exchange_url: string;
// Desired wire method, for example "iban" or "x-taler-bank"
wire_method: string;
}
export interface CreateMerchantTippingReserveConfirmation {
// Public key identifying the reserve
reserve_pub: string;
// Wire account of the exchange where to transfer the funds
payto_url: string;
}
export class MerchantService implements MerchantServiceInterface {

View File

@ -68,6 +68,8 @@ import {
durationMax,
durationMin,
isTimestampExpired,
durationMul,
durationAdd,
} from "../util/time";
import { strcmp, canonicalJson } from "../util/helpers";
import {
@ -614,8 +616,8 @@ function getProposalRequestTimeout(proposal: ProposalRecord): Duration {
);
}
function getPurchaseRequestTimeout(purchase: PurchaseRecord): Duration {
return { d_ms: 5000 };
function getPayRequestTimeout(purchase: PurchaseRecord): Duration {
return durationMul({ d_ms: 5000 }, 1 + purchase.payCoinSelection.coinPubs.length / 20);
}
async function processDownloadProposalImpl(
@ -936,7 +938,7 @@ export async function submitPay(
const resp = await ws.runSequentialized([EXCHANGE_COINS_LOCK], () =>
ws.http.postJson(payUrl, reqBody, {
timeout: getPurchaseRequestTimeout(purchase),
timeout: getPayRequestTimeout(purchase),
}),
);

View File

@ -151,6 +151,13 @@ export function durationMul(d: Duration, n: number): Duration {
return { d_ms: Math.round(d.d_ms * n) };
}
export function durationAdd(d1: Duration, d2: Duration): Duration {
if (d1.d_ms === "forever" || d2.d_ms === "forever") {
return { d_ms: "forever" };
}
return { d_ms: d1.d_ms + d2.d_ms };
}
export function timestampCmp(t1: Timestamp, t2: Timestamp): number {
if (t1.t_ms === "never") {
if (t2.t_ms === "never") {