Exemple #1
0
    def serialize(self):
        self.bytes_data += write_bit64(self.transaction['amount'])
        self.bytes_data += write_bit32(self.transaction.get('expiration', 0))
        recipientId = hexlify(b58decode_check(self.transaction['recipientId']))
        self.bytes_data += write_high(recipientId)

        return self.bytes_data
Exemple #2
0
    def to_bytes(self, skip_signature=True, skip_second_signature=True):
        """Convert the transaction to its byte representation

        Args:
            skip_signature (bool, optional): do you want to skip the signature
            skip_second_signature (bool, optional): do you want to skip the 2nd signature

        Returns:
            bytes: bytes representation of the transaction
        """
        bytes_data = bytes()
        bytes_data += write_bit8(self.type)
        bytes_data += write_bit32(self.timestamp)
        bytes_data += write_high(self.senderPublicKey)

        if self.recipientId:
            bytes_data += b58decode_check(self.recipientId)
        else:
            bytes_data += pack('21x')

        if self.vendorField and len(self.vendorField) < 64:
            bytes_data += self.vendorField
            bytes_data += pack('{}x'.format(64 - len(self.vendorField)))
        else:
            bytes_data += pack('64x')

        bytes_data += write_bit64(self.amount)
        bytes_data += write_bit64(self.fee)

        bytes_data = self._handle_transaction_type(bytes_data)
        bytes_data = self._handle_signature(bytes_data, skip_signature,
                                            skip_second_signature)

        return bytes_data
Exemple #3
0
    def serialize(self):
        """Perform AIP11 compliant serialization

        Returns:
            bytes: bytes string
        """
        network_config = get_network()
        bytes_data = bytes()
        bytes_data += write_bit8(0xff)
        bytes_data += write_low(self.transaction.get('version') or 0x01)
        bytes_data += write_bit8(self.transaction.get('network') or network_config['version'])
        bytes_data += write_low(self.transaction['type'])
        bytes_data += write_bit32(self.transaction['timestamp'])
        bytes_data += write_high(self.transaction['senderPublicKey'])
        bytes_data += write_bit64(self.transaction['fee'])

        if self.transaction.get('vendorField'):
            vendorFieldLength = len(self.transaction['vendorField'])
            bytes_data += write_bit8(vendorFieldLength)
            bytes_data += self.transaction['vendorField']
        elif self.transaction.get('vendorFieldHex'):
            vendorField_hex_length = len(self.transaction['vendorFieldHex'])
            bytes_data += write_bit8(vendorField_hex_length / 2)
            bytes_data += self.transaction['vendorFieldHex']
        else:
            bytes_data += write_bit8(0x00)

        bytes_data = self._handle_transaction_type(bytes_data)
        bytes_data = self._handle_signature(bytes_data)

        return hexlify(bytes_data).decode()
Exemple #4
0
    def _handle_signature(self, bytes_data, skip_signature,
                          skip_second_signature):
        """Internal method, used to handle the signature

        Args:
            bytes_data (bytes): input the bytes data to which you want to append new bytes from
            signature
            skip_signature (bool): whether you want to skip it or not
            skip_second_signature (bool): whether you want to skip it or not

        Returns:
            bytes: bytes string
        """
        if not skip_signature and self.signature:
            bytes_data += write_high(self.signature)
        if not skip_second_signature and self.signSignature:
            bytes_data += write_high(self.signSignature)
        return bytes_data
 def serialize(self):
     self.bytes_data += write_bit64(
         self.transaction['recipientId']['amount'])
     self.bytes_data += write_low(
         self.transaction['recipientId']['timelocktype'])
     self.bytes_data += write_bit32(
         self.transaction['recipientId']['timelock'])
     recipientId = hexlify(b58decode_check(self.transaction['recipientId']))
     self.bytes_data += write_high(recipientId)
     return self.bytes_data
Exemple #6
0
    def serialize(self):
        self.bytes_data += write_bit16(
            len(self.transaction['asset']['payments']))

        for payment in self.transaction['asset']['payments']:
            self.bytes_data += write_bit64(payment['amount'])
            recipientId = hexlify(b58decode_check(payment['recipientId']))
            self.bytes_data += write_high(recipientId)

        return self.bytes_data
Exemple #7
0
    def serialize(self):
        self.bytes_data += write_bit64(self.transaction['amount'])
        self.bytes_data += unhexlify(
            self.transaction['asset']['lock']['secretHash'].encode())
        self.bytes_data += write_bit8(
            self.transaction['asset']['lock']['expiration']['type'])
        self.bytes_data += write_bit32(
            self.transaction['asset']['lock']['expiration']['value'])

        recipientId = hexlify(b58decode_check(self.transaction['recipientId']))
        self.bytes_data += write_high(recipientId)

        return self.bytes_data
Exemple #8
0
    def serialize(self,
                  skip_signature=True,
                  skip_second_signature=True,
                  skip_multi_signature=True,
                  raw=False):
        """Perform AIP11 compliant serialization

        Returns:
            bytes: bytes string
        """
        network_config = get_network()
        bytes_data = bytes()

        bytes_data += write_bit8(0xff)

        bytes_data += write_bit8(self.transaction.get('version') or 0x02)
        bytes_data += write_bit8(
            self.transaction.get('network') or network_config['version'])
        bytes_data += write_bit32(self.transaction.get('typeGroup') or 0x01)
        bytes_data += write_bit16(self.transaction.get('type'))
        bytes_data += write_bit64(self.transaction.get('nonce') or 0x01)

        bytes_data += write_high(self.transaction.get('senderPublicKey'))
        bytes_data += write_bit64(self.transaction.get('fee'))

        if self.transaction.get('vendorField'):
            vendorFieldLength = len(self.transaction.get('vendorField'))
            bytes_data += write_bit8(vendorFieldLength)
            bytes_data += self.transaction['vendorField'].encode()
        elif self.transaction.get('vendorFieldHex'):
            vendorField_hex_length = len(self.transaction['vendorFieldHex'])
            bytes_data += write_bit8(vendorField_hex_length / 2)
            bytes_data += self.transaction['vendorFieldHex']
        else:
            bytes_data += write_bit8(0x00)
        bytes_data = self._handle_transaction_type(bytes_data)
        bytes_data = self._handle_signature(bytes_data, skip_signature,
                                            skip_second_signature,
                                            skip_multi_signature)

        return bytes_data if raw else hexlify(bytes_data).decode()