Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/v20180911'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Sep 11, 2018
2 parents b416ea8 + f9b971f commit 0555ffd
Show file tree
Hide file tree
Showing 21 changed files with 390 additions and 102 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
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__
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GARDEN=`. $(ACTIVATE_PATH); which garden`
PYTHON="$(VENV_NAME)/bin/python"
SYSTEM_DEPENDENCIES=python3-dev virtualenv build-essential libssl-dev \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \
xclip xsel
libffi-dev libgmp3-dev xclip xsel
OS=$(shell lsb_release -si)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://secure.travis-ci.org/AndreMiras/EtherollApp.png?branch=develop)](http://travis-ci.org/AndreMiras/EtherollApp)

<a href="https://github.com/AndreMiras/EtherollApp/releases/download/v20180531/Etheroll-2018.0531-debug.apk"><img src="https://www.scottishchildrenslottery.com/export/system/modules/com.assense.gaming.stv.template/resources/images/google-play-store.svg" width="200"></a>
<a href="https://github.com/AndreMiras/EtherollApp/releases/download/v20180617/etheroll-2018.0617-debug.apk"><img src="https://www.scottishchildrenslottery.com/export/system/modules/com.assense.gaming.stv.template/resources/images/google-play-store.svg" width="200"></a>

Provably fair dice game running on the [Ethereum blockchain](https://etheroll.com/#/smart-contract).
Built with Python, [Kivy](https://github.com/kivy/kivy) and love.
Expand Down
8 changes: 6 additions & 2 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,7 +41,8 @@ requirements =
hostpython3crystax==3.6,
python3crystax==3.6,
setuptools,
kivy,
kivy==d8ef8c2,
plyer==1.3.0,
android,
gevent,
cffi,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions dockerfiles/Dockerfile-linux
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# TODO:
# - delete archives to keep small the container small
# - setup caching (for apt, and pip)
FROM ubuntu:16.04
FROM ubuntu:18.04

# configure locale
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
Expand All @@ -23,7 +23,7 @@ ENV LANG="en_US.UTF-8" \
# install system dependencies
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
python3 python3-dev virtualenv make lsb-release pkg-config git build-essential \
libssl-dev tox
sudo libssl-dev tox

# install kivy system dependencies
# https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2
Expand All @@ -32,4 +32,5 @@ RUN apt install --yes --no-install-recommends \

WORKDIR /app
COPY . /app
RUN make system_dependencies
ENTRYPOINT ["./dockerfiles/start.sh"]
38 changes: 38 additions & 0 deletions docs/Oraclize.md
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".
25 changes: 25 additions & 0 deletions docs/iOS.md
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>
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ isort
# is fixed by installing kivy master
# https://github.com/kivy/kivy/archive/27e3b90eae2a0155b22a435f1b6f65c913519db6.zip#egg=kivy
# on Ubuntu 18.04 Bionic, the compile error related to `MIX_INIT_MOD` is fixed by installing:
https://github.com/kivy/kivy/archive/d8ef8c2834293098bc404c0432049b2761f9b721.zip#egg=kivy
https://github.com/kivy/kivy/archive/d8ef8c2.zip#egg=kivy
# Kivy==1.10.0
https://gitlab.com/kivymd/KivyMD/repository/archive.zip?ref=19e587e6#egg=kivymd
ethereum==2.1.1
Expand All @@ -24,3 +24,4 @@ rlp==0.6.0
# https://github.com/golemfactory/golem-messages/pull/112/files
https://github.com/mfranciszkiewicz/pyelliptic/archive/1.5.10.tar.gz#egg=pyelliptic
https://github.com/AndreMiras/garden.layoutmargin/archive/20180517.zip#egg=layoutmargin
plyer==1.3.0
6 changes: 6 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [v20180911]

- Fix pycryptodome compilation, refs #99
- Notifie when roll processed, refs #57
- Update to new contract address

## [v20180617]

- Fix crash when deployed on SD, refs #96
Expand Down
25 changes: 20 additions & 5 deletions src/etheroll/controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import os
from os.path import expanduser

from kivy.app import App
from kivy.clock import Clock, mainthread
Expand All @@ -15,11 +14,10 @@
from raven.handlers.logging import SentryHandler

from etheroll.constants import KEYSTORE_DIR_SUFFIX
from etheroll.patches import patch_find_library_android, patch_typing_python351
from etheroll.settings import SettingsScreen
from etheroll.switchaccount import SwitchAccountScreen
from etheroll.utils import (Dialog, load_kv_from_py,
patch_find_library_android, patch_typing_python351,
run_in_thread)
from etheroll.utils import Dialog, load_kv_from_py, run_in_thread
from version import __version__

patch_find_library_android()
Expand Down Expand Up @@ -121,7 +119,7 @@ def get_default_keystore_path():
Returns the keystore path, which is the same as the default pyethapp
one.
"""
KEYSTORE_DIR_PREFIX = expanduser("~")
KEYSTORE_DIR_PREFIX = os.path.expanduser("~")
# uses kivy user_data_dir (/sdcard/<app_name>)
if platform == "android":
KEYSTORE_DIR_PREFIX = App.get_running_app().user_data_dir
Expand Down Expand Up @@ -478,8 +476,25 @@ def build(self):
self.icon = "docs/images/icon.png"
self.theme_cls.theme_style = 'Dark'
self.theme_cls.primary_palette = 'Indigo'
self.start_service()
return Controller()

def start_service(self):
"""
Starts the roll pulling service.
"""
if platform == 'android':
from jnius import autoclass
package_name = 'etheroll'
package_domain = 'com.github.andremiras'
service_name = 'service'
service_class = '{}.{}.Service{}'.format(
package_domain, package_name, service_name.title())
service = autoclass(service_class)
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
service.start(mActivity, argument)


def main():
# only send Android errors to Sentry
Expand Down
52 changes: 52 additions & 0 deletions src/etheroll/patches.py
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
3 changes: 2 additions & 1 deletion src/etheroll/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from etheroll.utils import Store, SubScreen, load_kv_from_py
from etheroll.store import Store
from etheroll.utils import SubScreen, load_kv_from_py
from pyetheroll.constants import DEFAULT_GAS_PRICE_GWEI, ChainID

load_kv_from_py(__file__)
Expand Down
25 changes: 25 additions & 0 deletions src/etheroll/store.py
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
Loading

0 comments on commit 0555ffd

Please sign in to comment.