fix feeDeposit/max_fee corner case

This commit is contained in:
Florian Dold 2016-11-20 04:15:49 +01:00
parent 9197bda90a
commit 7356d4257e
4 changed files with 31 additions and 8 deletions

View File

@ -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();
}
}
}

View File

@ -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>

View File

@ -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();

View File

@ -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"
]
}