mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 00:28:10 +00:00
nem: mosaics definitions are generated from trezor-common
This commit is contained in:
parent
0093d21bb6
commit
3422474811
15
src/apps/nem/mosaic/helpers.py
Normal file
15
src/apps/nem/mosaic/helpers.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from .nem_mosaics import mosaics
|
||||||
|
|
||||||
|
|
||||||
|
def get_mosaic_definition(namespace_name: str, mosaic_name: str, network: int):
|
||||||
|
for m in mosaics:
|
||||||
|
if namespace_name == m["namespace"] and mosaic_name == m["mosaic"]:
|
||||||
|
if ("networks" not in m) or (network in m["networks"]):
|
||||||
|
return m
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def is_nem_xem_mosaic(namespace_name: str, mosaic_name: str):
|
||||||
|
if namespace_name == "nem" and mosaic_name == "xem":
|
||||||
|
return True
|
||||||
|
return False
|
@ -1,19 +1,4 @@
|
|||||||
# todo move to common and generate via script
|
# generated using gen_nem_mosaics.py from trezor-common nem_mosaics.json - do not edit directly!
|
||||||
|
|
||||||
|
|
||||||
def get_mosaic_definition(namespace_name: str, mosaic_name: str, network: int):
|
|
||||||
for m in mosaics:
|
|
||||||
if namespace_name == m["namespace"] and mosaic_name == m["mosaic"]:
|
|
||||||
if ("networks" not in m) or (network in m["networks"]):
|
|
||||||
return m
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def is_nem_xem_mosaic(namespace_name: str, mosaic_name: str):
|
|
||||||
if namespace_name == "nem" and mosaic_name == "xem":
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
mosaics = [
|
mosaics = [
|
||||||
{
|
{
|
||||||
@ -21,7 +6,7 @@ mosaics = [
|
|||||||
"ticker": " XEM",
|
"ticker": " XEM",
|
||||||
"namespace": "nem",
|
"namespace": "nem",
|
||||||
"mosaic": "xem",
|
"mosaic": "xem",
|
||||||
"divisibility": 6
|
"divisibility": 6,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DIMCOIN",
|
"name": "DIMCOIN",
|
||||||
@ -33,7 +18,7 @@ mosaics = [
|
|||||||
"fee": 10,
|
"fee": 10,
|
||||||
"levy_namespace": "dim",
|
"levy_namespace": "dim",
|
||||||
"levy_mosaic": "coin",
|
"levy_mosaic": "coin",
|
||||||
"networks": [ 104 ]
|
"networks": [104],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DIM TOKEN",
|
"name": "DIM TOKEN",
|
||||||
@ -41,7 +26,7 @@ mosaics = [
|
|||||||
"namespace": "dim",
|
"namespace": "dim",
|
||||||
"mosaic": "token",
|
"mosaic": "token",
|
||||||
"divisibility": 6,
|
"divisibility": 6,
|
||||||
"networks": [ 104 ]
|
"networks": [104],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Breeze Token",
|
"name": "Breeze Token",
|
||||||
@ -49,7 +34,7 @@ mosaics = [
|
|||||||
"namespace": "breeze",
|
"namespace": "breeze",
|
||||||
"mosaic": "breeze-token",
|
"mosaic": "breeze-token",
|
||||||
"divisibility": 0,
|
"divisibility": 0,
|
||||||
"networks": [ 104 ]
|
"networks": [104],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "PacNEM Game Credits",
|
"name": "PacNEM Game Credits",
|
||||||
@ -57,7 +42,7 @@ mosaics = [
|
|||||||
"namespace": "pacnem",
|
"namespace": "pacnem",
|
||||||
"mosaic": "heart",
|
"mosaic": "heart",
|
||||||
"divisibility": 0,
|
"divisibility": 0,
|
||||||
"networks": [ 104 ]
|
"networks": [104],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "PacNEM Score Tokens",
|
"name": "PacNEM Score Tokens",
|
||||||
@ -69,6 +54,6 @@ mosaics = [
|
|||||||
"fee": 100,
|
"fee": 100,
|
||||||
"levy_namespace": "nem",
|
"levy_namespace": "nem",
|
||||||
"levy_mosaic": "xem",
|
"levy_mosaic": "xem",
|
||||||
"networks": [ 104 ]
|
"networks": [104],
|
||||||
}
|
},
|
||||||
]
|
]
|
@ -1,5 +1,5 @@
|
|||||||
from apps.nem.layout import *
|
from apps.nem.layout import *
|
||||||
from apps.nem.mosaic.definitions import *
|
from apps.nem.mosaic.helpers import *
|
||||||
from trezor.messages import NEMImportanceTransferMode
|
from trezor.messages import NEMImportanceTransferMode
|
||||||
from trezor.messages import NEMTransfer
|
from trezor.messages import NEMTransfer
|
||||||
from trezor.messages import NEMImportanceTransfer
|
from trezor.messages import NEMImportanceTransfer
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from common import *
|
from common import *
|
||||||
from apps.nem.transfer import *
|
from apps.nem.transfer import *
|
||||||
from apps.nem.mosaic.definitions import get_mosaic_definition
|
from apps.nem.mosaic.helpers import get_mosaic_definition
|
||||||
|
|
||||||
|
|
||||||
class TestNemMosaic(unittest.TestCase):
|
class TestNemMosaic(unittest.TestCase):
|
||||||
|
46
tools/codegen/gen_nem_mosaics.py
Executable file
46
tools/codegen/gen_nem_mosaics.py
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def format_str(value):
|
||||||
|
return '"' + value + '"'
|
||||||
|
|
||||||
|
|
||||||
|
def format_primitive(value):
|
||||||
|
if isinstance(value, int):
|
||||||
|
return value
|
||||||
|
elif isinstance(value, str):
|
||||||
|
return format_str(value)
|
||||||
|
elif isinstance(value, list):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
'name',
|
||||||
|
'ticker',
|
||||||
|
'namespace',
|
||||||
|
'mosaic',
|
||||||
|
'divisibility',
|
||||||
|
'levy',
|
||||||
|
'fee',
|
||||||
|
'levy_namespace',
|
||||||
|
'levy_mosaic',
|
||||||
|
'networks',
|
||||||
|
]
|
||||||
|
|
||||||
|
mosaics = json.load(open('../../vendor/trezor-common/defs/nem/nem_mosaics.json', 'r'))
|
||||||
|
|
||||||
|
print('# generated using gen_nem_mosaics.py from trezor-common nem_mosaics.json - do not edit directly!')
|
||||||
|
print('')
|
||||||
|
print('mosaics = [')
|
||||||
|
for m in mosaics:
|
||||||
|
print(' {')
|
||||||
|
for name in fields:
|
||||||
|
if name in m:
|
||||||
|
print(' %s: %s,' % (format_str(name), format_primitive(m[name])))
|
||||||
|
# else:
|
||||||
|
# print(' %s: None,' % format_str(name))
|
||||||
|
print(' },')
|
||||||
|
print(']')
|
Loading…
Reference in New Issue
Block a user