From 8cbef4c4c7a976967527234b6c3b6117b6de9808 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 5 Mar 2016 01:36:38 +0100 Subject: fix inadvertent double spending with coin selection --- lib/wallet/query.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/wallet/query.ts') diff --git a/lib/wallet/query.ts b/lib/wallet/query.ts index 62411dab3..1e39fda0f 100644 --- a/lib/wallet/query.ts +++ b/lib/wallet/query.ts @@ -144,6 +144,7 @@ class QueryStreamIndexJoin extends QueryStreamBase { f(true, undefined, tx); return; } + console.log("joining on", this.key(value)); let s = tx.objectStore(this.storeName).index(this.indexName); let req = s.openCursor(IDBKeyRange.only(this.key(value))); req.onsuccess = () => { @@ -163,14 +164,14 @@ class QueryStreamIndexJoin extends QueryStreamBase { class IterQueryStream extends QueryStreamBase { private storeName; private options; + private subscribers; constructor(qr, storeName, options) { super(qr); this.options = options; this.storeName = storeName; - } + this.subscribers = []; - subscribe(f) { let doIt = (tx) => { const {indexName = void 0, only = void 0} = this.options; let s; @@ -188,16 +189,24 @@ class IterQueryStream extends QueryStreamBase { req.onsuccess = (e) => { let cursor: IDBCursorWithValue = req.result; if (cursor) { - f(false, cursor.value, tx); + for (let f of this.subscribers) { + f(false, cursor.value, tx); + } cursor.continue(); } else { - f(true, undefined, tx); + for (let f of this.subscribers) { + f(true, undefined, tx); + } } } }; this.root.addWork(doIt, null, false); } + + subscribe(f) { + this.subscribers.push(f); + } } -- cgit v1.2.3