This commit is contained in:
Florian Dold 2015-12-18 13:38:22 +01:00
parent 3ddfad1973
commit bc05121da2
4 changed files with 30 additions and 15 deletions

View File

@ -303,7 +303,6 @@ function mixin(obj, method, name) {
if (!name) { if (!name) {
throw Error("Mixin needs a name."); throw Error("Mixin needs a name.");
} }
console.log("mixing in", name, "into", obj.name);
obj.prototype[method.name] = method; obj.prototype[method.name] = method;
} }
function mixinStatic(obj, method, name) { function mixinStatic(obj, method, name) {
@ -498,7 +497,6 @@ class AbsoluteTimeNbo extends PackedArenaObject {
throw Error(); throw Error();
} }
let n = parseInt(m[1]); let n = parseInt(m[1]);
console.log("setting", n);
// XXX: This only works up to 54 bit numbers. // XXX: This only works up to 54 bit numbers.
set64(x.getNative(), n); set64(x.getNative(), n);
return x; return x;

View File

@ -466,7 +466,6 @@ function mixin(obj, method, name?: string) {
if (!name) { if (!name) {
throw Error("Mixin needs a name."); throw Error("Mixin needs a name.");
} }
console.log("mixing in", name, "into", obj.name);
obj.prototype[method.name] = method; obj.prototype[method.name] = method;
} }
@ -717,7 +716,6 @@ class AbsoluteTimeNbo extends PackedArenaObject {
throw Error(); throw Error();
} }
let n = parseInt(m[1]); let n = parseInt(m[1]);
console.log("setting", n);
// XXX: This only works up to 54 bit numbers. // XXX: This only works up to 54 bit numbers.
set64(x.getNative(), n); set64(x.getNative(), n);
return x; return x;

View File

@ -21,12 +21,19 @@ function signDeposit(db, offer, cds) {
cds = copy(cds); cds = copy(cds);
for (let cd of cds) { for (let cd of cds) {
let coinSpend; let coinSpend;
console.log("amount remaining:", amountRemaining.toJson());
if (amountRemaining.value == 0 && amountRemaining.fraction == 0) {
console.log("full amount spent");
break;
}
if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) {
coinSpend = new Amount(amountRemaining.toJson()); coinSpend = new Amount(amountRemaining.toJson());
} }
else { else {
coinSpend = new Amount(cd.coin.currentAmount); coinSpend = new Amount(cd.coin.currentAmount);
} }
amountSpent.add(coinSpend);
amountRemaining.sub(coinSpend);
let d = new DepositRequestPS({ let d = new DepositRequestPS({
h_contract: HashCode.fromCrock(offer.H_contract), h_contract: HashCode.fromCrock(offer.H_contract),
h_wire: HashCode.fromCrock(offer.contract.H_wire), h_wire: HashCode.fromCrock(offer.contract.H_wire),
@ -38,7 +45,6 @@ function signDeposit(db, offer, cds) {
timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp), timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp),
transaction_id: UInt64.fromNumber(offer.contract.transaction_id), transaction_id: UInt64.fromNumber(offer.contract.transaction_id),
}); });
amountSpent.add(coinSpend);
let newAmount = new Amount(cd.coin.currentAmount); let newAmount = new Amount(cd.coin.currentAmount);
newAmount.sub(coinSpend); newAmount.sub(coinSpend);
cd.coin.currentAmount = newAmount.toJson(); cd.coin.currentAmount = newAmount.toJson();
@ -51,7 +57,7 @@ function signDeposit(db, offer, cds) {
denom_pub: cd.coin.denomPub, denom_pub: cd.coin.denomPub,
f: amountSpent.toJson(), f: amountSpent.toJson(),
}; };
ret.push({ sig: coinSig, updatedCoin: cd.coin }); ret.push({ sig: s, updatedCoin: cd.coin });
} }
return ret; return ret;
} }
@ -141,10 +147,11 @@ function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
reqData["H_contract"] = offer.H_contract; reqData["H_contract"] = offer.H_contract;
reqData["transaction_id"] = offer.contract.transaction_id; reqData["transaction_id"] = offer.contract.transaction_id;
reqData["refund_deadline"] = offer.contract.refund_deadline; reqData["refund_deadline"] = offer.contract.refund_deadline;
reqData["mint"] = chosenMint; reqData["mint"] = URI(chosenMint).hostname();
reqData["coins"] = payCoinInfo.map((x) => x.sig); reqData["coins"] = payCoinInfo.map((x) => x.sig);
let payUrl = URI(merchantBaseUrl).absoluteTo(merchantBaseUrl); reqData["timestamp"] = offer.contract.timestamp;
console.log("Merchant URL", payUrl); let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl);
console.log("Merchant URL", payUrl.href());
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.open('post', payUrl.href()); req.open('post', payUrl.href());
req.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
@ -152,6 +159,7 @@ function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
req.addEventListener('readystatechange', (e) => { req.addEventListener('readystatechange', (e) => {
if (req.readyState == XMLHttpRequest.DONE) { if (req.readyState == XMLHttpRequest.DONE) {
if (req.status == 200) { if (req.status == 200) {
console.log("Merchant response:", req.responseText);
resolve(); resolve();
} }
else { else {

View File

@ -79,12 +79,23 @@ function signDeposit(db: IDBDatabase,
cds = copy(cds); cds = copy(cds);
for (let cd of cds) { for (let cd of cds) {
let coinSpend; let coinSpend;
console.log("amount remaining:", amountRemaining.toJson());
if (amountRemaining.value == 0 && amountRemaining.fraction == 0) {
console.log("full amount spent");
break;
}
if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) {
coinSpend = new Amount(amountRemaining.toJson()); coinSpend = new Amount(amountRemaining.toJson());
} else { } else {
coinSpend = new Amount(cd.coin.currentAmount); coinSpend = new Amount(cd.coin.currentAmount);
} }
amountSpent.add(coinSpend);
amountRemaining.sub(coinSpend);
let d = new DepositRequestPS({ let d = new DepositRequestPS({
h_contract: HashCode.fromCrock(offer.H_contract), h_contract: HashCode.fromCrock(offer.H_contract),
h_wire: HashCode.fromCrock(offer.contract.H_wire), h_wire: HashCode.fromCrock(offer.contract.H_wire),
@ -97,8 +108,6 @@ function signDeposit(db: IDBDatabase,
transaction_id: UInt64.fromNumber(offer.contract.transaction_id), transaction_id: UInt64.fromNumber(offer.contract.transaction_id),
}); });
amountSpent.add(coinSpend);
let newAmount = new Amount(cd.coin.currentAmount); let newAmount = new Amount(cd.coin.currentAmount);
newAmount.sub(coinSpend); newAmount.sub(coinSpend);
cd.coin.currentAmount = newAmount.toJson(); cd.coin.currentAmount = newAmount.toJson();
@ -114,7 +123,7 @@ function signDeposit(db: IDBDatabase,
denom_pub: cd.coin.denomPub, denom_pub: cd.coin.denomPub,
f: amountSpent.toJson(), f: amountSpent.toJson(),
}; };
ret.push({sig: coinSig, updatedCoin: cd.coin}); ret.push({sig: s, updatedCoin: cd.coin});
} }
return ret; return ret;
} }
@ -223,10 +232,11 @@ function executePay(db,
reqData["H_contract"] = offer.H_contract; reqData["H_contract"] = offer.H_contract;
reqData["transaction_id"] = offer.contract.transaction_id; reqData["transaction_id"] = offer.contract.transaction_id;
reqData["refund_deadline"] = offer.contract.refund_deadline; reqData["refund_deadline"] = offer.contract.refund_deadline;
reqData["mint"] = chosenMint; reqData["mint"] = URI(chosenMint).hostname();
reqData["coins"] = payCoinInfo.map((x) => x.sig); reqData["coins"] = payCoinInfo.map((x) => x.sig);
let payUrl = URI(merchantBaseUrl).absoluteTo(merchantBaseUrl); reqData["timestamp"] = offer.contract.timestamp;
console.log("Merchant URL", payUrl); let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl);
console.log("Merchant URL", payUrl.href());
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.open('post', payUrl.href()); req.open('post', payUrl.href());
req.setRequestHeader("Content-Type", req.setRequestHeader("Content-Type",
@ -235,6 +245,7 @@ function executePay(db,
req.addEventListener('readystatechange', (e) => { req.addEventListener('readystatechange', (e) => {
if (req.readyState == XMLHttpRequest.DONE) { if (req.readyState == XMLHttpRequest.DONE) {
if (req.status == 200) { if (req.status == 200) {
console.log("Merchant response:", req.responseText);
resolve(); resolve();
} else { } else {
throw Error("bad status " + req.status); throw Error("bad status " + req.status);