def encode(self, field_id=None): buf = self.object_id() buf += self['pub_key'].encode() if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['inputs'].encode(1) buf += self['outputs'].encode(2) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['from'].encode(1) buf += self['time_lock_id'].encode(2) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['proposal_id'].encode(1) buf += self['voter'].encode(2) buf += self['option'].encode(3) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += Address(self['from']).encode(1) buf += String(self['symbol']).encode(2) buf += VarInt(self['amount']).encode(3) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['sender'].encode(1) buf += self['symbol'].encode(2) buf += self['refid'].encode(3) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['from'].encode(1) buf += self['description'].encode(2) buf += self['amount'].encode(3) buf += self['lock_time'].encode(4) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
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 encode(self, field_id=None): buf = self.object_id() buf += self['from'].encode(1) buf += self['name'].encode(2) buf += self['symbol'].encode(3) buf += self['total_supply'].encode(4) buf += Bool(self['mintable']).encode(5) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['from'].encode(1) buf += self['proposal_id'].encode(2) buf += self['base_asset_symbol'].encode(3) buf += self['quote_asset_symbol'].encode(4) buf += self['init_price'].encode(5) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
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 VarInt(0), data data = data[len(prefix):] assert data[0:4] == PubKeySecp256k1.object_id() data = data[4:] pub_key, data = Bytes.decode(data) return PubKeySecp256k1(pub_key), 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] == Send.object_id() data = data[4:] inputs, data = Repeated.decode(data, bytes([8 | 2]), Input) outputs, data = Repeated.decode(data, bytes([16 | 2]), Output) return Send(inputs, outputs), data
def decode(data, field_id): if field_id is not None: prefix = make_prefix(field_id, 2) for i in range(len(prefix)): if prefix[i] != data[i]: return VarInt(0), data data = data[len(prefix):] pub_key, data = PubKeySecp256k1.decode(data, 1) signature, data = Bytes.decode(data, 2) account_number, data = VarInt.decode(data, 3) sequence, data = VarInt.decode(data, 4) return BnbSignature(pub_key, signature, account_number, sequence), data
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 encode(self, field_id=None): # buf = bytes.fromhex('ACCBA2DE') buf = self.object_id() buf += self['title'].encode(1) buf += self['description'].encode(2) buf += VarInt(proposal_type_to_int[self['proposal_type']]).encode(3) buf += self['proposer'].encode(4) buf += self['initial_deposit'].encode(5) buf += self['voting_period'].encode(6) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
def encode(self, field_id=None): buf = self.object_id() buf += self['sender'].encode(1) buf += self['id'].encode(2) buf += self['symbol'].encode(3) buf += self['ordertype'].encode(4) buf += self['side'].encode(5) buf += self['price'].encode(6) buf += self['quantity'].encode(7) buf += self['timeinforce'].encode(8) if field_id is None: return buf else: return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf
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):] 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, 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): prefix = make_prefix(field_id, 2) object_id = data[len(prefix):len(prefix) + 4] return msg_class_by_object_id[object_id].decode(data, prefix)
def encode(self, field_id): buf = self['pub_key'].encode(1) buf += self['signature'].encode(2) buf += self['account_number'].encode(3) buf += self['sequence'].encode(4) return make_prefix(field_id, 2) + VarInt(len(buf)).encode() + buf