summaryrefslogtreecommitdiff
path: root/src/operations/reserves.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-12 19:25:38 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-12 19:25:38 +0530
commitb5b8f96cc94e3a3c0ee7d989819197ab5df393cd (patch)
tree0382770a735c4f43e09bfb9d03345bc93ecc498a /src/operations/reserves.ts
parent2ec6799c8c6836d44944460a41fabefb8eb8186f (diff)
downloadwallet-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/reserves.ts')
-rw-r--r--src/operations/reserves.ts45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index c909555fe..efca08a45 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -203,6 +203,35 @@ export async function createReserve(
}
/**
+ * Re-query the status of a reserve.
+ */
+export async function forceQueryReserve(
+ ws: InternalWalletState,
+ reservePub: string,
+): Promise<void> {
+ await ws.db.runWithWriteTransaction([Stores.reserves], async (tx) => {
+ const reserve = await tx.get(Stores.reserves, reservePub);
+ if (!reserve) {
+ return;
+ }
+ // Only force status query where it makes sense
+ switch (reserve.reserveStatus) {
+ case ReserveRecordStatus.DORMANT:
+ case ReserveRecordStatus.WITHDRAWING:
+ case ReserveRecordStatus.QUERYING_STATUS:
+ break;
+ default:
+ return;
+ }
+ reserve.reserveStatus = ReserveRecordStatus.QUERYING_STATUS;
+ reserve.retryInfo = initRetryInfo();
+ await tx.put(Stores.reserves, reserve);
+
+ });
+ await processReserve(ws, reservePub);
+}
+
+/**
* First fetch information requred to withdraw from the reserve,
* then deplete the reserve, withdrawing coins until it is empty.
*
@@ -408,7 +437,7 @@ async function updateReserve(
console.log("got reserves/${RESERVE_PUB} response", await resp.json());
if (resp.status === 404) {
const m = "reserve not known to the exchange yet"
- throw new OperationFailedError(m, {
+ throw new OperationFailedError({
type: "waiting",
message: m,
details: {},
@@ -420,12 +449,13 @@ async function updateReserve(
} catch (e) {
logger.trace("caught exception for reserve/status");
const m = e.message;
- await incrementReserveRetry(ws, reservePub, {
+ const opErr = {
type: "network",
details: {},
message: m,
- });
- throw new OperationFailedAndReportedError(m);
+ };
+ await incrementReserveRetry(ws, reservePub, opErr);
+ throw new OperationFailedAndReportedError(opErr);
}
const respJson = await resp.json();
const reserveInfo = codecForReserveStatus().decode(respJson);
@@ -600,13 +630,14 @@ async function depleteReserve(
logger.trace(`got denom list`);
if (denomsForWithdraw.length === 0) {
const m = `Unable to withdraw from reserve, no denominations are available to withdraw.`;
- await incrementReserveRetry(ws, reserve.reservePub, {
+ const opErr = {
type: "internal",
message: m,
details: {},
- });
+ };
+ await incrementReserveRetry(ws, reserve.reservePub, opErr);
console.log(m);
- throw new OperationFailedAndReportedError(m);
+ throw new OperationFailedAndReportedError(opErr);
}
logger.trace("selected denominations");