aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/backup
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-05-18 14:41:51 -0300
committerSebastian <sebasjm@gmail.com>2022-05-18 14:41:51 -0300
commitc67d0bff1daa35d380d1d71b94428a5026b56450 (patch)
treeb4e1f164e1bed3b13fa4ff5969806d2212079f41 /packages/taler-wallet-core/src/operations/backup
parentd3a857743dd9ed2f7350bb64af8808729156edba (diff)
downloadwallet-core-c67d0bff1daa35d380d1d71b94428a5026b56450.tar.xz
all retryInfo function in the same namespace, adding missing retryInfo increment
Diffstat (limited to 'packages/taler-wallet-core/src/operations/backup')
-rw-r--r--packages/taler-wallet-core/src/operations/backup/import.ts68
-rw-r--r--packages/taler-wallet-core/src/operations/backup/index.ts73
2 files changed, 50 insertions, 91 deletions
diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts
index a0a603ca3..16a88fe7c 100644
--- a/packages/taler-wallet-core/src/operations/backup/import.ts
+++ b/packages/taler-wallet-core/src/operations/backup/import.ts
@@ -15,54 +15,30 @@
*/
import {
- BackupPurchase,
AmountJson,
- Amounts,
- BackupDenomSel,
- WalletBackupContentV1,
- BackupCoinSourceType,
- BackupProposalStatus,
- codecForContractTerms,
- BackupRefundState,
- RefreshReason,
- BackupRefreshReason,
- DenomKeyType,
- AbsoluteTime,
- TalerProtocolTimestamp,
+ Amounts, BackupCoinSourceType, BackupDenomSel, BackupProposalStatus,
+ BackupPurchase, BackupRefreshReason, BackupRefundState, codecForContractTerms,
+ DenomKeyType, j2s, Logger, RefreshReason, TalerProtocolTimestamp,
+ WalletBackupContentV1
} from "@gnu-taler/taler-util";
import {
- WalletContractData,
- DenomSelectionState,
- DenominationVerificationStatus,
- CoinSource,
+ AbortStatus, CoinSource,
CoinSourceType,
- CoinStatus,
- ReserveBankInfo,
- ReserveRecordStatus,
- ProposalDownload,
- ProposalStatus,
- WalletRefundItem,
- RefundState,
- AbortStatus,
- RefreshSessionRecord,
- WireInfo,
- WalletStoresV1,
- RefreshCoinStatus,
- OperationStatus,
+ CoinStatus, DenominationVerificationStatus, DenomSelectionState, OperationStatus, ProposalDownload,
+ ProposalStatus, RefreshCoinStatus, RefreshSessionRecord, RefundState, ReserveBankInfo,
+ ReserveRecordStatus, WalletContractData, WalletRefundItem, WalletStoresV1, WireInfo
} from "../../db.js";
+import { InternalWalletState } from "../../internal-wallet-state.js";
import { PayCoinSelection } from "../../util/coinSelection.js";
-import { j2s } from "@gnu-taler/taler-util";
import {
checkDbInvariant,
- checkLogicInvariant,
+ checkLogicInvariant
} from "../../util/invariants.js";
-import { Logger } from "@gnu-taler/taler-util";
-import { resetRetryInfo } from "../../util/retries.js";
-import { InternalWalletState } from "../../internal-wallet-state.js";
-import { provideBackupState } from "./state.js";
-import { makeEventId, TombstoneTag } from "../transactions.js";
-import { getExchangeDetails } from "../exchanges.js";
import { GetReadOnlyAccess, GetReadWriteAccess } from "../../util/query.js";
+import { RetryInfo } from "../../util/retries.js";
+import { getExchangeDetails } from "../exchanges.js";
+import { makeEventId, TombstoneTag } from "../transactions.js";
+import { provideBackupState } from "./state.js";
const logger = new Logger("operations/backup/import.ts");
@@ -276,7 +252,7 @@ export async function importBackup(
protocolVersionRange: backupExchange.protocol_version_range,
},
permanent: true,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
lastUpdate: undefined,
nextUpdate: TalerProtocolTimestamp.now(),
nextRefreshCheck: TalerProtocolTimestamp.now(),
@@ -464,7 +440,7 @@ export async function importBackup(
timestampReserveInfoPosted:
backupReserve.bank_info?.timestamp_reserve_info_posted,
senderWire: backupReserve.sender_wire,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
lastError: undefined,
initialWithdrawalGroupId:
backupReserve.initial_withdrawal_group_id,
@@ -505,7 +481,7 @@ export async function importBackup(
backupWg.raw_withdrawal_amount,
),
reservePub,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
secretSeed: backupWg.secret_seed,
timestampStart: backupWg.timestamp_created,
timestampFinish: backupWg.timestamp_finish,
@@ -618,7 +594,7 @@ export async function importBackup(
cryptoComp.proposalNoncePrivToPub[backupProposal.nonce_priv],
proposalId: backupProposal.proposal_id,
repurchaseProposalId: backupProposal.repurchase_proposal_id,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
download,
proposalStatus,
});
@@ -753,7 +729,7 @@ export async function importBackup(
cryptoComp.proposalNoncePrivToPub[backupPurchase.nonce_priv],
lastPayError: undefined,
autoRefundDeadline: TalerProtocolTimestamp.never(),
- refundStatusRetryInfo: resetRetryInfo(),
+ refundStatusRetryInfo: RetryInfo.reset(),
lastRefundStatusError: undefined,
refundAwaiting: undefined,
timestampAccept: backupPurchase.timestamp_accept,
@@ -764,7 +740,7 @@ export async function importBackup(
lastSessionId: undefined,
abortStatus,
// FIXME!
- payRetryInfo: resetRetryInfo(),
+ payRetryInfo: RetryInfo.reset(),
download,
paymentSubmitPending:
!backupPurchase.timestamp_first_successful_pay,
@@ -865,7 +841,7 @@ export async function importBackup(
Amounts.parseOrThrow(x.estimated_output_amount),
),
refreshSessionPerCoin,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
});
}
}
@@ -891,7 +867,7 @@ export async function importBackup(
merchantBaseUrl: backupTip.exchange_base_url,
merchantTipId: backupTip.merchant_tip_id,
pickedUpTimestamp: backupTip.timestamp_finished,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
secretSeed: backupTip.secret_seed,
tipAmountEffective: denomsSel.totalCoinValue,
tipAmountRaw: Amounts.parseOrThrow(backupTip.tip_amount_raw),
diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts b/packages/taler-wallet-core/src/operations/backup/index.ts
index 0b2bd7b80..69ba1ddbc 100644
--- a/packages/taler-wallet-core/src/operations/backup/index.ts
+++ b/packages/taler-wallet-core/src/operations/backup/index.ts
@@ -25,10 +25,9 @@
* Imports.
*/
import {
- AmountString,
+ AbsoluteTime, AmountString,
BackupRecovery,
- buildCodecForObject,
- canonicalizeBaseUrl,
+ buildCodecForObject, bytesToString, canonicalizeBaseUrl,
canonicalJson,
Codec,
codecForAmountString,
@@ -37,39 +36,22 @@ import {
codecForNumber,
codecForString,
codecOptional,
- ConfirmPayResultType,
- DenomKeyType,
- durationFromSpec,
- hashDenomPub,
+ ConfirmPayResultType, decodeCrock, DenomKeyType,
+ durationFromSpec, eddsaGetPublic,
+ EddsaKeyPair,
+ encodeCrock,
+ getRandomBytes,
+ hash, hashDenomPub,
HttpStatusCode,
- j2s,
- Logger,
+ j2s, kdf, Logger,
notEmpty,
PreparePayResultType,
RecoveryLoadRequest,
- RecoveryMergeStrategy,
- TalerErrorDetail,
- AbsoluteTime,
- URL,
- WalletBackupContentV1,
- TalerProtocolTimestamp,
+ RecoveryMergeStrategy, rsaBlind, secretbox, secretbox_open, stringToBytes, TalerErrorDetail, TalerProtocolTimestamp, URL,
+ WalletBackupContentV1
} from "@gnu-taler/taler-util";
import { gunzipSync, gzipSync } from "fflate";
-import { InternalWalletState } from "../../internal-wallet-state.js";
-import { kdf } from "@gnu-taler/taler-util";
-import { secretbox, secretbox_open } from "@gnu-taler/taler-util";
-import {
- bytesToString,
- decodeCrock,
- eddsaGetPublic,
- EddsaKeyPair,
- encodeCrock,
- getRandomBytes,
- hash,
- rsaBlind,
- stringToBytes,
-} from "@gnu-taler/taler-util";
-import { CryptoDispatcher } from "../../crypto/workers/cryptoDispatcher.js";
+import { TalerCryptoInterface } from "../../crypto/cryptoImplementation.js";
import {
BackupProviderRecord,
BackupProviderState,
@@ -78,28 +60,28 @@ import {
ConfigRecord,
WalletBackupConfState,
WalletStoresV1,
- WALLET_BACKUP_STATE_KEY,
+ WALLET_BACKUP_STATE_KEY
} from "../../db.js";
+import { InternalWalletState } from "../../internal-wallet-state.js";
import {
readSuccessResponseJsonOrThrow,
- readTalerErrorResponse,
+ readTalerErrorResponse
} from "../../util/http.js";
import {
checkDbInvariant,
- checkLogicInvariant,
+ checkLogicInvariant
} from "../../util/invariants.js";
import { GetReadWriteAccess } from "../../util/query.js";
-import { resetRetryInfo, updateRetryInfoTimeout } from "../../util/retries.js";
+import { RetryInfo } from "../../util/retries.js";
+import { guardOperationException } from "../common.js";
import {
checkPaymentByProposalId,
confirmPay,
- preparePayForUri,
+ preparePayForUri
} from "../pay.js";
import { exportBackup } from "./export.js";
import { BackupCryptoPrecomputedData, importBackup } from "./import.js";
import { getWalletBackupState, provideBackupState } from "./state.js";
-import { guardOperationException } from "../common.js";
-import { TalerCryptoInterface } from "../../crypto/cryptoImplementation.js";
const logger = new Logger("operations/backup.ts");
@@ -309,8 +291,8 @@ async function runBackupCycleForProvider(
"if-none-match": newHash,
...(provider.lastBackupHash
? {
- "if-match": provider.lastBackupHash,
- }
+ "if-match": provider.lastBackupHash,
+ }
: {}),
},
});
@@ -344,7 +326,7 @@ async function runBackupCycleForProvider(
}
const res = await preparePayForUri(ws, talerUri);
let proposalId = res.proposalId;
- let doPay: boolean = false;
+ let doPay = false;
switch (res.status) {
case PreparePayResultType.InsufficientBalance:
// FIXME: record in provider state!
@@ -434,7 +416,7 @@ async function runBackupCycleForProvider(
// FIXME: Allocate error code for this situation?
prov.state = {
tag: BackupProviderStateTag.Retrying,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
};
await tx.backupProvider.put(prov);
});
@@ -472,13 +454,12 @@ async function incrementBackupRetryInTx(
return;
}
if (pr.state.tag === BackupProviderStateTag.Retrying) {
- pr.state.retryInfo.retryCounter++;
pr.state.lastError = err;
- updateRetryInfoTimeout(pr.state.retryInfo);
+ pr.state.retryInfo = RetryInfo.increment(pr.state.retryInfo);
} else if (pr.state.tag === BackupProviderStateTag.Ready) {
pr.state = {
tag: BackupProviderStateTag.Retrying,
- retryInfo: resetRetryInfo(),
+ retryInfo: RetryInfo.reset(),
lastError: err,
};
}
@@ -685,7 +666,9 @@ export async function addBackupProvider(
});
}
-export async function restoreFromRecoverySecret(): Promise<void> {}
+export async function restoreFromRecoverySecret(): Promise<void> {
+ return;
+}
/**
* Information about one provider.