remove ToS storage

This commit is contained in:
Florian Dold 2023-09-06 18:43:37 +02:00
parent cd9c3a143b
commit 1fcb55c84d
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 10 additions and 147 deletions

View File

@ -1076,13 +1076,6 @@ export interface KnownBankAccounts {
accounts: KnownBankAccountsInfo[];
}
export interface ExchangeTosStatusDetails {
acceptedVersion?: string;
currentVersion?: string;
contentType?: string;
content?: string;
}
/**
* Wire fee for one wire method
*/
@ -1253,7 +1246,6 @@ export interface ExchangeFullDetails {
exchangeBaseUrl: string;
currency: string;
paytoUris: string[];
tos: ExchangeTosStatusDetails;
auditors: ExchangeAuditor[];
wireInfo: WireInfo;
denomFees: DenomOperationMap<FeeDescription[]>;
@ -1317,14 +1309,6 @@ const codecForExchangeAuditor = (): Codec<ExchangeAuditor> =>
.property("denomination_keys", codecForList(codecForAuditorDenomSig()))
.build("codecForExchangeAuditor");
const codecForExchangeTos = (): Codec<ExchangeTosStatusDetails> =>
buildCodecForObject<ExchangeTosStatusDetails>()
.property("acceptedVersion", codecOptional(codecForString()))
.property("currentVersion", codecOptional(codecForString()))
.property("contentType", codecOptional(codecForString()))
.property("content", codecOptional(codecForString()))
.build("ExchangeTos");
export const codecForFeeDescriptionPair = (): Codec<FeeDescriptionPair> =>
buildCodecForObject<FeeDescriptionPair>()
.property("group", codecForString())
@ -1357,7 +1341,6 @@ export const codecForExchangeFullDetails = (): Codec<ExchangeFullDetails> =>
.property("currency", codecForString())
.property("exchangeBaseUrl", codecForString())
.property("paytoUris", codecForList(codecForString()))
.property("tos", codecForExchangeTos())
.property("auditors", codecForList(codecForExchangeAuditor()))
.property("wireInfo", codecForWireInfo())
.property("denomFees", codecForFeesByOperations())

View File

@ -2382,13 +2382,6 @@ export const WalletStoresV1 = {
byReservePub: describeIndex("byReservePub", "reservePub", {}),
},
),
exchangeTos: describeStore(
"exchangeTos",
describeContents<ExchangeTosRecord>({
keyPath: ["exchangeBaseUrl", "etag"],
}),
{},
),
config: describeStore(
"config",
describeContents<ConfigRecord>({ keyPath: "key" }),

View File

@ -157,35 +157,6 @@ export async function getExchangeDetails(
getExchangeDetails.makeContext = (db: DbAccess<typeof WalletStoresV1>) =>
db.mktx((x) => [x.exchanges, x.exchangeDetails]);
/**
* Update the database based on the download of the terms of service.
*/
export async function updateExchangeTermsOfService(
ws: InternalWalletState,
exchangeBaseUrl: string,
tos: ExchangeTosDownloadResult,
): Promise<void> {
await ws.db
.mktx((x) => [x.exchanges, x.exchangeTos, x.exchangeDetails])
.runReadWrite(async (tx) => {
const d = await getExchangeDetails(tx, exchangeBaseUrl);
let tosRecord = await tx.exchangeTos.get([exchangeBaseUrl, tos.tosEtag]);
if (!tosRecord) {
tosRecord = {
etag: tos.tosEtag,
exchangeBaseUrl,
termsOfServiceContentType: tos.tosContentType,
termsOfServiceText: tos.tosText,
};
await tx.exchangeTos.put(tosRecord);
}
if (d) {
d.tosCurrentEtag = tos.tosEtag;
await tx.exchangeDetails.put(d);
}
});
}
/**
* Mark a ToS version as accepted by the user.
*
@ -740,7 +711,6 @@ export async function updateExchangeFromUrlHandler(
const updated = await ws.db
.mktx((x) => [
x.exchanges,
x.exchangeTos,
x.exchangeDetails,
x.exchangeSignKeys,
x.denominations,
@ -801,21 +771,6 @@ export async function updateExchangeFromUrlHandler(
const drRowId = await tx.exchangeDetails.put(newDetails);
checkDbInvariant(typeof drRowId.key === "number");
let tosRecord = await tx.exchangeTos.get([
exchangeBaseUrl,
tosDownload.tosEtag,
]);
if (!tosRecord || tosRecord.etag !== existingTosAccepted?.etag) {
tosRecord = {
etag: tosDownload.tosEtag,
exchangeBaseUrl,
termsOfServiceContentType: tosDownload.tosContentType,
termsOfServiceText: tosDownload.tosText,
};
await tx.exchangeTos.put(tosRecord);
}
for (const sk of keysInfo.signingKeys) {
// FIXME: validate signing keys before inserting them
await tx.exchangeSignKeys.put({

View File

@ -1856,7 +1856,6 @@ export async function getWithdrawalDetailsForUri(
.mktx((x) => [
x.exchanges,
x.exchangeDetails,
x.exchangeTos,
x.denominations,
x.operationRetries,
])

View File

@ -34,7 +34,6 @@ import {
Duration,
ExchangeDetailedResponse,
ExchangeListItem,
ExchangeTosStatusDetails,
ExchangesListResponse,
FeeDescription,
GetExchangeTosResult,
@ -202,7 +201,6 @@ import {
provideExchangeRecordInTx,
updateExchangeFromUrl,
updateExchangeFromUrlHandler,
updateExchangeTermsOfService,
} from "./operations/exchanges.js";
import { getMerchantInfo } from "./operations/merchants.js";
import {
@ -557,33 +555,6 @@ async function getExchangeTos(
): Promise<GetExchangeTosResult> {
// FIXME: download ToS in acceptable format if passed!
const { exchangeDetails } = await updateExchangeFromUrl(ws, exchangeBaseUrl);
const tosDetails = await ws.db
.mktx((x) => [x.exchangeTos])
.runReadOnly(async (tx) => {
return await getExchangeTosStatusDetails(tx, exchangeDetails);
});
const content = tosDetails.content;
const currentEtag = tosDetails.currentVersion;
const contentType = tosDetails.contentType;
if (
content === undefined ||
currentEtag === undefined ||
contentType === undefined
) {
throw Error("exchange is in invalid state");
}
if (
acceptedFormat &&
acceptedFormat.findIndex((f) => f === contentType) !== -1
) {
return {
acceptedEtag: exchangeDetails.tosAccepted?.etag,
currentEtag,
content,
contentType,
tosStatus: getExchangeTosStatus(exchangeDetails),
};
}
const tosDownload = await downloadTosFromAcceptedFormat(
ws,
@ -592,17 +563,15 @@ async function getExchangeTos(
acceptedFormat,
);
if (tosDownload.tosContentType === contentType) {
return {
acceptedEtag: exchangeDetails.tosAccepted?.etag,
currentEtag,
content,
contentType,
tosStatus: getExchangeTosStatus(exchangeDetails),
};
}
await updateExchangeTermsOfService(ws, exchangeBaseUrl, tosDownload);
await ws.db
.mktx((x) => [x.exchanges, x.exchangeDetails])
.runReadWrite(async (tx) => {
const d = await getExchangeDetails(tx, exchangeBaseUrl);
if (d) {
d.tosCurrentEtag = tosDownload.tosEtag;
await tx.exchangeDetails.put(d);
}
});
return {
acceptedEtag: exchangeDetails.tosAccepted?.etag,
@ -683,32 +652,6 @@ async function forgetKnownBankAccounts(
return;
}
async function getExchangeTosStatusDetails(
tx: GetReadOnlyAccess<{ exchangeTos: typeof WalletStoresV1.exchangeTos }>,
exchangeDetails: ExchangeDetailsRecord,
): Promise<ExchangeTosStatusDetails> {
let exchangeTos = await tx.exchangeTos.get([
exchangeDetails.exchangeBaseUrl,
exchangeDetails.tosCurrentEtag,
]);
if (!exchangeTos) {
exchangeTos = {
etag: "not-available",
termsOfServiceContentType: "text/plain",
termsOfServiceText: "terms of service unavailable",
exchangeBaseUrl: exchangeDetails.exchangeBaseUrl,
};
}
return {
acceptedVersion: exchangeDetails.tosAccepted?.etag,
content: exchangeTos.termsOfServiceText,
contentType: exchangeTos.termsOfServiceContentType,
currentVersion: exchangeTos.etag,
};
}
async function getExchanges(
ws: InternalWalletState,
): Promise<ExchangesListResponse> {
@ -717,7 +660,6 @@ async function getExchanges(
.mktx((x) => [
x.exchanges,
x.exchangeDetails,
x.exchangeTos,
x.denominations,
x.operationRetries,
])
@ -742,12 +684,7 @@ async function getExchangeDetailedInfo(
): Promise<ExchangeDetailedResponse> {
//TODO: should we use the forceUpdate parameter?
const exchange = await ws.db
.mktx((x) => [
x.exchanges,
x.exchangeTos,
x.exchangeDetails,
x.denominations,
])
.mktx((x) => [x.exchanges, x.exchangeDetails, x.denominations])
.runReadOnly(async (tx) => {
const ex = await tx.exchanges.get(exchangeBaseurl);
const dp = ex?.detailsPointer;
@ -769,8 +706,6 @@ async function getExchangeDetailedInfo(
return;
}
const tos = await getExchangeTosStatusDetails(tx, exchangeDetails);
const denominations: DenominationInfo[] = denominationRecords.map((x) =>
DenominationRecord.toDenomInfo(x),
);
@ -779,7 +714,6 @@ async function getExchangeDetailedInfo(
info: {
exchangeBaseUrl: ex.baseUrl,
currency,
tos,
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
auditors: exchangeDetails.auditors,
wireInfo: exchangeDetails.wireInfo,

View File

@ -23,7 +23,6 @@ import {
ExchangeTosStatus,
TalerError,
parseWithdrawExchangeUri,
stringifyWithdrawUri,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { useEffect, useState } from "preact/hooks";