1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

signtx: do not include change in total

This commit is contained in:
Jan Pochyla 2016-11-11 15:54:38 +01:00
parent 44f6f21186
commit 8754d74620
2 changed files with 12 additions and 8 deletions

View File

@ -33,8 +33,8 @@ class UiConfirmOutput:
class UiConfirmTotal: class UiConfirmTotal:
def __init__(self, total_out: int, fee: int, coin: CoinType): def __init__(self, spending: int, fee: int, coin: CoinType):
self.total_out = total_out self.spending = spending
self.fee = fee self.fee = fee
self.coin = coin self.coin = coin
@ -43,8 +43,8 @@ def confirm_output(output: TxOutputType, coin: CoinType):
return (yield UiConfirmOutput(output, coin)) return (yield UiConfirmOutput(output, coin))
def confirm_total(total_out: int, fee: int, coin: CoinType): def confirm_total(spending: int, fee: int, coin: CoinType):
return (yield UiConfirmTotal(total_out, fee, coin)) return (yield UiConfirmTotal(spending, fee, coin))
def request_tx_meta(tx_req: TxRequest, tx_hash: bytes=None): 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 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, raise SigningError(FailureType.ActionCancelled,
'Total cancelled') 'Total cancelled')

View File

@ -20,14 +20,14 @@ async def confirm_output(session_id, output, coin):
return await confirm(session_id, content, ConfirmOutput) 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 import ui
from trezor.ui.text import Text from trezor.ui.text import Text
from trezor.messages.ButtonRequestType import SignTx from trezor.messages.ButtonRequestType import SignTx
from ..common.confirm import confirm from ..common.confirm import confirm
content = Text('Confirm transaction', ui.ICON_RESET, 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)) 'Fee: %s' % format_amount(fee, coin))
return await confirm(session_id, content, SignTx) return await confirm(session_id, content, SignTx)
@ -57,7 +57,7 @@ async def layout_sign_tx(message, session_id):
elif isinstance(req, signtx.UiConfirmOutput): elif isinstance(req, signtx.UiConfirmOutput):
res = await confirm_output(session_id, req.output, req.coin) res = await confirm_output(session_id, req.output, req.coin)
elif isinstance(req, signtx.UiConfirmTotal): 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: else:
print(req) print(req)
raise ValueError('Invalid signing instruction') raise ValueError('Invalid signing instruction')