DB tweaks

This commit is contained in:
Florian Dold 2020-09-08 21:03:10 +05:30
parent ddbb09b140
commit aae06c680f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
9 changed files with 37 additions and 98 deletions

View File

@ -222,7 +222,7 @@ async function updateExchangeWithKeys(
for (const newDenom of newDenominations) {
const oldDenom = await tx.get(Stores.denominations, [
baseUrl,
newDenom.denomPub,
newDenom.denomPubHash,
]);
if (oldDenom) {
// FIXME: Do consistency check
@ -236,10 +236,10 @@ async function updateExchangeWithKeys(
const newlyRevokedCoinPubs: string[] = [];
logger.trace("recoup list from exchange", recoupDenomList);
for (const recoupInfo of recoupDenomList) {
const oldDenom = await tx.getIndexed(
Stores.denominations.denomPubHashIndex,
const oldDenom = await tx.get(Stores.denominations, [
r.baseUrl,
recoupInfo.h_denom_pub,
);
]);
if (!oldDenom) {
// We never even knew about the revoked denomination, all good.
continue;

View File

@ -131,7 +131,7 @@ export async function getTotalPaymentCost(
}
const denom = await ws.db.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPub,
coin.denomPubHash,
]);
if (!denom) {
throw Error(
@ -332,7 +332,7 @@ async function getCoinsForPayment(
// coins have the same currency
const firstDenom = await ws.db.get(Stores.denominations, [
exchange.baseUrl,
coins[0].denomPub,
coins[0].denomPubHash,
]);
if (!firstDenom) {
throw Error("db inconsistent");
@ -342,7 +342,7 @@ async function getCoinsForPayment(
for (const coin of coins) {
const denom = await ws.db.get(Stores.denominations, [
exchange.baseUrl,
coin.denomPub,
coin.denomPubHash,
]);
if (!denom) {
throw Error("db inconsistent");
@ -1148,7 +1148,7 @@ export async function confirmPay(
}
const denom = await ws.db.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPub,
coin.denomPubHash,
]);
if (!denom) {
throw Error(

View File

@ -134,7 +134,7 @@ async function refreshCreateSession(
const oldDenom = await ws.db.get(Stores.denominations, [
exchange.baseUrl,
coin.denomPub,
coin.denomPubHash,
]);
if (!oldDenom) {
@ -367,7 +367,7 @@ async function refreshReveal(
for (let i = 0; i < reveal.ev_sigs.length; i++) {
const denom = await ws.db.get(Stores.denominations, [
refreshSession.exchangeBaseUrl,
refreshSession.newDenoms[i],
refreshSession.newDenomHashes[i],
]);
if (!denom) {
console.error("denom not found");
@ -598,7 +598,7 @@ export async function createRefreshGroup(
checkDbInvariant(!!coin, "coin must be in database");
const denom = await tx.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPub,
coin.denomPubHash,
]);
checkDbInvariant(
!!denom,
@ -701,7 +701,7 @@ export async function autoRefresh(
}
const denom = await tx.get(Stores.denominations, [
exchangeBaseUrl,
coin.denomPub,
coin.denomPubHash,
]);
if (!denom) {
logger.warn("denomination not in database");

View File

@ -104,10 +104,10 @@ async function applySuccessfulRefund(
console.warn("coin not found, can't apply refund");
return;
}
const denom = await tx.getIndexed(
Stores.denominations.denomPubHashIndex,
const denom = await tx.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPubHash,
);
]);
if (!denom) {
throw Error("inconsistent database");
}
@ -161,10 +161,10 @@ async function storePendingRefund(
console.warn("coin not found, can't apply refund");
return;
}
const denom = await tx.getIndexed(
Stores.denominations.denomPubHashIndex,
const denom = await tx.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPubHash,
);
]);
if (!denom) {
throw Error("inconsistent database");
@ -211,10 +211,10 @@ async function storeFailedRefund(
console.warn("coin not found, can't apply refund");
return;
}
const denom = await tx.getIndexed(
Stores.denominations.denomPubHashIndex,
const denom = await tx.get(Stores.denominations, [
coin.exchangeBaseUrl,
coin.denomPubHash,
);
]);
if (!denom) {
throw Error("inconsistent database");
@ -294,7 +294,8 @@ async function acceptRefunds(
// Still pending.
if (
refundStatus.type === "failure" && !isPermanentFailure &&
refundStatus.type === "failure" &&
!isPermanentFailure &&
existingRefundInfo?.type === RefundState.Pending
) {
continue;

View File

@ -172,14 +172,6 @@ export async function createReserve(
expectedAmount: req.amount,
});
const senderWire = req.senderWire;
if (senderWire) {
const rec = {
paytoUri: senderWire,
};
await ws.db.put(Stores.senderWires, rec);
}
const exchangeInfo = await updateExchangeFromUrl(ws, req.exchange);
const exchangeDetails = exchangeInfo.details;
if (!exchangeDetails) {

View File

@ -104,10 +104,11 @@ export async function prepareTip(
planchets: undefined,
createdTimestamp: getTimestampNow(),
merchantTipId: res.merchantTipId,
tipAmountEffective: Amounts.sub(amount, Amounts.add(
withdrawDetails.overhead,
withdrawDetails.withdrawFee,
).amount).amount,
tipAmountEffective: Amounts.sub(
amount,
Amounts.add(withdrawDetails.overhead, withdrawDetails.withdrawFee)
.amount,
).amount,
retryInfo: initRetryInfo(),
lastError: undefined,
denomsSel: denomSelectionInfoToState(selectedDenoms),
@ -200,10 +201,10 @@ async function processTipImpl(
const planchets: TipPlanchet[] = [];
for (const sd of denomsForWithdraw.selectedDenoms) {
const denom = await ws.db.getIndexed(
Stores.denominations.denomPubHashIndex,
const denom = await ws.db.get(Stores.denominations, [
tipRecord.exchangeBaseUrl,
sd.denomPubHash,
);
]);
if (!denom) {
throw Error("denom does not exist anymore");
}

View File

@ -233,10 +233,10 @@ async function processPlanchetGenerate(
if (!denomPubHash) {
throw Error("invariant violated");
}
const denom = await ws.db.getIndexed(
Stores.denominations.denomPubHashIndex,
const denom = await ws.db.get(Stores.denominations, [
withdrawalGroup.exchangeBaseUrl,
denomPubHash,
);
]);
if (!denom) {
throw Error("invariant violated");
}
@ -325,7 +325,7 @@ async function processPlanchetExchangeRequest(
const denom = await ws.db.get(Stores.denominations, [
withdrawalGroup.exchangeBaseUrl,
planchet.denomPub,
planchet.denomPubHash,
]);
if (!denom) {

View File

@ -1383,13 +1383,6 @@ export interface PurchaseRecord {
autoRefundDeadline: Timestamp | undefined;
}
/**
* Information about wire information for bank accounts we withdrew coins from.
*/
export interface SenderWireRecord {
paytoUri: string;
}
/**
* Configuration key/value entries to configure
* the wallet.
@ -1589,25 +1582,14 @@ class DenominationsStore extends Store<DenominationRecord> {
constructor() {
// cast needed because of bug in type annotations
super("denominations", {
keyPath: (["exchangeBaseUrl", "denomPub"] as any) as IDBKeyPath,
keyPath: (["exchangeBaseUrl", "denomPubHash"] as any) as IDBKeyPath,
});
}
denomPubHashIndex = new Index<string, DenominationRecord>(
this,
"denomPubHashIndex",
"denomPubHash",
);
exchangeBaseUrlIndex = new Index<string, DenominationRecord>(
this,
"exchangeBaseUrlIndex",
"exchangeBaseUrl",
);
denomPubIndex = new Index<string, DenominationRecord>(
this,
"denomPubIndex",
"denomPub",
);
}
class CurrenciesStore extends Store<CurrencyRecord> {
@ -1640,12 +1622,6 @@ class TipsStore extends Store<TipRecord> {
}
}
class SenderWiresStore extends Store<SenderWireRecord> {
constructor() {
super("senderWires", { keyPath: "paytoUri" });
}
}
class WithdrawalGroupsStore extends Store<WithdrawalGroupRecord> {
constructor() {
super("withdrawals", { keyPath: "withdrawalGroupId" });
@ -1698,7 +1674,6 @@ export const Stores = {
reserveHistory: new ReserveHistoryStore(),
purchases: new PurchasesStore(),
tips: new TipsStore(),
senderWires: new SenderWiresStore(),
withdrawalGroups: new WithdrawalGroupsStore(),
planchets: new PlanchetsStore(),
bankWithdrawUris: new BankWithdrawUrisStore(),

View File

@ -709,36 +709,6 @@ export class Wallet {
this.ws.cryptoApi.stop();
}
async getSenderWireInfos(): Promise<SenderWireInfos> {
const m: { [url: string]: Set<string> } = {};
await this.db.iter(Stores.exchanges).forEach((x) => {
const wi = x.wireInfo;
if (!wi) {
return;
}
const s = (m[x.baseUrl] = m[x.baseUrl] || new Set());
Object.keys(wi.feesForType).map((k) => s.add(k));
});
const exchangeWireTypes: { [url: string]: string[] } = {};
Object.keys(m).map((e) => {
exchangeWireTypes[e] = Array.from(m[e]);
});
const senderWiresSet: Set<string> = new Set();
await this.db.iter(Stores.senderWires).forEach((x) => {
senderWiresSet.add(x.paytoUri);
});
const senderWires: string[] = Array.from(senderWiresSet);
return {
exchangeWireTypes,
senderWires,
};
}
/**
* Trigger paying coins back into the user's account.
*/
@ -894,7 +864,7 @@ export class Wallet {
for (const c of coins) {
const denom = await this.db.get(Stores.denominations, [
c.exchangeBaseUrl,
c.denomPub,
c.denomPubHash,
]);
if (!denom) {
console.error("no denom session found for coin");