def decode(klass, data): assert data[0:4] == klass.object_id() data = data[4:] msgs, data = Repeated.decode(data, 1, Msg) signatures, data = Repeated.decode(data, 2, BnbSignature) memo, data = String.decode(data, 3) source, data = StringVarInt.decode(data, 4) tx_data, data = String.decode(data, 5) account_number = signatures[0]['account_number'] sequence = signatures[0]['sequence'] tx = klass(msgs, account_number, sequence, source) tx['msgs'] = msgs tx['signatures'] = signatures tx['chain_id'] = klass.chain_id() return tx, data
def decode(data, field_id=None, hrp='bnb'): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return None, data data = data[len(field_id):] assert data[0:4] == Issue.object_id() data = data[4:] address, data = Address.decode(data, 1, hrp) name, data = String.decode(data, 2) symbol, data = String.decode(data, 3) total_supply, data = VarInt.decode(data, 4) mintable, data = Bool.decode(data, 5) mintable = True if mintable else 0 return Issue(address, name, symbol, total_supply, mintable), data
def decode(data, field_id=None): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return None, data data = data[len(field_id):] assert data[0:4] == Proposal.object_id() data = data[4:] title, data = String.decode(data, 1) description, data = String.decode(data, 2) proposal_type, data = VarInt.decode(data, 3) proposer, data = Address.decode(data, 4) initial_deposit, data = Repeated.decode(data, 5, Token) voting_period, data = StringVarInt.decode(data, 6) return Proposal(title, description, proposal_type, proposer, initial_deposit, voting_period)
def decode(data, field_id=None): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return None, data data = data[len(field_id):] assert data[0:4] == DexList.object_id() data = data[4:] from_address, data = Address.decode(data, 1) proposal_id, data = VarInt.decode(data, 2) base_asset_symbol, data = String.decode(data, 3) quote_asset_symbol, data = String.decode(data, 4) init_price, data = VarInt.decode(data, 5) return DexList(from_address, proposal_id, base_asset_symbol, quote_asset_symbol, init_price)
def decode(data, field_id=None): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return None, data data = data[len(field_id):] from_address, data = Address.decode(data, 1) symbol, data = String.decode(data, 2) amount, data = VarInt.decode(data, 3) return Mint(from_address, symbol, amount)
def decode(klass, data, field_id=None): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return None, data data = data[len(field_id):] assert data[0:4] == klass.object_id() data = data[4:] from_address, data = Address.decode(data, 1) symbol, data = String.decode(data, 2) amount, data = VarInt.decode(data, 3) return klass(from_address, symbol, amount), data
def test_decode_str(): for val in ["", "TrueUSD"]: encoded = String(val).encode() decoded, remaining = String.decode(encoded) assert decoded == val assert remaining == b''