diff options
Diffstat (limited to 'packages/taler-wallet-core/src/util')
| -rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.test.ts | 5 | ||||
| -rw-r--r-- | packages/taler-wallet-core/src/util/coinSelection.ts | 21 | 
2 files changed, 22 insertions, 4 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts index ed48b8dd1..b4dc2a18b 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.test.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts @@ -33,7 +33,10 @@ function fakeAci(current: string, feeDeposit: string): AvailableCoinInfo {    return {      availableAmount: a(current),      coinPub: "foobar", -    denomPub: "foobar", +    denomPub: { +      cipher: 1, +      rsa_public_key: "foobar", +    },      feeDeposit: a(feeDeposit),      exchangeBaseUrl: "https://example.com/",    }; 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.  | 
