summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/recoup.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-04-23 03:09:40 +0200
committerFlorian Dold <florian@dold.me>2024-04-23 03:09:40 +0200
commit1edc144b3595ae1ab6b8af7a43d26b811b2c2623 (patch)
treedb552f6b4a351eb1d0dae902f4d504031852bda7 /packages/taler-wallet-core/src/recoup.ts
parent4b69853c347071acb73efcde9d4969cf06d0dfcc (diff)
downloadwallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.gz
wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.tar.bz2
wallet-core-1edc144b3595ae1ab6b8af7a43d26b811b2c2623.zip
wallet-core: pass options object to all transactions
Diffstat (limited to 'packages/taler-wallet-core/src/recoup.ts')
-rw-r--r--packages/taler-wallet-core/src/recoup.ts81
1 files changed, 46 insertions, 35 deletions
diff --git a/packages/taler-wallet-core/src/recoup.ts b/packages/taler-wallet-core/src/recoup.ts
index 758ba106d..6a09f9a0e 100644
--- a/packages/taler-wallet-core/src/recoup.ts
+++ b/packages/taler-wallet-core/src/recoup.ts
@@ -99,7 +99,7 @@ async function recoupRewardCoin(
// Thus we just put the coin to sleep.
// FIXME: somehow report this to the user
await wex.db.runReadWriteTx(
- ["recoupGroups", "denominations", "refreshGroups", "coins"],
+ { storeNames: ["recoupGroups", "denominations", "refreshGroups", "coins"] },
async (tx) => {
const recoupGroup = await tx.recoupGroups.get(recoupGroupId);
if (!recoupGroup) {
@@ -121,7 +121,7 @@ async function recoupRefreshCoin(
cs: RefreshCoinSource,
): Promise<void> {
const d = await wex.db.runReadOnlyTx(
- ["coins", "denominations"],
+ { storeNames: ["coins", "denominations"] },
async (tx) => {
const denomInfo = await getDenomInfo(
wex,
@@ -168,7 +168,7 @@ async function recoupRefreshCoin(
}
await wex.db.runReadWriteTx(
- ["coins", "denominations", "recoupGroups", "refreshGroups"],
+ { storeNames: ["coins", "denominations", "recoupGroups", "refreshGroups"] },
async (tx) => {
const recoupGroup = await tx.recoupGroups.get(recoupGroupId);
if (!recoupGroup) {
@@ -233,7 +233,7 @@ export async function recoupWithdrawCoin(
): Promise<void> {
const reservePub = cs.reservePub;
const denomInfo = await wex.db.runReadOnlyTx(
- ["denominations"],
+ { storeNames: ["denominations"] },
async (tx) => {
const denomInfo = await getDenomInfo(
wex,
@@ -276,7 +276,7 @@ export async function recoupWithdrawCoin(
// FIXME: verify that our expectations about the amount match
await wex.db.runReadWriteTx(
- ["coins", "denominations", "recoupGroups", "refreshGroups"],
+ { storeNames: ["coins", "denominations", "recoupGroups", "refreshGroups"] },
async (tx) => {
const recoupGroup = await tx.recoupGroups.get(recoupGroupId);
if (!recoupGroup) {
@@ -300,9 +300,12 @@ export async function processRecoupGroup(
wex: WalletExecutionContext,
recoupGroupId: string,
): Promise<TaskRunResult> {
- let recoupGroup = await wex.db.runReadOnlyTx(["recoupGroups"], async (tx) => {
- return tx.recoupGroups.get(recoupGroupId);
- });
+ let recoupGroup = await wex.db.runReadOnlyTx(
+ { storeNames: ["recoupGroups"] },
+ async (tx) => {
+ return tx.recoupGroups.get(recoupGroupId);
+ },
+ );
if (!recoupGroup) {
return TaskRunResult.finished();
}
@@ -320,9 +323,12 @@ export async function processRecoupGroup(
});
await Promise.all(ps);
- recoupGroup = await wex.db.runReadOnlyTx(["recoupGroups"], async (tx) => {
- return tx.recoupGroups.get(recoupGroupId);
- });
+ recoupGroup = await wex.db.runReadOnlyTx(
+ { storeNames: ["recoupGroups"] },
+ async (tx) => {
+ return tx.recoupGroups.get(recoupGroupId);
+ },
+ );
if (!recoupGroup) {
return TaskRunResult.finished();
}
@@ -339,22 +345,25 @@ export async function processRecoupGroup(
const reservePrivMap: Record<string, string> = {};
for (let i = 0; i < recoupGroup.coinPubs.length; i++) {
const coinPub = recoupGroup.coinPubs[i];
- await wex.db.runReadOnlyTx(["coins", "reserves"], async (tx) => {
- const coin = await tx.coins.get(coinPub);
- if (!coin) {
- throw Error(`Coin ${coinPub} not found, can't request recoup`);
- }
- if (coin.coinSource.type === CoinSourceType.Withdraw) {
- const reserve = await tx.reserves.indexes.byReservePub.get(
- coin.coinSource.reservePub,
- );
- if (!reserve) {
- return;
+ await wex.db.runReadOnlyTx(
+ { storeNames: ["coins", "reserves"] },
+ async (tx) => {
+ const coin = await tx.coins.get(coinPub);
+ if (!coin) {
+ throw Error(`Coin ${coinPub} not found, can't request recoup`);
}
- reserveSet.add(coin.coinSource.reservePub);
- reservePrivMap[coin.coinSource.reservePub] = reserve.reservePriv;
- }
- });
+ if (coin.coinSource.type === CoinSourceType.Withdraw) {
+ const reserve = await tx.reserves.indexes.byReservePub.get(
+ coin.coinSource.reservePub,
+ );
+ if (!reserve) {
+ return;
+ }
+ reserveSet.add(coin.coinSource.reservePub);
+ reservePrivMap[coin.coinSource.reservePub] = reserve.reservePriv;
+ }
+ },
+ );
}
for (const reservePub of reserveSet) {
@@ -385,14 +394,16 @@ export async function processRecoupGroup(
}
await wex.db.runReadWriteTx(
- [
- "recoupGroups",
- "coinAvailability",
- "denominations",
- "refreshGroups",
- "refreshSessions",
- "coins",
- ],
+ {
+ storeNames: [
+ "recoupGroups",
+ "coinAvailability",
+ "denominations",
+ "refreshGroups",
+ "refreshSessions",
+ "coins",
+ ],
+ },
async (tx) => {
const rg2 = await tx.recoupGroups.get(recoupGroupId);
if (!rg2) {
@@ -502,7 +513,7 @@ async function processRecoupForCoin(
coinIdx: number,
): Promise<void> {
const coin = await wex.db.runReadOnlyTx(
- ["coins", "recoupGroups"],
+ { storeNames: ["coins", "recoupGroups"] },
async (tx) => {
const recoupGroup = await tx.recoupGroups.get(recoupGroupId);
if (!recoupGroup) {