Skip to content

Commit

Permalink
Add oracle module
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmp01 committed Apr 24, 2022
1 parent 5bab1c5 commit 8ffca38
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
42 changes: 40 additions & 2 deletions demo-app/relayer/provable.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
def run(args, identity):
print('provable: Not implemented')
import json
import requests

oracle_endpoint = "https://api.provable.xyz/api/v1"

def query_status(id):
resp = requests.get(f"{oracle_endpoint}/api/v1/query/{id}/status").json()

result = None
try:
result = resp['result']['checks'][0]['results'][0]
except Exception as e:

return False

return (result, None)

def fetch_with_proof(url):
payload = {
'datasource': 'URL',
'query': url,
'proof_type': 0,
}
resp = requests.post(oracle_endpoint + "/query/create", data=payload).json()
id = resp['result']['id']

resp = requests.get(oracle_endpoint + '/api/v1/query/{}/status'.format(id)).json()

result = None

# while not result:
# (result, proof) = query_status(id)

result, proof = query_status(id)

if not proof:
proof = b'C0FFEE' # FIXME: handle the case when the proof is missing
return (result, proof)


15 changes: 9 additions & 6 deletions demo-app/relayer/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ def get_stream(config, identity, oracle_module, set):
text_data = bytes(text, 'utf-8')

print('Fetching the proof from the selected oracle...')
time.sleep(10)

proof = b'C0FFEE'

print('Proof successfully retrieved!')

try:
(result, proof) = oracle_module.fetch_with_proof(get_url_from_username(username))
except:
# FIXME: handle the case when the oracle call fails to fetch data
proof = b'C0FFEE'

print('Submitting tx onchain...')

tx = contract.functions.sendHexagonsProtocolMessage(
Expand All @@ -167,9 +168,11 @@ def get_stream(config, identity, oracle_module, set):
else:
print("The author is out of scope, skipping...")

def get_url_from_username(username):
return f"https://api.hexagons.cafe/getNftDetailsByUsername?username={username}"

def nft_from_username(username):
res = requests.get(f"https://api.hexagons.cafe/getNftDetailsByUsername?username={username}").json()
res = requests.get(get_url_from_username(username)).json()
if "err" in res.keys():
if username == "stylishbuidler":
return {
Expand Down

0 comments on commit 8ffca38

Please sign in to comment.