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,
Codec,
} from "./codec.js";
import { AmountString } from "./talerTypes.js";
import { AmountString } from "./taler-types.js";
import {
ReserveTransaction,
codecForReserveTransaction,

View File

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

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@
*/
import test from "ava";
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
// init the PRNG manually.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ import {
codecForMerchantInfo,
codecForProduct,
Location,
} from "./talerTypes.js";
} from "./taler-types.js";
import {
Codec,
buildCodecForObject,
@ -43,7 +43,11 @@ import {
codecForList,
codecForAny,
} from "./codec.js";
import { RefreshReason, TalerErrorDetail } from "./walletTypes.js";
import {
RefreshReason,
TalerErrorDetail,
TransactionIdStr,
} from "./wallet-types.js";
export interface TransactionsRequest {
/**
@ -68,7 +72,7 @@ export interface TransactionsResponse {
export interface TransactionCommon {
// 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)
transactionId: string;
transactionId: TransactionIdStr;
// the type of the transaction; different types might provide additional information
type: TransactionType;

View File

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

View File

@ -62,14 +62,24 @@ import {
DenomKeyType,
ExchangeAuditor,
UnblindedSignature,
} from "./talerTypes.js";
import { OrderShortInfo, codecForOrderShortInfo } from "./transactionsTypes.js";
import { BackupRecovery } from "./backupTypes.js";
} from "./taler-types.js";
import { OrderShortInfo, codecForOrderShortInfo } from "./transactions-types.js";
import { BackupRecovery } from "./backup-types.js";
import { PaytoUri } from "./payto.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";
/**
* 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.
*/

View File

@ -48,6 +48,7 @@ import {
GlobalFees,
ExchangeGlobalFees,
DenomSelectionState,
TransactionIdStr,
} from "@gnu-taler/taler-util";
import { RetryInfo, RetryTags } from "./util/retries.js";
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.
*/
export interface CoinAllocation {
// FIXME: Specify format!
id: string;
/**
* ID of the allocation, should be the ID of the transaction that
*/
id: TransactionIdStr;
amount: AmountString;
}
@ -1065,6 +1068,9 @@ export enum PurchaseStatus {
*/
Paying = 11,
/**
* Currently in the process of aborting with a refund.
*/
AbortingWithRefund = 12,
/**
@ -1118,7 +1124,7 @@ export enum PurchaseStatus {
* Only contains data that is relevant for indexing on the
* "purchases" object stores.
*/
export interface ProposalDownload {
export interface ProposalDownloadInfo {
contractTermsHash: string;
fulfillmentUrl?: string;
currency: string;
@ -1129,15 +1135,6 @@ export interface PurchasePayInfo {
payCoinSelection: PayCoinSelection;
totalPayCost: AmountJson;
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.
*
* FIXME: Move this into another object store,
* to improve read/write perf on purchases.
*/
download: ProposalDownload | undefined;
download: ProposalDownloadInfo | undefined;
payInfo: PurchasePayInfo | undefined;

View File

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

View File

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

View File

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