aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-12-12 21:24:21 +0100
committerFlorian Dold <florian@dold.me>2023-12-12 21:24:28 +0100
commit387416f02dec4a7f948ba96e918e3cacaf92639e (patch)
tree959fde0a7f8c51c2749251ddff32588907e44f4b /packages/taler-wallet-core/src/util
parentf7e01690b44e42b7088457374a2a8606fd94f84e (diff)
downloadwallet-core-387416f02dec4a7f948ba96e918e3cacaf92639e.tar.gz
wallet-core-387416f02dec4a7f948ba96e918e3cacaf92639e.tar.bz2
wallet-core-387416f02dec4a7f948ba96e918e3cacaf92639e.zip
wallet-core: implement maxExpirationDate for checkPeerPushDebit
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.test.ts7
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts26
2 files changed, 33 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index 69c25a2fa..055c42902 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -19,6 +19,7 @@ import {
Amounts,
DenomKeyType,
Duration,
+ TalerProtocolTimestamp,
j2s,
} from "@gnu-taler/taler-util";
import test, { ExecutionContext } from "ava";
@@ -66,6 +67,8 @@ test("p2p: should select the coin", (t) => {
denomPubHash: "hash0",
maxAge: 32,
contributions: [Amounts.parseOrThrow("LOCAL:2.1")],
+ expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
+ expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
},
});
@@ -106,6 +109,8 @@ test("p2p: should select 3 coins", (t) => {
Amounts.parseOrThrow("LOCAL:9.9"),
Amounts.parseOrThrow("LOCAL:0.5"),
],
+ expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
+ expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
},
});
@@ -192,6 +197,8 @@ test("pay: select one coin to pay with fee", (t) => {
denomPubHash: "hash0",
maxAge: 32,
contributions: [Amounts.parseOrThrow("LOCAL:2.2")],
+ expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
+ expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
},
});
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index 5928cd19b..e3fbffe98 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -51,10 +51,12 @@ import {
PayMerchantInsufficientBalanceDetails,
PayPeerInsufficientBalanceDetails,
strcmp,
+ TalerProtocolTimestamp,
UnblindedSignature,
} from "@gnu-taler/taler-util";
import { DenominationRecord } from "../db.js";
import {
+ getAutoRefreshExecuteThreshold,
getExchangeDetails,
isWithdrawableDenom,
WalletDbReadOnlyTransaction,
@@ -416,6 +418,8 @@ interface SelResult {
[avKey: string]: {
exchangeBaseUrl: string;
denomPubHash: string;
+ expireWithdraw: TalerProtocolTimestamp;
+ expireDeposit: TalerProtocolTimestamp;
maxAge: number;
contributions: AmountJson[];
};
@@ -426,6 +430,7 @@ export function testing_selectGreedy(
): ReturnType<typeof selectGreedy> {
return selectGreedy(...args);
}
+
function selectGreedy(
req: SelectPayCoinRequestNg,
candidateDenoms: AvailableDenom[],
@@ -483,6 +488,8 @@ function selectGreedy(
denomPubHash: denom.denomPubHash,
exchangeBaseUrl: denom.exchangeBaseUrl,
maxAge: denom.maxAge,
+ expireDeposit: denom.stampExpireDeposit,
+ expireWithdraw: denom.stampExpireWithdraw,
};
}
sd.contributions.push(...contributions);
@@ -521,6 +528,8 @@ function selectForced(
denomPubHash: aci.denomPubHash,
exchangeBaseUrl: aci.exchangeBaseUrl,
maxAge: aci.maxAge,
+ expireDeposit: aci.stampExpireDeposit,
+ expireWithdraw: aci.stampExpireWithdraw,
};
}
sd.contributions.push(Amounts.parseOrThrow(forcedCoin.value));
@@ -870,6 +879,8 @@ export interface PeerCoinSelectionDetails {
* How much of the deposit fees is the customer paying?
*/
depositFees: AmountJson;
+
+ maxExpirationDate: TalerProtocolTimestamp;
}
export type SelectPeerCoinsResult =
@@ -1009,6 +1020,8 @@ function greedySelectPeer(
denomPubHash: denom.denomPubHash,
exchangeBaseUrl: denom.exchangeBaseUrl,
maxAge: denom.maxAge,
+ expireDeposit: denom.stampExpireDeposit,
+ expireWithdraw: denom.stampExpireWithdraw,
};
}
sd.contributions.push(...contributions);
@@ -1114,8 +1127,20 @@ export async function selectPeerCoins(
);
if (selectedDenom) {
+ let minAutorefreshExecuteThreshold = TalerProtocolTimestamp.never();
for (const dph of Object.keys(selectedDenom)) {
const selInfo = selectedDenom[dph];
+ // Compute earliest time that a selected denom
+ // would have its coins auto-refreshed.
+ minAutorefreshExecuteThreshold = TalerProtocolTimestamp.min(
+ minAutorefreshExecuteThreshold,
+ AbsoluteTime.toProtocolTimestamp(
+ getAutoRefreshExecuteThreshold({
+ stampExpireDeposit: selInfo.expireDeposit,
+ stampExpireWithdraw: selInfo.expireWithdraw,
+ }),
+ ),
+ );
const numRequested = selInfo.contributions.length;
const query = [
selInfo.exchangeBaseUrl,
@@ -1150,6 +1175,7 @@ export async function selectPeerCoins(
exchangeBaseUrl: exch.baseUrl,
coins: resCoins,
depositFees: tally.depositFeesAcc,
+ maxExpirationDate: minAutorefreshExecuteThreshold,
};
return { type: "success", result: res };
}