diff options
author | Florian Dold <florian@dold.me> | 2021-11-17 10:23:22 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-17 10:23:30 +0100 |
commit | 9f0429cb2f8ad9cb2e98a787139602d913c1aefa (patch) | |
tree | cda55e2d07a291dd2ff6f243bb423121ecf220b3 /packages/taler-wallet-core/src/util/coinSelection.ts | |
parent | a994009d2f094c4d9c12da68dac3abb28bdef4b3 (diff) | |
download | wallet-core-9f0429cb2f8ad9cb2e98a787139602d913c1aefa.tar.gz wallet-core-9f0429cb2f8ad9cb2e98a787139602d913c1aefa.tar.bz2 wallet-core-9f0429cb2f8ad9cb2e98a787139602d913c1aefa.zip |
wallet: implement exchange protocol v9
Diffstat (limited to 'packages/taler-wallet-core/src/util/coinSelection.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index 500cee5d8..ba26c98fe 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -23,7 +23,7 @@ /** * Imports. */ -import { AmountJson, Amounts } from "@gnu-taler/taler-util"; +import { AmountJson, Amounts, DenominationPubKey } from "@gnu-taler/taler-util"; import { strcmp, Logger } from "@gnu-taler/taler-util"; const logger = new Logger("coinSelection.ts"); @@ -72,7 +72,7 @@ export interface AvailableCoinInfo { /** * Coin's denomination public key. */ - denomPub: string; + denomPub: DenominationPubKey; /** * Amount still remaining (typically the full amount, @@ -206,6 +206,21 @@ function tallyFees( }; } +function denomPubCmp( + p1: DenominationPubKey, + p2: DenominationPubKey, +): -1 | 0 | 1 { + if (p1.cipher < p2.cipher) { + return -1; + } else if (p1.cipher > p2.cipher) { + return +1; + } + if (p1.cipher !== 1 || p2.cipher !== 1) { + throw Error("unsupported cipher"); + } + return strcmp(p1.rsa_public_key, p2.rsa_public_key); +} + /** * Given a list of candidate coins, select coins to spend under the merchant's * constraints. @@ -272,7 +287,7 @@ export function selectPayCoins( (o1, o2) => -Amounts.cmp(o1.availableAmount, o2.availableAmount) || Amounts.cmp(o1.feeDeposit, o2.feeDeposit) || - strcmp(o1.denomPub, o2.denomPub), + denomPubCmp(o1.denomPub, o2.denomPub), ); // FIXME: Here, we should select coins in a smarter way. |