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

View File

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