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/v20190418'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Apr 18, 2019
2 parents 24bc426 + 10b3125 commit 10c3a14
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 73 deletions.
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/v20181028/etheroll-2019.0217-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/v20190418/etheroll-2019.0418-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
65 changes: 37 additions & 28 deletions dockerfiles/Dockerfile-fdroid
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
# Docker image for running F-Droid build scripts.
# Build with:
# docker build --tag=fdroid --file=dockerfiles/Dockerfile-fdroid .
# docker build --tag=fdroid --file=dockerfiles/Dockerfile-fdroid .
# Run with:
# docker run fdroid /bin/sh -c 'fdroid build -v -l com.github.andremiras.etheroll'
# docker run fdroid /bin/sh -c 'fdroid build -v -l com.github.andremiras.etheroll'
# Or using the entry point shortcut:
# docker run fdroid 'fdroid build -v -l com.github.andremiras.etheroll'
# docker run fdroid 'fdroid build -v -l com.github.andremiras.etheroll'
# Or for interactive shell:
# docker run -it --rm fdroid
FROM ubuntu:18.04
# docker run -it --rm fdroid
# WARNING:
# The `--on-server` option should only be used in a container since it could
# could mess up with the system it's running in.
#
FROM debian:stretch

ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}" \
PATH="${HOME_DIR}/.local/bin:${PATH}" \
FDROIDDATA_ARCHIVE="fdroiddata-master.tar.bz2"
FDROIDDATA_ARCHIVE="fdroiddata-feature-new_app_etheroll.tar.bz2"
# FDROIDDATA_ARCHIVE="fdroiddata-master.tar.bz2"
ENV FDROIDDATA_DL_URL="https://gitlab.com/fdroid/fdroiddata/-/archive/master/${FDROIDDATA_ARCHIVE}"
# currently needed because buildozer still uses `tools/android` binary
# even though we have the new `tools/bin/sdkmanager` available
ENV USE_SDK_WRAPPER=true
# fdroid requires these two variables, see:
# fdroid requires this env, see:
# https://gitlab.com/fdroid/fdroidserver/merge_requests/290
ENV ANDROID_HOME="${HOME_DIR}/.android" \
ANDROID_NDK="${HOME_DIR}/.buildozer/crystax-ndk"
ENV ANDROID_HOME="${HOME_DIR}/.android"

ENV DOCKERFILES_VERSION="master" \
DOCKERFILES_URL="https://raw.githubusercontent.com/AndreMiras/dockerfiles"
Expand All @@ -32,25 +33,38 @@ ENV MAKEFILES_URL="${DOCKERFILES_URL}/${DOCKERFILES_VERSION}/buildozer_android_n
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
locales && \
locale-gen en_US.UTF-8
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="en_US.UTF-8"
ENV LANG="C.UTF-8" \
LANGUAGE="C.UTF-8" \
LC_ALL="C.UTF-8"
RUN dpkg-reconfigure --frontend noninteractive locales

# install system dependencies (required to setup all the tools)
RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \
make curl wget ca-certificates xz-utils unzip openjdk-8-jdk sudo python-pip \
python-setuptools

# install build dependencies (required to successfully build the project)
# TODO: should this go to a Makefile instead?
# install fdroid basebox dependencies, refs:
# https://gitlab.com/fdroid/basebox/blob/0.5.1/fdroid_basebox.py#L80
# https://gitlab.com/fdroid/fdroidserver/blob/1.1.1/buildserver/provision-apt-get-install#L45
RUN apt install -qq --yes --no-install-recommends \
python3.6 libpython3.6-dev python3-setuptools python3-pip \
autoconf automake libtool libltdl-dev libffi-dev
autoconf \
automake \
ca-certificates \
curl \
git \
lbzip2 \
libpython3-dev \
libtool \
make \
openjdk-8-jdk \
python3 \
python3-pip \
python3-setuptools \
sudo \
unzip \
zip

# make python3 the default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1


# prepare non root env
RUN useradd --create-home --shell /bin/bash ${USER}
# with sudo access and no password
Expand All @@ -64,14 +78,9 @@ WORKDIR ${WORK_DIR}
RUN curl --location --progress-bar ${MAKEFILES_URL}/android_sdk.mk --output android_sdk.mk
RUN make -f android_sdk.mk

# install buildozer and dependencies
RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk
RUN make -f buildozer.mk

# install fdroidserver and fdroiddata
RUN pip install fdroidserver
RUN curl --location --progress-bar "${FDROIDDATA_DL_URL}" --output "${FDROIDDATA_ARCHIVE}" && \
tar -xf "${FDROIDDATA_ARCHIVE}" --directory "${WORK_DIR}"

WORKDIR ${WORK_DIR}
ENTRYPOINT ["./dockerfiles/start.sh"]
24 changes: 15 additions & 9 deletions dockerfiles/Dockerfile-linux
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# For running UI:
# xhost +"local:docker@"
# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix etheroll-linux 'make uitest'
# TODO:
# - delete archives to keep small the container small
FROM ubuntu:18.04

ENV USER="user"
Expand All @@ -27,14 +25,22 @@ ENV LANG="en_US.UTF-8" \
LC_ALL="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 \
sudo libssl-dev tox

# install kivy system dependencies
# https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2
RUN apt install --yes --no-install-recommends \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
build-essential \
git \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libssl-dev \
lsb-release \
make \
pkg-config \
python3 \
python3-dev \
sudo \
tox \
virtualenv

# prepare non root env
RUN useradd --create-home --shell /bin/bash ${USER}
Expand Down
8 changes: 7 additions & 1 deletion src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Change Log


## [v20190418]

- Pull minimum bet from contract, refs #129
- Fix permission issue on settings, refs #131


## [v20190217]

- Migrate to upstream recipes
- UI testing in Travis via xvfb, refs #65
- Split dedicated Etheroll library, refs #97
- Remove legacy dependencies, refs #122
- Move to python3 recipe, refs #123
- Handles write storage permission, refs #125
- Handle write storage permission, refs #125
- Non root Docker user, refs #127


Expand Down
20 changes: 20 additions & 0 deletions src/etheroll/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,26 @@ def open_address_options(self):
lambda x: self.copy_address_clipboard(), icon='content-copy')
bottom_sheet.open()

@staticmethod
def check_request_write_permission():
"""
Android runtime storage permission check.
"""
if platform != "android":
return
from android.permissions import (
Permission, request_permission, check_permission)
permission = Permission.WRITE_EXTERNAL_STORAGE
if not check_permission(permission):
request_permission(permission)

@staticmethod
def on_permission_error(exception):
title = "Permission denied"
body = str(exception.args)
dialog = Dialog.create_dialog(title, body)
dialog.open()


class DebugRavenClient(object):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/etheroll/roll.kv
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
size_hint_y: None
MDTextField:
id: bet_size_input_id
text: "0.10"
text: "{}".format(root.min_bet_property)
font_size: dp(20)
input_filter: 'float'
width: dp(40)
size_hint_x: None
MDSlider:
id: bet_size_slider_id
range: 0, 10
range: root.min_bet_property, 10
step: 0.05

<ChanceOfWinning>:
Expand Down
24 changes: 24 additions & 0 deletions src/etheroll/roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import Screen
from pyetheroll.constants import ROUND_DIGITS
from requests.exceptions import ConnectionError

from etheroll.ui_utils import Dialog, load_kv_from_py
from etheroll.utils import run_in_thread

load_kv_from_py(__file__)
DEFAULT_MIN_BET = 0.10


class RollUnderRecap(GridLayout):
Expand All @@ -20,6 +22,7 @@ class RollUnderRecap(GridLayout):


class BetSize(BoxLayout):
min_bet_property = NumericProperty(DEFAULT_MIN_BET)

def __init__(self, **kwargs):
super(BetSize, self).__init__(**kwargs)
Expand All @@ -35,6 +38,27 @@ def _after_init(self, dt):
# shows less digits than the constant default to keep the input tiny
round_digits = 2
BetSize.bind_slider_input(slider, inpt, cast_to, round_digits)
self.pull_min_bet_from_contract()

@run_in_thread
def pull_min_bet_from_contract(self):
"""
Retrieves (async) the minimum bet size by calling the contract.
On network error fallback to default minimum bet.
"""
controller = App.get_running_app().root
pyetheroll = controller.pyetheroll
min_bet = DEFAULT_MIN_BET
try:
min_bet_wei = pyetheroll.contract.functions.minBet().call()
min_bet = round(min_bet_wei / 1e18, ROUND_DIGITS)
except ConnectionError:
pass
self.set_min_bet(min_bet)

@mainthread
def set_min_bet(self, min_bet):
self.min_bet_property = min_bet

@staticmethod
def bind_slider_input(
Expand Down
32 changes: 24 additions & 8 deletions src/etheroll/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from kivy.app import App
from pyetheroll.constants import DEFAULT_GAS_PRICE_GWEI, ChainID

from etheroll.store import Store
Expand All @@ -14,19 +15,34 @@ class SettingsScreen(SubScreen):
def __init__(self, **kwargs):
super(SettingsScreen, self).__init__(**kwargs)

@staticmethod
def get_store():
"""
Wrappers around get_store for handling permissions on Android.
"""
controller = App.get_running_app().root
# would also work for read permission
controller.check_request_write_permission()
try:
store = Store.get_store()
except PermissionError as exception:
controller.on_permission_error(exception)
store = {}
return store

def store_network(self):
"""
Saves selected network to the store.
"""
store = Store.get_store()
store = self.get_store()
network = self.get_ui_network()
store.put('network', value=network.name)

def store_gas_price(self):
"""
Saves gas price value to the store.
"""
store = Store.get_store()
store = self.get_store()
gas_price = self.get_ui_gas_price()
store.put('gas_price', value=gas_price)

Expand All @@ -53,12 +69,12 @@ def is_ui_mainnet(self):
def is_ui_testnet(self):
return self.ids.testnet_checkbox_id.active

@staticmethod
def get_stored_network():
@classmethod
def get_stored_network(cls):
"""
Retrieves last stored network value, defaults to Mainnet.
"""
store = Store.get_store()
store = cls.get_store()
try:
network_dict = store['network']
except KeyError:
Expand All @@ -81,12 +97,12 @@ def is_stored_testnet(cls):
def get_ui_gas_price(self):
return self.ids.gas_price_slider_id.value

@staticmethod
def get_stored_gas_price():
@classmethod
def get_stored_gas_price(cls):
"""
Retrieves stored gas price value, defaults to DEFAULT_GAS_PRICE_GWEI.
"""
store = Store.get_store()
store = cls.get_store()
try:
gas_price_dict = store['gas_price']
except KeyError:
Expand Down
Loading

0 comments on commit 10c3a14

Please sign in to comment.