Пример #1
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
Пример #2
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
Пример #3
0
class MassType(Enum):
    to_int = 11
    to_byte = b'\x0b'
    fee = lunes_to_unes(0.005)
Пример #4
0
class AliasType(Enum):
    to_int = 10
    to_byte = b'\x0a'
    mount = b'\x02'
    fee = lunes_to_unes(0.01)
Пример #5
0
class CancelLeaseType(Enum):
    to_int = 9
    to_byte = b'\x09'
    fee = lunes_to_unes(0.01)
Пример #6
0
class IssueType(Enum):
    to_int = 3
    to_byte = b'\x03'
    fee = lunes_to_unes(1)
Пример #7
0
class LeaseType(Enum):
    to_int = 8
    to_byte = b'\x08'
    fee = lunes_to_unes(0.01)
Пример #8
0
class LunexType(Enum):
    to_int = 7
    to_byte = b'\x07'
    fee = lunes_to_unes(0.01)
Пример #9
0
class BurnType(Enum):
    to_int = 6
    to_byte = b'\x06'
    fee = lunes_to_unes(0.01)
Пример #10
0
class ReissueType(Enum):
    to_int = 5
    to_byte = b'\x05'
    fee = lunes_to_unes(0.01)
Пример #11
0
class TransferType(Enum):
    to_int = 4
    to_byte = b'\x04'
    fee = lunes_to_unes(0.01)