remove excessive logging

This commit is contained in:
Florian Dold 2016-02-22 23:31:21 +01:00
parent 0ad69f120f
commit 33abcfd4dc
2 changed files with 36 additions and 60 deletions

View File

@ -175,30 +175,24 @@ export namespace Amounts {
}
export function add(first: AmountJson, ...rest: AmountJson[]): Result {
const doit = () => {
let currency = first.currency;
let value = first.value + Math.floor(first.fraction / 1e6);
let currency = first.currency;
let value = first.value + Math.floor(first.fraction / 1e6);
if (value > Number.MAX_SAFE_INTEGER) {
return {amount: getMaxAmount(currency), saturated: true};
}
let fraction = first.fraction % 1e6;
for (let x of rest) {
if (x.currency !== currency) {
throw Error(`Mismatched currency: ${x.currency} and ${currency}`);
}
value = value + x.value + Math.floor((fraction + x.fraction) / 1e6);
fraction = (fraction + x.fraction) % 1e6;
if (value > Number.MAX_SAFE_INTEGER) {
return {amount: getMaxAmount(currency), saturated: true};
}
let fraction = first.fraction % 1e6;
for (let x of rest) {
if (x.currency !== currency) {
throw Error(`Mismatched currency: ${x.currency} and ${currency}`);
}
value = value + x.value + Math.floor((fraction + x.fraction) / 1e6);
fraction = (fraction + x.fraction) % 1e6;
if (value > Number.MAX_SAFE_INTEGER) {
return {amount: getMaxAmount(currency), saturated: true};
}
}
return {amount: {currency, value, fraction}, saturated: false};
};
console.log("adding", first, "and", rest);
let ret = doit();
console.log("result is", ret);
return ret;
}
return {amount: {currency, value, fraction}, saturated: false};
}
@ -226,35 +220,27 @@ export namespace Amounts {
}
export function cmp(a: AmountJson, b: AmountJson): number {
const doit = () => {
if (a.currency !== b.currency) {
throw Error(`Mismatched currency: ${a.currency} and ${b.currency}`);
}
let av = a.value + Math.floor(a.fraction / 1e6);
let af = a.fraction % 1e6;
let bv = b.value + Math.floor(b.fraction / 1e6);
let bf = b.fraction % 1e6;
switch (true) {
case av < bv:
return -1;
case av > bv:
return 1;
case af < bf:
return -1;
case af > bf:
return 1;
case af == bf:
return 0;
default:
throw Error("assertion failed");
}
};
console.log("comparing", a, "and", b);
let res = doit();
console.log("result:", res);
return res;
if (a.currency !== b.currency) {
throw Error(`Mismatched currency: ${a.currency} and ${b.currency}`);
}
let av = a.value + Math.floor(a.fraction / 1e6);
let af = a.fraction % 1e6;
let bv = b.value + Math.floor(b.fraction / 1e6);
let bf = b.fraction % 1e6;
switch (true) {
case av < bv:
return -1;
case av > bv:
return 1;
case af < bf:
return -1;
case af > bf:
return 1;
case af == bf:
return 0;
default:
throw Error("assertion failed");
}
}
export function copy(a: AmountJson): AmountJson {

View File

@ -356,10 +356,6 @@ function getWithdrawDenomList(amountAvailable: AmountJson,
denoms = denoms.filter(isWithdrawableDenom);
denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value));
console.log("ranked denoms");
console.dir(denoms);
// This is an arbitrary number of coins
// we can withdraw in one go. It's not clear if this limit
// is useful ...
@ -376,7 +372,6 @@ function getWithdrawDenomList(amountAvailable: AmountJson,
break;
}
if (!found) {
console.log("did not find coins for remaining ", remaining);
break;
}
}
@ -561,7 +556,6 @@ export class Wallet {
error: "coins-insufficient",
};
}
console.log("about to record ...");
let mintUrl = Object.keys(mcs)[0];
return this.cryptoApi.signDeposit(offer, mcs[mintUrl])
@ -848,8 +842,6 @@ export class Wallet {
.map((d: Denomination) => Amounts.add(d.value,
d.fee_withdraw).amount)
.reduce((a, b) => Amounts.add(a, b).amount);
console.log("actual coin cost", actualCoinCost);
console.log("amount", amount);
let ret: ReserveCreationInfo = {
mintInfo,
selectedDenoms,
@ -877,8 +869,6 @@ export class Wallet {
return Query(this.db).get("mints", baseUrl).then((r) => {
let mintInfo;
console.log("got mints result");
console.dir(r);
if (!r) {