Esempio n. 1
0
 def __init__(self, from_address, proposal_id, base_asset_symbol,
              quote_asset_symbol, init_price):
     dict.__init__(self,
                   proposal_id=VarInt(proposal_id),
                   base_asset_symbol=String(base_asset_symbol),
                   quote_asset_symbol=String(quote_asset_symbol),
                   init_price=VarInt(init_price))
     self['from'] = Address(from_address)
Esempio n. 2
0
 def __init__(self, from_address, name, symbol, total_supply, mintable):
     dict.__init__(
         self,
         name=String(name),
         symbol=String(symbol),
         total_supply=VarInt(total_supply),
         mintable=bool(mintable))
     self['from'] = Address(from_address)
Esempio n. 3
0
 def __init__(self, title, description, proposal_type, proposer, initial_deposit, voting_period):
     dict.__init__(
         self,
         title=String(title),
         description=String(description),
         proposal_type=String(proposal_type),
         proposer=Address(proposer),
         initial_deposit=initial_deposit,
         voting_period=StringVarInt(voting_period)
     )
Esempio n. 4
0
 def __init__(self, sender, order_id, symbol, ordertype, side, price,
              quantity, timeinforce):
     dict.__init__(self,
                   sender=Address(sender),
                   symbol=String(symbol),
                   ordertype=VarInt(ordertype),
                   side=VarInt(side),
                   price=VarInt(price),
                   quantity=VarInt(quantity),
                   timeinforce=VarInt(timeinforce))
     self['id'] = String(order_id)
Esempio n. 5
0
 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
Esempio n. 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] == 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)
Esempio n. 7
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)
Esempio n. 8
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
Esempio n. 9
0
 def __init__(self, from_address, symbol, amount):
     dict.__init__(
         self,
         amount=VarInt(amount),
         symbol=String(symbol)
     )
     self['from'] = Address(from_address)
Esempio n. 10
0
 def from_obj(klass, transaction_data):
     tx = klass(StringVarInt(transaction_data['account_number']),
                StringVarInt(transaction_data['sequence']),
                StringVarInt(transaction_data.get('source', 0)))
     tx['memo'] = String(transaction_data['memo'])
     for msg in transaction_data['msgs']:
         tx.add_msg(Msg.from_msg_obj(msg))
     return tx
Esempio n. 11
0
 def __init__(self, from_address, description, amount, lock_time):
     dict.__init__(
         self,
         description=String(description),
         amount=Repeated(amount),
         lock_time=VarInt(lock_time)
     )
     self['from'] = from_address
Esempio n. 12
0
 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
Esempio n. 13
0
 def from_msg_obj(timelock_data):
     coins = []
     for amount in timelock_data['amount']:
         coins.append(Token(VarInt(amount['amount']), amount['denom']))
     return TimeLock(
         Address(timelock_data['from']),
         String(timelock_data.get('description', '')),
         Repeated(coins),
         VarInt(timelock_data['lock_time'])
     )
Esempio n. 14
0
 def from_msg_obj(timerelock_data):
     amounts = []
     for amount in timerelock_data['amount']:
         amounts.append(Token(VarInt(amount['amount']), String(amount['denom'])))
     return TimeRelock(
         timerelock_data['from'],
         timerelock_data['time_lock_id'],
         timerelock_data['description'],
         amounts,
         timerelock_data['lock_time']
     )
Esempio n. 15
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)
Esempio n. 16
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
Esempio n. 17
0
 def from_msg_obj(cancel_data):
     return CancelOrder(Address(cancel_data['sender']),
                        String(cancel_data['symbol']),
                        String(cancel_data['refid']))
Esempio n. 18
0
 def chain_id():
     return String("Binance-Chain-Nile")
Esempio n. 19
0
 def chain_id():
     return String("Binance-Chain-Tigris")
Esempio n. 20
0
def test_decode_str():
    for val in ["", "TrueUSD"]:
        encoded = String(val).encode()
        decoded, remaining = String.decode(encoded)
        assert decoded == val
        assert remaining == b''