parent
342c3646e1
commit
4693c071b4
@ -0,0 +1,24 @@
|
||||
from ustruct import unpack
|
||||
|
||||
from trezor.utils import format_amount
|
||||
|
||||
currencies = {1: "OMNI", 2: "tOMNI", 3: "MAID", 31: "USDT"}
|
||||
|
||||
|
||||
def is_valid(data: bytes) -> bool:
|
||||
return data[:4] == b"omni"
|
||||
|
||||
|
||||
def parse(data: bytes) -> bool:
|
||||
if not is_valid(data):
|
||||
return None
|
||||
tx_version, tx_type = unpack(">HH", data[4:8])
|
||||
if tx_version == 0 and tx_type == 0 and len(data) == 20: # OMNI simple send
|
||||
currency, amount = unpack(">IQ", data[8:20])
|
||||
return "Simple send of %s %s" % (
|
||||
format_amount(amount, 8),
|
||||
currencies.get(currency, "UNKN"),
|
||||
)
|
||||
else:
|
||||
# unknown OMNI transaction
|
||||
return "Unknown transaction"
|
@ -0,0 +1,32 @@
|
||||
from common import *
|
||||
|
||||
from apps.wallet.sign_tx.omni import is_valid, parse
|
||||
|
||||
class TestSignTxOmni(unittest.TestCase):
|
||||
|
||||
def test_is_valid(self):
|
||||
VECTORS = {
|
||||
"6f6d6e69000000000000001f000000002b752ee0": True,
|
||||
"6f6d6e69000000000000001f0000000020c85580": True,
|
||||
"0f6d6e69000000000000001f0000000020c85580": False,
|
||||
"6f6d6e69000000000000001f0000000020c8558000": True,
|
||||
"6f6d6e69000000000000001f0000000020c855": True,
|
||||
}
|
||||
for k, v in VECTORS.items():
|
||||
k = unhexlify(k)
|
||||
self.assertEqual(is_valid(k), v)
|
||||
|
||||
def test_parse(self):
|
||||
VECTORS = {
|
||||
"6f6d6e69000000000000001f000000002b752ee0": "Simple send of 7.291 USDT",
|
||||
"6f6d6e69000000000000001f0000000020c85580": "Simple send of 5.5 USDT",
|
||||
"6f6d6e690000000000000003000000002b752ee0": "Simple send of 7.291 MAID",
|
||||
"6f6d6e690000000000000000000000002b752ee0": "Simple send of 7.291 UNKN",
|
||||
"6f6d6e6901000000": "Unknown transaction",
|
||||
}
|
||||
for k, v in VECTORS.items():
|
||||
k = unhexlify(k)
|
||||
self.assertEqual(parse(k), v)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in new issue