def unpack(self, data): """Unpack data into transaction 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_utils.get_bigint(ptr, data) ptr, pt_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.pointers = list() for i in range(pt_num): ptr, size = bbclib_utils.get_n_byte_int(ptr, 2, data) ptr, ptdata = bbclib_utils.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_utils.get_n_byte_int(ptr, 4, data) if astsize > 0: self.asset = BBcAsset(id_length=self.id_length) ptr, astdata = bbclib_utils.get_n_bytes(ptr, astsize, data) if not self.asset.unpack(astdata): return False except: return False return True
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_utils.get_bigint(ptr, data) ptr, self.user_id = bbclib_utils.get_bigint(ptr, data) ptr, noncelen = bbclib_utils.get_n_byte_int(ptr, 2, data) ptr, self.nonce = bbclib_utils.get_n_bytes(ptr, noncelen, data) ptr, self.asset_file_size = bbclib_utils.get_n_byte_int( ptr, 4, data) if self.asset_file_size > 0: ptr, self.asset_file_digest = bbclib_utils.get_bigint( ptr, data) else: self.asset_file_digest = None ptr, dict_flag = bbclib_utils.get_n_byte_int(ptr, 2, data) if dict_flag != 1: ptr, self.asset_body_size = bbclib_utils.get_n_byte_int( ptr, 2, data) if self.asset_body_size > 0: ptr, self.asset_body = bbclib_utils.get_n_bytes( ptr, self.asset_body_size, data) else: ptr, sz = bbclib_utils.get_n_byte_int(ptr, 2, data) ptr, astbdy = bbclib_utils.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
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_utils.get_n_byte_int(ptr, 4, data) if self.key_type == KeyType.NOT_INITIALIZED: return True ptr, pubkey_len_bit = bbclib_utils.get_n_byte_int(ptr, 4, data) pubkey_len = int(pubkey_len_bit / 8) ptr, pubkey = bbclib_utils.get_n_bytes(ptr, pubkey_len, data) ptr, sig_len_bit = bbclib_utils.get_n_byte_int(ptr, 4, data) sig_len = int(sig_len_bit / 8) ptr, signature = bbclib_utils.get_n_bytes(ptr, sig_len, data) self.add(signature=signature, pubkey=pubkey) except: return False return True
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_utils.get_bigint(ptr, data) ptr, ref_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.reference_indices = [] for i in range(ref_num): ptr, idx = bbclib_utils.get_n_byte_int(ptr, 2, data) self.reference_indices.append(idx) if ptr >= data_size: return False ptr, appr_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.mandatory_approvers = [] for i in range(appr_num): ptr, appr = bbclib_utils.get_bigint(ptr, data) self.mandatory_approvers.append(appr) if ptr >= data_size: return False ptr, self.option_approver_num_numerator = bbclib_utils.get_n_byte_int( ptr, 2, data) ptr, self.option_approver_num_denominator = bbclib_utils.get_n_byte_int( ptr, 2, data) self.option_approvers = [] for i in range(self.option_approver_num_denominator): ptr, appr = bbclib_utils.get_bigint(ptr, data) self.option_approvers.append(appr) if ptr >= data_size: return False ptr, astsize = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, astdata = bbclib_utils.get_n_bytes(ptr, astsize, data) self.asset = BBcAsset(id_length=self.id_length) self.asset.unpack(astdata) except: return False return True
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_utils.get_n_byte_int(ptr, 4, data) ptr, self.timestamp = bbclib_utils.get_n_byte_int(ptr, 8, data) if self.version != 0: ptr, self.id_length = bbclib_utils.get_n_byte_int(ptr, 2, data) ptr, evt_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.events = [] for i in range(evt_num): ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, evtdata = bbclib_utils.get_n_bytes(ptr, size, data) evt = BBcEvent(id_length=self.id_length) 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_utils.get_n_byte_int(ptr, 2, data) self.references = [] for i in range(ref_num): ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, refdata = bbclib_utils.get_n_bytes(ptr, size, data) refe = BBcReference(None, self, id_length=self.id_length) if not refe.unpack(refdata): return False self.references.append(refe) if ptr >= data_size: return False ptr, rtn_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.relations = [] for i in range(rtn_num): ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, rtndata = bbclib_utils.get_n_bytes(ptr, size, data) rtn = BBcRelation(id_length=self.id_length) if not rtn.unpack(rtndata): return False self.relations.append(rtn) if ptr >= data_size: return False self.asset_group_ids[rtn.asset.asset_id] = rtn.asset_group_id ptr, witness_num = bbclib_utils.get_n_byte_int(ptr, 2, data) if witness_num == 0: self.witness = None else: ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, witnessdata = bbclib_utils.get_n_bytes(ptr, size, data) self.witness = BBcWitness(id_length=self.id_length) self.witness.transaction = self if not self.witness.unpack(witnessdata): return False ptr, cross_num = bbclib_utils.get_n_byte_int(ptr, 2, data) if cross_num == 0: self.cross_ref = None else: ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) ptr, crossdata = bbclib_utils.get_n_bytes(ptr, size, data) self.cross_ref = BBcCrossRef() if not self.cross_ref.unpack(crossdata): return False ptr, sig_num = bbclib_utils.get_n_byte_int(ptr, 2, data) self.signatures = [] for i in range(sig_num): ptr, size = bbclib_utils.get_n_byte_int(ptr, 4, data) sig = BBcSignature() if size > 4: ptr, sigdata = bbclib_utils.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