Exemplo n.º 1
0
def mount_burn(sender: Account, burn_data: dict) -> dict:
    from lunespy.utils import now
    from lunespy.client.transactions.constants import BurnType
    from lunespy.utils.crypto.converters import sign
    from base58 import b58decode
    import struct

    timestamp: int = burn_data.get('timestamp', now())
    fee: int = burn_data.get('fee', BurnType.fee.value)
    quantity: int = burn_data.get('quantity', 0)
    asset_id: int = burn_data['asset_id']

    bytes_data: bytes = BurnType.to_byte.value + \
        b58decode(sender.public_key) + \
        b58decode(asset_id) + \
        struct.pack(">Q", quantity) + \
        struct.pack(">Q", fee) + \
        struct.pack(">Q", timestamp)

    signature: bytes = sign(sender.private_key, bytes_data)
    mount_tx = {
        "type": BurnType.to_int.value,
        "senderPublicKey": sender.public_key,
        "signature": signature.decode(),
        "timestamp": timestamp,
        "fee": fee,

        "assetId": asset_id,
        "quantity": quantity
    }
    return mount_tx
Exemplo n.º 2
0
def mount_lease(sender: Account, lease_data: dict) -> dict:
    from lunespy.client.transactions.constants import LeaseType
    from lunespy.utils.crypto.converters import sign
    from lunespy.utils import now, lunes_to_unes
    from base58 import b58decode
    import struct

    node_address: str = lease_data['node_address']
    timestamp: int = lease_data.get('timestamp', now())
    amount: int = lunes_to_unes(lease_data['amount'])
    fee: int = lease_data.get('fee', LeaseType.fee.value)

    bytes_data: bytes = LeaseType.to_byte.value + \
        b58decode(sender.public_key) + \
        b58decode(node_address) + \
        struct.pack(">Q", amount) + \
        struct.pack(">Q", fee) + \
        struct.pack(">Q", timestamp)

    signature: bytes = sign(sender.private_key, bytes_data)
    mount_tx: dict = {
        "type": LeaseType.to_int.value,
        "senderPublicKey": sender.public_key,
        "signature": signature.decode(),
        "timestamp": timestamp,
        "fee": fee,
        "recipient": node_address,
        "amount": amount
    }
    return mount_tx
Exemplo n.º 3
0
def mount_cancel(sender: Account, cancel_data: dict) -> dict:
    from lunespy.client.transactions.constants import CancelLeaseType
    from lunespy.utils.crypto.converters import sign
    from lunespy.utils import now
    from base58 import b58decode
    import struct

    lease_tx_id: str = cancel_data['lease_tx_id']
    timestamp: int = cancel_data.get('timestamp', now())
    fee: int = cancel_data.get('fee', CancelLeaseType.fee.value)

    bytes_data: bytes = CancelLeaseType.to_byte.value + \
        b58decode(sender.public_key) + \
        struct.pack(">Q", fee) + \
        struct.pack(">Q", timestamp) + \
        b58decode(lease_tx_id)

    signature: bytes = sign(sender.private_key, bytes_data)
    mount_tx: dict = {
        "type": CancelLeaseType.to_int.value,
        "senderPublicKey": sender.public_key,
        "signature": signature.decode(),
        "timestamp": timestamp,
        "fee": fee,
        "leaseId": lease_tx_id
    }
    return mount_tx
Exemplo n.º 4
0
def mount_reissue(sender: Account, reissue_data: dict) -> dict:
    from lunespy.client.transactions.constants import ReissueType
    from lunespy.utils.crypto.converters import sign
    from lunespy.utils import now
    from base58 import b58decode
    import struct

    fee = reissue_data.get('fee', ReissueType.fee.value)
    quantity = reissue_data['quantity']
    reissuable = reissue_data.get('reissuable', False)
    timestamp = reissue_data.get('timestamp', now())
    asset_id = reissue_data['asset_id']

    bytes_data = ReissueType.to_byte.value + \
        b58decode(sender.public_key) + \
        b58decode(asset_id) + \
        struct.pack(">Q", quantity) + \
        (b'\1' if reissuable else b'\0') + \
        struct.pack(">Q",fee) + \
        struct.pack(">Q", timestamp)

    signature: bytes = sign(sender.private_key, bytes_data)
    mount_tx = {
        "type": ReissueType.to_int.value,
        "senderPublicKey": sender.public_key,
        "signature": signature.decode(),
        "timestamp": timestamp,
        "fee": fee,
        "assetId": asset_id,
        "reissuable": reissuable,
        "quantity": quantity
    }
    return mount_tx
Exemplo n.º 5
0
def mount_mass_transfer(sender: Account, receivers_list: list,
                        mass_transfer_data: dict) -> dict:
    from lunespy.client.transactions.constants import TransferType
    from lunespy.client.transactions.constants import MassType
    from lunespy.utils.crypto.converters import sign
    from lunespy.utils import lunes_to_unes
    from lunespy.utils import now
    from base58 import b58decode
    import struct

    fee: int = TransferType.fee.value + len(
        receivers_list) * mass_transfer_data.get('fee', MassType.fee.value)
    timestamp: int = mass_transfer_data.get('timestamp', now())
    asset_id: str = mass_transfer_data.get('asset_id', "")
    receivers_list: list = [{
        'receiver': tx['receiver'],
        'amount': lunes_to_unes(tx['amount'])
    } for tx in receivers_list]

    hash_transfer: bytes = lambda tx: b58decode(tx['receiver']) + struct.pack(
        ">Q", tx['amount'])
    receivers_list_data = b''.join(map(hash_transfer, receivers_list))

    bytes_data: bytes = MassType.to_byte.value + \
            b'\1' + \
            b58decode(sender.public_key) + \
            (b'\1' + b58decode(asset_id) if asset_id != "" else b'\0') + \
            struct.pack(">H", len(receivers_list)) + \
            receivers_list_data + \
            struct.pack(">Q", timestamp) + \
            struct.pack(">Q", fee)

    signature: bytes = sign(sender.private_key, bytes_data)

    data = {
        "type":
        MassType.to_int.value,
        "senderPublicKey":
        sender.public_key,
        "signature":
        signature.decode(),
        "timestamp":
        timestamp,
        "fee":
        fee,
        "version":
        1,
        "assetId":
        asset_id,
        "transfers": [{
            'recipient': tx['receiver'],
            'amount': tx['amount']
        } for tx in receivers_list],
        "proofs": [signature.decode()]
    }

    return data
Exemplo n.º 6
0
def mount_alias(sender: Account, alias_data: dict) -> dict:
    from lunespy.utils import now
    from lunespy.utils.crypto.converters import sign
    from lunespy.client.transactions.constants import AliasType
    from lunespy.utils.crypto.converters import string_to_bytes
    from base58 import b58decode
    import struct

    timestamp: int = alias_data.get('timestamp', now())
    fee: int = alias_data.get('fee', AliasType.fee.value)
    alias: str = alias_data['alias']
    chain_id: str = sender.chain_id

    aliasWithNetwork = AliasType.mount.value +\
        string_to_bytes(str(chain_id)) + \
        struct.pack(">H", len(alias)) + \
        string_to_bytes(alias)

    bytes_data = AliasType.to_byte.value + \
        b58decode(sender.public_key) + \
        struct.pack(">H", len(aliasWithNetwork)) + \
        aliasWithNetwork + \
        struct.pack(">Q", fee) + \
        struct.pack(">Q", timestamp)

    signature: bytes = sign(sender.private_key, bytes_data)

    mount_tx = {
        "type": AliasType.to_int.value,
        "senderPublicKey": sender.public_key,
        "signature": signature.decode(),
        "timestamp": timestamp,
        "fee": fee,
        "alias": alias
    }
    return mount_tx