summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-02-09 22:44:36 +0100
committerFlorian Dold <florian@dold.me>2023-02-10 00:07:33 +0100
commit3cf2d4cba919203065f210f80f3f081948ad257a (patch)
treeb5f6e80f800cffbb59c0c7cf0b54398eb89f4b95 /packages/taler-wallet-core/src
parenta8c5a9696c1735a178158cbc9ac4f9bb4b6f013d (diff)
downloadwallet-core-3cf2d4cba919203065f210f80f3f081948ad257a.tar.gz
wallet-core-3cf2d4cba919203065f210f80f3f081948ad257a.tar.bz2
wallet-core-3cf2d4cba919203065f210f80f3f081948ad257a.zip
wallet-core: expose withdrawal progress, towards huge withdrawal test
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts59
-rw-r--r--packages/taler-wallet-core/src/remote.ts1
2 files changed, 48 insertions, 12 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 667b97361..caa280fe5 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -462,9 +462,10 @@ async function processPlanchetGenerate(
*/
async function processPlanchetExchangeRequest(
ws: InternalWalletState,
- withdrawalGroup: WithdrawalGroupRecord,
+ wgContext: WithdrawalGroupContext,
coinIdx: number,
): Promise<WithdrawResponse | undefined> {
+ const withdrawalGroup: WithdrawalGroupRecord = wgContext.wgRecord;
logger.info(
`processing planchet exchange request ${withdrawalGroup.withdrawalGroupId}/${coinIdx}`,
);
@@ -593,8 +594,9 @@ async function processPlanchetExchangeRequest(
*/
async function processPlanchetExchangeBatchRequest(
ws: InternalWalletState,
- withdrawalGroup: WithdrawalGroupRecord,
+ wgContext: WithdrawalGroupContext,
): Promise<WithdrawBatchResponse | undefined> {
+ const withdrawalGroup: WithdrawalGroupRecord = wgContext.wgRecord;
logger.info(
`processing planchet exchange batch request ${withdrawalGroup.withdrawalGroupId}`,
);
@@ -671,10 +673,11 @@ async function processPlanchetExchangeBatchRequest(
async function processPlanchetVerifyAndStoreCoin(
ws: InternalWalletState,
- withdrawalGroup: WithdrawalGroupRecord,
+ wgContext: WithdrawalGroupContext,
coinIdx: number,
resp: WithdrawResponse,
): Promise<void> {
+ const withdrawalGroup = wgContext.wgRecord;
const d = await ws.db
.mktx((x) => [x.withdrawalGroups, x.planchets, x.denominations])
.runReadOnly(async (tx) => {
@@ -786,6 +789,8 @@ async function processPlanchetVerifyAndStoreCoin(
const planchetCoinPub = planchet.coinPub;
+ wgContext.planchetsFinished.add(planchet.coinPub);
+
// Check if this is the first time that the whole
// withdrawal succeeded. If so, mark the withdrawal
// group as finished.
@@ -811,6 +816,8 @@ async function processPlanchetVerifyAndStoreCoin(
if (firstSuccess) {
ws.notify({
type: NotificationType.CoinWithdrawn,
+ numTotal: wgContext.numPlanchets,
+ numWithdrawn: wgContext.planchetsFinished.size,
});
}
}
@@ -983,6 +990,21 @@ enum BankStatusResultCode {
Aborted = "aborted",
}
+/**
+ * Withdrawal context that is kept in-memory.
+ *
+ * Used to store some cached info during a withdrawal operation.
+ */
+export interface WithdrawalGroupContext {
+ numPlanchets: number;
+ planchetsFinished: Set<string>;
+
+ /**
+ * Cached withdrawal group record from the database.
+ */
+ wgRecord: WithdrawalGroupRecord;
+}
+
export async function processWithdrawalGroup(
ws: InternalWalletState,
withdrawalGroupId: string,
@@ -1122,8 +1144,27 @@ export async function processWithdrawalGroup(
.map((x) => x.count)
.reduce((a, b) => a + b);
+ const wgContext: WithdrawalGroupContext = {
+ numPlanchets: numTotalCoins,
+ planchetsFinished: new Set<string>(),
+ wgRecord: withdrawalGroup,
+ };
+
let work: Promise<void>[] = [];
+ await ws.db
+ .mktx((x) => [x.planchets])
+ .runReadOnly(async (tx) => {
+ const planchets = await tx.planchets.indexes.byGroup.getAll(
+ withdrawalGroupId,
+ );
+ for (const p of planchets) {
+ if (p.planchetStatus === PlanchetStatus.WithdrawalDone) {
+ wgContext.planchetsFinished.add(p.coinPub);
+ }
+ }
+ });
+
for (let i = 0; i < numTotalCoins; i++) {
work.push(processPlanchetGenerate(ws, withdrawalGroup, i));
}
@@ -1134,7 +1175,7 @@ export async function processWithdrawalGroup(
work = [];
if (ws.batchWithdrawal) {
- const resp = await processPlanchetExchangeBatchRequest(ws, withdrawalGroup);
+ const resp = await processPlanchetExchangeBatchRequest(ws, wgContext);
if (!resp) {
throw Error("unable to do batch withdrawal");
}
@@ -1142,7 +1183,7 @@ export async function processWithdrawalGroup(
work.push(
processPlanchetVerifyAndStoreCoin(
ws,
- withdrawalGroup,
+ wgContext,
coinIdx,
resp.ev_sigs[coinIdx],
),
@@ -1150,16 +1191,12 @@ export async function processWithdrawalGroup(
}
} else {
for (let coinIdx = 0; coinIdx < numTotalCoins; coinIdx++) {
- const resp = await processPlanchetExchangeRequest(
- ws,
- withdrawalGroup,
- coinIdx,
- );
+ const resp = await processPlanchetExchangeRequest(ws, wgContext, coinIdx);
if (!resp) {
continue;
}
work.push(
- processPlanchetVerifyAndStoreCoin(ws, withdrawalGroup, coinIdx, resp),
+ processPlanchetVerifyAndStoreCoin(ws, wgContext, coinIdx, resp),
);
}
}
diff --git a/packages/taler-wallet-core/src/remote.ts b/packages/taler-wallet-core/src/remote.ts
index a240d4606..2628fea07 100644
--- a/packages/taler-wallet-core/src/remote.ts
+++ b/packages/taler-wallet-core/src/remote.ts
@@ -110,7 +110,6 @@ export async function createRemoteWallet(
}
h.promiseCapability.resolve(m as any);
} else if (type === "notification") {
- logger.info("got notification");
if (args.notificationHandler) {
args.notificationHandler((m as any).payload);
}