nem: transaction mosaic creation

pull/25/head
Tomas Susanka 6 years ago committed by Jan Pochyla
parent 302ec82d3d
commit 2696968894

@ -57,6 +57,70 @@ 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_write_mosaic(w: bytearray, name: str, value):
if type(value) == bool:
if value:
value = "true"
else:
value = "false"
elif type(value) == int:
# todo might need more formatting
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

@ -0,0 +1,36 @@
from common import *
from apps.nem.transaction import *
from trezor.crypto import hashlib
class TestNemTransactionMosaicCreation(unittest.TestCase):
def test_nem_transaction_mosaic_creation(self):
t = nem_transaction_create_mosaic_creation(NEM_NETWORK_TESTNET,
14070896,
unhexlify('994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324'),
108000000,
14074496,
'gimre.games.pong',
'paddles',
'Paddles for the bong game.\n',
0,
10000,
True,
True,
0,
0,
'',
'',
'',
'TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC',
50000000000)
self.assertEqual(t, unhexlify('014000000100009870b4d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd32400f36f060000000080c2d600de00000020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3241f0000001000000067696d72652e67616d65732e706f6e6707000000706164646c65731b000000506164646c657320666f722074686520626f6e672067616d652e0a04000000150000000c00000064697669736962696c69747901000000301a0000000d000000696e697469616c537570706c79050000003130303030190000000d000000737570706c794d757461626c650400000074727565180000000c0000007472616e7366657261626c650400000074727565000000002800000054424d4f534149434f443446353445453543444d523233434342474f414d3258534a4252354f4c4300743ba40b000000'))
self.assertEqual(hashlib.sha3_256(t).digest(True), unhexlify('68364353c29105e6d361ad1a42abbccbf419cfc7adb8b74c8f35d8f8bdaca3fa'))
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save