You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.4 KiB
104 lines
3.4 KiB
![]()
6 years ago
|
from trezor.messages.NEMMosaicCreation import NEMMosaicCreation
|
||
![]()
6 years ago
|
from trezor.messages.NEMMosaicSupplyChange import NEMMosaicSupplyChange
|
||
|
from trezor.messages.NEMTransactionCommon import NEMTransactionCommon
|
||
|
|
||
![]()
6 years ago
|
from ..helpers import (
|
||
|
NEM_TRANSACTION_TYPE_MOSAIC_CREATION,
|
||
|
NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE,
|
||
|
)
|
||
![]()
6 years ago
|
from ..writers import (
|
||
|
serialize_tx_common,
|
||
|
write_bytes_with_len,
|
||
|
write_uint32_le,
|
||
|
write_uint64_le,
|
||
|
)
|
||
![]()
6 years ago
|
|
||
|
|
||
![]()
6 years ago
|
def serialize_mosaic_creation(
|
||
|
common: NEMTransactionCommon, creation: NEMMosaicCreation, public_key: bytes
|
||
|
):
|
||
![]()
6 years ago
|
w = serialize_tx_common(common, public_key, NEM_TRANSACTION_TYPE_MOSAIC_CREATION)
|
||
![]()
6 years ago
|
|
||
|
mosaics_w = bytearray()
|
||
![]()
6 years ago
|
write_bytes_with_len(mosaics_w, public_key)
|
||
|
|
||
|
identifier_w = bytearray()
|
||
|
write_bytes_with_len(identifier_w, creation.definition.namespace.encode())
|
||
|
write_bytes_with_len(identifier_w, creation.definition.mosaic.encode())
|
||
|
|
||
|
write_bytes_with_len(mosaics_w, identifier_w)
|
||
|
write_bytes_with_len(mosaics_w, creation.definition.description.encode())
|
||
|
write_uint32_le(mosaics_w, 4) # number of properties
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
_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)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
if creation.definition.levy:
|
||
![]()
6 years ago
|
|
||
|
levy_identifier_w = bytearray()
|
||
|
write_bytes_with_len(
|
||
|
levy_identifier_w, creation.definition.levy_namespace.encode()
|
||
![]()
6 years ago
|
)
|
||
![]()
6 years ago
|
write_bytes_with_len(
|
||
|
levy_identifier_w, creation.definition.levy_mosaic.encode()
|
||
![]()
6 years ago
|
)
|
||
![]()
6 years ago
|
|
||
|
levy_w = bytearray()
|
||
|
write_uint32_le(levy_w, creation.definition.levy)
|
||
|
write_bytes_with_len(levy_w, creation.definition.levy_address.encode())
|
||
|
write_bytes_with_len(levy_w, levy_identifier_w)
|
||
|
write_uint64_le(levy_w, creation.definition.fee)
|
||
|
|
||
|
write_bytes_with_len(mosaics_w, levy_w)
|
||
![]()
6 years ago
|
else:
|
||
![]()
6 years ago
|
write_uint32_le(mosaics_w, 0) # no levy
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
write_bytes_with_len(w, mosaics_w)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
write_bytes_with_len(w, creation.sink.encode())
|
||
|
write_uint64_le(w, creation.fee)
|
||
![]()
6 years ago
|
|
||
|
return w
|
||
|
|
||
|
|
||
![]()
6 years ago
|
def serialize_mosaic_supply_change(
|
||
|
common: NEMTransactionCommon, change: NEMMosaicSupplyChange, public_key: bytes
|
||
|
):
|
||
![]()
6 years ago
|
w = serialize_tx_common(
|
||
|
common, public_key, NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE
|
||
![]()
6 years ago
|
)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
identifier_w = bytearray()
|
||
|
write_bytes_with_len(identifier_w, change.namespace.encode())
|
||
|
write_bytes_with_len(identifier_w, change.mosaic.encode())
|
||
|
|
||
|
write_bytes_with_len(w, identifier_w)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
write_uint32_le(w, change.type)
|
||
|
write_uint64_le(w, change.delta)
|
||
![]()
6 years ago
|
return w
|
||
|
|
||
|
|
||
![]()
6 years ago
|
def _write_property(w: bytearray, name: str, value):
|
||
![]()
6 years ago
|
if value is None:
|
||
![]()
6 years ago
|
if name in ("divisibility", "initialSupply"):
|
||
![]()
6 years ago
|
value = 0
|
||
![]()
6 years ago
|
elif name in ("supplyMutable", "transferable"):
|
||
![]()
6 years ago
|
value = False
|
||
|
if type(value) == bool:
|
||
|
if value:
|
||
![]()
6 years ago
|
value = "true"
|
||
![]()
6 years ago
|
else:
|
||
![]()
6 years ago
|
value = "false"
|
||
![]()
6 years ago
|
elif type(value) == int:
|
||
|
value = str(value)
|
||
![]()
6 years ago
|
if type(value) != str:
|
||
![]()
6 years ago
|
raise ValueError("Incompatible value type")
|
||
![]()
6 years ago
|
name = name.encode()
|
||
|
value = value.encode()
|
||
|
write_uint32_le(w, 4 + len(name) + 4 + len(value))
|
||
|
write_bytes_with_len(w, name)
|
||
|
write_bytes_with_len(w, value)
|