aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-09-07 15:54:22 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-09-07 15:54:22 +0530
commitbe77ee284a819f7932831bd85e88c47c655addb2 (patch)
treee0e57cdc9a2889a16c6640f1e2346df85054409e /packages
parentd0088323ce02c6cc2cbe1413eddb0b81f3f147f2 (diff)
dynamic pay request timeout
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-integrationtests/src/harness.ts24
-rw-r--r--packages/taler-wallet-core/src/operations/pay.ts8
-rw-r--r--packages/taler-wallet-core/src/util/time.ts7
3 files changed, 36 insertions, 3 deletions
diff --git a/packages/taler-integrationtests/src/harness.ts b/packages/taler-integrationtests/src/harness.ts
index 90a618e17..620b89e76 100644
--- a/packages/taler-integrationtests/src/harness.ts
+++ b/packages/taler-integrationtests/src/harness.ts
@@ -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 {
diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts
index 6452a11ae..50f863e48 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -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),
}),
);
diff --git a/packages/taler-wallet-core/src/util/time.ts b/packages/taler-wallet-core/src/util/time.ts
index 5a5e9c608..be63aef6b 100644
--- a/packages/taler-wallet-core/src/util/time.ts
+++ b/packages/taler-wallet-core/src/util/time.ts
@@ -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") {