diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-09-08 21:03:10 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-09-08 21:03:10 +0530 |
commit | aae06c680f7d31d0a2f2a2059b57a8d7c575d3c7 (patch) | |
tree | 25653034f74b5e043edd58702a24cad9acdc6fdd /packages/taler-wallet-core/src/operations | |
parent | ddbb09b1403214cff3e5a598dc51bdf37df72971 (diff) | |
download | wallet-core-aae06c680f7d31d0a2f2a2059b57a8d7c575d3c7.tar.gz wallet-core-aae06c680f7d31d0a2f2a2059b57a8d7c575d3c7.tar.bz2 wallet-core-aae06c680f7d31d0a2f2a2059b57a8d7c575d3c7.zip |
DB tweaks
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
7 files changed, 35 insertions, 41 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 7bf07ab2a..d598e3987 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -222,7 +222,7 @@ async function updateExchangeWithKeys( for (const newDenom of newDenominations) { const oldDenom = await tx.get(Stores.denominations, [ baseUrl, - newDenom.denomPub, + newDenom.denomPubHash, ]); if (oldDenom) { // FIXME: Do consistency check @@ -236,10 +236,10 @@ async function updateExchangeWithKeys( const newlyRevokedCoinPubs: string[] = []; logger.trace("recoup list from exchange", recoupDenomList); for (const recoupInfo of recoupDenomList) { - const oldDenom = await tx.getIndexed( - Stores.denominations.denomPubHashIndex, + const oldDenom = await tx.get(Stores.denominations, [ + r.baseUrl, recoupInfo.h_denom_pub, - ); + ]); if (!oldDenom) { // We never even knew about the revoked denomination, all good. continue; diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts index a6f941ff1..3dc5e1600 100644 --- a/packages/taler-wallet-core/src/operations/pay.ts +++ b/packages/taler-wallet-core/src/operations/pay.ts @@ -131,7 +131,7 @@ export async function getTotalPaymentCost( } const denom = await ws.db.get(Stores.denominations, [ coin.exchangeBaseUrl, - coin.denomPub, + coin.denomPubHash, ]); if (!denom) { throw Error( @@ -332,7 +332,7 @@ async function getCoinsForPayment( // coins have the same currency const firstDenom = await ws.db.get(Stores.denominations, [ exchange.baseUrl, - coins[0].denomPub, + coins[0].denomPubHash, ]); if (!firstDenom) { throw Error("db inconsistent"); @@ -342,7 +342,7 @@ async function getCoinsForPayment( for (const coin of coins) { const denom = await ws.db.get(Stores.denominations, [ exchange.baseUrl, - coin.denomPub, + coin.denomPubHash, ]); if (!denom) { throw Error("db inconsistent"); @@ -1148,7 +1148,7 @@ export async function confirmPay( } const denom = await ws.db.get(Stores.denominations, [ coin.exchangeBaseUrl, - coin.denomPub, + coin.denomPubHash, ]); if (!denom) { throw Error( diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index a6917c285..c92ce9209 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -134,7 +134,7 @@ async function refreshCreateSession( const oldDenom = await ws.db.get(Stores.denominations, [ exchange.baseUrl, - coin.denomPub, + coin.denomPubHash, ]); if (!oldDenom) { @@ -367,7 +367,7 @@ async function refreshReveal( for (let i = 0; i < reveal.ev_sigs.length; i++) { const denom = await ws.db.get(Stores.denominations, [ refreshSession.exchangeBaseUrl, - refreshSession.newDenoms[i], + refreshSession.newDenomHashes[i], ]); if (!denom) { console.error("denom not found"); @@ -598,7 +598,7 @@ export async function createRefreshGroup( checkDbInvariant(!!coin, "coin must be in database"); const denom = await tx.get(Stores.denominations, [ coin.exchangeBaseUrl, - coin.denomPub, + coin.denomPubHash, ]); checkDbInvariant( !!denom, @@ -701,7 +701,7 @@ export async function autoRefresh( } const denom = await tx.get(Stores.denominations, [ exchangeBaseUrl, - coin.denomPub, + coin.denomPubHash, ]); if (!denom) { logger.warn("denomination not in database"); diff --git a/packages/taler-wallet-core/src/operations/refund.ts b/packages/taler-wallet-core/src/operations/refund.ts index 097e20863..e15a27b3a 100644 --- a/packages/taler-wallet-core/src/operations/refund.ts +++ b/packages/taler-wallet-core/src/operations/refund.ts @@ -104,10 +104,10 @@ async function applySuccessfulRefund( console.warn("coin not found, can't apply refund"); return; } - const denom = await tx.getIndexed( - Stores.denominations.denomPubHashIndex, + const denom = await tx.get(Stores.denominations, [ + coin.exchangeBaseUrl, coin.denomPubHash, - ); + ]); if (!denom) { throw Error("inconsistent database"); } @@ -161,10 +161,10 @@ async function storePendingRefund( console.warn("coin not found, can't apply refund"); return; } - const denom = await tx.getIndexed( - Stores.denominations.denomPubHashIndex, + const denom = await tx.get(Stores.denominations, [ + coin.exchangeBaseUrl, coin.denomPubHash, - ); + ]); if (!denom) { throw Error("inconsistent database"); @@ -211,10 +211,10 @@ async function storeFailedRefund( console.warn("coin not found, can't apply refund"); return; } - const denom = await tx.getIndexed( - Stores.denominations.denomPubHashIndex, + const denom = await tx.get(Stores.denominations, [ + coin.exchangeBaseUrl, coin.denomPubHash, - ); + ]); if (!denom) { throw Error("inconsistent database"); @@ -294,7 +294,8 @@ async function acceptRefunds( // Still pending. if ( - refundStatus.type === "failure" && !isPermanentFailure && + refundStatus.type === "failure" && + !isPermanentFailure && existingRefundInfo?.type === RefundState.Pending ) { continue; diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts index 6db203472..cced6a1d5 100644 --- a/packages/taler-wallet-core/src/operations/reserves.ts +++ b/packages/taler-wallet-core/src/operations/reserves.ts @@ -172,14 +172,6 @@ export async function createReserve( expectedAmount: req.amount, }); - const senderWire = req.senderWire; - if (senderWire) { - const rec = { - paytoUri: senderWire, - }; - await ws.db.put(Stores.senderWires, rec); - } - const exchangeInfo = await updateExchangeFromUrl(ws, req.exchange); const exchangeDetails = exchangeInfo.details; if (!exchangeDetails) { diff --git a/packages/taler-wallet-core/src/operations/tip.ts b/packages/taler-wallet-core/src/operations/tip.ts index 7b914568f..08f45eb89 100644 --- a/packages/taler-wallet-core/src/operations/tip.ts +++ b/packages/taler-wallet-core/src/operations/tip.ts @@ -104,10 +104,11 @@ export async function prepareTip( planchets: undefined, createdTimestamp: getTimestampNow(), merchantTipId: res.merchantTipId, - tipAmountEffective: Amounts.sub(amount, Amounts.add( - withdrawDetails.overhead, - withdrawDetails.withdrawFee, - ).amount).amount, + tipAmountEffective: Amounts.sub( + amount, + Amounts.add(withdrawDetails.overhead, withdrawDetails.withdrawFee) + .amount, + ).amount, retryInfo: initRetryInfo(), lastError: undefined, denomsSel: denomSelectionInfoToState(selectedDenoms), @@ -200,10 +201,10 @@ async function processTipImpl( const planchets: TipPlanchet[] = []; for (const sd of denomsForWithdraw.selectedDenoms) { - const denom = await ws.db.getIndexed( - Stores.denominations.denomPubHashIndex, + const denom = await ws.db.get(Stores.denominations, [ + tipRecord.exchangeBaseUrl, sd.denomPubHash, - ); + ]); if (!denom) { throw Error("denom does not exist anymore"); } diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index fd472fdfe..e44ac7cf2 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -233,10 +233,10 @@ async function processPlanchetGenerate( if (!denomPubHash) { throw Error("invariant violated"); } - const denom = await ws.db.getIndexed( - Stores.denominations.denomPubHashIndex, + const denom = await ws.db.get(Stores.denominations, [ + withdrawalGroup.exchangeBaseUrl, denomPubHash, - ); + ]); if (!denom) { throw Error("invariant violated"); } @@ -325,7 +325,7 @@ async function processPlanchetExchangeRequest( const denom = await ws.db.get(Stores.denominations, [ withdrawalGroup.exchangeBaseUrl, - planchet.denomPub, + planchet.denomPubHash, ]); if (!denom) { |