This repository has been archived by the owner on Sep 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
21 changed files
with
390 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
venv/ | ||
.git/ | ||
.buildozer/ | ||
.pytest_cache/ | ||
**/.pytest_cache/ | ||
.tox/ | ||
bin/ | ||
*.pyc | ||
**/__pycache__ |
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ package.name = etheroll | |
package.domain = com.github.andremiras | ||
|
||
# (str) Source code where the main.py live | ||
source.dir = src/ | ||
source.dir = src | ||
|
||
# (list) Source files to include (let empty to include all the files) | ||
source.include_exts = py,png,jpg,kv,atlas,md,json | ||
|
@@ -41,7 +41,8 @@ requirements = | |
hostpython3crystax==3.6, | ||
python3crystax==3.6, | ||
setuptools, | ||
kivy, | ||
kivy==d8ef8c2, | ||
plyer==1.3.0, | ||
android, | ||
gevent, | ||
cffi, | ||
|
@@ -121,6 +122,7 @@ orientation = portrait | |
# (list) List of service to declare | ||
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY | ||
services = service:service/main.py | ||
# | ||
# OSX Specific | ||
|
@@ -284,9 +286,11 @@ p4a.local_recipes = %(source.dir)s/python-for-android/recipes/ | |
# (str) Name of the certificate to use for signing the debug version | ||
# Get a list of available identities: buildozer ios list_identities | ||
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)" | ||
ios.codesign.debug = "iPhone Developer: [email protected] (9BF7W3M52N)" | ||
# (str) Name of the certificate to use for signing the release version | ||
#ios.codesign.release = %(ios.codesign.debug)s | ||
ios.codesign.release = %(ios.codesign.debug)s | ||
[buildozer] | ||
|
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,38 @@ | ||
# Oraclize notes | ||
|
||
Some note taking about how Etheroll random number are being generated, plus Oraclize tips and tricks. | ||
|
||
|
||
## random.org | ||
It's using `generateSignedIntegers` method from random.org. | ||
First go to [random.org Request Builder](https://api.random.org/json-rpc/1/request-builder) to give it a try. | ||
To make the request looks like the one Etheroll is using, we need to set a couple of things. | ||
1. in the "API Method" dropdown select "generateSignedIntegers" | ||
2. set "n" to "1" | ||
3. set "max" to "100" | ||
|
||
We can leave the default value on the other fields. At the end the "Request Body" should look like this: | ||
```javascript | ||
{"jsonrpc":"2.0","method":"generateSignedIntegers","params":{"apiKey":"00000000-0000-0000-0000-000000000000","n":1,"min":1,"max":100,"replacement":true,"base":10},"id":15234} | ||
``` | ||
After clicking "Send Request", the response ("Response Body") should look like this: | ||
```javascript | ||
{"jsonrpc":"2.0","result":{"random":{"method":"generateSignedIntegers","hashedApiKey":"oT3AdLMVZKajz0pgW/8Z+t5sGZkqQSOnAi1aB8Li0tXgWf8LolrgdQ1wn9sKx1ehxhUZmhwUIpAtM8QeRbn51Q==","n":1,"min":1,"max":100,"replacement":true,"base":10,"data":[42],"completionTime":"2018-08-04 10:04:12Z","serialNumber":31337},"signature":"3BQWz+YS7nUkAzfmWeba+S9hzYsTceuPSFKqt45tJ3v3F0I5XJmq6Z2Fxyz3/iRXkJrbI+51IDU8FRnufgbAkbgGW4ZHef5cBMDm2wbhU4d26K8Z28L2AiTE13CN4xuFQL+BencG0bJkjnwjKhZqVzUPyxIsGVaukQnslUBkDsZCX1CIlGsEiN+AHIcUtKi0owCq24KaWS/4bu16nYDNm8oRjZ74ibPqmnFhFQX8CTtEcn6YTRv0aeSe+fjYUBYgyJZshVOXzlmdIxBfb3Iy58yOlIxES7WofZFj7GWIX4LRva+4bHsncxeZXQh8eChcoMvLToBNi0LIxpittfMWY3b37MtVdbh+NejciBjg2oFGLxE80rwBjdxeYzwCZnw1uQFK3PZhzO6aVp/2oxKgzZgk2eg9aJjq+ns63pnV+ohvNftuftvFI6UCpZQ7wip9dgz5PLoAMxxCpHmk4ynSZ04Jk0XPAtTkFmUwLLxlL6J8VaS1NoIzBW6NaG0wSw6d6qL2BuIVHol7QBcdejZxUNGWbHOz1W60C40ebDg7IP9SCpKwjpyp5ZqUEUs7Dn3rwW8oadP6OnfIgt6BIQTP0oAW31plXSTcytDaGV8wyhMFq31Z8IZXPjVsdT9h1tD1mZiE8RlDs87wTu7+/S+JRftmhzcLoSWNI2lYdxHtRE8=","bitsUsed":7,"bitsLeft":1918697,"requestsLeft":396391,"advisoryDelay":840},"id":15234} | ||
``` | ||
Etheroll will only use "serialNumber" for debugging and "data" our actual roll result. | ||
So next is to build the same through the oracle to send that request. The response is received via the `__callback()` where the result is parsed in the solidity code. | ||
|
||
## Oraclize.it | ||
Now let's integrate that to the oracle. In the similar fashion random.org has a request builder, [Oraclize has a test query tool](http://app.oraclize.it/home/test_query). | ||
For sending request to random.org we're using [nested queries](https://docs.oraclize.it/#data-sources-nested). So on the online test query, we need to select [nested](http://app.oraclize.it/home/test_query#bmVzdGVk:) query type. | ||
So remember we have a payload to send to random.org and we want to keep "serialNumber" and "data", so here is the nested query: | ||
Then we fill the payload with the following: | ||
```javascript | ||
[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random["serialNumber","data"]', '\n{"jsonrpc":"2.0","method":"generateSignedIntegers","params":{"apiKey":"00000000-0000-0000-0000-000000000000","n":1,"min":1,"max":100,"replacement":true,"base":"10"},"id":"1"}'] | ||
``` | ||
The response should contain `[serialNumber, [data]]`, e.g.: | ||
```javascript | ||
[31337, [42]] | ||
``` | ||
|
||
That reponse is later parsed in the `__callback()` method of the Etheroll contract to extract both "serialNumber" and "data". |
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,25 @@ | ||
# iOS support | ||
|
||
## Current status | ||
iOS is currently not supported, but there're plans to do so, see | ||
[AndreMiras/EtherollApp#37](https://github.com/AndreMiras/EtherollApp/issues/37). | ||
|
||
## Build | ||
```sh | ||
buildozer ios debug | ||
``` | ||
|
||
## Virtual Machine | ||
Currently running through a Virtual Machine from | ||
[AndrewDryga/vagrant-box-osx](https://github.com/AndrewDryga/vagrant-box-osx). | ||
|
||
## Troubleshoot | ||
``` | ||
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance | ||
``` | ||
This is because `xcode-select` is pointing to the wrong developer directory. | ||
Fix with: | ||
```sh | ||
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer | ||
``` | ||
More info: <https://stackoverflow.com/a/17980786/185510> |
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,52 @@ | ||
import ctypes.util | ||
import os | ||
import typing | ||
from ctypes.util import find_library as original_find_library | ||
|
||
from kivy.utils import platform | ||
|
||
|
||
def find_library(name): | ||
""" | ||
Looks in the right places on Android, see: | ||
https://github.com/kivy/python-for-android/blob/0.6.0/ | ||
pythonforandroid/recipes/python2/patches/ctypes-find-library-updated.patch | ||
""" | ||
# Check the user app lib dir | ||
app_root = os.path.abspath('../../').split(os.path.sep) | ||
lib_search = os.path.sep.join(app_root) + os.path.sep + 'lib' | ||
for filename in os.listdir(lib_search): | ||
if filename.endswith('.so') and name in filename: | ||
return lib_search + os.path.sep + filename | ||
# Check the normal Android system libraries | ||
for filename in os.listdir('/system/lib'): | ||
if filename.endswith('.so') and name in filename: | ||
return lib_search + os.path.sep + filename | ||
# fallback on the original find_library() | ||
return original_find_library(name) | ||
|
||
|
||
def patch_find_library_android(): | ||
""" | ||
Monkey patches find_library() to first try to find libraries on Android. | ||
https://github.com/AndreMiras/EtherollApp/issues/30 | ||
""" | ||
if platform == 'android': | ||
ctypes.util.find_library = find_library | ||
|
||
|
||
CT_co = typing.TypeVar('CT_co', covariant=True, bound=type) | ||
|
||
|
||
class Type(typing.Generic[CT_co], extra=type): | ||
__slots__ = () | ||
|
||
|
||
def patch_typing_python351(): | ||
""" | ||
Python 3.5.1 doesn't have typing.Type, refs: | ||
https://github.com/crystax/android-vendor-python-3-5/issues/1 | ||
""" | ||
# TODO: check Python version and only patch if == 3.5.1 | ||
if not hasattr(typing, 'Type'): | ||
typing.Type = Type |
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,25 @@ | ||
import os | ||
|
||
from kivy.app import App | ||
from kivy.storage.jsonstore import JsonStore | ||
|
||
|
||
class Store: | ||
|
||
@staticmethod | ||
def get_store_path(): | ||
""" | ||
Returns the full user store path. | ||
""" | ||
user_data_dir = App.get_running_app().user_data_dir | ||
store_path = os.path.join(user_data_dir, 'store.json') | ||
return store_path | ||
|
||
@classmethod | ||
def get_store(cls): | ||
""" | ||
Returns user Store object. | ||
""" | ||
store_path = cls.get_store_path() | ||
store = JsonStore(store_path) | ||
return store |
Oops, something went wrong.