Пример #1
0
 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
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
 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)
Пример #7
0
def test_decode_varint():
    for val in [5, 257, 1000000, 0]:
        encoded = VarInt(val).encode()
        decoded, remaining = VarInt.decode(encoded)
        assert decoded == val
        assert remaining == b''