コード例 #1
0
ファイル: bbclib_signature.py プロジェクト: ks91/py-bbclib
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        try:
            ptr, self.key_type = bbclib_binary.get_n_byte_int(ptr, 4, data)
            if self.key_type == KeyType.NOT_INITIALIZED:
                return True
            ptr, pubkey_len_bit = bbclib_binary.get_n_byte_int(ptr, 4, data)
            if pubkey_len_bit > 0:
                pubkey_len = int(pubkey_len_bit / 8)
                ptr, pubkey = bbclib_binary.get_n_bytes(ptr, pubkey_len, data)
            else:
                pubkey = None
            ptr, sig_len_bit = bbclib_binary.get_n_byte_int(ptr, 4, data)
            sig_len = int(sig_len_bit / 8)
            ptr, signature = bbclib_binary.get_n_bytes(ptr, sig_len, data)
            self.add(signature=signature, pubkey=pubkey)
        except:
            return False
        return True
コード例 #2
0
ファイル: bbclib_reference.py プロジェクト: ks91/py-bbclib
    def unpack(self, data):
        """unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        data_size = len(data)
        try:
            ptr, self.asset_group_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["asset_group_id"] = len(self.asset_group_id)
            ptr, self.transaction_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["transaction_id"] = len(self.transaction_id)
            ptr, self.event_index_in_ref = bbclib_binary.get_n_byte_int(ptr, 2, data)
            ptr, signum = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.sig_indices = []
            for i in range(signum):
                ptr, idx = bbclib_binary.get_n_byte_int(ptr, 2, data)
                self.sig_indices.append(idx)
                if ptr > data_size:
                    return False
        except:
            return False
        return True
コード例 #3
0
ファイル: bbclib_relation.py プロジェクト: ks91/py-bbclib
    def unpack(self, data, version=2):
        """Unpack data into transaction object

        Args:
            data (bytes): packed binary data
            version (int): version of the data format
        Returns:
            bool: True if successful
        """
        ptr = 0
        self.version = version
        data_size = len(data)
        try:
            ptr, self.asset_group_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["asset_group_id"] = len(self.asset_group_id)
            ptr, pt_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.pointers = list()
            for i in range(pt_num):
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 2, data)
                ptr, ptdata = bbclib_binary.get_n_bytes(ptr, size, data)
                if ptr >= data_size:
                    return False
                pt = BBcPointer()
                if not pt.unpack(ptdata):
                    return False
                self.pointers.append(pt)
            self.asset = None
            ptr, astsize = bbclib_binary.get_n_byte_int(ptr, 4, data)
            if astsize > 0:
                self.asset = BBcAsset()
                ptr, astdata = bbclib_binary.get_n_bytes(ptr, astsize, data)
                if not self.asset.unpack(astdata):
                    return False

            if version >= 2:
                self.asset_raw = None
                ptr, astsize = bbclib_binary.get_n_byte_int(ptr, 4, data)
                if astsize > 0:
                    self.asset_raw = BBcAssetRaw()
                    ptr, astdata = bbclib_binary.get_n_bytes(
                        ptr, astsize, data)
                    if not self.asset_raw.unpack(astdata):
                        return False
                self.asset_hash = None
                ptr, astsize = bbclib_binary.get_n_byte_int(ptr, 4, data)
                if astsize > 0:
                    self.asset_hash = BBcAssetHash()
                    ptr, astdata = bbclib_binary.get_n_bytes(
                        ptr, astsize, data)
                    if not self.asset_hash.unpack(astdata):
                        return False

        except:
            return False
        return True
コード例 #4
0
    def from_serialized_data(ptr, data):

        if ptr >= len(data):
            return ptr, None
        try:
            ptr, command = bbclib_binary.get_n_byte_int(ptr, 1, data)
            ptr, num_pubkeys = bbclib_binary.get_n_byte_int(ptr, 2, data)
            public_keys = []
            key_types = []
            for i in range(num_pubkeys):
                ptr, key_type = bbclib_binary.get_n_byte_int(ptr, 2, data)
                key_types.append(int(key_type))
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 2, data)
                ptr, pubkey = bbclib_binary.get_n_bytes(ptr, size, data)
                public_keys.append(bytes(pubkey))
        except:
            raise

        return ptr, Directive(command, public_keys, key_types)
コード例 #5
0
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        try:
            ptr, self.asset_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["asset_id"] = len(self.asset_id)
            ptr, self.user_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["user_id"] = len(self.user_id)
            ptr, noncelen = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.idlen_conf["nonce"] = noncelen
            ptr, self.nonce = bbclib_binary.get_n_bytes(ptr, noncelen, data)
            ptr, self.asset_file_size = bbclib_binary.get_n_byte_int(
                ptr, 4, data)
            if self.asset_file_size > 0:
                ptr, self.asset_file_digest = bbclib_binary.get_bigint(
                    ptr, data)
            else:
                self.asset_file_digest = None
            ptr, dict_flag = bbclib_binary.get_n_byte_int(ptr, 2, data)
            if dict_flag != 1:
                ptr, self.asset_body_size = bbclib_binary.get_n_byte_int(
                    ptr, 2, data)
                if self.asset_body_size > 0:
                    ptr, self.asset_body = bbclib_binary.get_n_bytes(
                        ptr, self.asset_body_size, data)
            else:
                ptr, sz = bbclib_binary.get_n_byte_int(ptr, 2, data)
                ptr, astbdy = bbclib_binary.get_n_bytes(ptr, sz, data)
                self.asset_body = msgpack.loads(astbdy)
                self.asset_body_size = len(self.asset_body)

        except:
            traceback.print_exc()
            return False
        return True
コード例 #6
0
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        try:
            ptr, num_ids = bbclib_binary.get_n_byte_int(ptr, 2, data)
            for i in range(num_ids):
                ptr, asset_id = bbclib_binary.get_bigint(ptr, data)
                self.asset_ids.append(asset_id)
                self.idlen_conf["asset_id"] = len(asset_id)
        except:
            traceback.print_exc()
            return False
        return True
コード例 #7
0
ファイル: bbclib_asset_raw.py プロジェクト: ks91/py-bbclib
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        try:
            ptr, self.asset_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["asset_id"] = len(self.asset_id)
            ptr, self.asset_body_size = bbclib_binary.get_n_byte_int(
                ptr, 2, data)
            if self.asset_body_size > 0:
                ptr, self.asset_body = bbclib_binary.get_n_bytes(
                    ptr, self.asset_body_size, data)
        except:
            traceback.print_exc()
            return False
        return True
コード例 #8
0
ファイル: bbclib_pointer.py プロジェクト: ks91/py-bbclib
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        try:
            ptr, self.transaction_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["transaction_id"] = len(self.transaction_id)
            ptr, num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            if num == 1:
                ptr, self.asset_id = bbclib_binary.get_bigint(ptr, data)
                self.idlen_conf["asset_id"] = len(self.asset_id)
            else:
                self.asset_id = None
        except:
            return False
        return True
コード例 #9
0
ファイル: bbclib_event.py プロジェクト: ks91/py-bbclib
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        ptr = 0
        id_length_asgid = 32
        id_length_userid = 32
        data_size = len(data)
        try:
            ptr, self.asset_group_id = bbclib_binary.get_bigint(ptr, data)
            self.idlen_conf["asset_group_id"] = len(self.asset_group_id)
            ptr, ref_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.reference_indices = []
            for i in range(ref_num):
                ptr, idx = bbclib_binary.get_n_byte_int(ptr, 2, data)
                self.reference_indices.append(idx)
                if ptr >= data_size:
                    return False
            ptr, appr_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.mandatory_approvers = []
            for i in range(appr_num):
                ptr, appr = bbclib_binary.get_bigint(ptr, data)
                self.idlen_conf["user_id"] = len(appr)
                self.mandatory_approvers.append(appr)
                if ptr >= data_size:
                    return False
            ptr, self.option_approver_num_numerator = bbclib_binary.get_n_byte_int(ptr, 2, data)
            ptr, self.option_approver_num_denominator = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.option_approvers = []
            for i in range(self.option_approver_num_denominator):
                ptr, appr = bbclib_binary.get_bigint(ptr, data)
                self.idlen_conf["user_id"] = len(appr)
                self.option_approvers.append(appr)
                if ptr >= data_size:
                    return False
            ptr, astsize = bbclib_binary.get_n_byte_int(ptr, 4, data)
            ptr, astdata = bbclib_binary.get_n_bytes(ptr, astsize, data)
            self.asset = BBcAsset()
            self.asset.unpack(astdata)
        except:
            return False
        return True
コード例 #10
0
    def unpack(self, data):
        """Unpack into this object

        Args:
            data (bytes): packed binary data
        Returns:
            bool: True if successful
        """
        self.transaction_data = data[:]
        ptr = 0
        data_size = len(data)
        try:
            ptr, self.version = bbclib_binary.get_n_byte_int(ptr, 4, data)
            ptr, self.timestamp = bbclib_binary.get_n_byte_int(ptr, 8, data)
            if self.version != 0:
                ptr, id_length = bbclib_binary.get_n_byte_int(ptr, 2, data)
                self.idlen_conf["transaction_id"] = id_length
            ptr, evt_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.events = []
            for i in range(evt_num):
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                ptr, evtdata = bbclib_binary.get_n_bytes(ptr, size, data)
                evt = BBcEvent()
                if not evt.unpack(evtdata):
                    return False
                self.events.append(evt)
                if ptr >= data_size:
                    return False
                self.asset_group_ids[evt.asset.asset_id] = evt.asset_group_id

            ptr, ref_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.references = []
            for i in range(ref_num):
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                ptr, refdata = bbclib_binary.get_n_bytes(ptr, size, data)
                refe = BBcReference(None, self)
                if not refe.unpack(refdata):
                    return False
                self.references.append(refe)
                if ptr >= data_size:
                    return False

            ptr, rtn_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.relations = []
            for i in range(rtn_num):
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                ptr, rtndata = bbclib_binary.get_n_bytes(ptr, size, data)
                rtn = BBcRelation()
                if not rtn.unpack(rtndata, self.version):
                    return False
                self.relations.append(rtn)
                if ptr >= data_size:
                    return False
                if rtn.asset is not None:
                    self.asset_group_ids[
                        rtn.asset.asset_id] = rtn.asset_group_id
                if rtn.asset_raw is not None:
                    self.asset_group_ids[
                        rtn.asset_raw.asset_id] = rtn.asset_group_id
                if rtn.asset_hash is not None:
                    for h in rtn.asset_hash.asset_ids:
                        self.asset_group_ids[h] = rtn.asset_group_id

            ptr, witness_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            if witness_num == 0:
                self.witness = None
            else:
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                ptr, witnessdata = bbclib_binary.get_n_bytes(ptr, size, data)
                self.witness = BBcWitness()
                self.witness.transaction = self
                if not self.witness.unpack(witnessdata):
                    return False

            ptr, cross_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            if cross_num == 0:
                self.cross_ref = None
            else:
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                ptr, crossdata = bbclib_binary.get_n_bytes(ptr, size, data)
                self.cross_ref = BBcCrossRef()
                if not self.cross_ref.unpack(crossdata):
                    return False

            ptr, sig_num = bbclib_binary.get_n_byte_int(ptr, 2, data)
            self.signatures = []
            for i in range(sig_num):
                ptr, size = bbclib_binary.get_n_byte_int(ptr, 4, data)
                sig = BBcSignature()
                if size > 4:
                    ptr, sigdata = bbclib_binary.get_n_bytes(ptr, size, data)
                    if not sig.unpack(sigdata):
                        return False
                self.signatures.append(sig)
                if ptr > data_size:
                    return False
            self.digest()
        except Exception as e:
            print("Transaction data unpack: %s" % e)
            print(traceback.format_exc())
            return False
        return True