wallet-core: DB tweaks, consistent file naming convention

This commit is contained in:
Florian Dold 2022-10-14 22:38:40 +02:00
parent a57fcb144d
commit eec6695be0
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
19 changed files with 65 additions and 67 deletions

View File

@ -27,7 +27,7 @@ import {
codecForList, codecForList,
Codec, Codec,
} from "./codec.js"; } from "./codec.js";
import { AmountString } from "./talerTypes.js"; import { AmountString } from "./taler-types.js";
import { import {
ReserveTransaction, ReserveTransaction,
codecForReserveTransaction, codecForReserveTransaction,

View File

@ -37,7 +37,7 @@ import {
EddsaSignatureString, EddsaSignatureString,
EddsaPublicKeyString, EddsaPublicKeyString,
CoinPublicKeyString, CoinPublicKeyString,
} from "./talerTypes.js"; } from "./taler-types.js";
import { import {
AbsoluteTime, AbsoluteTime,
codecForTimestamp, codecForTimestamp,

View File

@ -27,7 +27,7 @@ import {
codecForNumber, codecForNumber,
Codec, Codec,
} from "./codec.js"; } from "./codec.js";
import { AmountString } from "./talerTypes.js"; import { AmountString } from "./taler-types.js";
/** /**
* Number of fractional units that one value unit represents. * Number of fractional units that one value unit represents.

View File

@ -62,7 +62,7 @@
/** /**
* Imports. * Imports.
*/ */
import { DenominationPubKey, UnblindedSignature } from "./talerTypes.js"; import { DenominationPubKey, UnblindedSignature } from "./taler-types.js";
import { TalerProtocolDuration, TalerProtocolTimestamp } from "./time.js"; import { TalerProtocolDuration, TalerProtocolTimestamp } from "./time.js";
export const BACKUP_TAG = "gnu-taler-wallet-backup-content" as const; export const BACKUP_TAG = "gnu-taler-wallet-backup-content" as const;

View File

@ -23,7 +23,7 @@
* Imports. * Imports.
*/ */
import { AmountJson, Amounts } from "./amounts.js"; import { AmountJson, Amounts } from "./amounts.js";
import { decodeCrock } from "./talerCrypto.js"; import { decodeCrock } from "./taler-crypto.js";
import * as segwit from "./segwit_addr.js"; import * as segwit from "./segwit_addr.js";
function buf2hex(buffer: Uint8Array) { function buf2hex(buffer: Uint8Array) {

View File

@ -19,7 +19,7 @@
*/ */
import test from "ava"; import test from "ava";
import { initNodePrng } from "./prng-node.js"; import { initNodePrng } from "./prng-node.js";
import { ContractTermsUtil } from "./contractTerms.js"; import { ContractTermsUtil } from "./contract-terms.js";
// Since we import nacl-fast directly (and not via index.node.ts), we need to // Since we import nacl-fast directly (and not via index.node.ts), we need to
// init the PRNG manually. // init the PRNG manually.

View File

@ -23,7 +23,7 @@ import {
getRandomBytes, getRandomBytes,
hash, hash,
stringToBytes, stringToBytes,
} from "./talerCrypto.js"; } from "./taler-crypto.js";
const logger = new Logger("contractTerms.ts"); const logger = new Logger("contractTerms.ts");

View File

@ -3,7 +3,7 @@ import { TalerErrorCode } from "./taler-error-codes.js";
export { TalerErrorCode }; export { TalerErrorCode };
export * from "./amounts.js"; export * from "./amounts.js";
export * from "./backupTypes.js"; export * from "./backup-types.js";
export * from "./codec.js"; export * from "./codec.js";
export * from "./helpers.js"; export * from "./helpers.js";
export * from "./libtool-version.js"; export * from "./libtool-version.js";
@ -11,17 +11,17 @@ export * from "./notifications.js";
export * from "./payto.js"; export * from "./payto.js";
export * from "./ReserveStatus.js"; export * from "./ReserveStatus.js";
export * from "./ReserveTransaction.js"; export * from "./ReserveTransaction.js";
export * from "./talerTypes.js"; export * from "./taler-types.js";
export * from "./taleruri.js"; export * from "./taleruri.js";
export * from "./time.js"; export * from "./time.js";
export * from "./transactionsTypes.js"; export * from "./transactions-types.js";
export * from "./walletTypes.js"; export * from "./wallet-types.js";
export * from "./i18n.js"; export * from "./i18n.js";
export * from "./logging.js"; export * from "./logging.js";
export * from "./url.js"; export * from "./url.js";
export { fnutil } from "./fnutils.js"; export { fnutil } from "./fnutils.js";
export * from "./kdf.js"; export * from "./kdf.js";
export * from "./talerCrypto.js"; export * from "./taler-crypto.js";
export * from "./http-status-codes.js"; export * from "./http-status-codes.js";
export * from "./bitcoin.js"; export * from "./bitcoin.js";
export { export {
@ -32,4 +32,4 @@ export {
} from "./nacl-fast.js"; } from "./nacl-fast.js";
export { RequestThrottler } from "./RequestThrottler.js"; export { RequestThrottler } from "./RequestThrottler.js";
export * from "./CancellationToken.js"; export * from "./CancellationToken.js";
export * from "./contractTerms.js"; export * from "./contract-terms.js";

View File

@ -22,7 +22,7 @@
/** /**
* Imports. * Imports.
*/ */
import { TalerErrorDetail } from "./walletTypes.js"; import { TalerErrorDetail } from "./wallet-types.js";
export enum NotificationType { export enum NotificationType {
CoinWithdrawn = "coin-withdrawn", CoinWithdrawn = "coin-withdrawn",

View File

@ -38,7 +38,7 @@ import {
getRandomBytes, getRandomBytes,
bigintToNaclArr, bigintToNaclArr,
bigintFromNaclArr, bigintFromNaclArr,
} from "./talerCrypto.js"; } from "./taler-crypto.js";
import { sha512, kdf } from "./kdf.js"; import { sha512, kdf } from "./kdf.js";
import * as nacl from "./nacl-fast.js"; import * as nacl from "./nacl-fast.js";
import { initNodePrng } from "./prng-node.js"; import { initNodePrng } from "./prng-node.js";

View File

@ -30,7 +30,7 @@ import {
DenominationPubKey, DenominationPubKey,
DenomKeyType, DenomKeyType,
HashCodeString, HashCodeString,
} from "./talerTypes.js"; } from "./taler-types.js";
import { Logger } from "./logging.js"; import { Logger } from "./logging.js";
import { secretbox } from "./nacl-fast.js"; import { secretbox } from "./nacl-fast.js";
import * as fflate from "fflate"; import * as fflate from "fflate";

View File

@ -41,7 +41,7 @@ import {
codecOptional, codecOptional,
} from "./codec.js"; } from "./codec.js";
import { strcmp } from "./helpers.js"; import { strcmp } from "./helpers.js";
import { AgeCommitmentProof, Edx25519PublicKeyEnc } from "./talerCrypto.js"; import { AgeCommitmentProof, Edx25519PublicKeyEnc } from "./taler-crypto.js";
import { import {
codecForAbsoluteTime, codecForAbsoluteTime,
codecForDuration, codecForDuration,

View File

@ -34,7 +34,7 @@ import {
codecForMerchantInfo, codecForMerchantInfo,
codecForProduct, codecForProduct,
Location, Location,
} from "./talerTypes.js"; } from "./taler-types.js";
import { import {
Codec, Codec,
buildCodecForObject, buildCodecForObject,
@ -43,7 +43,11 @@ import {
codecForList, codecForList,
codecForAny, codecForAny,
} from "./codec.js"; } from "./codec.js";
import { RefreshReason, TalerErrorDetail } from "./walletTypes.js"; import {
RefreshReason,
TalerErrorDetail,
TransactionIdStr,
} from "./wallet-types.js";
export interface TransactionsRequest { export interface TransactionsRequest {
/** /**
@ -68,7 +72,7 @@ export interface TransactionsResponse {
export interface TransactionCommon { export interface TransactionCommon {
// opaque unique ID for the transaction, used as a starting point for paginating queries // opaque unique ID for the transaction, used as a starting point for paginating queries
// and for invoking actions on the transaction (e.g. deleting/hiding it from the history) // and for invoking actions on the transaction (e.g. deleting/hiding it from the history)
transactionId: string; transactionId: TransactionIdStr;
// the type of the transaction; different types might provide additional information // the type of the transaction; different types might provide additional information
type: TransactionType; type: TransactionType;

View File

@ -15,7 +15,7 @@
*/ */
import test from "ava"; import test from "ava";
import { codecForContractTerms } from "./talerTypes.js"; import { codecForContractTerms } from "./taler-types.js";
test("contract terms validation", (t) => { test("contract terms validation", (t) => {
const c = { const c = {

View File

@ -62,14 +62,24 @@ import {
DenomKeyType, DenomKeyType,
ExchangeAuditor, ExchangeAuditor,
UnblindedSignature, UnblindedSignature,
} from "./talerTypes.js"; } from "./taler-types.js";
import { OrderShortInfo, codecForOrderShortInfo } from "./transactionsTypes.js"; import { OrderShortInfo, codecForOrderShortInfo } from "./transactions-types.js";
import { BackupRecovery } from "./backupTypes.js"; import { BackupRecovery } from "./backup-types.js";
import { PaytoUri } from "./payto.js"; import { PaytoUri } from "./payto.js";
import { TalerErrorCode } from "./taler-error-codes.js"; import { TalerErrorCode } from "./taler-error-codes.js";
import { AgeCommitmentProof } from "./talerCrypto.js"; import { AgeCommitmentProof } from "./taler-crypto.js";
import { VersionMatchResult } from "./libtool-version.js"; import { VersionMatchResult } from "./libtool-version.js";
/**
* Identifier for a transaction in the wallet.
*/
export type TransactionIdStr = `tx:${string}:${string}`;
/**
* Identifier for a pending task in the wallet.
*/
export type PendingIdStr = `pd:${string}:string`;
/** /**
* Response for the create reserve request to the wallet. * Response for the create reserve request to the wallet.
*/ */

View File

@ -48,6 +48,7 @@ import {
GlobalFees, GlobalFees,
ExchangeGlobalFees, ExchangeGlobalFees,
DenomSelectionState, DenomSelectionState,
TransactionIdStr,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { RetryInfo, RetryTags } from "./util/retries.js"; import { RetryInfo, RetryTags } from "./util/retries.js";
import { Event, IDBDatabase } from "@gnu-taler/idb-bridge"; import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
@ -765,8 +766,10 @@ export interface CoinRecord {
* Coin allocation, i.e. what a coin has been used for. * Coin allocation, i.e. what a coin has been used for.
*/ */
export interface CoinAllocation { export interface CoinAllocation {
// FIXME: Specify format! /**
id: string; * ID of the allocation, should be the ID of the transaction that
*/
id: TransactionIdStr;
amount: AmountString; amount: AmountString;
} }
@ -1065,6 +1068,9 @@ export enum PurchaseStatus {
*/ */
Paying = 11, Paying = 11,
/**
* Currently in the process of aborting with a refund.
*/
AbortingWithRefund = 12, AbortingWithRefund = 12,
/** /**
@ -1118,7 +1124,7 @@ export enum PurchaseStatus {
* Only contains data that is relevant for indexing on the * Only contains data that is relevant for indexing on the
* "purchases" object stores. * "purchases" object stores.
*/ */
export interface ProposalDownload { export interface ProposalDownloadInfo {
contractTermsHash: string; contractTermsHash: string;
fulfillmentUrl?: string; fulfillmentUrl?: string;
currency: string; currency: string;
@ -1129,15 +1135,6 @@ export interface PurchasePayInfo {
payCoinSelection: PayCoinSelection; payCoinSelection: PayCoinSelection;
totalPayCost: AmountJson; totalPayCost: AmountJson;
payCoinSelectionUid: string; payCoinSelectionUid: string;
/**
* Deposit permissions, available once the user has accepted the payment.
*
* This value is cached and derived from payCoinSelection.
*
* FIXME: Should probably be cached somewhere else, maybe not even in DB!
*/
coinDepositPermissions: CoinDepositPermission[] | undefined;
} }
/** /**
@ -1191,11 +1188,8 @@ export interface PurchaseRecord {
/** /**
* Downloaded and parsed proposal data. * Downloaded and parsed proposal data.
*
* FIXME: Move this into another object store,
* to improve read/write perf on purchases.
*/ */
download: ProposalDownload | undefined; download: ProposalDownloadInfo | undefined;
payInfo: PurchasePayInfo | undefined; payInfo: PurchasePayInfo | undefined;

View File

@ -45,7 +45,7 @@ import {
DenominationRecord, DenominationRecord,
DenominationVerificationStatus, DenominationVerificationStatus,
OperationStatus, OperationStatus,
ProposalDownload, ProposalDownloadInfo,
PurchaseStatus, PurchaseStatus,
PurchasePayInfo, PurchasePayInfo,
RefreshCoinStatus, RefreshCoinStatus,
@ -649,7 +649,7 @@ export async function importBackup(
} else { } else {
maxWireFee = Amounts.getZero(amount.currency); maxWireFee = Amounts.getZero(amount.currency);
} }
const download: ProposalDownload = { const download: ProposalDownloadInfo = {
contractTermsHash, contractTermsHash,
contractTermsMerchantSig: backupPurchase.merchant_sig!, contractTermsMerchantSig: backupPurchase.merchant_sig!,
currency: amount.currency, currency: amount.currency,
@ -665,7 +665,6 @@ export async function importBackup(
let payInfo: PurchasePayInfo | undefined = undefined; let payInfo: PurchasePayInfo | undefined = undefined;
if (backupPurchase.pay_info) { if (backupPurchase.pay_info) {
payInfo = { payInfo = {
coinDepositPermissions: undefined,
payCoinSelection: await recoverPayCoinSelection( payCoinSelection: await recoverPayCoinSelection(
tx, tx,
contractData, contractData,

View File

@ -25,6 +25,7 @@ import {
RefreshReason, RefreshReason,
TalerErrorCode, TalerErrorCode,
TalerErrorDetail, TalerErrorDetail,
TransactionIdStr,
TransactionType, TransactionType,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletStoresV1, CoinStatus, CoinRecord } from "../db.js"; import { WalletStoresV1, CoinStatus, CoinRecord } from "../db.js";
@ -37,7 +38,6 @@ import {
OperationAttemptResultType, OperationAttemptResultType,
RetryInfo, RetryInfo,
} from "../util/retries.js"; } from "../util/retries.js";
import { createRefreshGroup } from "./refresh.js";
const logger = new Logger("operations/common.ts"); const logger = new Logger("operations/common.ts");
@ -48,7 +48,7 @@ export interface CoinsSpendInfo {
/** /**
* Identifier for what the coin has been spent for. * Identifier for what the coin has been spent for.
*/ */
allocationId: string; allocationId: TransactionIdStr;
} }
export async function makeCoinAvailable( export async function makeCoinAvailable(

View File

@ -80,9 +80,8 @@ import {
CoinRecord, CoinRecord,
CoinStatus, CoinStatus,
DenominationRecord, DenominationRecord,
ProposalDownload,
PurchaseStatus,
PurchaseRecord, PurchaseRecord,
PurchaseStatus,
RefundReason, RefundReason,
RefundState, RefundState,
WalletContractData, WalletContractData,
@ -115,7 +114,6 @@ import {
throwUnexpectedRequestError, throwUnexpectedRequestError,
} from "../util/http.js"; } from "../util/http.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
import { GetReadOnlyAccess } from "../util/query.js";
import { import {
OperationAttemptResult, OperationAttemptResult,
OperationAttemptResultType, OperationAttemptResultType,
@ -124,10 +122,10 @@ import {
scheduleRetry, scheduleRetry,
} from "../util/retries.js"; } from "../util/retries.js";
import { import {
spendCoins,
storeOperationPending,
storeOperationError,
makeEventId, makeEventId,
spendCoins,
storeOperationError,
storeOperationPending,
} from "./common.js"; } from "./common.js";
import { getExchangeDetails } from "./exchanges.js"; import { getExchangeDetails } from "./exchanges.js";
import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js"; import { createRefreshGroup, getTotalRefreshCost } from "./refresh.js";
@ -858,10 +856,9 @@ async function handleInsufficientFunds(
payInfo.payCoinSelection = res; payInfo.payCoinSelection = res;
payInfo.payCoinSelection = res; payInfo.payCoinSelection = res;
payInfo.payCoinSelectionUid = encodeCrock(getRandomBytes(32)); payInfo.payCoinSelectionUid = encodeCrock(getRandomBytes(32));
payInfo.coinDepositPermissions = undefined;
await tx.purchases.put(p); await tx.purchases.put(p);
await spendCoins(ws, tx, { await spendCoins(ws, tx, {
allocationId: `proposal:${p.proposalId}`, allocationId: `tx:proposal:${p.proposalId}`,
coinPubs: payInfo.payCoinSelection.coinPubs, coinPubs: payInfo.payCoinSelection.coinPubs,
contributions: payInfo.payCoinSelection.coinContributions, contributions: payInfo.payCoinSelection.coinContributions,
refreshReason: RefreshReason.PayMerchant, refreshReason: RefreshReason.PayMerchant,
@ -1732,14 +1729,13 @@ export async function confirmPay(
payCoinSelection: coinSelection, payCoinSelection: coinSelection,
payCoinSelectionUid: encodeCrock(getRandomBytes(16)), payCoinSelectionUid: encodeCrock(getRandomBytes(16)),
totalPayCost: payCostInfo, totalPayCost: payCostInfo,
coinDepositPermissions: depositPermissions,
}; };
p.lastSessionId = sessionId; p.lastSessionId = sessionId;
p.timestampAccept = TalerProtocolTimestamp.now(); p.timestampAccept = TalerProtocolTimestamp.now();
p.purchaseStatus = PurchaseStatus.Paying; p.purchaseStatus = PurchaseStatus.Paying;
await tx.purchases.put(p); await tx.purchases.put(p);
await spendCoins(ws, tx, { await spendCoins(ws, tx, {
allocationId: `proposal:${p.proposalId}`, allocationId: `tx:proposal:${p.proposalId}`,
coinPubs: coinSelection.coinPubs, coinPubs: coinSelection.coinPubs,
contributions: coinSelection.coinContributions, contributions: coinSelection.coinContributions,
refreshReason: RefreshReason.PayMerchant, refreshReason: RefreshReason.PayMerchant,
@ -1856,17 +1852,12 @@ export async function processPurchasePay(
).href; ).href;
let depositPermissions: CoinDepositPermission[]; let depositPermissions: CoinDepositPermission[];
// FIXME: Cache!
if (purchase.payInfo?.coinDepositPermissions) {
depositPermissions = purchase.payInfo.coinDepositPermissions;
} else {
// FIXME: also cache!
depositPermissions = await generateDepositPermissions( depositPermissions = await generateDepositPermissions(
ws, ws,
payInfo.payCoinSelection, payInfo.payCoinSelection,
download.contractData, download.contractData,
); );
}
const reqBody = { const reqBody = {
coins: depositPermissions, coins: depositPermissions,