From 8754d74620082928762fcbee0ce4560204d988b6 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Fri, 11 Nov 2016 15:54:38 +0100 Subject: [PATCH] signtx: do not include change in total --- src/apps/common/signtx.py | 14 +++++++++----- src/apps/wallet/layout_sign_tx.py | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/apps/common/signtx.py b/src/apps/common/signtx.py index 1c04cda136..a687ed95e0 100644 --- a/src/apps/common/signtx.py +++ b/src/apps/common/signtx.py @@ -33,8 +33,8 @@ class UiConfirmOutput: class UiConfirmTotal: - def __init__(self, total_out: int, fee: int, coin: CoinType): - self.total_out = total_out + def __init__(self, spending: int, fee: int, coin: CoinType): + self.spending = spending self.fee = fee self.coin = coin @@ -43,8 +43,8 @@ def confirm_output(output: TxOutputType, coin: CoinType): return (yield UiConfirmOutput(output, coin)) -def confirm_total(total_out: int, fee: int, coin: CoinType): - return (yield UiConfirmTotal(total_out, fee, coin)) +def confirm_total(spending: int, fee: int, coin: CoinType): + return (yield UiConfirmTotal(spending, fee, coin)) def request_tx_meta(tx_req: TxRequest, tx_hash: bytes=None): @@ -141,7 +141,11 @@ async def sign_tx(tx: SignTx, root): fee = total_in - total_out - if not await confirm_total(total_out, fee, coin): + if fee < 0: + raise SigningError(FailureType.NotEnoughFunds, + 'Not enough funds') + + if not await confirm_total(total_out - change_out, fee, coin): raise SigningError(FailureType.ActionCancelled, 'Total cancelled') diff --git a/src/apps/wallet/layout_sign_tx.py b/src/apps/wallet/layout_sign_tx.py index a51f76cfcf..0dc01e78ae 100644 --- a/src/apps/wallet/layout_sign_tx.py +++ b/src/apps/wallet/layout_sign_tx.py @@ -20,14 +20,14 @@ async def confirm_output(session_id, output, coin): return await confirm(session_id, content, ConfirmOutput) -async def confirm_total(session_id, total_out, fee, coin): +async def confirm_total(session_id, spending, fee, coin): from trezor import ui from trezor.ui.text import Text from trezor.messages.ButtonRequestType import SignTx from ..common.confirm import confirm content = Text('Confirm transaction', ui.ICON_RESET, - 'Sending: %s' % format_amount(total_out, coin), + 'Sending: %s' % format_amount(spending, coin), 'Fee: %s' % format_amount(fee, coin)) return await confirm(session_id, content, SignTx) @@ -57,7 +57,7 @@ async def layout_sign_tx(message, session_id): elif isinstance(req, signtx.UiConfirmOutput): res = await confirm_output(session_id, req.output, req.coin) elif isinstance(req, signtx.UiConfirmTotal): - res = await confirm_total(session_id, req.total_out, req.fee, req.coin) + res = await confirm_total(session_id, req.spending, req.fee, req.coin) else: print(req) raise ValueError('Invalid signing instruction')