aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-20 04:15:49 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-20 04:15:49 +0100
commit7356d4257ebbd35ef8735edd1a287f87e2aa1f1b (patch)
tree20238d7e55b109f57249531f99348d1425871e44
parent9197bda90a9c88132545d85b054d29b36d449c1b (diff)
fix feeDeposit/max_fee corner case
-rw-r--r--src/cryptoLib.ts20
-rw-r--r--src/pages/tree.tsx2
-rw-r--r--src/wallet.ts13
-rw-r--r--tsconfig.json4
4 files changed, 31 insertions, 8 deletions
diff --git a/src/cryptoLib.ts b/src/cryptoLib.ts
index 6473e1b58..fe1d6f36b 100644
--- a/src/cryptoLib.ts
+++ b/src/cryptoLib.ts
@@ -173,8 +173,16 @@ namespace RpcFunctions {
export function signDeposit(offer: OfferRecord,
cds: CoinWithDenom[]): PayCoinInfo {
let ret: PayCoinInfo = [];
+
+
+ let feeList: AmountJson[] = cds.map((x) => x.denom.feeDeposit);
+ let fees = Amounts.add(Amounts.getZero(feeList[0].currency), ...feeList).amount;
+ // okay if saturates
+ fees = Amounts.sub(fees, offer.contract.max_fee).amount;
+ let total = Amounts.add(fees, offer.contract.amount).amount;
+
let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
- let amountRemaining = new native.Amount(offer.contract.amount);
+ let amountRemaining = new native.Amount(total);
for (let cd of cds) {
let coinSpend: Amount;
@@ -191,6 +199,14 @@ namespace RpcFunctions {
amountSpent.add(coinSpend);
amountRemaining.sub(coinSpend);
+ let feeDeposit: Amount = new native.Amount(cd.denom.feeDeposit);
+
+ // Give the merchant at least the deposit fee, otherwise it'll reject
+ // the coin.
+ if (coinSpend.cmp(feeDeposit) < 0) {
+ coinSpend = feeDeposit;
+ }
+
let newAmount = new native.Amount(cd.coin.currentAmount);
newAmount.sub(coinSpend);
cd.coin.currentAmount = newAmount.toJson();
@@ -342,4 +358,4 @@ namespace RpcFunctions {
const b = native.ByteArray.fromStringWithNull(str);
return b.hash().toCrock();
}
-} \ No newline at end of file
+}
diff --git a/src/pages/tree.tsx b/src/pages/tree.tsx
index 9eca80636..dab637147 100644
--- a/src/pages/tree.tsx
+++ b/src/pages/tree.tsx
@@ -124,6 +124,8 @@ class CoinView extends React.Component<CoinViewProps, void> {
<li>Current amount: {prettyAmount(c.currentAmount)}</li>
<li>Denomination: <ExpanderText text={c.denomPub} /></li>
<li>Suspended: {(c.suspended || false).toString()}</li>
+ <li>Dirty: {(c.dirty || false).toString()}</li>
+ <li>Transaction Pending: {(c.transactionPending || false).toString()}</li>
<li><RefreshDialog coin={c} /></li>
</ul>
</div>
diff --git a/src/wallet.ts b/src/wallet.ts
index 932d61eda..971fa6700 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -632,6 +632,9 @@ export class Wallet {
offer.contract.max_fee,
offer.contract.exchanges);
+ console.log("max_fee", offer.contract.max_fee);
+ console.log("coin selection result", res);
+
if (!res) {
console.log("not confirming payment, insufficient coins");
return {
@@ -1172,7 +1175,7 @@ export class Wallet {
(e) => e.exchangeBaseUrl)
.reduce((cd: JoinLeftResult<CoinRecord,DenominationRecord>,
suspendedCoins: CoinRecord[]) => {
- if (!cd.right || !cd.right.isOffered) {
+ if ((!cd.right) || (!cd.right.isOffered)) {
return Array.prototype.concat(suspendedCoins, [cd.left]);
}
return Array.prototype.concat(suspendedCoins);
@@ -1243,12 +1246,14 @@ export class Wallet {
);
const newDenoms: typeof existingDenoms = {};
+ const newAndUnseenDenoms: typeof existingDenoms = {};
for (let d of newKeys.denoms) {
+ let dr = denominationRecordFromKeys(exchangeInfo.baseUrl, d);
if (!(d.denom_pub in existingDenoms)) {
- let dr = denominationRecordFromKeys(exchangeInfo.baseUrl, d);
- newDenoms[dr.denomPub] = dr;
+ newAndUnseenDenoms[dr.denomPub] = dr;
}
+ newDenoms[dr.denomPub] = dr;
}
for (let oldDenomPub in existingDenoms) {
@@ -1260,7 +1265,7 @@ export class Wallet {
await this.q()
.putAll(Stores.denominations,
- Object.keys(newDenoms).map((d) => newDenoms[d]))
+ Object.keys(newAndUnseenDenoms).map((d) => newAndUnseenDenoms[d]))
.putAll(Stores.denominations,
Object.keys(existingDenoms).map((d) => existingDenoms[d]))
.finish();
diff --git a/tsconfig.json b/tsconfig.json
index ed6eebfc4..c4e4143c2 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -45,12 +45,12 @@
"src/background/background.ts",
"src/content_scripts/notify.ts",
"src/emscripten/taler-emscripten-lib.d.ts",
+ "src/popup/popup.tsx",
"src/pages/show-db.ts",
"src/pages/confirm-contract.tsx",
"src/pages/confirm-create-reserve.tsx",
"src/pages/error.tsx",
"src/pages/logs.tsx",
- "src/pages/tree.tsx",
- "src/popup/popup.tsx"
+ "src/pages/tree.tsx"
]
} \ No newline at end of file