diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-05-11 18:03:25 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-05-11 18:03:25 +0530 |
commit | 5d6192b0cd356f7e56fa8d6193a2e74233a52f4b (patch) | |
tree | 0360ba1d39e6ff081e25045652f457faca8cb879 /src/types | |
parent | 7e947ca2cdd8e66ea49822acbad81e7d35289c0a (diff) | |
download | wallet-core-5d6192b0cd356f7e56fa8d6193a2e74233a52f4b.tar.xz |
make planchet management during withdrawal O(n) instead of O(n^2)
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/dbTypes.ts | 80 | ||||
-rw-r--r-- | src/types/walletTypes.ts | 4 |
2 files changed, 67 insertions, 17 deletions
diff --git a/src/types/dbTypes.ts b/src/types/dbTypes.ts index 158d438cf..df019fc00 100644 --- a/src/types/dbTypes.ts +++ b/src/types/dbTypes.ts @@ -1,17 +1,17 @@ /* - This file is part of TALER - (C) 2018 GNUnet e.V. and INRIA + This file is part of GNU Taler + (C) 2018-2020 Taler Systems S.A. - TALER is free software; you can redistribute it and/or modify it under the + GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. - TALER is distributed in the hope that it will be useful, but WITHOUT ANY + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** @@ -608,7 +608,25 @@ export interface PlanchetRecord { * Public key of the coin. */ coinPub: string; + + /** + * Private key of the coin. + */ coinPriv: string; + + /** + * Withdrawal group that this planchet belongs to + * (or the empty string). + */ + withdrawalGroupId: string; + + /** + * Index within the withdrawal group (or -1). + */ + coinIdx: number; + + withdrawalDone: boolean; + /** * Public key of the reserve, this might be a reserve not * known to the wallet if the planchet is from a tip. @@ -889,6 +907,8 @@ export interface TipRecord { */ planchets?: TipPlanchet[]; + denomsSel: DenomSelectionState; + /** * Response if the merchant responded, * undefined otherwise. @@ -1356,6 +1376,28 @@ export interface WithdrawalSourceReserve { export type WithdrawalSource = WithdrawalSourceTip | WithdrawalSourceReserve; +export interface DenominationSelectionInfo { + totalCoinValue: AmountJson; + totalWithdrawCost: AmountJson; + selectedDenoms: { + /** + * How many times do we withdraw this denomination? + */ + count: number; + denom: DenominationRecord; + }[]; +} + +export interface DenomSelectionState { + totalCoinValue: AmountJson; + totalWithdrawCost: AmountJson; + selectedDenoms: { + denomPubHash: string; + countAllocated: number; + countPlanchetCreated: number; + }[]; +} + export interface WithdrawalGroupRecord { withdrawalGroupId: string; @@ -1379,22 +1421,13 @@ export interface WithdrawalGroupRecord { */ timestampFinish?: Timestamp; - totalCoinValue: AmountJson; - /** * Amount including fees (i.e. the amount subtracted from the * reserve to withdraw all coins in this withdrawal session). */ rawWithdrawalAmount: AmountJson; - denoms: string[]; - - planchets: (undefined | PlanchetRecord)[]; - - /** - * Coins in this session that are withdrawn are set to true. - */ - withdrawn: boolean[]; + denomsSel: DenomSelectionState; /** * Retry info, always present even on completed operations so that indexing works. @@ -1625,6 +1658,22 @@ export namespace Stores { } } + class PlanchetsStore extends Store<PlanchetRecord> { + constructor() { + super("planchets", { keyPath: "coinPub" }); + } + byGroupAndIndex = new Index<string, PlanchetRecord>( + this, + "withdrawalGroupAndCoinIdxIndex", + ["withdrawalGroupId", "coinIdx"], + ); + byGroup = new Index<string, PlanchetRecord>( + this, + "withdrawalGroupIndex", + "withdrawalGroupId", + ); + } + class RefundEventsStore extends Store<RefundEventRecord> { constructor() { super("refundEvents", { keyPath: "refundGroupId" }); @@ -1681,6 +1730,7 @@ export namespace Stores { export const tips = new TipsStore(); export const senderWires = new SenderWiresStore(); export const withdrawalGroups = new WithdrawalGroupsStore(); + export const planchets = new PlanchetsStore(); export const bankWithdrawUris = new BankWithdrawUrisStore(); export const refundEvents = new RefundEventsStore(); export const payEvents = new PayEventsStore(); diff --git a/src/types/walletTypes.ts b/src/types/walletTypes.ts index ed334bc47..da87b1c1c 100644 --- a/src/types/walletTypes.ts +++ b/src/types/walletTypes.ts @@ -30,9 +30,9 @@ import { AmountJson, codecForAmountJson } from "../util/amounts"; import * as LibtoolVersion from "../util/libtoolVersion"; import { - DenominationRecord, ExchangeRecord, ExchangeWireInfo, + DenominationSelectionInfo, } from "./dbTypes"; import { Timestamp } from "../util/time"; import { @@ -77,7 +77,7 @@ export interface ExchangeWithdrawDetails { /** * Selected denominations for withdraw. */ - selectedDenoms: DenominationRecord[]; + selectedDenoms: DenominationSelectionInfo; /** * Fees for withdraw. |