mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
nem: remove star-imports, fix some style
This commit is contained in:
parent
3dc1c79b1a
commit
1b495324e7
@ -1,11 +1,14 @@
|
||||
from .validators import *
|
||||
from apps.common import seed
|
||||
from apps.common.confirm import confirm
|
||||
from trezor import ui
|
||||
from trezor.messages.NEMAddress import NEMAddress
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.messages.NEMAddress import NEMAddress
|
||||
from trezor.ui.text import Text
|
||||
from trezor.utils import chunks
|
||||
|
||||
from apps.common import seed
|
||||
from apps.common.confirm import require_confirm
|
||||
|
||||
from .layout import split_address
|
||||
from .helpers import get_network_str, NEM_CURVE
|
||||
from .validators import validate_network
|
||||
|
||||
|
||||
async def get_address(ctx, msg):
|
||||
@ -14,35 +17,16 @@ async def get_address(ctx, msg):
|
||||
address = node.nem_address(network)
|
||||
|
||||
if msg.show_display:
|
||||
while True:
|
||||
if await _show_address(ctx, address, network):
|
||||
break
|
||||
await _require_confirm_address(ctx, address, network)
|
||||
|
||||
return NEMAddress(address=address)
|
||||
|
||||
|
||||
async def _show_address(ctx, address: str, network: int):
|
||||
lines = _split_address(address)
|
||||
content = Text('Export NEM address', ui.ICON_RECEIVE,
|
||||
ui.MONO, _get_network_str(network) + ' network',
|
||||
ui.MONO, *lines,
|
||||
icon_color=ui.GREEN)
|
||||
|
||||
return await confirm(
|
||||
ctx,
|
||||
content,
|
||||
code=ButtonRequestType.Address,
|
||||
cancel_style=ui.BTN_KEY)
|
||||
|
||||
|
||||
def _split_address(address: str):
|
||||
return chunks(address, 17)
|
||||
|
||||
|
||||
def _get_network_str(network: int) -> str:
|
||||
if network == NEM_NETWORK_MAINNET:
|
||||
return 'Mainnet'
|
||||
elif network == NEM_NETWORK_TESTNET:
|
||||
return 'Testnet'
|
||||
elif network == NEM_NETWORK_MIJIN:
|
||||
return 'Mijin'
|
||||
async def _require_confirm_address(ctx, address: str, network: int):
|
||||
lines = split_address(address)
|
||||
content = Text(
|
||||
'Export NEM address', ui.ICON_RECEIVE,
|
||||
ui.NORMAL, '%s network' % get_network_str(network),
|
||||
ui.MONO, *lines,
|
||||
icon_color=ui.GREEN)
|
||||
await require_confirm(ctx, content, code=ButtonRequestType.Address)
|
||||
|
@ -26,3 +26,12 @@ NEM_MOSAIC_AMOUNT_DIVISOR = const(1000000)
|
||||
|
||||
NEM_MAX_PLAIN_PAYLOAD_SIZE = const(1024)
|
||||
NEM_MAX_ENCRYPTED_PAYLOAD_SIZE = const(960)
|
||||
|
||||
|
||||
def get_network_str(network: int) -> str:
|
||||
if network == NEM_NETWORK_MAINNET:
|
||||
return 'Mainnet'
|
||||
elif network == NEM_NETWORK_TESTNET:
|
||||
return 'Testnet'
|
||||
elif network == NEM_NETWORK_MIJIN:
|
||||
return 'Mijin'
|
||||
|
@ -1,39 +1,44 @@
|
||||
from apps.common.confirm import *
|
||||
from trezor import ui
|
||||
from trezor.messages import ButtonRequestType
|
||||
from trezor.ui.text import Text
|
||||
from trezor.utils import chunks, format_amount, split_words
|
||||
from .helpers import *
|
||||
|
||||
from apps.common.confirm import require_confirm, require_hold_to_confirm
|
||||
|
||||
from .helpers import NEM_MAX_DIVISIBILITY
|
||||
|
||||
|
||||
async def require_confirm_text(ctx, action: str):
|
||||
await require_confirm_content(ctx, 'Confirm action', split_words(action, 18))
|
||||
words = split_words(action, 18)
|
||||
await require_confirm_content(ctx, 'Confirm action', words)
|
||||
|
||||
|
||||
async def require_confirm_fee(ctx, action: str, fee: int):
|
||||
content = [ui.NORMAL, action,
|
||||
ui.BOLD, format_amount(fee, NEM_MAX_DIVISIBILITY) + ' XEM']
|
||||
content = (
|
||||
ui.NORMAL, action,
|
||||
ui.BOLD, '%s XEM' % format_amount(fee, NEM_MAX_DIVISIBILITY),
|
||||
)
|
||||
await require_confirm_content(ctx, 'Confirm fee', content)
|
||||
|
||||
|
||||
async def require_confirm_content(ctx, headline: str, content: []):
|
||||
text = Text(headline, ui.ICON_SEND,
|
||||
*content,
|
||||
icon_color=ui.GREEN)
|
||||
async def require_confirm_content(ctx, headline: str, content: list):
|
||||
text = Text(headline, ui.ICON_SEND, *content, icon_color=ui.GREEN)
|
||||
await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
|
||||
async def require_confirm_final(ctx, fee: int):
|
||||
content = Text('Final confirm', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Sign this transaction',
|
||||
ui.BOLD, 'and pay ' + format_amount(fee, NEM_MAX_DIVISIBILITY) + ' XEM',
|
||||
ui.NORMAL, 'for network fee?',
|
||||
icon_color=ui.GREEN)
|
||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
content = Text(
|
||||
'Final confirm', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Sign this transaction',
|
||||
ui.BOLD, 'and pay %s XEM' % format_amount(fee, NEM_MAX_DIVISIBILITY),
|
||||
ui.NORMAL, 'for network fee?',
|
||||
icon_color=ui.GREEN)
|
||||
# we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx)
|
||||
|
||||
|
||||
def split_address(data):
|
||||
return chunks(data, 17)
|
||||
def split_address(address: str):
|
||||
return chunks(address, 17)
|
||||
|
||||
|
||||
def trim(payload: str, length: int) -> str:
|
||||
|
@ -1,12 +1,15 @@
|
||||
from .layout import *
|
||||
from .serialize import *
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMMosaicCreation import NEMMosaicCreation
|
||||
from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange
|
||||
|
||||
from . import layout, serialize
|
||||
|
||||
|
||||
async def mosaic_creation(ctx, public_key: bytes, common: NEMTransactionCommon, creation: NEMMosaicCreation) -> bytearray:
|
||||
await ask_mosaic_creation(ctx, common, creation)
|
||||
return serialize_mosaic_creation(common, creation, public_key)
|
||||
await layout.ask_mosaic_creation(ctx, common, creation)
|
||||
return serialize.serialize_mosaic_creation(common, creation, public_key)
|
||||
|
||||
|
||||
async def supply_change(ctx, public_key: bytes, common: NEMTransactionCommon, change: NEMMosaicSupplyChange):
|
||||
await ask_supply_change(ctx, common, change)
|
||||
return serialize_mosaic_supply_change(common, change, public_key)
|
||||
async def supply_change(ctx, public_key: bytes, common: NEMTransactionCommon, change: NEMMosaicSupplyChange) -> bytearray:
|
||||
await layout.ask_supply_change(ctx, common, change)
|
||||
return serialize.serialize_mosaic_supply_change(common, change, public_key)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from .nem_mosaics import mosaics
|
||||
|
||||
|
||||
def get_mosaic_definition(namespace_name: str, mosaic_name: str, network: int):
|
||||
def get_mosaic_definition(namespace_name: str, mosaic_name: str, network: int) -> dict:
|
||||
for m in mosaics:
|
||||
if namespace_name == m["namespace"] and mosaic_name == m["mosaic"]:
|
||||
if ("networks" not in m) or (network in m["networks"]):
|
||||
@ -9,7 +9,7 @@ def get_mosaic_definition(namespace_name: str, mosaic_name: str, network: int):
|
||||
return None
|
||||
|
||||
|
||||
def is_nem_xem_mosaic(namespace_name: str, mosaic_name: str):
|
||||
def is_nem_xem_mosaic(namespace_name: str, mosaic_name: str) -> bool:
|
||||
if namespace_name == "nem" and mosaic_name == "xem":
|
||||
return True
|
||||
return False
|
||||
|
@ -1,11 +1,16 @@
|
||||
from apps.nem.layout import *
|
||||
from trezor.messages import NEMTransactionCommon
|
||||
from trezor.messages import NEMSupplyChangeType
|
||||
from trezor.messages import NEMMosaicDefinition
|
||||
from trezor.messages import NEMMosaicCreation
|
||||
from trezor.messages import NEMMosaicSupplyChange
|
||||
from trezor.messages import NEMMosaicLevy
|
||||
from micropython import const
|
||||
from trezor import ui
|
||||
from trezor.messages import (NEMMosaicCreation, NEMMosaicDefinition,
|
||||
NEMMosaicLevy, NEMMosaicSupplyChange,
|
||||
NEMSupplyChangeType, NEMTransactionCommon)
|
||||
from trezor.ui.confirm import ConfirmDialog
|
||||
from trezor.ui.scroll import Scrollpage, animate_swipe, paginate
|
||||
from trezor.ui.text import Text
|
||||
from trezor.utils import split_words
|
||||
|
||||
from ..layout import (require_confirm_content, require_confirm_fee,
|
||||
require_confirm_final, require_confirm_text,
|
||||
split_address, trim)
|
||||
|
||||
|
||||
async def ask_mosaic_creation(ctx, common: NEMTransactionCommon, creation: NEMMosaicCreation):
|
||||
|
@ -1,8 +1,11 @@
|
||||
from apps.nem.writers import *
|
||||
from apps.nem.helpers import *
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange
|
||||
from trezor.messages.NEMMosaicCreation import NEMMosaicCreation
|
||||
from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
|
||||
from ..helpers import (NEM_TRANSACTION_TYPE_MOSAIC_CREATION,
|
||||
NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE)
|
||||
from ..writers import (write_bytes_with_length, write_common, write_uint32,
|
||||
write_uint64)
|
||||
|
||||
|
||||
def serialize_mosaic_creation(common: NEMTransactionCommon, creation: NEMMosaicCreation, public_key: bytes):
|
||||
@ -17,10 +20,10 @@ def serialize_mosaic_creation(common: NEMTransactionCommon, creation: NEMMosaicC
|
||||
write_bytes_with_length(mosaics_w, bytearray(creation.definition.description))
|
||||
write_uint32(mosaics_w, 4) # number of properties
|
||||
|
||||
_write_property(mosaics_w, "divisibility", creation.definition.divisibility)
|
||||
_write_property(mosaics_w, "initialSupply", creation.definition.supply)
|
||||
_write_property(mosaics_w, "supplyMutable", creation.definition.mutable_supply)
|
||||
_write_property(mosaics_w, "transferable", creation.definition.transferable)
|
||||
_write_property(mosaics_w, 'divisibility', creation.definition.divisibility)
|
||||
_write_property(mosaics_w, 'initialSupply', creation.definition.supply)
|
||||
_write_property(mosaics_w, 'supplyMutable', creation.definition.mutable_supply)
|
||||
_write_property(mosaics_w, 'transferable', creation.definition.transferable)
|
||||
|
||||
if creation.definition.levy:
|
||||
levy_identifier_length = 4 + len(creation.definition.levy_namespace) + 4 + len(creation.definition.levy_mosaic)
|
||||
@ -58,15 +61,15 @@ def serialize_mosaic_supply_change(common: NEMTransactionCommon, change: NEMMosa
|
||||
|
||||
def _write_property(w: bytearray, name: str, value):
|
||||
if value is None:
|
||||
if name in ['divisibility', 'initialSupply']:
|
||||
if name in ('divisibility', 'initialSupply'):
|
||||
value = 0
|
||||
elif name in ['supplyMutable', 'transferable']:
|
||||
elif name in ('supplyMutable', 'transferable'):
|
||||
value = False
|
||||
if type(value) == bool:
|
||||
if value:
|
||||
value = "true"
|
||||
value = 'true'
|
||||
else:
|
||||
value = "false"
|
||||
value = 'false'
|
||||
elif type(value) == int:
|
||||
value = str(value)
|
||||
elif type(value) != str:
|
||||
|
@ -1,21 +1,20 @@
|
||||
from .serialize import *
|
||||
from .layout import *
|
||||
from trezor.messages.NEMAggregateModification import NEMAggregateModification
|
||||
from trezor.messages.NEMSignTx import NEMSignTx
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
|
||||
from . import layout, serialize
|
||||
|
||||
|
||||
async def ask(ctx, msg: NEMSignTx):
|
||||
await ask_multisig(ctx, msg)
|
||||
await layout.ask_multisig(ctx, msg)
|
||||
|
||||
|
||||
def initiate(public_key, common: NEMTransactionCommon, inner_tx: bytes) -> bytes:
|
||||
return serialize_multisig(common, public_key, inner_tx)
|
||||
return serialize.serialize_multisig(common, public_key, inner_tx)
|
||||
|
||||
|
||||
def cosign(public_key, common: NEMTransactionCommon, inner_tx: bytes, signer: bytes) -> bytes:
|
||||
return serialize_multisig_signature(common,
|
||||
public_key,
|
||||
inner_tx,
|
||||
signer)
|
||||
return serialize.serialize_multisig_signature(common, public_key, inner_tx, signer)
|
||||
|
||||
|
||||
async def aggregate_modification(ctx,
|
||||
@ -23,12 +22,12 @@ async def aggregate_modification(ctx,
|
||||
common: NEMTransactionCommon,
|
||||
aggr: NEMAggregateModification,
|
||||
multisig: bool):
|
||||
await ask_aggregate_modification(ctx, common, aggr, multisig)
|
||||
w = serialize_aggregate_modification(common, aggr, public_key)
|
||||
await layout.ask_aggregate_modification(ctx, common, aggr, multisig)
|
||||
w = serialize.serialize_aggregate_modification(common, aggr, public_key)
|
||||
|
||||
for m in aggr.modifications:
|
||||
serialize_cosignatory_modification(w, m.type, m.public_key)
|
||||
serialize.serialize_cosignatory_modification(w, m.type, m.public_key)
|
||||
|
||||
if aggr.relative_change:
|
||||
serialize_minimum_cosignatories(w, aggr.relative_change)
|
||||
serialize.serialize_minimum_cosignatories(w, aggr.relative_change)
|
||||
return w
|
||||
|
@ -1,9 +1,13 @@
|
||||
from apps.nem.layout import *
|
||||
from trezor.messages import NEMAggregateModification
|
||||
from trezor.messages import NEMModificationType
|
||||
from trezor.messages import NEMSignTx
|
||||
from trezor.messages import NEMTransactionCommon
|
||||
from trezor import ui
|
||||
from trezor.crypto import nem
|
||||
from trezor.messages import (ButtonRequestType, NEMAggregateModification,
|
||||
NEMModificationType, NEMSignTx,
|
||||
NEMTransactionCommon)
|
||||
from trezor.ui.text import Text
|
||||
|
||||
from ..layout import (require_confirm, require_confirm_fee,
|
||||
require_confirm_final, require_confirm_text,
|
||||
split_address)
|
||||
|
||||
|
||||
async def ask_multisig(ctx, msg: NEMSignTx):
|
||||
|
@ -1,10 +1,11 @@
|
||||
from apps.nem.writers import *
|
||||
from apps.nem.helpers import *
|
||||
from trezor.messages.NEMSignTx import NEMSignTx
|
||||
from trezor.crypto import hashlib
|
||||
from trezor.crypto import nem
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.crypto import hashlib, nem
|
||||
from trezor.messages.NEMAggregateModification import NEMAggregateModification
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
|
||||
from ..helpers import (NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION,
|
||||
NEM_TRANSACTION_TYPE_MULTISIG,
|
||||
NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE)
|
||||
from ..writers import write_bytes_with_length, write_common, write_uint32
|
||||
|
||||
|
||||
def serialize_multisig(common: NEMTransactionCommon, public_key: bytes, inner: bytes):
|
||||
|
@ -1,7 +1,9 @@
|
||||
from .layout import *
|
||||
from .serialize import *
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace
|
||||
|
||||
from . import layout, serialize
|
||||
|
||||
|
||||
async def namespace(ctx, public_key: bytes, common: NEMTransactionCommon, namespace: NEMProvisionNamespace) -> bytearray:
|
||||
await ask_provision_namespace(ctx, common, namespace)
|
||||
return serialize_provision_namespace(common, namespace, public_key)
|
||||
await layout.ask_provision_namespace(ctx, common, namespace)
|
||||
return serialize.serialize_provision_namespace(common, namespace, public_key)
|
||||
|
@ -1,18 +1,20 @@
|
||||
from apps.nem.layout import *
|
||||
from trezor.messages import NEMTransactionCommon
|
||||
from trezor.messages import NEMProvisionNamespace
|
||||
from trezor import ui
|
||||
from trezor.messages import NEMProvisionNamespace, NEMTransactionCommon
|
||||
|
||||
from ..layout import (require_confirm_content, require_confirm_fee,
|
||||
require_confirm_final)
|
||||
|
||||
|
||||
async def ask_provision_namespace(ctx, common: NEMTransactionCommon, namespace: NEMProvisionNamespace):
|
||||
if namespace.parent:
|
||||
content = [ui.NORMAL, 'Create namespace',
|
||||
content = (ui.NORMAL, 'Create namespace',
|
||||
ui.BOLD, namespace.namespace,
|
||||
ui.NORMAL, 'under namespace',
|
||||
ui.BOLD, namespace.parent]
|
||||
ui.BOLD, namespace.parent)
|
||||
await require_confirm_content(ctx, 'Confirm namespace', content)
|
||||
else:
|
||||
content = [ui.NORMAL, 'Create namespace',
|
||||
ui.BOLD, namespace.namespace]
|
||||
content = (ui.NORMAL, 'Create namespace',
|
||||
ui.BOLD, namespace.namespace)
|
||||
await require_confirm_content(ctx, 'Confirm namespace', content)
|
||||
|
||||
await require_confirm_fee(ctx, 'Confirm rental fee', namespace.fee)
|
||||
|
@ -1,7 +1,8 @@
|
||||
from apps.nem.helpers import *
|
||||
from apps.nem.writers import *
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMProvisionNamespace import NEMProvisionNamespace
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
|
||||
from ..helpers import NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE
|
||||
from ..writers import write_bytes_with_length, write_common, write_uint32, write_uint64
|
||||
|
||||
|
||||
def serialize_provision_namespace(common: NEMTransactionCommon, namespace: NEMProvisionNamespace, public_key: bytes) -> bytearray:
|
||||
|
@ -1,13 +1,11 @@
|
||||
from apps.nem import namespace
|
||||
from apps.nem import transfer
|
||||
from apps.nem import mosaic
|
||||
from apps.nem import multisig
|
||||
from apps.nem.validators import validate
|
||||
from apps.nem.helpers import *
|
||||
from apps.common import seed
|
||||
from trezor.messages.NEMSignTx import NEMSignTx
|
||||
from trezor.messages.NEMSignedTx import NEMSignedTx
|
||||
from trezor.crypto.curve import ed25519
|
||||
from trezor.messages.NEMSignedTx import NEMSignedTx
|
||||
from trezor.messages.NEMSignTx import NEMSignTx
|
||||
from apps.common import seed
|
||||
|
||||
from . import mosaic, multisig, namespace, transfer
|
||||
from .helpers import NEM_CURVE, NEM_HASH_ALG
|
||||
from .validators import validate
|
||||
|
||||
|
||||
async def sign_tx(ctx, msg: NEMSignTx):
|
||||
|
@ -1,20 +1,22 @@
|
||||
from .layout import *
|
||||
from .serialize import *
|
||||
from trezor.messages.NEMSignTx import NEMTransfer
|
||||
from trezor.messages.NEMTransfer import NEMTransfer
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMImportanceTransfer import NEMImportanceTransfer
|
||||
|
||||
from . import layout, serialize
|
||||
|
||||
|
||||
async def transfer(ctx, public_key: bytes, common: NEMTransactionCommon, transfer: NEMTransfer, node):
|
||||
transfer.mosaics = canonicalize_mosaics(transfer.mosaics)
|
||||
transfer.mosaics = serialize.canonicalize_mosaics(transfer.mosaics)
|
||||
payload, encrypted = serialize.get_transfer_payload(transfer, node)
|
||||
|
||||
payload, encrypted = get_transfer_payload(transfer, node)
|
||||
await ask_transfer(ctx, common, transfer, payload, encrypted)
|
||||
await layout.ask_transfer(ctx, common, transfer, payload, encrypted)
|
||||
|
||||
w = serialize_transfer(common, transfer, public_key, payload, encrypted)
|
||||
w = serialize.serialize_transfer(common, transfer, public_key, payload, encrypted)
|
||||
for mosaic in transfer.mosaics:
|
||||
serialize_mosaic(w, mosaic.namespace, mosaic.mosaic, mosaic.quantity)
|
||||
serialize.serialize_mosaic(w, mosaic.namespace, mosaic.mosaic, mosaic.quantity)
|
||||
return w
|
||||
|
||||
|
||||
async def importance_transfer(ctx, public_key: bytes, common: NEMTransactionCommon, imp: NEMImportanceTransfer):
|
||||
await ask_importance_transfer(ctx, common, imp)
|
||||
return serialize_importance_transfer(common, imp, public_key)
|
||||
await layout.ask_importance_transfer(ctx, common, imp)
|
||||
return serialize.serialize_importance_transfer(common, imp, public_key)
|
||||
|
@ -1,22 +1,24 @@
|
||||
from apps.nem.layout import *
|
||||
from apps.nem.mosaic.helpers import *
|
||||
from trezor.messages import NEMImportanceTransferMode
|
||||
from trezor.messages import NEMTransfer
|
||||
from trezor.messages import NEMImportanceTransfer
|
||||
from trezor.messages import NEMTransactionCommon
|
||||
from trezor.messages import NEMMosaic
|
||||
from trezor.messages import NEMMosaicLevy
|
||||
from trezor import ui
|
||||
from trezor.messages import (ButtonRequestType, NEMImportanceTransfer,
|
||||
NEMImportanceTransferMode, NEMMosaic,
|
||||
NEMMosaicLevy, NEMTransactionCommon, NEMTransfer)
|
||||
from trezor.ui.text import Text
|
||||
from trezor.utils import format_amount, split_words
|
||||
|
||||
from apps.common.confirm import require_confirm
|
||||
|
||||
from ..helpers import (NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE,
|
||||
NEM_MAX_DIVISIBILITY, NEM_MOSAIC_AMOUNT_DIVISOR)
|
||||
from ..layout import require_confirm_final, require_confirm_text, split_address
|
||||
from ..mosaic.helpers import get_mosaic_definition, is_nem_xem_mosaic
|
||||
|
||||
|
||||
async def ask_transfer(ctx, common: NEMTransactionCommon, transfer: NEMTransfer, payload, encrypted):
|
||||
async def ask_transfer(ctx, common: NEMTransactionCommon, transfer: NEMTransfer, payload: bytes, encrypted: bool):
|
||||
if payload:
|
||||
await _require_confirm_payload(ctx, transfer.payload, encrypted)
|
||||
|
||||
for mosaic in transfer.mosaics:
|
||||
await ask_transfer_mosaic(ctx, common, transfer, mosaic)
|
||||
|
||||
await _require_confirm_transfer(ctx, transfer.recipient, _get_xem_amount(transfer))
|
||||
|
||||
await require_confirm_final(ctx, common.fee)
|
||||
|
||||
|
||||
@ -29,20 +31,22 @@ async def ask_transfer_mosaic(ctx, common: NEMTransactionCommon, transfer: NEMTr
|
||||
|
||||
if definition:
|
||||
msg = Text('Confirm mosaic', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Confirm transfer of',
|
||||
ui.BOLD, format_amount(mosaic_quantity, definition["divisibility"]) + definition["ticker"],
|
||||
'Confirm transfer of',
|
||||
ui.BOLD, format_amount(mosaic_quantity, definition['divisibility']) + definition['ticker'],
|
||||
ui.NORMAL, 'of',
|
||||
ui.BOLD, definition["name"],
|
||||
ui.BOLD, definition['name'],
|
||||
icon_color=ui.GREEN)
|
||||
|
||||
await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
if "levy" in definition and "fee" in definition:
|
||||
if 'levy' in definition and 'fee' in definition:
|
||||
levy_msg = _get_levy_msg(definition, mosaic_quantity, common.network)
|
||||
msg = Text('Confirm mosaic', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Confirm mosaic',
|
||||
ui.NORMAL, 'levy fee of',
|
||||
'Confirm mosaic',
|
||||
'levy fee of',
|
||||
ui.BOLD, levy_msg,
|
||||
icon_color=ui.GREEN)
|
||||
|
||||
await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
else:
|
||||
@ -54,16 +58,16 @@ async def ask_transfer_mosaic(ctx, common: NEMTransactionCommon, transfer: NEMTr
|
||||
|
||||
msg = Text('Confirm mosaic', ui.ICON_SEND,
|
||||
ui.NORMAL, 'Confirm transfer of',
|
||||
ui.BOLD, str(mosaic_quantity) + ' raw units',
|
||||
ui.BOLD, '%s raw units' % mosaic_quantity,
|
||||
ui.NORMAL, 'of',
|
||||
ui.BOLD, mosaic.namespace + '.' + mosaic.mosaic,
|
||||
ui.BOLD, '%s.%s' % (mosaic.namespace, mosaic.mosaic),
|
||||
icon_color=ui.GREEN)
|
||||
await require_confirm(ctx, msg, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
|
||||
def _get_xem_amount(transfer: NEMTransfer):
|
||||
# mosaics are empty the transfer.amount denotes the xem amount
|
||||
if not len(transfer.mosaics):
|
||||
# if mosaics are empty the transfer.amount denotes the xem amount
|
||||
if not transfer.mosaics:
|
||||
return transfer.amount
|
||||
# otherwise xem amount is taken from the nem xem mosaic if present
|
||||
for mosaic in transfer.mosaics:
|
||||
@ -74,12 +78,18 @@ def _get_xem_amount(transfer: NEMTransfer):
|
||||
|
||||
|
||||
def _get_levy_msg(mosaic_definition, quantity: int, network: int) -> str:
|
||||
levy_definition = get_mosaic_definition(mosaic_definition["levy_namespace"], mosaic_definition["levy_mosaic"], network)
|
||||
if mosaic_definition["levy"] == NEMMosaicLevy.MosaicLevy_Absolute:
|
||||
levy_fee = mosaic_definition["fee"]
|
||||
levy_definition = get_mosaic_definition(
|
||||
mosaic_definition['levy_namespace'],
|
||||
mosaic_definition['levy_mosaic'],
|
||||
network)
|
||||
if mosaic_definition['levy'] == NEMMosaicLevy.MosaicLevy_Absolute:
|
||||
levy_fee = mosaic_definition['fee']
|
||||
else:
|
||||
levy_fee = quantity * mosaic_definition["fee"] / NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE
|
||||
return format_amount(levy_fee, levy_definition["divisibility"]) + levy_definition["ticker"]
|
||||
levy_fee = quantity * mosaic_definition['fee'] / NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE
|
||||
return format_amount(
|
||||
levy_fee,
|
||||
levy_definition['divisibility']
|
||||
) + levy_definition['ticker']
|
||||
|
||||
|
||||
async def ask_importance_transfer(ctx, common: NEMTransactionCommon, imp: NEMImportanceTransfer):
|
||||
@ -93,7 +103,7 @@ async def ask_importance_transfer(ctx, common: NEMTransactionCommon, imp: NEMImp
|
||||
|
||||
async def _require_confirm_transfer(ctx, recipient, value):
|
||||
content = Text('Confirm transfer', ui.ICON_SEND,
|
||||
ui.BOLD, 'Send ' + format_amount(value, NEM_MAX_DIVISIBILITY) + ' XEM',
|
||||
ui.BOLD, 'Send %s XEM' % format_amount(value, NEM_MAX_DIVISIBILITY),
|
||||
ui.NORMAL, 'to',
|
||||
ui.MONO, *split_address(recipient),
|
||||
icon_color=ui.GREEN)
|
||||
|
@ -1,15 +1,21 @@
|
||||
from apps.nem.writers import *
|
||||
from apps.nem.helpers import *
|
||||
from trezor.messages.NEMMosaic import NEMMosaic
|
||||
from trezor.messages.NEMImportanceTransfer import NEMImportanceTransfer
|
||||
from trezor.messages.NEMTransfer import NEMTransfer
|
||||
from trezor.crypto import random
|
||||
from trezor.messages.NEMImportanceTransfer import NEMImportanceTransfer
|
||||
from trezor.messages.NEMMosaic import NEMMosaic
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
from trezor.messages.NEMTransfer import NEMTransfer
|
||||
|
||||
from ..helpers import (AES_BLOCK_SIZE, NEM_SALT_SIZE,
|
||||
NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER,
|
||||
NEM_TRANSACTION_TYPE_TRANSFER)
|
||||
from ..writers import write_bytes_with_length, write_common, write_uint32, write_uint64
|
||||
|
||||
|
||||
def serialize_transfer(common: NEMTransactionCommon, transfer: NEMTransfer,
|
||||
public_key: bytes, payload: bytes=None, encrypted: bool=False) -> bytearray:
|
||||
tx = write_common(common,
|
||||
bytearray(public_key),
|
||||
def serialize_transfer(common: NEMTransactionCommon,
|
||||
transfer: NEMTransfer,
|
||||
public_key: bytes,
|
||||
payload: bytes = None,
|
||||
encrypted: bool = False) -> bytearray:
|
||||
tx = write_common(common, bytearray(public_key),
|
||||
NEM_TRANSACTION_TYPE_TRANSFER,
|
||||
_get_version(common.network, transfer.mosaics))
|
||||
|
||||
@ -43,8 +49,11 @@ def serialize_mosaic(w: bytearray, namespace: str, mosaic: str, quantity: int):
|
||||
write_uint64(w, quantity)
|
||||
|
||||
|
||||
def serialize_importance_transfer(common: NEMTransactionCommon, imp: NEMImportanceTransfer, public_key: bytes)-> bytearray:
|
||||
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER)
|
||||
def serialize_importance_transfer(common: NEMTransactionCommon,
|
||||
imp: NEMImportanceTransfer,
|
||||
public_key: bytes) -> bytearray:
|
||||
w = write_common(common, bytearray(public_key),
|
||||
NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER)
|
||||
|
||||
write_uint32(w, imp.mode)
|
||||
write_bytes_with_length(w, bytearray(imp.public_key))
|
||||
@ -56,7 +65,7 @@ def get_transfer_payload(transfer: NEMTransfer, node) -> [bytes, bool]:
|
||||
encrypted = False
|
||||
if transfer.public_key is not None:
|
||||
if payload is None:
|
||||
raise ValueError("Public key provided but no payload to encrypt")
|
||||
raise ValueError('Public key provided but no payload to encrypt')
|
||||
payload = _encrypt(node, transfer.public_key, transfer.payload)
|
||||
encrypted = True
|
||||
|
||||
@ -90,7 +99,7 @@ def are_mosaics_equal(a: NEMMosaic, b: NEMMosaic) -> bool:
|
||||
|
||||
|
||||
def merge_mosaics(mosaics: list) -> list:
|
||||
if not len(mosaics):
|
||||
if not mosaics:
|
||||
return list()
|
||||
ret = list()
|
||||
for i in mosaics:
|
||||
|
@ -1,18 +1,19 @@
|
||||
from apps.nem.helpers import *
|
||||
from trezor.messages import NEMModificationType
|
||||
from trezor.messages.NEMSignTx import NEMAggregateModification
|
||||
from trezor.messages.NEMSignTx import NEMImportanceTransfer
|
||||
from trezor.messages.NEMSignTx import NEMMosaicCreation
|
||||
from trezor.messages.NEMSignTx import NEMMosaicSupplyChange
|
||||
from trezor.messages.NEMSignTx import NEMProvisionNamespace
|
||||
from trezor.messages.NEMSignTx import NEMSignTx
|
||||
from trezor.messages.NEMSignTx import NEMTransactionCommon
|
||||
from trezor.messages.NEMSignTx import NEMTransfer
|
||||
from trezor.crypto import nem
|
||||
from trezor.messages import NEMModificationType
|
||||
from trezor.messages.NEMSignTx import (NEMAggregateModification,
|
||||
NEMImportanceTransfer,
|
||||
NEMMosaicCreation,
|
||||
NEMMosaicSupplyChange,
|
||||
NEMProvisionNamespace, NEMSignTx,
|
||||
NEMTransactionCommon, NEMTransfer)
|
||||
|
||||
from .helpers import (NEM_MAX_DIVISIBILITY, NEM_MAX_ENCRYPTED_PAYLOAD_SIZE,
|
||||
NEM_MAX_PLAIN_PAYLOAD_SIZE, NEM_MAX_SUPPLY,
|
||||
NEM_NETWORK_MAINNET, NEM_NETWORK_MIJIN,
|
||||
NEM_NETWORK_TESTNET, NEM_PUBLIC_KEY_SIZE)
|
||||
|
||||
|
||||
def validate(msg: NEMSignTx):
|
||||
|
||||
if msg.transaction is None:
|
||||
raise ValueError('No common provided')
|
||||
|
||||
@ -42,13 +43,9 @@ def validate(msg: NEMSignTx):
|
||||
def validate_network(network: int) -> int:
|
||||
if network is None:
|
||||
return NEM_NETWORK_MAINNET
|
||||
_validate_network(network)
|
||||
return network
|
||||
|
||||
|
||||
def _validate_network(network: int):
|
||||
if network not in [NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET, NEM_NETWORK_MIJIN]:
|
||||
if network not in (NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET, NEM_NETWORK_MIJIN):
|
||||
raise ValueError('Invalid NEM network')
|
||||
return network
|
||||
|
||||
|
||||
def _validate_single_tx(msg: NEMSignTx):
|
||||
@ -65,8 +62,7 @@ def _validate_single_tx(msg: NEMSignTx):
|
||||
raise ValueError('More than one transaction provided')
|
||||
|
||||
|
||||
def _validate_common(common: NEMTransactionCommon, inner: bool=False):
|
||||
|
||||
def _validate_common(common: NEMTransactionCommon, inner: bool = False):
|
||||
common.network = validate_network(common.network)
|
||||
|
||||
err = None
|
||||
@ -85,19 +81,19 @@ def _validate_common(common: NEMTransactionCommon, inner: bool=False):
|
||||
|
||||
if err:
|
||||
if inner:
|
||||
raise ValueError('No ' + err + ' provided in inner transaction')
|
||||
raise ValueError('No %s provided in inner transaction' % err)
|
||||
else:
|
||||
raise ValueError('No ' + err + ' provided')
|
||||
raise ValueError('No %s provided' % err)
|
||||
|
||||
if common.signer is not None:
|
||||
_validate_public_key(common.signer, 'Invalid signer public key in inner transaction')
|
||||
|
||||
|
||||
def _validate_public_key(public_key: bytes, err_msg):
|
||||
def _validate_public_key(public_key: bytes, err_msg: str):
|
||||
if not public_key:
|
||||
raise ValueError(err_msg + ' (none provided)')
|
||||
raise ValueError('%s (none provided)' % err_msg)
|
||||
if len(public_key) != NEM_PUBLIC_KEY_SIZE:
|
||||
raise ValueError(err_msg + ' (invalid length)')
|
||||
raise ValueError('%s (invalid length)' % err_msg)
|
||||
|
||||
|
||||
def _validate_importance_transfer(importance_transfer: NEMImportanceTransfer):
|
||||
@ -107,24 +103,26 @@ def _validate_importance_transfer(importance_transfer: NEMImportanceTransfer):
|
||||
|
||||
|
||||
def _validate_multisig(multisig: NEMTransactionCommon, network: int):
|
||||
_validate_public_key(multisig.signer, 'Invalid multisig signer public key provided')
|
||||
if multisig.network != network:
|
||||
raise ValueError('Inner transaction network is different')
|
||||
_validate_public_key(multisig.signer, 'Invalid multisig signer public key provided')
|
||||
|
||||
|
||||
def _validate_aggregate_modification(aggregate_modification: NEMAggregateModification, creation: bool=False):
|
||||
def _validate_aggregate_modification(
|
||||
aggregate_modification: NEMAggregateModification,
|
||||
creation: bool = False):
|
||||
|
||||
if creation and len(aggregate_modification.modifications) == 0:
|
||||
if creation and not aggregate_modification.modifications:
|
||||
raise ValueError('No modifications provided')
|
||||
|
||||
for m in aggregate_modification.modifications:
|
||||
if not m.type:
|
||||
raise ValueError('No modification type provided')
|
||||
if m.type not in [
|
||||
if m.type not in (
|
||||
NEMModificationType.CosignatoryModification_Add,
|
||||
NEMModificationType.CosignatoryModification_Delete
|
||||
]:
|
||||
raise ValueError('Unknown aggregate modification ')
|
||||
):
|
||||
raise ValueError('Unknown aggregate modification')
|
||||
if creation and m.type == NEMModificationType.CosignatoryModification_Delete:
|
||||
raise ValueError('Cannot remove cosignatory when converting account')
|
||||
_validate_public_key(m.public_key, 'Invalid cosignatory public key provided')
|
||||
@ -156,7 +154,7 @@ def _validate_mosaic_creation(mosaic_creation: NEMMosaicCreation, network: int):
|
||||
raise ValueError('Name not allowed in mosaic creation transactions')
|
||||
if mosaic_creation.definition.ticker is not None:
|
||||
raise ValueError('Ticker not allowed in mosaic creation transactions')
|
||||
if len(mosaic_creation.definition.networks):
|
||||
if mosaic_creation.definition.networks:
|
||||
raise ValueError('Networks not allowed in mosaic creation transactions')
|
||||
|
||||
if mosaic_creation.definition.namespace is None:
|
||||
@ -165,9 +163,9 @@ def _validate_mosaic_creation(mosaic_creation: NEMMosaicCreation, network: int):
|
||||
raise ValueError('No mosaic name provided')
|
||||
|
||||
if mosaic_creation.definition.supply is not None and mosaic_creation.definition.divisibility is None:
|
||||
raise ValueError('Definition divisibility needs to be provided when supply is')
|
||||
raise ValueError('Definition divisibility needs to be provided when supply is')
|
||||
if mosaic_creation.definition.supply is None and mosaic_creation.definition.divisibility is not None:
|
||||
raise ValueError('Definition supply needs to be provided when divisibility is')
|
||||
raise ValueError('Definition supply needs to be provided when divisibility is')
|
||||
|
||||
if mosaic_creation.definition.levy is not None:
|
||||
if mosaic_creation.definition.fee is None:
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||||
|
||||
|
||||
@ -29,8 +28,12 @@ def write_bytes_with_length(w, buf: bytearray):
|
||||
write_bytes(w, buf)
|
||||
|
||||
|
||||
def write_common(common: NEMTransactionCommon, public_key: bytearray, transaction_type: int, version: int=None) -> bytearray:
|
||||
def write_common(common: NEMTransactionCommon,
|
||||
public_key: bytearray,
|
||||
transaction_type: int,
|
||||
version: int = None) -> bytearray:
|
||||
ret = bytearray()
|
||||
|
||||
write_uint32(ret, transaction_type)
|
||||
if version is None:
|
||||
version = common.network << 24 | 1
|
||||
|
Loading…
Reference in New Issue
Block a user