fix inadvertent double spending with coin selection
This commit is contained in:
parent
1b2897c03b
commit
8cbef4c4c7
@ -35,34 +35,16 @@ var TalerNotify;
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
var handlers = [];
|
var handlers = [];
|
||||||
var connected = false;
|
|
||||||
// Hack to know when the extension is unloaded
|
// Hack to know when the extension is unloaded
|
||||||
var port;
|
var port = chrome.runtime.connect();
|
||||||
var connect = function (dh) {
|
port.onDisconnect.addListener(function () {
|
||||||
port = chrome.runtime.connect();
|
console.log("chrome runtime disconnected, removing handlers");
|
||||||
port.onDisconnect.addListener(dh);
|
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
|
||||||
chrome.runtime.sendMessage({ type: "ping" }, function () {
|
var handler = handlers_1[_i];
|
||||||
console.log("registering handlers");
|
document.removeEventListener(handler.type, handler.listener);
|
||||||
connected = true;
|
|
||||||
registerHandlers();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var disconectHandler = function () {
|
|
||||||
if (connected) {
|
|
||||||
console.log("chrome runtime disconnected, removing handlers");
|
|
||||||
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
|
|
||||||
var handler = handlers_1[_i];
|
|
||||||
document.removeEventListener(handler.type, handler.listener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
// We got disconnected before the extension was ready, reconnect ...
|
registerHandlers();
|
||||||
window.setTimeout(function () {
|
|
||||||
connect(disconectHandler);
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
connect(disconectHandler);
|
|
||||||
function registerHandlers() {
|
function registerHandlers() {
|
||||||
var $ = function (x) { return document.getElementById(x); };
|
var $ = function (x) { return document.getElementById(x); };
|
||||||
function addHandler(type, listener) {
|
function addHandler(type, listener) {
|
||||||
|
@ -45,36 +45,17 @@ namespace TalerNotify {
|
|||||||
|
|
||||||
const handlers = [];
|
const handlers = [];
|
||||||
|
|
||||||
let connected = false;
|
|
||||||
|
|
||||||
// Hack to know when the extension is unloaded
|
// Hack to know when the extension is unloaded
|
||||||
let port;
|
let port = chrome.runtime.connect();
|
||||||
|
|
||||||
const connect = (dh) => {
|
port.onDisconnect.addListener(() => {
|
||||||
port = chrome.runtime.connect();
|
console.log("chrome runtime disconnected, removing handlers");
|
||||||
port.onDisconnect.addListener(dh);
|
for (let handler of handlers) {
|
||||||
chrome.runtime.sendMessage({type: "ping"}, () => {
|
document.removeEventListener(handler.type, handler.listener);
|
||||||
console.log("registering handlers");
|
|
||||||
connected = true;
|
|
||||||
registerHandlers();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var disconectHandler = () => {
|
|
||||||
if (connected) {
|
|
||||||
console.log("chrome runtime disconnected, removing handlers");
|
|
||||||
for (let handler of handlers) {
|
|
||||||
document.removeEventListener(handler.type, handler.listener);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// We got disconnected before the extension was ready, reconnect ...
|
|
||||||
window.setTimeout(() => {
|
|
||||||
connect(disconectHandler);
|
|
||||||
}, 200);
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
connect(disconectHandler);
|
registerHandlers();
|
||||||
|
|
||||||
function registerHandlers() {
|
function registerHandlers() {
|
||||||
const $ = (x) => document.getElementById(x);
|
const $ = (x) => document.getElementById(x);
|
||||||
|
@ -144,6 +144,7 @@ class QueryStreamIndexJoin<T> extends QueryStreamBase<T> {
|
|||||||
f(true, undefined, tx);
|
f(true, undefined, tx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("joining on", this.key(value));
|
||||||
let s = tx.objectStore(this.storeName).index(this.indexName);
|
let s = tx.objectStore(this.storeName).index(this.indexName);
|
||||||
let req = s.openCursor(IDBKeyRange.only(this.key(value)));
|
let req = s.openCursor(IDBKeyRange.only(this.key(value)));
|
||||||
req.onsuccess = () => {
|
req.onsuccess = () => {
|
||||||
@ -163,14 +164,14 @@ class QueryStreamIndexJoin<T> extends QueryStreamBase<T> {
|
|||||||
class IterQueryStream<T> extends QueryStreamBase<T> {
|
class IterQueryStream<T> extends QueryStreamBase<T> {
|
||||||
private storeName;
|
private storeName;
|
||||||
private options;
|
private options;
|
||||||
|
private subscribers;
|
||||||
|
|
||||||
constructor(qr, storeName, options) {
|
constructor(qr, storeName, options) {
|
||||||
super(qr);
|
super(qr);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.storeName = storeName;
|
this.storeName = storeName;
|
||||||
}
|
this.subscribers = [];
|
||||||
|
|
||||||
subscribe(f) {
|
|
||||||
let doIt = (tx) => {
|
let doIt = (tx) => {
|
||||||
const {indexName = void 0, only = void 0} = this.options;
|
const {indexName = void 0, only = void 0} = this.options;
|
||||||
let s;
|
let s;
|
||||||
@ -188,16 +189,24 @@ class IterQueryStream<T> extends QueryStreamBase<T> {
|
|||||||
req.onsuccess = (e) => {
|
req.onsuccess = (e) => {
|
||||||
let cursor: IDBCursorWithValue = req.result;
|
let cursor: IDBCursorWithValue = req.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
f(false, cursor.value, tx);
|
for (let f of this.subscribers) {
|
||||||
|
f(false, cursor.value, tx);
|
||||||
|
}
|
||||||
cursor.continue();
|
cursor.continue();
|
||||||
} else {
|
} else {
|
||||||
f(true, undefined, tx);
|
for (let f of this.subscribers) {
|
||||||
|
f(true, undefined, tx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.root.addWork(doIt, null, false);
|
this.root.addWork(doIt, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscribe(f) {
|
||||||
|
this.subscribers.push(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,8 +352,9 @@ export class Wallet {
|
|||||||
// denomination
|
// denomination
|
||||||
let m: ExchangeCoins = {};
|
let m: ExchangeCoins = {};
|
||||||
|
|
||||||
function storeExchangeCoin(mc) {
|
function storeExchangeCoin(mc, url) {
|
||||||
let exchange: IExchangeInfo = mc[0];
|
let exchange: IExchangeInfo = mc[0];
|
||||||
|
console.log("got coin for exchange", url);
|
||||||
let coin: Coin = mc[1];
|
let coin: Coin = mc[1];
|
||||||
let cd = {
|
let cd = {
|
||||||
coin: coin,
|
coin: coin,
|
||||||
@ -366,20 +367,28 @@ export class Wallet {
|
|||||||
console.warn("same pubkey for different currencies");
|
console.warn("same pubkey for different currencies");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let x = m[exchange.baseUrl];
|
let x = m[url];
|
||||||
if (!x) {
|
if (!x) {
|
||||||
m[exchange.baseUrl] = [cd];
|
m[url] = [cd];
|
||||||
} else {
|
} else {
|
||||||
x.push(cd);
|
x.push(cd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ps = allowedExchanges.map((info) => {
|
// Make sure that we don't look up coins
|
||||||
|
// for the same URL twice ...
|
||||||
|
let handledExchanges = new Set();
|
||||||
|
|
||||||
|
let ps = allowedExchanges.map((info: ExchangeHandle) => {
|
||||||
|
if (handledExchanges.has(info.url)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handledExchanges.add(info.url);
|
||||||
console.log("Checking for merchant's exchange", JSON.stringify(info));
|
console.log("Checking for merchant's exchange", JSON.stringify(info));
|
||||||
return Query(this.db)
|
return Query(this.db)
|
||||||
.iter("exchanges", {indexName: "pubKey", only: info.master_pub})
|
.iter("exchanges", {indexName: "pubKey", only: info.master_pub})
|
||||||
.indexJoin("coins", "exchangeBaseUrl", (exchange) => exchange.baseUrl)
|
.indexJoin("coins", "exchangeBaseUrl", (exchange) => exchange.baseUrl)
|
||||||
.reduce(storeExchangeCoin);
|
.reduce((x) => storeExchangeCoin(x, info.url));
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(ps).then(() => {
|
return Promise.all(ps).then(() => {
|
||||||
@ -398,6 +407,8 @@ export class Wallet {
|
|||||||
nextExchange:
|
nextExchange:
|
||||||
for (let key in m) {
|
for (let key in m) {
|
||||||
let coins = m[key];
|
let coins = m[key];
|
||||||
|
console.log("trying coins");
|
||||||
|
console.log(coins);
|
||||||
// Sort by ascending deposit fee
|
// Sort by ascending deposit fee
|
||||||
coins.sort((o1, o2) => Amounts.cmp(o1.denom.fee_deposit,
|
coins.sort((o1, o2) => Amounts.cmp(o1.denom.fee_deposit,
|
||||||
o2.denom.fee_deposit));
|
o2.denom.fee_deposit));
|
||||||
|
Loading…
Reference in New Issue
Block a user