aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-04 11:08:39 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-04 11:08:39 +0100
commit02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1 (patch)
treed139d88ce51c328cb55a9e8ad8f9371c3351568e /src/wallet.ts
parentfd2cd9c383b07cd681c18137396deae025d98047 (diff)
store sender wire info in separate store
Diffstat (limited to 'src/wallet.ts')
-rw-r--r--src/wallet.ts41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/wallet.ts b/src/wallet.ts
index 41f8e7276..6ad9964c5 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -29,6 +29,7 @@ import {
canonicalJson,
canonicalizeBaseUrl,
getTalerStampSec,
+ hash,
} from "./helpers";
import {
HttpRequestLibrary,
@@ -62,6 +63,7 @@ import {
RefreshPreCoinRecord,
RefreshSessionRecord,
ReserveRecord,
+ SenderWireRecord,
TipRecord,
WireFee,
} from "./dbTypes";
@@ -79,6 +81,7 @@ import {
RefundPermission,
TipPlanchetDetail,
TipResponse,
+ isWireDetail,
} from "./talerTypes";
import {
CheckPayResult,
@@ -354,7 +357,7 @@ export const WALLET_PROTOCOL_VERSION = "2:0:0";
* In the future we might consider adding migration functions for
* each version increment.
*/
-export const WALLET_DB_VERSION = 23;
+export const WALLET_DB_VERSION = 24;
const builtinCurrencies: CurrencyRecord[] = [
{
@@ -533,7 +536,7 @@ function getWithdrawDenomList(amountAvailable: AmountJson,
export namespace Stores {
class ExchangeStore extends Store<ExchangeRecord> {
constructor() {
- super("exchanges", {keyPath: "baseUrl"});
+ super("exchanges", { keyPath: "baseUrl" });
}
pubKeyIndex = new Index<string, ExchangeRecord>(this, "pubKeyIndex", "masterPublicKey");
@@ -541,13 +544,13 @@ export namespace Stores {
class NonceStore extends Store<NonceRecord> {
constructor() {
- super("nonces", {keyPath: "pub"});
+ super("nonces", { keyPath: "pub" });
}
}
class CoinsStore extends Store<CoinRecord> {
constructor() {
- super("coins", {keyPath: "coinPub"});
+ super("coins", { keyPath: "coinPub" });
}
exchangeBaseUrlIndex = new Index<string, CoinRecord>(this, "exchangeBaseUrl", "exchangeBaseUrl");
@@ -566,7 +569,7 @@ export namespace Stores {
class PurchasesStore extends Store<PurchaseRecord> {
constructor() {
- super("purchases", {keyPath: "contractTermsHash"});
+ super("purchases", { keyPath: "contractTermsHash" });
}
fulfillmentUrlIndex = new Index<string, PurchaseRecord>(this,
@@ -590,25 +593,25 @@ export namespace Stores {
class CurrenciesStore extends Store<CurrencyRecord> {
constructor() {
- super("currencies", {keyPath: "name"});
+ super("currencies", { keyPath: "name" });
}
}
class ConfigStore extends Store<ConfigRecord> {
constructor() {
- super("config", {keyPath: "key"});
+ super("config", { keyPath: "key" });
}
}
class ExchangeWireFeesStore extends Store<ExchangeWireFeesRecord> {
constructor() {
- super("exchangeWireFees", {keyPath: "exchangeBaseUrl"});
+ super("exchangeWireFees", { keyPath: "exchangeBaseUrl" });
}
}
class ReservesStore extends Store<ReserveRecord> {
constructor() {
- super("reserves", {keyPath: "reserve_pub"});
+ super("reserves", { keyPath: "reserve_pub" });
}
timestampCreatedIndex = new Index<string, ReserveRecord>(this, "timestampCreatedIndex", "created");
timestampConfirmedIndex = new Index<string, ReserveRecord>(this, "timestampConfirmedIndex", "timestamp_confirmed");
@@ -617,11 +620,17 @@ export namespace Stores {
class TipsStore extends Store<TipRecord> {
constructor() {
- super("tips", {keyPath: ["tipId", "merchantDomain"] as any as IDBKeyPath});
+ super("tips", { keyPath: ["tipId", "merchantDomain"] as any as IDBKeyPath });
}
coinPubIndex = new Index<string, TipRecord>(this, "coinPubIndex", "coinPubs", { multiEntry: true });
}
+ class SenderWiresStore extends Store<SenderWireRecord> {
+ constructor() {
+ super("senderWires", { keyPath: "id" });
+ }
+ }
+
export const coins = new CoinsStore();
export const coinsReturns = new Store<CoinsReturnRecord>("coinsReturns", {keyPath: "contractTermsHash"});
export const config = new ConfigStore();
@@ -636,6 +645,7 @@ export namespace Stores {
export const reserves = new ReservesStore();
export const purchases = new PurchasesStore();
export const tips = new TipsStore();
+ export const senderWires = new SenderWiresStore();
}
/* tslint:enable:completed-docs */
@@ -1338,6 +1348,15 @@ export class Wallet {
timestamp_depleted: 0,
};
+ const senderWire = req.senderWire;
+ if (isWireDetail(senderWire)) {
+ const rec = {
+ id: hash(senderWire),
+ senderWire,
+ };
+ await this.q().put(Stores.senderWires, rec);
+ }
+
await this.updateExchangeUsedTime(req.exchange);
const exchangeInfo = await this.updateExchangeFromUrl(req.exchange);
const {isAudited, isTrusted} = await this.getExchangeTrust(exchangeInfo);
@@ -2671,7 +2690,7 @@ export class Wallet {
Object.keys(m).map((e) => { exchangeWireTypes[e] = Array.from(m[e]); });
const senderWiresSet = new Set();
- await this.q().iter(Stores.reserves).map((x) => {
+ await this.q().iter(Stores.senderWires).map((x) => {
if (x.senderWire) {
senderWiresSet.add(canonicalJson(x.senderWire));
}