mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-15 12:08:59 +00:00
nem: mosaics moved to seperate file
This commit is contained in:
parent
368b979a8a
commit
d07deecc7e
102
src/apps/nem/mosaic.py
Normal file
102
src/apps/nem/mosaic.py
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
from .helpers import *
|
||||
from .writers import *
|
||||
|
||||
|
||||
def nem_transaction_create_mosaic_creation(network: int, timestamp: int, signer_public_key: bytes, fee:int,
|
||||
deadline: int, namespace: str, mosaic: str, description: str,
|
||||
divisibility: int, supply: int, mutable_supply: bool, transferable: bool,
|
||||
levy_type: int, levy_fee: int, levy_address: str, levy_namespace: str,
|
||||
levy_mosaic: str, creation_sink: str, creation_fee: int):
|
||||
|
||||
w = nem_transaction_write_common(NEM_TRANSACTION_TYPE_MOSAIC_CREATION,
|
||||
nem_get_version(network),
|
||||
timestamp,
|
||||
signer_public_key,
|
||||
fee,
|
||||
deadline)
|
||||
|
||||
mosaics_w = bytearray()
|
||||
write_bytes_with_length(mosaics_w, bytearray(signer_public_key))
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
write_uint32(mosaics_w, identifier_length)
|
||||
write_bytes_with_length(mosaics_w, bytearray(namespace))
|
||||
write_bytes_with_length(mosaics_w, bytearray(mosaic))
|
||||
write_bytes_with_length(mosaics_w, bytearray(description))
|
||||
write_uint32(mosaics_w, 4) # number of properties
|
||||
|
||||
nem_write_mosaic(mosaics_w, "divisibility", divisibility)
|
||||
nem_write_mosaic(mosaics_w, "initialSupply", supply)
|
||||
nem_write_mosaic(mosaics_w, "supplyMutable", mutable_supply)
|
||||
nem_write_mosaic(mosaics_w, "transferable", transferable)
|
||||
|
||||
if levy_type:
|
||||
levy_identifier_length = 4 + len(levy_namespace) + 4 + len(levy_mosaic)
|
||||
write_uint32(mosaics_w, 4 + 4 + len(levy_address) + 4 + levy_identifier_length + 8)
|
||||
write_uint32(mosaics_w, levy_type)
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_address))
|
||||
write_uint32(mosaics_w, levy_identifier_length)
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_namespace))
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_mosaic))
|
||||
write_uint64(mosaics_w, levy_fee)
|
||||
else:
|
||||
write_uint32(mosaics_w, 0)
|
||||
|
||||
# write mosaic bytes with length
|
||||
write_bytes_with_length(w, mosaics_w)
|
||||
|
||||
write_bytes_with_length(w, bytearray(creation_sink))
|
||||
write_uint64(w, creation_fee)
|
||||
|
||||
return w
|
||||
|
||||
|
||||
def nem_transaction_create_mosaic_supply_change(network: int, timestamp: int, signer_public_key: bytes, fee: int,
|
||||
deadline: int, namespace: str, mosaic: str, type: int, delta: int):
|
||||
|
||||
w = nem_transaction_write_common(NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE,
|
||||
nem_get_version(network),
|
||||
timestamp,
|
||||
signer_public_key,
|
||||
fee,
|
||||
deadline)
|
||||
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
write_uint32(w, identifier_length)
|
||||
write_bytes_with_length(w, bytearray(namespace))
|
||||
write_bytes_with_length(w, bytearray(mosaic))
|
||||
|
||||
write_uint32(w, type)
|
||||
write_uint64(w, delta)
|
||||
|
||||
return w
|
||||
|
||||
|
||||
def nem_write_mosaic(w: bytearray, name: str, value):
|
||||
if value is None:
|
||||
if name in ['divisibility', 'initialSupply']:
|
||||
value = 0
|
||||
elif name in ['supplyMutable', 'transferable']:
|
||||
value = False
|
||||
if type(value) == bool:
|
||||
if value:
|
||||
value = "true"
|
||||
else:
|
||||
value = "false"
|
||||
elif type(value) == int:
|
||||
value = str(value)
|
||||
elif type(value) != str:
|
||||
raise ValueError('Incompatible value type')
|
||||
write_uint32(w, 4 + len(name) + 4 + len(value))
|
||||
write_bytes_with_length(w, bytearray(name))
|
||||
write_bytes_with_length(w, bytearray(value))
|
||||
|
||||
|
||||
def nem_transaction_write_mosaic(w: bytearray, namespace: str, mosaic: str, quantity: int):
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
# indentifier length (u32) + quantity (u64) + identifier size
|
||||
write_uint32(w, 4 + 8 + identifier_length)
|
||||
write_uint32(w, identifier_length)
|
||||
write_bytes_with_length(w, bytearray(namespace))
|
||||
write_bytes_with_length(w, bytearray(mosaic))
|
||||
write_uint64(w, quantity)
|
@ -1,5 +1,6 @@
|
||||
from apps.nem.layout import *
|
||||
from apps.nem.transaction import *
|
||||
from apps.nem.mosaic import *
|
||||
from apps.nem.validators import validate
|
||||
from apps.nem import helpers
|
||||
from apps.common import seed
|
||||
|
@ -56,75 +56,6 @@ def nem_transaction_create_provision_namespace(network: int, timestamp: int, sig
|
||||
return tx
|
||||
|
||||
|
||||
def nem_transaction_create_mosaic_creation(network: int, timestamp: int, signer_public_key: bytes, fee:int,
|
||||
deadline: int, namespace: str, mosaic: str, description: str,
|
||||
divisibility: int, supply: int, mutable_supply: bool, transferable: bool,
|
||||
levy_type: int, levy_fee: int, levy_address: str, levy_namespace: str,
|
||||
levy_mosaic: str, creation_sink: str, creation_fee: int):
|
||||
|
||||
w = nem_transaction_write_common(NEM_TRANSACTION_TYPE_MOSAIC_CREATION,
|
||||
nem_get_version(network),
|
||||
timestamp,
|
||||
signer_public_key,
|
||||
fee,
|
||||
deadline)
|
||||
|
||||
mosaics_w = bytearray()
|
||||
write_bytes_with_length(mosaics_w, bytearray(signer_public_key))
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
write_uint32(mosaics_w, identifier_length)
|
||||
write_bytes_with_length(mosaics_w, bytearray(namespace))
|
||||
write_bytes_with_length(mosaics_w, bytearray(mosaic))
|
||||
write_bytes_with_length(mosaics_w, bytearray(description))
|
||||
write_uint32(mosaics_w, 4) # number of properties
|
||||
|
||||
nem_write_mosaic(mosaics_w, "divisibility", divisibility)
|
||||
nem_write_mosaic(mosaics_w, "initialSupply", supply)
|
||||
nem_write_mosaic(mosaics_w, "supplyMutable", mutable_supply)
|
||||
nem_write_mosaic(mosaics_w, "transferable", transferable)
|
||||
|
||||
if levy_type:
|
||||
levy_identifier_length = 4 + len(levy_namespace) + 4 + len(levy_mosaic)
|
||||
write_uint32(mosaics_w, 4 + 4 + len(levy_address) + 4 + levy_identifier_length + 8)
|
||||
write_uint32(mosaics_w, levy_type)
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_address))
|
||||
write_uint32(mosaics_w, levy_identifier_length)
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_namespace))
|
||||
write_bytes_with_length(mosaics_w, bytearray(levy_mosaic))
|
||||
write_uint64(mosaics_w, levy_fee)
|
||||
else:
|
||||
write_uint32(mosaics_w, 0)
|
||||
|
||||
# write mosaic bytes with length
|
||||
write_bytes_with_length(w, mosaics_w)
|
||||
|
||||
write_bytes_with_length(w, bytearray(creation_sink))
|
||||
write_uint64(w, creation_fee)
|
||||
|
||||
return w
|
||||
|
||||
|
||||
def nem_transaction_create_mosaic_supply_change(network: int, timestamp: int, signer_public_key: bytes, fee: int,
|
||||
deadline: int, namespace: str, mosaic: str, type: int, delta: int):
|
||||
|
||||
w = nem_transaction_write_common(NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE,
|
||||
nem_get_version(network),
|
||||
timestamp,
|
||||
signer_public_key,
|
||||
fee,
|
||||
deadline)
|
||||
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
write_uint32(w, identifier_length)
|
||||
write_bytes_with_length(w, bytearray(namespace))
|
||||
write_bytes_with_length(w, bytearray(mosaic))
|
||||
|
||||
write_uint32(w, type)
|
||||
write_uint64(w, delta)
|
||||
|
||||
return w
|
||||
|
||||
|
||||
def nem_transaction_create_importance_transfer(network: int, timestamp: int, signer_public_key: bytes, fee: int,
|
||||
deadline: int, mode: int, remote: bytes):
|
||||
|
||||
@ -163,33 +94,3 @@ def nem_transaction_write_cosignatory_modification(w: bytearray, type: int, cosi
|
||||
def nem_transaction_write_minimum_cosignatories(w: bytearray, relative_change: int):
|
||||
write_uint32(w, 4)
|
||||
write_uint32(w, relative_change)
|
||||
|
||||
|
||||
def nem_write_mosaic(w: bytearray, name: str, value):
|
||||
if value is None:
|
||||
if name in ['divisibility', 'initialSupply']:
|
||||
value = 0
|
||||
elif name in ['supplyMutable', 'transferable']:
|
||||
value = False
|
||||
if type(value) == bool:
|
||||
if value:
|
||||
value = "true"
|
||||
else:
|
||||
value = "false"
|
||||
elif type(value) == int:
|
||||
value = str(value)
|
||||
elif type(value) != str:
|
||||
raise ValueError('Incompatible value type')
|
||||
write_uint32(w, 4 + len(name) + 4 + len(value))
|
||||
write_bytes_with_length(w, bytearray(name))
|
||||
write_bytes_with_length(w, bytearray(value))
|
||||
|
||||
|
||||
def nem_transaction_write_mosaic(w: bytearray, namespace: str, mosaic: str, quantity: int):
|
||||
identifier_length = 4 + len(namespace) + 4 + len(mosaic)
|
||||
# indentifier length (u32) + quantity (u64) + identifier size
|
||||
write_uint32(w, 4 + 8 + identifier_length)
|
||||
write_uint32(w, identifier_length)
|
||||
write_bytes_with_length(w, bytearray(namespace))
|
||||
write_bytes_with_length(w, bytearray(mosaic))
|
||||
write_uint64(w, quantity)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from common import *
|
||||
|
||||
from apps.nem.transaction import *
|
||||
from apps.nem.mosaic import *
|
||||
from trezor.crypto import hashlib
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from common import *
|
||||
|
||||
from apps.nem.transaction import *
|
||||
from apps.nem.mosaic import *
|
||||
from trezor.crypto import hashlib
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from common import *
|
||||
|
||||
from apps.nem.transaction import *
|
||||
from apps.nem.mosaic import *
|
||||
from trezor.crypto import hashlib
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user