forked from PyWaves/PyWaves
-
Notifications
You must be signed in to change notification settings - Fork 2
/
oracle.py
40 lines (31 loc) · 1.33 KB
/
oracle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
import pywaves as pw
class Oracle(object):
def __init__(self, oracleAddress = None, seed = None, pywaves=pw):
self.pw = pywaves
if seed != None:
self.oracleAcc = self.pw.Address(seed=seed)
self.oracleAddress = self.oracleAcc.address
else:
self.oracleAddress = oracleAddress
def getData(self, key = None, regex = None):
if key == None and regex == None:
result = self._getDataWithoutKey()
elif key != None:
result = self._getDataWithKey(key)
elif regex != None:
result = self._getDataWithRegex(regex)
return result
def _getDataWithRegex(self, regex):
return requests.get(self.pw.NODE + '/addresses/data/' + self.oracleAddress + '?matches=' + regex).json()
def _getDataWithoutKey(self):
return requests.get(self.pw.NODE + '/addresses/data/' + self.oracleAddress).json()
def _getDataWithKey(self, key):
return requests.get(self.pw.NODE + '/addresses/data/' + self.oracleAddress + '/' + key).json()['value']
def storeData(self, key, type, dataEntry, minimalFee=500000):
dataToStore = [{
'type': type,
'key': key,
'value': dataEntry
}]
return self.oracleAcc.dataTransaction(dataToStore,minimalFee=minimalFee)