forked from PyWaves/PyWaves
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5f81df
commit 73583e7
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import requests | ||
import pywaves as pw | ||
|
||
class Oracle(object): | ||
|
||
def __init__(self, oracleAddress = None, seed = None): | ||
if seed != None: | ||
self.oracleAddress = pw.Address(seed=seed) | ||
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): | ||
print(pw.NODE + '/addresses/data/' + self.oracleAddress + '?matches=' + regex) | ||
return requests.get(pw.NODE + '/addresses/data/' + self.oracleAddress + '?matches=' + regex).json() | ||
|
||
def _getDataWithoutKey(self): | ||
return requests.get(pw.NODE + '/addresses/data/' + self.oracleAddress).json() | ||
|
||
def _getDataWithKey(self, key): | ||
return requests.get(pw.NODE + '/addresses/data/' + self.oracleAddress + '/' + key).json()['value'] | ||
|
||
def storeData(self, key, type, dataEntry): | ||
dataToStore = [{ | ||
'type': type, | ||
'key': key, | ||
'value': dataEntry | ||
}] | ||
|
||
return self.oracleAddress.dataTransaction(dataToStore) |