diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-01-05 17:11:01 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-01-05 17:11:01 +0100 |
commit | 91fc8d56f02628a257b6681a379ef6f28824b24e (patch) | |
tree | 6b3f952338a9bc3aa512d6bcb8531fa3bbead237 /extension/background | |
parent | 3bf1846ed81b7c137a3d751400a74546f502a37b (diff) |
fix more query wrapper bugs
Diffstat (limited to 'extension/background')
-rw-r--r-- | extension/background/emscriptif.js | 1 | ||||
-rw-r--r-- | extension/background/emscriptif.ts | 1 | ||||
-rw-r--r-- | extension/background/messaging.ts | 8 | ||||
-rw-r--r-- | extension/background/query.ts | 30 | ||||
-rw-r--r-- | extension/background/wallet.js | 2 | ||||
-rw-r--r-- | extension/background/wallet.ts | 2 |
6 files changed, 36 insertions, 8 deletions
diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 6cf22420e..58b14b41c 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -559,7 +559,6 @@ class UInt64 extends PackedArenaObject { static fromNumber(n) { let x = new UInt64(); x.alloc(); - console.log("Creating UINT64 with", n); set64(x.getNative(), n); return x; } diff --git a/extension/background/emscriptif.ts b/extension/background/emscriptif.ts index 0e35bc9b1..6b9d5014a 100644 --- a/extension/background/emscriptif.ts +++ b/extension/background/emscriptif.ts @@ -799,7 +799,6 @@ class UInt64 extends PackedArenaObject { static fromNumber(n: number): UInt64 { let x = new UInt64(); x.alloc(); - console.log("Creating UINT64 with", n); set64(x.getNative(), n); return x; } diff --git a/extension/background/messaging.ts b/extension/background/messaging.ts index 4bd5ec24e..6d444f95d 100644 --- a/extension/background/messaging.ts +++ b/extension/background/messaging.ts @@ -25,6 +25,8 @@ "use strict"; +// FIXME: none of these handlers should pass on the sendResponse. + let handlers = { ["balances"]: function(db, detail, sendResponse) { getBalances(db).then(sendResponse); @@ -48,6 +50,12 @@ let handlers = { ["confirm-reserve"]: function(db, detail, sendResponse) { return confirmReserveHandler(db, detail, sendResponse); }, + ["confirm-pay"]: function(db, detail, sendResponse) { + return confirmPayHandler(db, detail, sendResponse); + }, + ["execute-payment"]: function(db, detail, sendResponse) { + return doPaymentHandler(db, detail, sendResponse); + } }; diff --git a/extension/background/query.ts b/extension/background/query.ts index 75201c2d4..61847a74d 100644 --- a/extension/background/query.ts +++ b/extension/background/query.ts @@ -25,6 +25,7 @@ "use strict"; + function Query(db) { return new QueryRoot(db); } @@ -32,6 +33,7 @@ function Query(db) { abstract class QueryStreamBase { abstract subscribe(f: (isDone: boolean, value: any) => void); + root: QueryRoot; constructor(root: QueryRoot) { @@ -41,6 +43,7 @@ abstract class QueryStreamBase { indexJoin(storeName: string, indexName: string, key: any): QueryStreamBase { // join on the source relation's key, which may be // a path or a transformer function + this.root.stores.add(storeName); return new QueryStreamIndexJoin(this, storeName, indexName, key); } @@ -95,11 +98,14 @@ class QueryStreamIndexJoin extends QueryStreamBase { s: QueryStreamBase; storeName; key; + indexName; + constructor(s, storeName: string, indexName: string, key: any) { super(s.root); this.s = s; this.storeName = storeName; this.key = key; + this.indexName = indexName; } subscribe(f) { @@ -108,9 +114,8 @@ class QueryStreamIndexJoin extends QueryStreamBase { f(true, undefined); return; } - - let s = this.root.tx.objectStore(this.storeName); - let req = s.openCursor(IDBKeyRange.only(value)); + let s = this.root.tx.objectStore(this.storeName).index(this.indexName); + let req = s.openCursor(IDBKeyRange.only(this.key(value))); req.onsuccess = () => { let cursor = req.result; if (cursor) { @@ -140,7 +145,13 @@ class IterQueryStream extends QueryStreamBase { subscribe(f) { function doIt() { - let s = this.qr.tx.objectStore(this.storeName); + let s; + if (this.options && this.options.indexName) { + s = this.qr.tx.objectStore(this.storeName) + .index(this.options.indexName); + } else { + s = this.qr.tx.objectStore(this.storeName); + } let kr = undefined; if (this.options && ("only" in this.options)) { kr = IDBKeyRange.only(this.options.only); @@ -156,6 +167,7 @@ class IterQueryStream extends QueryStreamBase { } } } + this.qr.work.push(doIt.bind(this)); } } @@ -182,11 +194,17 @@ class QueryRoot { return new IterQueryStream(this, storeName, {only: key}); } + iterIndex(storeName, indexName, key) { + this.stores.add(storeName); + return new IterQueryStream(this, storeName, {indexName: indexName}); + } + put(storeName, val): QueryRoot { this.stores.add(storeName); function doPut() { this.tx.objectStore(storeName).put(val); } + this.work.push(doPut.bind(this)); return this; } @@ -198,6 +216,7 @@ class QueryRoot { this.tx.objectStore(storeName).put(obj); } } + this.work.push(doPutAll.bind(this)); return this; } @@ -207,6 +226,7 @@ class QueryRoot { function doAdd() { this.tx.objectStore(storeName).add(val); } + this.work.push(doAdd.bind(this)); return this; } @@ -227,6 +247,7 @@ class QueryRoot { leakedResolve(req.result); }; } + this.work.push(doGet.bind(this)); return Promise.resolve().then(() => { return this.finish().then(() => p); @@ -255,6 +276,7 @@ class QueryRoot { function doDelete() { this.tx.objectStore(storeName).delete(key); } + this.work.push(doDelete.bind(this)); return this; } diff --git a/extension/background/wallet.js b/extension/background/wallet.js index beb66c57a..ebb04e832 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -111,7 +111,7 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints) } let ps = allowedMints.map((info) => { return Query(db) - .iterOnly("mints", info.master_pub) + .iterIndex("mints", "pubKey", info.master_pub) .indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl) .reduce(storeMintCoin); }); diff --git a/extension/background/wallet.ts b/extension/background/wallet.ts index 6231baad0..5f9bb65a6 100644 --- a/extension/background/wallet.ts +++ b/extension/background/wallet.ts @@ -208,7 +208,7 @@ function getPossibleMintCoins(db: IDBDatabase, let ps = allowedMints.map((info) => { return Query(db) - .iterOnly("mints", info.master_pub) + .iterIndex("mints", "pubKey", info.master_pub) .indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl) .reduce(storeMintCoin); }); |