示例#1
0
 def pack(self):
     """Pack this object"""
     if self.not_initialized:
         dat = bytearray(bbclib_utils.to_4byte(KeyType.NOT_INITIALIZED))
         return bytes(dat)
     dat = bytearray(bbclib_utils.to_4byte(self.key_type))
     pubkey_len_bit = len(self.pubkey) * 8
     dat.extend(bbclib_utils.to_4byte(pubkey_len_bit))
     dat.extend(self.pubkey)
     sig_len_bit = len(self.signature) * 8
     dat.extend(bbclib_utils.to_4byte(sig_len_bit))
     dat.extend(self.signature)
     return bytes(dat)
示例#2
0
    def pack(self, for_digest_calculation=False):
        """Pack this object

        Args:
            for_digest_calculation (bool): True if digest calculation
        Returns:
            bytes: packed binary data
        """
        dat = bytearray()
        if not for_digest_calculation:
            dat.extend(
                bbclib_utils.to_bigint(self.asset_id, size=self.id_length))
        dat.extend(bbclib_utils.to_bigint(self.user_id, size=self.id_length))
        dat.extend(bbclib_utils.to_2byte(len(self.nonce)))
        dat.extend(self.nonce)
        dat.extend(bbclib_utils.to_4byte(self.asset_file_size))
        if self.asset_file_size > 0:
            dat.extend(bbclib_utils.to_bigint(self.asset_file_digest))
        if isinstance(self.asset_body, dict):
            dat.extend(bbclib_utils.to_2byte(1))
            astbdy = msgpack.dumps(self.asset_body)
            dat.extend(bbclib_utils.to_2byte(len(astbdy)))
            dat.extend(astbdy)
        else:
            dat.extend(bbclib_utils.to_2byte(0))
            dat.extend(bbclib_utils.to_2byte(self.asset_body_size))
            if self.asset_body_size > 0:
                dat.extend(self.asset_body)
        return bytes(dat)
示例#3
0
    def pack(self):
        """Pack this object

        Returns:
            bytes: packed binary data
        """
        dat = bytearray(
            bbclib_utils.to_bigint(self.asset_group_id, size=self.id_length))
        dat.extend(bbclib_utils.to_2byte(len(self.reference_indices)))
        for i in range(len(self.reference_indices)):
            dat.extend(bbclib_utils.to_2byte(self.reference_indices[i]))
        dat.extend(bbclib_utils.to_2byte(len(self.mandatory_approvers)))
        for i in range(len(self.mandatory_approvers)):
            dat.extend(
                bbclib_utils.to_bigint(self.mandatory_approvers[i],
                                       size=self.id_length))
        dat.extend(bbclib_utils.to_2byte(self.option_approver_num_numerator))
        dat.extend(bbclib_utils.to_2byte(self.option_approver_num_denominator))
        for i in range(self.option_approver_num_denominator):
            dat.extend(
                bbclib_utils.to_bigint(self.option_approvers[i],
                                       size=self.id_length))
        ast = self.asset.pack()
        dat.extend(bbclib_utils.to_4byte(len(ast)))
        dat.extend(ast)
        return bytes(dat)
示例#4
0
    def pack(self):
        """Pack this object

        Returns:
            bytes: packed binary data
        """
        dat = bytearray(
            bbclib_utils.to_bigint(self.asset_group_id, size=self.id_length))
        dat.extend(bbclib_utils.to_2byte(len(self.pointers)))
        for i in range(len(self.pointers)):
            pt = self.pointers[i].pack()
            dat.extend(bbclib_utils.to_2byte(len(pt)))
            dat.extend(pt)
        if self.asset is not None:
            ast = self.asset.pack()
            dat.extend(bbclib_utils.to_4byte(len(ast)))
            dat.extend(ast)
        else:
            dat.extend(bbclib_utils.to_4byte(0))
        return bytes(dat)
示例#5
0
    def pack(self, for_id=False):
        """Pack the whole parts"""
        dat = bytearray(bbclib_utils.to_4byte(self.version))
        dat.extend(bbclib_utils.to_8byte(self.timestamp))
        if self.version != 0:
            dat.extend(bbclib_utils.to_2byte(self.id_length))
        dat.extend(bbclib_utils.to_2byte(len(self.events)))
        for i in range(len(self.events)):
            evt = self.events[i].pack()
            dat.extend(bbclib_utils.to_4byte(len(evt)))
            dat.extend(evt)
        dat.extend(bbclib_utils.to_2byte(len(self.references)))
        for i in range(len(self.references)):
            refe = self.references[i].pack()
            dat.extend(bbclib_utils.to_4byte(len(refe)))
            dat.extend(refe)
        dat.extend(bbclib_utils.to_2byte(len(self.relations)))
        for i in range(len(self.relations)):
            rtn = self.relations[i].pack()
            dat.extend(bbclib_utils.to_4byte(len(rtn)))
            dat.extend(rtn)
        if self.witness is not None:
            dat.extend(bbclib_utils.to_2byte(1))
            witness = self.witness.pack()
            dat.extend(bbclib_utils.to_4byte(len(witness)))
            dat.extend(witness)
        else:
            dat.extend(bbclib_utils.to_2byte(0))
        self.transaction_base_digest = hashlib.sha256(dat).digest()

        dat_cross = bytearray()
        if self.cross_ref is not None:
            cross = self.cross_ref.pack()
            dat_cross.extend(bbclib_utils.to_2byte(1))
            dat_cross.extend(bbclib_utils.to_4byte(len(cross)))
            dat_cross.extend(cross)
        else:
            dat_cross.extend(bbclib_utils.to_2byte(0))

        if for_id:
            dat_for_id = bytearray(self.transaction_base_digest)
            dat_for_id.extend(dat_cross)
            return bytes(dat_for_id)

        dat.extend(dat_cross)

        dat.extend(bbclib_utils.to_2byte(len(self.signatures)))
        for signature in self.signatures:
            sig = signature.pack()
            dat.extend(bbclib_utils.to_4byte(len(sig)))
            dat.extend(sig)
        self.transaction_data = bytes(dat)
        return self.transaction_data