def __decode_exchange(address, data): """Detail decode a unmatched or matched address""" def quantity_to_prime(quantity, rquant): quantity['value'] = \ int.from_bytes(rquant.value, byteorder='little') quantity['unit'] = int.from_bytes(rquant.unit, byteorder='little') quantity['asset'] = int.from_bytes(rquant.asset, byteorder='little') if utxq_addresser.is_mtype_prefix(address): item = UTXQ() mtype = 'utxq' deep = False else: item = MTXQ() mtype = 'mtxq' deep = True item.ParseFromString(data) match = MessageToDict(item) match["plus"] = key_owner(item.plus.decode()) match["minus"] = key_owner(item.minus.decode()) quantity_to_prime(match['quantity'], item.quantity) if deep: # Get address of utxq match["utxqAddr"] = item.utxq_addr.decode() match["matched"] = utxq_addresser.is_matched(match["utxqAddr"]) quantity_to_prime(match['ratio']['numerator'], item.ratio.numerator) quantity_to_prime(match['ratio']['denominator'], item.ratio.denominator) return {'family': 'match', 'type': mtype, 'data': match}
def decode_exchange_reciprocate_list(agreement): """Decorate reciprocates with text conversions""" sec = agreement_secret(agreement) results = __get_encrypted_list_data(mtxq_addresser.mtype_address, sec)['data'] data = [] for element in results: ladd = element['address'] mtxq = MTXQ() mtxq.ParseFromString(element['data']) data.append({ "plus": key_owner(mtxq.plus.decode("utf-8")), "minus": key_owner(mtxq.minus.decode("utf-8")), "operation": mtxq.operation, "address": ladd }) return {'family': 'match', 'dimension': 'mtxq', 'data': data}
def __decode_settings(address, data): """Decode a settings address """ settings = Settings() settings.ParseFromString(data) if address == setting_addresser.settings("unit"): stype = 'unit' else: stype = 'asset' data = MessageToDict(settings) data['authList'] = [key_owner(x) for x in data['authList'].split(",")] return {'family': stype, 'type': 'settings', 'data': data}
def __decode_unit_proposals(address, data): """Decode a proposals address""" proposals = UnitCandidates() proposals.ParseFromString(data) unit = Unit() data = [] for candidate in proposals.candidates: msg = MessageToDict(candidate) unit.ParseFromString(candidate.proposal.unit) msg['proposal']['asset'] = MessageToDict(unit) for voter in msg['votes']: voter['publicKey'] = key_owner(voter['publicKey']) data.append(msg) return {'family': 'unit', 'type': 'proposal', 'data': data}