fix query abstraction
This commit is contained in:
parent
b459ffb424
commit
3bf1846ed8
@ -20,6 +20,8 @@
|
||||
* Declarations and helpers for
|
||||
* things that are stored in the wallet's
|
||||
* database.
|
||||
* @module Db
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
|
||||
|
@ -13,6 +13,12 @@
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
/**
|
||||
* High-level interface to emscripten-compiled modules used
|
||||
* by the wallet.
|
||||
* @module EmscriptIf
|
||||
* @author Florian Dold
|
||||
*/
|
||||
"use strict";
|
||||
// Size of a native pointer.
|
||||
const PTR_SIZE = 4;
|
||||
|
@ -14,6 +14,14 @@
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* High-level interface to emscripten-compiled modules used
|
||||
* by the wallet.
|
||||
* @module EmscriptIf
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
declare var Module: EmscModule;
|
||||
|
@ -14,6 +14,12 @@
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helpers for doing XMLHttpRequest-s that are based on ES6 promises.
|
||||
* @module Http
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
interface HttpResponse {
|
||||
@ -37,6 +43,8 @@ function httpReq(method: string,
|
||||
myRequest.open(method, urlString);
|
||||
if (options && options.req) {
|
||||
myRequest.send(options.req);
|
||||
} else {
|
||||
myRequest.send();
|
||||
}
|
||||
myRequest.addEventListener("readystatechange", (e) => {
|
||||
if (myRequest.readyState == XMLHttpRequest.DONE) {
|
||||
|
@ -34,7 +34,7 @@ let handlers = {
|
||||
exportDb(db).then(sendResponse);
|
||||
return true;
|
||||
},
|
||||
["reset-db"]: function(db, detail, sendResponse) {
|
||||
["reset"]: function(db, detail, sendResponse) {
|
||||
let tx = db.transaction(db.objectStoreNames, 'readwrite');
|
||||
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
||||
tx.objectStore(db.objectStoreNames[i]).clear();
|
||||
@ -47,7 +47,7 @@ let handlers = {
|
||||
},
|
||||
["confirm-reserve"]: function(db, detail, sendResponse) {
|
||||
return confirmReserveHandler(db, detail, sendResponse);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
@ -187,7 +187,7 @@ class QueryRoot {
|
||||
function doPut() {
|
||||
this.tx.objectStore(storeName).put(val);
|
||||
}
|
||||
this.work.push(doPut);
|
||||
this.work.push(doPut.bind(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ class QueryRoot {
|
||||
this.tx.objectStore(storeName).put(obj);
|
||||
}
|
||||
}
|
||||
this.work.push(doPutAll);
|
||||
this.work.push(doPutAll.bind(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ class QueryRoot {
|
||||
function doAdd() {
|
||||
this.tx.objectStore(storeName).add(val);
|
||||
}
|
||||
this.work.push(doAdd);
|
||||
this.work.push(doAdd.bind(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -224,11 +224,13 @@ class QueryRoot {
|
||||
function doGet() {
|
||||
let req = this.tx.objectStore(storeName).get(key);
|
||||
req.onsuccess = (r) => {
|
||||
leakedResolve(r);
|
||||
leakedResolve(req.result);
|
||||
};
|
||||
}
|
||||
this.work.push(doGet);
|
||||
return p;
|
||||
this.work.push(doGet.bind(this));
|
||||
return Promise.resolve().then(() => {
|
||||
return this.finish().then(() => p);
|
||||
});
|
||||
}
|
||||
|
||||
finish(): Promise<void> {
|
||||
@ -253,7 +255,7 @@ class QueryRoot {
|
||||
function doDelete() {
|
||||
this.tx.objectStore(storeName).delete(key);
|
||||
}
|
||||
this.work.push(doDelete);
|
||||
this.work.push(doDelete.bind(this));
|
||||
return this;
|
||||
}
|
||||
}
|
@ -13,6 +13,12 @@
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
/**
|
||||
* High-level wallet operations that should be indepentent from the underlying
|
||||
* browser extension interface.
|
||||
* @module Wallet
|
||||
* @author Florian Dold
|
||||
*/
|
||||
/// <reference path="../decl/urijs/URIjs.d.ts" />
|
||||
/// <reference path="../decl/chrome/chrome.d.ts" />
|
||||
'use strict';
|
||||
@ -247,12 +253,13 @@ function confirmReserveHandler(db, detail, sendResponse) {
|
||||
.then(() => {
|
||||
// Do this in the background
|
||||
updateMintFromUrl(db, reserveRecord.mint_base_url)
|
||||
.then((mint) => {
|
||||
updateReserve(db, reservePub, mint)
|
||||
.then((reserve) => depleteReserve(db, reserve, mint));
|
||||
});
|
||||
.then((mint) => updateReserve(db, reservePub, mint)
|
||||
.then((reserve) => depleteReserve(db, reserve, mint)));
|
||||
return resp;
|
||||
});
|
||||
})
|
||||
.then((resp) => {
|
||||
sendResponse(resp);
|
||||
});
|
||||
// Allow async response
|
||||
return true;
|
||||
|
@ -14,6 +14,14 @@
|
||||
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* High-level wallet operations that should be indepentent from the underlying
|
||||
* browser extension interface.
|
||||
* @module Wallet
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
|
||||
/// <reference path="../decl/urijs/URIjs.d.ts" />
|
||||
/// <reference path="../decl/chrome/chrome.d.ts" />
|
||||
'use strict';
|
||||
@ -364,12 +372,15 @@ function confirmReserveHandler(db, detail, sendResponse) {
|
||||
.then(() => {
|
||||
// Do this in the background
|
||||
updateMintFromUrl(db, reserveRecord.mint_base_url)
|
||||
.then((mint) => {
|
||||
.then((mint) =>
|
||||
updateReserve(db, reservePub, mint)
|
||||
.then((reserve) => depleteReserve(db, reserve, mint));
|
||||
});
|
||||
.then((reserve) => depleteReserve(db, reserve, mint))
|
||||
);
|
||||
return resp;
|
||||
});
|
||||
})
|
||||
.then((resp) => {
|
||||
sendResponse(resp);
|
||||
});
|
||||
|
||||
// Allow async response
|
||||
@ -516,7 +527,7 @@ function withdraw(db, denom, reserve): Promise<void> {
|
||||
/**
|
||||
* Withdraw coins from a reserve until it is empty.
|
||||
*/
|
||||
function depleteReserve(db, reserve, mint) {
|
||||
function depleteReserve(db, reserve, mint): void {
|
||||
let denoms = copy(mint.keys.denoms);
|
||||
let remaining = new Amount(reserve.current_amount);
|
||||
denoms.sort(rankDenom);
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"jsx": "react"
|
||||
"jsx": "react",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"background/wallet.ts",
|
||||
|
Loading…
Reference in New Issue
Block a user