From 6b51e3e48f7e0d9bc0ef7b3d64ae7176bd8ce9b4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 18 Oct 2016 02:07:38 +0200 Subject: generate db from schema --- lib/wallet/wallet.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'lib/wallet/wallet.ts') diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index f55ba2170..e39b492ed 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -305,46 +305,52 @@ function getWithdrawDenomList(amountAvailable: AmountJson, } -namespace Stores { +export namespace Stores { class ExchangeStore extends Store { constructor() { - super("exchanges"); + super("exchanges", {keyPath: "baseUrl"}); } - pubKeyIndex = new Index(this, "pubKey"); + + pubKeyIndex = new Index(this, "pubKey", "masterPublicKey"); } class CoinsStore extends Store { constructor() { - super("coins"); + super("coins", {keyPath: "coinPub"}); } - exchangeBaseUrlIndex = new Index(this, "exchangeBaseUrl"); + exchangeBaseUrlIndex = new Index(this, "exchangeBaseUrl", "exchageBaseUrl"); } class HistoryStore extends Store { constructor() { - super("history"); + super("history", { + keyPath: "id", + autoIncrement: true + }); } - timestampIndex = new Index(this, "timestamp"); + timestampIndex = new Index(this, "timestamp", "timestamp"); } class TransactionsStore extends Store { constructor() { - super("transactions"); + super("transactions", {keyPath: "contractHash"}); } - repurchaseIndex = new Index<[string,string],Transaction>(this, "repurchase"); + repurchaseIndex = new Index<[string,string],Transaction>(this, "repurchase", [ + "contract.merchant_pub", + "contract.repurchase_correlation_id" + ]); } - export let exchanges: ExchangeStore = new ExchangeStore(); export let transactions: TransactionsStore = new TransactionsStore(); - export let reserves: Store = new Store("reserves"); + export let reserves: Store = new Store("reserves", {keyPath: "reserve_pub"}); export let coins: CoinsStore = new CoinsStore(); - export let refresh: Store = new Store("refresh"); + export let refresh: Store = new Store("refresh", {keyPath: "meltCoinPub"}); export let history: HistoryStore = new HistoryStore(); - export let precoins: Store = new Store("precoins"); + export let precoins: Store = new Store("precoins", {keyPath: "coinPub"}); } @@ -1270,7 +1276,8 @@ export class Wallet { return; } - let coin = await this.q().get(Stores.coins, refreshSession.meltCoinPub); + let coin = await this.q().get(Stores.coins, + refreshSession.meltCoinPub); if (!coin) { console.error("can't melt coin, it does not exist"); return; @@ -1475,7 +1482,8 @@ export class Wallet { async paymentSucceeded(contractHash: string): Promise { const doPaymentSucceeded = async() => { - let t = await this.q().get(Stores.transactions, contractHash); + let t = await this.q().get(Stores.transactions, + contractHash); if (!t) { console.error("contract not found"); return; -- cgit v1.2.3