diff options
author | Florian Dold <florian.dold@gmail.com> | 2015-12-17 22:56:24 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2015-12-17 22:56:24 +0100 |
commit | 38c947d7712d77070ca521b4718032fb31c0f108 (patch) | |
tree | f460392f7f20fdf7ae01e1d3f57b524edd52932f /extension/background/db.js | |
parent | 5f907c13fc76189ace1537af43903e7cd2c82c84 (diff) | |
download | wallet-core-38c947d7712d77070ca521b4718032fb31c0f108.tar.xz |
Towards payment.
Diffstat (limited to 'extension/background/db.js')
-rw-r--r-- | extension/background/db.js | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/extension/background/db.js b/extension/background/db.js index b52ee457a..f6d81d9ac 100644 --- a/extension/background/db.js +++ b/extension/background/db.js @@ -1,5 +1,34 @@ +"use strict"; +const DB_NAME = "taler"; +const DB_VERSION = 1; /** - * Declarations and helpers for - * things that are stored in the wallet's - * database. + * Return a promise that resolves + * to the taler wallet db. */ +function openTalerDb() { + return new Promise((resolve, reject) => { + let req = indexedDB.open(DB_NAME, DB_VERSION); + req.onerror = (e) => { + reject(e); + }; + req.onsuccess = (e) => { + resolve(req.result); + }; + req.onupgradeneeded = (e) => { + let db = req.result; + console.log("DB: upgrade needed: oldVersion = " + e.oldVersion); + switch (e.oldVersion) { + case 0: + let mints = db.createObjectStore("mints", { keyPath: "baseUrl" }); + mints.createIndex("pubKey", "keys.master_public_key"); + db.createObjectStore("reserves", { keyPath: "reserve_pub" }); + db.createObjectStore("denoms", { keyPath: "denomPub" }); + let coins = db.createObjectStore("coins", { keyPath: "coinPub" }); + coins.createIndex("mintBaseUrl", "mintBaseUrl"); + db.createObjectStore("transactions", { keyPath: "contractHash" }); + db.createObjectStore("precoins", { keyPath: "coinPub", autoIncrement: true }); + break; + } + }; + }); +} |