aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-09-15 20:16:42 +0200
committerFlorian Dold <florian@dold.me>2022-09-16 16:31:16 +0200
commitb7f7b956028566c689d802258937deb081d5dc60 (patch)
tree26b955114d22ed11d2591d710505bf24b3ee76cc /packages/taler-wallet-core/src/util
parent5d0837913901a2947c66209d64855b324824757d (diff)
downloadwallet-core-b7f7b956028566c689d802258937deb081d5dc60.tar.xz
wallet-core: towards faster coin selection
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.test.ts22
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts6
2 files changed, 14 insertions, 14 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index 55c007bbc..3c6ad0d82 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -19,7 +19,7 @@
*/
import test from "ava";
import { AmountJson, Amounts, DenomKeyType } from "@gnu-taler/taler-util";
-import { AvailableCoinInfo, selectPayCoins } from "./coinSelection.js";
+import { AvailableCoinInfo, selectPayCoinsLegacy } from "./coinSelection.js";
function a(x: string): AmountJson {
const amt = Amounts.parse(x);
@@ -66,7 +66,7 @@ test("it should be able to pay if merchant takes the fees", (t) => {
];
acis.forEach((x, i) => (x.coinPub = String(i)));
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -94,7 +94,7 @@ test("it should take the last two coins if it pays less fees", (t) => {
];
acis.forEach((x, i) => (x.coinPub = String(i)));
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -122,7 +122,7 @@ test("it should take the last coins if the merchant doest not take all the fee",
];
acis.forEach((x, i) => (x.coinPub = String(i)));
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -148,7 +148,7 @@ test("it should use 3 coins to cover fees and payment", (t) => {
fakeAci("EUR:1.0", "EUR:0.5"), //contributed value .5
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -174,7 +174,7 @@ test("it should return undefined if there is not enough coins", (t) => {
fakeAci("EUR:1.0", "EUR:0.5"),
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -194,7 +194,7 @@ test("it should return undefined if there is not enough coins (taking into accou
fakeAci("EUR:1.0", "EUR:0.5"),
fakeAci("EUR:1.0", "EUR:0.5"),
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -213,7 +213,7 @@ test("it should not count into customer fee if merchant can afford it", (t) => {
fakeAci("EUR:1.0", "EUR:0.1"),
fakeAci("EUR:1.0", "EUR:0.1"),
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -240,7 +240,7 @@ test("it should use the coins that spent less relative fee", (t) => {
];
acis.forEach((x, i) => (x.coinPub = String(i)));
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -263,7 +263,7 @@ test("coin selection 9", (t) => {
fakeAci("EUR:1.0", "EUR:0.2"),
fakeAci("EUR:0.2", "EUR:0.2"),
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
@@ -290,7 +290,7 @@ test("it should be able to use unrestricted coins for age restricted contract",
fakeAciWithAgeRestriction("EUR:1.0", "EUR:0.2"),
fakeAciWithAgeRestriction("EUR:0.2", "EUR:0.2"),
];
- const res = selectPayCoins({
+ const res = selectPayCoinsLegacy({
candidates: {
candidateCoins: acis,
wireFeesPerExchange: {},
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index 97e25abd3..9622b3a76 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -97,7 +97,7 @@ export interface SelectPayCoinRequest {
requiredMinimumAge?: number;
}
-interface CoinSelectionTally {
+export interface CoinSelectionTally {
/**
* Amount that still needs to be paid.
* May increase during the computation when fees need to be covered.
@@ -125,7 +125,7 @@ interface CoinSelectionTally {
/**
* Account for the fees of spending a coin.
*/
-function tallyFees(
+export function tallyFees(
tally: CoinSelectionTally,
wireFeesPerExchange: Record<string, AmountJson>,
wireFeeAmortization: number,
@@ -204,7 +204,7 @@ function tallyFees(
*
* This function is only exported for the sake of unit tests.
*/
-export function selectPayCoins(
+export function selectPayCoinsLegacy(
req: SelectPayCoinRequest,
): PayCoinSelection | undefined {
const {