1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 02:31:05 +00:00
trezor-firmware/core/src/apps/lisk/helpers.py

32 lines
757 B
Python
Raw Normal View History

2018-05-21 13:09:06 +00:00
from trezor.crypto.hashlib import sha256
2018-05-21 13:09:06 +00:00
def get_address_from_public_key(pubkey):
pubkeyhash = sha256(pubkey).digest()
2018-07-03 14:20:58 +00:00
address = int.from_bytes(pubkeyhash[:8], "little")
return str(address) + "L"
2018-05-21 13:09:06 +00:00
def get_votes_count(votes):
2018-04-21 18:46:59 +00:00
plus, minus = 0, 0
for vote in votes:
2018-07-03 14:20:58 +00:00
if vote.startswith("+"):
2018-04-21 18:46:59 +00:00
plus += 1
else:
minus += 1
return plus, minus
2018-05-21 13:09:06 +00:00
def get_vote_tx_text(votes):
plus, minus = get_votes_count(votes)
text = []
if plus > 0:
2018-07-03 14:20:58 +00:00
text.append(_text_with_plural("Add", plus))
if minus > 0:
2018-07-03 14:20:58 +00:00
text.append(_text_with_plural("Remove", minus))
return text
2018-05-21 13:09:06 +00:00
def _text_with_plural(txt, value):
2018-07-03 14:20:58 +00:00
return "%s %s %s" % (txt, value, ("votes" if value != 1 else "vote"))