2018-05-21 13:09:06 +00:00
|
|
|
from trezor.crypto.hashlib import sha256
|
2018-04-16 20:03:04 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-04-16 20:03:04 +00:00
|
|
|
|
|
|
|
def get_votes_count(votes):
|
2018-04-21 18:46:59 +00:00
|
|
|
plus, minus = 0, 0
|
2018-04-16 20:03:04 +00:00
|
|
|
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-04-16 20:03:04 +00:00
|
|
|
|
2018-05-21 13:09:06 +00:00
|
|
|
|
2018-04-16 20:03:04 +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))
|
2018-04-16 20:03:04 +00:00
|
|
|
if minus > 0:
|
2018-07-03 14:20:58 +00:00
|
|
|
text.append(_text_with_plural("Remove", minus))
|
2018-04-16 20:03:04 +00:00
|
|
|
return text
|
|
|
|
|
2018-05-21 13:09:06 +00:00
|
|
|
|
2018-04-16 20:03:04 +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"))
|