DB tweaks
This commit is contained in:
parent
ddbb09b140
commit
aae06c680f
@ -222,7 +222,7 @@ async function updateExchangeWithKeys(
|
|||||||
for (const newDenom of newDenominations) {
|
for (const newDenom of newDenominations) {
|
||||||
const oldDenom = await tx.get(Stores.denominations, [
|
const oldDenom = await tx.get(Stores.denominations, [
|
||||||
baseUrl,
|
baseUrl,
|
||||||
newDenom.denomPub,
|
newDenom.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (oldDenom) {
|
if (oldDenom) {
|
||||||
// FIXME: Do consistency check
|
// FIXME: Do consistency check
|
||||||
@ -236,10 +236,10 @@ async function updateExchangeWithKeys(
|
|||||||
const newlyRevokedCoinPubs: string[] = [];
|
const newlyRevokedCoinPubs: string[] = [];
|
||||||
logger.trace("recoup list from exchange", recoupDenomList);
|
logger.trace("recoup list from exchange", recoupDenomList);
|
||||||
for (const recoupInfo of recoupDenomList) {
|
for (const recoupInfo of recoupDenomList) {
|
||||||
const oldDenom = await tx.getIndexed(
|
const oldDenom = await tx.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
r.baseUrl,
|
||||||
recoupInfo.h_denom_pub,
|
recoupInfo.h_denom_pub,
|
||||||
);
|
]);
|
||||||
if (!oldDenom) {
|
if (!oldDenom) {
|
||||||
// We never even knew about the revoked denomination, all good.
|
// We never even knew about the revoked denomination, all good.
|
||||||
continue;
|
continue;
|
||||||
|
@ -131,7 +131,7 @@ export async function getTotalPaymentCost(
|
|||||||
}
|
}
|
||||||
const denom = await ws.db.get(Stores.denominations, [
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
coin.exchangeBaseUrl,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error(
|
throw Error(
|
||||||
@ -332,7 +332,7 @@ async function getCoinsForPayment(
|
|||||||
// coins have the same currency
|
// coins have the same currency
|
||||||
const firstDenom = await ws.db.get(Stores.denominations, [
|
const firstDenom = await ws.db.get(Stores.denominations, [
|
||||||
exchange.baseUrl,
|
exchange.baseUrl,
|
||||||
coins[0].denomPub,
|
coins[0].denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!firstDenom) {
|
if (!firstDenom) {
|
||||||
throw Error("db inconsistent");
|
throw Error("db inconsistent");
|
||||||
@ -342,7 +342,7 @@ async function getCoinsForPayment(
|
|||||||
for (const coin of coins) {
|
for (const coin of coins) {
|
||||||
const denom = await ws.db.get(Stores.denominations, [
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
exchange.baseUrl,
|
exchange.baseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("db inconsistent");
|
throw Error("db inconsistent");
|
||||||
@ -1148,7 +1148,7 @@ export async function confirmPay(
|
|||||||
}
|
}
|
||||||
const denom = await ws.db.get(Stores.denominations, [
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
coin.exchangeBaseUrl,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error(
|
throw Error(
|
||||||
|
@ -134,7 +134,7 @@ async function refreshCreateSession(
|
|||||||
|
|
||||||
const oldDenom = await ws.db.get(Stores.denominations, [
|
const oldDenom = await ws.db.get(Stores.denominations, [
|
||||||
exchange.baseUrl,
|
exchange.baseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!oldDenom) {
|
if (!oldDenom) {
|
||||||
@ -367,7 +367,7 @@ async function refreshReveal(
|
|||||||
for (let i = 0; i < reveal.ev_sigs.length; i++) {
|
for (let i = 0; i < reveal.ev_sigs.length; i++) {
|
||||||
const denom = await ws.db.get(Stores.denominations, [
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
refreshSession.exchangeBaseUrl,
|
refreshSession.exchangeBaseUrl,
|
||||||
refreshSession.newDenoms[i],
|
refreshSession.newDenomHashes[i],
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
console.error("denom not found");
|
console.error("denom not found");
|
||||||
@ -598,7 +598,7 @@ export async function createRefreshGroup(
|
|||||||
checkDbInvariant(!!coin, "coin must be in database");
|
checkDbInvariant(!!coin, "coin must be in database");
|
||||||
const denom = await tx.get(Stores.denominations, [
|
const denom = await tx.get(Stores.denominations, [
|
||||||
coin.exchangeBaseUrl,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
checkDbInvariant(
|
checkDbInvariant(
|
||||||
!!denom,
|
!!denom,
|
||||||
@ -701,7 +701,7 @@ export async function autoRefresh(
|
|||||||
}
|
}
|
||||||
const denom = await tx.get(Stores.denominations, [
|
const denom = await tx.get(Stores.denominations, [
|
||||||
exchangeBaseUrl,
|
exchangeBaseUrl,
|
||||||
coin.denomPub,
|
coin.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
logger.warn("denomination not in database");
|
logger.warn("denomination not in database");
|
||||||
|
@ -104,10 +104,10 @@ async function applySuccessfulRefund(
|
|||||||
console.warn("coin not found, can't apply refund");
|
console.warn("coin not found, can't apply refund");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const denom = await tx.getIndexed(
|
const denom = await tx.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPubHash,
|
coin.denomPubHash,
|
||||||
);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("inconsistent database");
|
throw Error("inconsistent database");
|
||||||
}
|
}
|
||||||
@ -161,10 +161,10 @@ async function storePendingRefund(
|
|||||||
console.warn("coin not found, can't apply refund");
|
console.warn("coin not found, can't apply refund");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const denom = await tx.getIndexed(
|
const denom = await tx.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPubHash,
|
coin.denomPubHash,
|
||||||
);
|
]);
|
||||||
|
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("inconsistent database");
|
throw Error("inconsistent database");
|
||||||
@ -211,10 +211,10 @@ async function storeFailedRefund(
|
|||||||
console.warn("coin not found, can't apply refund");
|
console.warn("coin not found, can't apply refund");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const denom = await tx.getIndexed(
|
const denom = await tx.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
coin.exchangeBaseUrl,
|
||||||
coin.denomPubHash,
|
coin.denomPubHash,
|
||||||
);
|
]);
|
||||||
|
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("inconsistent database");
|
throw Error("inconsistent database");
|
||||||
@ -294,7 +294,8 @@ async function acceptRefunds(
|
|||||||
|
|
||||||
// Still pending.
|
// Still pending.
|
||||||
if (
|
if (
|
||||||
refundStatus.type === "failure" && !isPermanentFailure &&
|
refundStatus.type === "failure" &&
|
||||||
|
!isPermanentFailure &&
|
||||||
existingRefundInfo?.type === RefundState.Pending
|
existingRefundInfo?.type === RefundState.Pending
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -172,14 +172,6 @@ export async function createReserve(
|
|||||||
expectedAmount: req.amount,
|
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 exchangeInfo = await updateExchangeFromUrl(ws, req.exchange);
|
||||||
const exchangeDetails = exchangeInfo.details;
|
const exchangeDetails = exchangeInfo.details;
|
||||||
if (!exchangeDetails) {
|
if (!exchangeDetails) {
|
||||||
|
@ -104,10 +104,11 @@ export async function prepareTip(
|
|||||||
planchets: undefined,
|
planchets: undefined,
|
||||||
createdTimestamp: getTimestampNow(),
|
createdTimestamp: getTimestampNow(),
|
||||||
merchantTipId: res.merchantTipId,
|
merchantTipId: res.merchantTipId,
|
||||||
tipAmountEffective: Amounts.sub(amount, Amounts.add(
|
tipAmountEffective: Amounts.sub(
|
||||||
withdrawDetails.overhead,
|
amount,
|
||||||
withdrawDetails.withdrawFee,
|
Amounts.add(withdrawDetails.overhead, withdrawDetails.withdrawFee)
|
||||||
).amount).amount,
|
.amount,
|
||||||
|
).amount,
|
||||||
retryInfo: initRetryInfo(),
|
retryInfo: initRetryInfo(),
|
||||||
lastError: undefined,
|
lastError: undefined,
|
||||||
denomsSel: denomSelectionInfoToState(selectedDenoms),
|
denomsSel: denomSelectionInfoToState(selectedDenoms),
|
||||||
@ -200,10 +201,10 @@ async function processTipImpl(
|
|||||||
const planchets: TipPlanchet[] = [];
|
const planchets: TipPlanchet[] = [];
|
||||||
|
|
||||||
for (const sd of denomsForWithdraw.selectedDenoms) {
|
for (const sd of denomsForWithdraw.selectedDenoms) {
|
||||||
const denom = await ws.db.getIndexed(
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
tipRecord.exchangeBaseUrl,
|
||||||
sd.denomPubHash,
|
sd.denomPubHash,
|
||||||
);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("denom does not exist anymore");
|
throw Error("denom does not exist anymore");
|
||||||
}
|
}
|
||||||
|
@ -233,10 +233,10 @@ async function processPlanchetGenerate(
|
|||||||
if (!denomPubHash) {
|
if (!denomPubHash) {
|
||||||
throw Error("invariant violated");
|
throw Error("invariant violated");
|
||||||
}
|
}
|
||||||
const denom = await ws.db.getIndexed(
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
Stores.denominations.denomPubHashIndex,
|
withdrawalGroup.exchangeBaseUrl,
|
||||||
denomPubHash,
|
denomPubHash,
|
||||||
);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
throw Error("invariant violated");
|
throw Error("invariant violated");
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ async function processPlanchetExchangeRequest(
|
|||||||
|
|
||||||
const denom = await ws.db.get(Stores.denominations, [
|
const denom = await ws.db.get(Stores.denominations, [
|
||||||
withdrawalGroup.exchangeBaseUrl,
|
withdrawalGroup.exchangeBaseUrl,
|
||||||
planchet.denomPub,
|
planchet.denomPubHash,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
|
@ -1383,13 +1383,6 @@ export interface PurchaseRecord {
|
|||||||
autoRefundDeadline: Timestamp | undefined;
|
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
|
* Configuration key/value entries to configure
|
||||||
* the wallet.
|
* the wallet.
|
||||||
@ -1589,25 +1582,14 @@ class DenominationsStore extends Store<DenominationRecord> {
|
|||||||
constructor() {
|
constructor() {
|
||||||
// cast needed because of bug in type annotations
|
// cast needed because of bug in type annotations
|
||||||
super("denominations", {
|
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>(
|
exchangeBaseUrlIndex = new Index<string, DenominationRecord>(
|
||||||
this,
|
this,
|
||||||
"exchangeBaseUrlIndex",
|
"exchangeBaseUrlIndex",
|
||||||
"exchangeBaseUrl",
|
"exchangeBaseUrl",
|
||||||
);
|
);
|
||||||
denomPubIndex = new Index<string, DenominationRecord>(
|
|
||||||
this,
|
|
||||||
"denomPubIndex",
|
|
||||||
"denomPub",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CurrenciesStore extends Store<CurrencyRecord> {
|
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> {
|
class WithdrawalGroupsStore extends Store<WithdrawalGroupRecord> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("withdrawals", { keyPath: "withdrawalGroupId" });
|
super("withdrawals", { keyPath: "withdrawalGroupId" });
|
||||||
@ -1698,7 +1674,6 @@ export const Stores = {
|
|||||||
reserveHistory: new ReserveHistoryStore(),
|
reserveHistory: new ReserveHistoryStore(),
|
||||||
purchases: new PurchasesStore(),
|
purchases: new PurchasesStore(),
|
||||||
tips: new TipsStore(),
|
tips: new TipsStore(),
|
||||||
senderWires: new SenderWiresStore(),
|
|
||||||
withdrawalGroups: new WithdrawalGroupsStore(),
|
withdrawalGroups: new WithdrawalGroupsStore(),
|
||||||
planchets: new PlanchetsStore(),
|
planchets: new PlanchetsStore(),
|
||||||
bankWithdrawUris: new BankWithdrawUrisStore(),
|
bankWithdrawUris: new BankWithdrawUrisStore(),
|
||||||
|
@ -709,36 +709,6 @@ export class Wallet {
|
|||||||
this.ws.cryptoApi.stop();
|
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.
|
* Trigger paying coins back into the user's account.
|
||||||
*/
|
*/
|
||||||
@ -894,7 +864,7 @@ export class Wallet {
|
|||||||
for (const c of coins) {
|
for (const c of coins) {
|
||||||
const denom = await this.db.get(Stores.denominations, [
|
const denom = await this.db.get(Stores.denominations, [
|
||||||
c.exchangeBaseUrl,
|
c.exchangeBaseUrl,
|
||||||
c.denomPub,
|
c.denomPubHash,
|
||||||
]);
|
]);
|
||||||
if (!denom) {
|
if (!denom) {
|
||||||
console.error("no denom session found for coin");
|
console.error("no denom session found for coin");
|
||||||
|
Loading…
Reference in New Issue
Block a user