Esempio n. 1
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. 2
0
 def __init__(self, account_number, sequence, source='887'):
     dict.__init__(self,
                   account_number=StringVarInt(account_number),
                   sequence=StringVarInt(sequence),
                   source=StringVarInt(source),
                   msgs=Repeated([]),
                   chain_id=self.chain_id(),
                   memo='',
                   signatures=Repeated([]),
                   data=None)
Esempio n. 3
0
 def __init__(self, proposal_id, voter, option):
     dict.__init__(
         self,
         proposal_id=StringVarInt(proposal_id),
         voter=Address(voter),
         option=VoteOption(option)
     )
Esempio n. 4
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. 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] == 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. 7
0
 def from_msg_obj(vote_data):
     return Vote(
         StringVarInt(vote_data['proposal_id']),
         Address(vote_data['voter']),
         VoteOption(vote_data['option'])
     )
Esempio n. 8
0
def test_decode_strvarint():
    for val in ['5', '257', '1000000', '0']:
        encoded = StringVarInt(val).encode()
        decoded, remaining = StringVarInt.decode(encoded)
        assert decoded == val
        assert remaining == b''
Esempio n. 9
0
 def __init__(self, pub_key, signature, account_number, sequence):
     dict.__init__(self,
                   pub_key=PubKeySecp256k1(pub_key),
                   signature=Bytes(signature),
                   account_number=StringVarInt(account_number),
                   sequence=StringVarInt(sequence))