Ejemplo n.º 1
0
 def execute(self,
             sender,
             query,
             query_fee=defaults.ORACLE_QUERY_FEE,
             query_ttl_type=defaults.ORACLE_TTL_TYPE,
             query_ttl_value=defaults.ORACLE_QUERY_TTL_VALUE,
             response_ttl_type=defaults.ORACLE_TTL_TYPE,
             response_ttl_value=defaults.ORACLE_RESPONSE_TTL_VALUE,
             fee=defaults.FEE,
             tx_ttl=defaults.TX_TTL):
     """
     Execute a query to the oracle
     """
     if self.oracle_id is None:
         raise ValueError(
             "Oracle id must be provided before executing a query")
     # get the transaction builder
     txb = self.client.tx_builder
     # get the account nonce and ttl
     nonce, ttl = self.client._get_nonce_ttl(sender.get_address(), tx_ttl)
     # create spend_tx
     tx = txb.tx_oracle_query(self.oracle_id, sender.get_address(), query,
                              query_fee, query_ttl_type, query_ttl_value,
                              response_ttl_type, response_ttl_value, fee,
                              ttl, nonce)
     # sign the transaction
     tx_signed = self.client.sign_transaction(sender, tx.tx)
     # post the transaction to the chain
     self.client.broadcast_transaction(tx_signed.tx, tx_signed.hash)
     # save the query id
     self.id = hashing.oracle_query_id(sender.get_address(), nonce,
                                       self.oracle_id)
     # return the transaction
     return tx_signed
Ejemplo n.º 2
0
def test_hashing_oracle_query_id():
    # TODO: add more scenarios
    # sender_id, nonce, oracle_id -> query_id, match
    tt = [
        ('ak_2ZjpYpJbzq8xbzjgPuEpdq9ahZE7iJRcAYC1weq3xdrNbzRiP4', 1, 'ok_2iqfJjbhGgJFRezjX6Q6DrvokkTM5niGEHBEJZ7uAG5fSGJAw1',
         'oq_2YvZnoohcSvbQCsPKSMxc98i5HZ1sU5mR6xwJUZC3SvkuSynMj', True),
    ]

    for t in tt:
        assert (hashing.oracle_query_id(t[0], t[1], t[2]) == t[3]) == t[4]