wallet-core: use more numeric fields

This commit is contained in:
Florian Dold 2022-09-21 21:13:31 +02:00
parent 7d6bcd42ea
commit a398959670
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 37 additions and 19 deletions

View File

@ -65,6 +65,8 @@ import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
* - Every record that has a corresponding transaction item must have * - Every record that has a corresponding transaction item must have
* an index for a mandatory timestamp field. * an index for a mandatory timestamp field.
* - Optional fields should be avoided, use "T | undefined" instead. * - Optional fields should be avoided, use "T | undefined" instead.
* - Do all records have some obvious, indexed field that can
* be used for range queries?
* *
* @author Florian Dold <dold@taler.net> * @author Florian Dold <dold@taler.net>
*/ */
@ -99,8 +101,8 @@ export const WALLET_DB_MINOR_VERSION = 1;
export namespace OperationStatusRange { export namespace OperationStatusRange {
export const ACTIVE_START = 10; export const ACTIVE_START = 10;
export const ACTIVE_END = 29; export const ACTIVE_END = 29;
export const DORMANT_START = 40; export const DORMANT_START = 50;
export const DORMANT_END = 59; export const DORMANT_END = 69;
} }
/** /**
@ -148,7 +150,7 @@ export interface ReserveBankInfo {
* URL that the user can be redirected to, and allows * URL that the user can be redirected to, and allows
* them to confirm (or abort) the bank-integrated withdrawal. * them to confirm (or abort) the bank-integrated withdrawal.
*/ */
confirmUrl?: string; confirmUrl: string | undefined;
/** /**
* Exchange payto URI that the bank will use to fund the reserve. * Exchange payto URI that the bank will use to fund the reserve.
@ -162,14 +164,14 @@ export interface ReserveBankInfo {
* *
* Set to undefined if that hasn't happened yet. * Set to undefined if that hasn't happened yet.
*/ */
timestampReserveInfoPosted?: TalerProtocolTimestamp; timestampReserveInfoPosted: TalerProtocolTimestamp | undefined;
/** /**
* Time when the reserve was confirmed by the bank. * Time when the reserve was confirmed by the bank.
* *
* Set to undefined if not confirmed yet. * Set to undefined if not confirmed yet.
*/ */
timestampBankConfirmed?: TalerProtocolTimestamp; timestampBankConfirmed: TalerProtocolTimestamp | undefined;
} }
/** /**
@ -195,6 +197,8 @@ export interface AuditorTrustRecord {
/** /**
* UIDs for the operation of adding this auditor * UIDs for the operation of adding this auditor
* as a trusted auditor. * as a trusted auditor.
*
* (Used for backup/sync merging and tombstones.)
*/ */
uids: string[]; uids: string[];
} }
@ -232,15 +236,17 @@ export enum DenominationVerificationStatus {
/** /**
* Verification was delayed. * Verification was delayed.
*/ */
Unverified = "unverified", Unverified = OperationStatusRange.ACTIVE_START,
/** /**
* Verified as valid. * Verified as valid.
*/ */
VerifiedGood = "verified-good", VerifiedGood = OperationStatusRange.DORMANT_START,
/** /**
* Verified as invalid. * Verified as invalid.
*/ */
VerifiedBad = "verified-bad", VerifiedBad = OperationStatusRange.DORMANT_START + 1,
} }
export interface DenomFees { export interface DenomFees {
@ -705,13 +711,16 @@ export interface CoinRecord {
/** /**
* Information about what the coin has been allocated for. * Information about what the coin has been allocated for.
* Used to prevent allocation of the same coin for two different payments. *
* Used for:
* - Diagnostics
* - Idempotency of applying a coin selection (e.g. after re-selection)
*/ */
allocation?: CoinAllocation; allocation: CoinAllocation | undefined;
maxAge: number; maxAge: number;
ageCommitmentProof?: AgeCommitmentProof; ageCommitmentProof: AgeCommitmentProof | undefined;
} }
export interface CoinAllocation { export interface CoinAllocation {
@ -801,7 +810,7 @@ export interface ProposalRecord {
/** /**
* Session ID we got when downloading the contract. * Session ID we got when downloading the contract.
*/ */
downloadSessionId?: string; downloadSessionId: string | undefined;
} }
/** /**
@ -875,19 +884,19 @@ export interface TipRecord {
} }
export enum RefreshCoinStatus { export enum RefreshCoinStatus {
Pending = "pending", Pending = OperationStatusRange.ACTIVE_START,
Finished = "finished", Finished = OperationStatusRange.DORMANT_START,
/** /**
* The refresh for this coin has been frozen, because of a permanent error. * The refresh for this coin has been frozen, because of a permanent error.
* More info in lastErrorPerCoin. * More info in lastErrorPerCoin.
*/ */
Frozen = "frozen", Frozen = OperationStatusRange.DORMANT_START + 1,
} }
export enum OperationStatus { export enum OperationStatus {
Finished = "finished", Finished = OperationStatusRange.DORMANT_START,
Pending = "pending", Pending = OperationStatusRange.ACTIVE_START,
} }
export interface RefreshGroupRecord { export interface RefreshGroupRecord {

View File

@ -285,6 +285,10 @@ export async function importCoin(
coinSource, coinSource,
// FIXME! // FIXME!
maxAge: AgeRestriction.AGE_UNRESTRICTED, maxAge: AgeRestriction.AGE_UNRESTRICTED,
// FIXME!
ageCommitmentProof: undefined,
// FIXME!
allocation: undefined,
}; };
if (coinRecord.status === CoinStatus.Fresh) { if (coinRecord.status === CoinStatus.Fresh) {
await makeCoinAvailable(ws, tx, coinRecord); await makeCoinAvailable(ws, tx, coinRecord);
@ -655,6 +659,8 @@ export async function importBackup(
repurchaseProposalId: backupProposal.repurchase_proposal_id, repurchaseProposalId: backupProposal.repurchase_proposal_id,
download, download,
proposalStatus, proposalStatus,
// FIXME!
downloadSessionId: undefined,
}); });
} }
} }

View File

@ -28,8 +28,6 @@ import {
BackupProviderStateTag, BackupProviderStateTag,
RefreshCoinStatus, RefreshCoinStatus,
OperationStatus, OperationStatus,
WithdrawalGroupRecord,
WithdrawalGroupStatus,
OperationStatusRange, OperationStatusRange,
} from "../db.js"; } from "../db.js";
import { import {

View File

@ -682,6 +682,7 @@ async function refreshReveal(
coinEvHash: pc.coinEvHash, coinEvHash: pc.coinEvHash,
maxAge: pc.maxAge, maxAge: pc.maxAge,
ageCommitmentProof: pc.ageCommitmentProof, ageCommitmentProof: pc.ageCommitmentProof,
allocation: undefined,
}; };
coins.push(coin); coins.push(coin);

View File

@ -320,6 +320,7 @@ export async function processTip(
coinEvHash: planchet.coinEvHash, coinEvHash: planchet.coinEvHash,
maxAge: AgeRestriction.AGE_UNRESTRICTED, maxAge: AgeRestriction.AGE_UNRESTRICTED,
ageCommitmentProof: planchet.ageCommitmentProof, ageCommitmentProof: planchet.ageCommitmentProof,
allocation: undefined,
}); });
} }

View File

@ -834,6 +834,7 @@ async function processPlanchetVerifyAndStoreCoin(
}, },
maxAge: planchet.maxAge, maxAge: planchet.maxAge,
ageCommitmentProof: planchet.ageCommitmentProof, ageCommitmentProof: planchet.ageCommitmentProof,
allocation: undefined,
}; };
const planchetCoinPub = planchet.coinPub; const planchetCoinPub = planchet.coinPub;
@ -1832,6 +1833,8 @@ export async function acceptWithdrawalFromUri(
exchangePaytoUri, exchangePaytoUri,
talerWithdrawUri: req.talerWithdrawUri, talerWithdrawUri: req.talerWithdrawUri,
confirmUrl: withdrawInfo.confirmTransferUrl, confirmUrl: withdrawInfo.confirmTransferUrl,
timestampBankConfirmed: undefined,
timestampReserveInfoPosted: undefined,
}, },
}, },
restrictAge: req.restrictAge, restrictAge: req.restrictAge,