diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-03-12 19:25:38 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-03-12 19:25:38 +0530 |
commit | b5b8f96cc94e3a3c0ee7d989819197ab5df393cd (patch) | |
tree | 0382770a735c4f43e09bfb9d03345bc93ecc498a /src/operations/recoup.ts | |
parent | 2ec6799c8c6836d44944460a41fabefb8eb8186f (diff) | |
download | wallet-core-b5b8f96cc94e3a3c0ee7d989819197ab5df393cd.tar.gz wallet-core-b5b8f96cc94e3a3c0ee7d989819197ab5df393cd.tar.bz2 wallet-core-b5b8f96cc94e3a3c0ee7d989819197ab5df393cd.zip |
improved error reporting / towards a working recoup
Diffstat (limited to 'src/operations/recoup.ts')
-rw-r--r-- | src/operations/recoup.ts | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/operations/recoup.ts b/src/operations/recoup.ts index 842a67b87..3097dd05c 100644 --- a/src/operations/recoup.ts +++ b/src/operations/recoup.ts @@ -40,7 +40,7 @@ import { import { codecForRecoupConfirmation } from "../types/talerTypes"; import { NotificationType } from "../types/notifications"; -import { processReserve } from "./reserves"; +import { forceQueryReserve } from "./reserves"; import * as Amounts from "../util/amounts"; import { createRefreshGroup, processRefreshGroup } from "./refresh"; @@ -48,7 +48,7 @@ import { RefreshReason, OperationError } from "../types/walletTypes"; import { TransactionHandle } from "../util/query"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { getTimestampNow } from "../util/time"; -import { guardOperationException } from "./errors"; +import { guardOperationException, scrutinizeTalerJsonResponse } from "./errors"; async function incrementRecoupRetry( ws: InternalWalletState, @@ -133,17 +133,17 @@ async function recoupWithdrawCoin( const recoupRequest = await ws.cryptoApi.createRecoupRequest(coin); const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, coin.exchangeBaseUrl); const resp = await ws.http.postJson(reqUrl.href, recoupRequest); - if (resp.status !== 200) { - throw Error("recoup request failed"); - } - const recoupConfirmation = codecForRecoupConfirmation().decode( - await resp.json(), + const recoupConfirmation = await scrutinizeTalerJsonResponse( + resp, + codecForRecoupConfirmation(), ); if (recoupConfirmation.reserve_pub !== reservePub) { throw Error(`Coin's reserve doesn't match reserve on recoup`); } + // FIXME: verify signature + // FIXME: verify that our expectations about the amount match await ws.db.runWithWriteTransaction( @@ -178,8 +178,8 @@ async function recoupWithdrawCoin( type: NotificationType.RecoupFinished, }); - processReserve(ws, reserve.reservePub).catch(e => { - console.log("processing reserve after recoup failed:", e); + forceQueryReserve(ws, reserve.reservePub).catch(e => { + console.log("re-querying reserve after recoup failed:", e); }); } @@ -196,12 +196,11 @@ async function recoupRefreshCoin( const recoupRequest = await ws.cryptoApi.createRecoupRequest(coin); const reqUrl = new URL(`/coins/${coin.coinPub}/recoup`, coin.exchangeBaseUrl); + console.log("making recoup request"); const resp = await ws.http.postJson(reqUrl.href, recoupRequest); - if (resp.status !== 200) { - throw Error("recoup request failed"); - } - const recoupConfirmation = codecForRecoupConfirmation().decode( - await resp.json(), + const recoupConfirmation = await scrutinizeTalerJsonResponse( + resp, + codecForRecoupConfirmation(), ); if (recoupConfirmation.old_coin_pub != cs.oldCoinPub) { @@ -283,11 +282,14 @@ async function processRecoupGroupImpl( if (forceNow) { await resetRecoupGroupRetry(ws, recoupGroupId); } + console.log("in processRecoupGroupImpl"); const recoupGroup = await ws.db.get(Stores.recoupGroups, recoupGroupId); if (!recoupGroup) { return; } + console.log(recoupGroup); if (recoupGroup.timestampFinished) { + console.log("recoup group finished"); return; } const ps = recoupGroup.coinPubs.map((x, i) => @@ -317,11 +319,11 @@ export async function createRecoupGroup( const coinPub = coinPubs[coinIdx]; const coin = await tx.get(Stores.coins, coinPub); if (!coin) { - recoupGroup.recoupFinishedPerCoin[coinIdx] = true; + await putGroupAsFinished(tx, recoupGroup, coinIdx); continue; } if (Amounts.isZero(coin.currentAmount)) { - recoupGroup.recoupFinishedPerCoin[coinIdx] = true; + await putGroupAsFinished(tx, recoupGroup, coinIdx); continue; } coin.currentAmount = Amounts.getZero(coin.currentAmount.currency); |