Skip to content

Commit

Permalink
Merge branch 'release/20181030'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Oct 30, 2018
2 parents 7ba3d46 + 2a92333 commit 34b0545
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Custom
*.swp
*.sqlite

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo: false
language: python
python:
- "3.6"
install: pip install tox-travis
script: tox
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log


## [20181030]

- Add tox testing
- Enable Travis CI
- Installable module


## [v20181029]

- Initial release import from EtherollApp v20181028
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# pyetheroll

[![Build Status](https://travis-ci.com/AndreMiras/pyetheroll.svg?branch=develop)](https://travis-ci.com/AndreMiras/pyetheroll)

Python library to Etheroll smart contract


## Usage

Simply set bet size, chances and wallet settings before rolling:
```python
from pyetheroll.etheroll import Etheroll

etheroll = Etheroll()
bet_size_ether = 0.1
chances = 50
wallet_path = '~/.ethereum/keystore/wallet.json'
wallet_password = 'password'

transaction = etheroll.player_roll_dice(
bet_size_ether, chances, wallet_path, wallet_password)
```

It's also possible to set different contract address and chain ID:
```python
from pyetheroll.constants import ChainID
from pyetheroll.etheroll import Etheroll

chain_id = ChainID.ROPSTEN
contract_address = '0xe12c6dEb59f37011d2D9FdeC77A6f1A8f3B8B1e8'
etheroll = Etheroll(chain_id, contract_address)
```

## Install

Latest stable release:
```sh
pip install https://github.com/AndreMiras/pyetheroll/archive/master.zip
```

Development branch:
```sh
pip install https://github.com/AndreMiras/pyetheroll/archive/develop.zip
```
18 changes: 14 additions & 4 deletions pyetheroll/etheroll.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Python Etheroll library.
"""
Expand All @@ -16,7 +14,6 @@
from web3.auto import w3
from web3.contract import Contract

from ethereum_utils import AccountUtils
from pyetheroll.constants import DEFAULT_GAS_PRICE_GWEI, ROUND_DIGITS, ChainID
from pyetheroll.etherscan_utils import (ChainEtherscanAccountFactory,
ChainEtherscanContractFactory,
Expand Down Expand Up @@ -168,13 +165,26 @@ def player_roll_dice(
}
transaction = self.contract.functions.playerRollDice(
roll_under).buildTransaction(transaction)
private_key = AccountUtils.get_private_key(
private_key = self.get_private_key(
wallet_path, wallet_password)
signed_tx = self.web3.eth.account.signTransaction(
transaction, private_key)
tx_hash = self.web3.eth.sendRawTransaction(signed_tx.rawTransaction)
return tx_hash

@staticmethod
def get_private_key(wallet_path, wallet_password):
"""
Given wallet path and password, returns private key.
Made this way to workaround pyethapp slow account management:
https://github.com/ethereum/pyethapp/issues/292
"""
# lazy loading
from web3.auto import w3
encrypted_key = open(wallet_path).read()
private_key = w3.eth.account.decrypt(encrypted_key, wallet_password)
return private_key

def get_transaction_page(
self, address=None, page=1, offset=100, internal=False):
"""
Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
isort
https://github.com/corpetty/py-etherscan-api/archive/cb91fb3.zip#egg=py-etherscan-api
eth-account
ethereum==2.1.1
web3==4.0.0b11
https://github.com/ethereum/pyethapp/archive/8406f32.zip#egg=pyethapp
rlp==0.6.0
requests-cache
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from distutils.core import setup


setup(name='pyetheroll',
version='20181030',
description='Python library to Etheroll smart contract',
author='Andre Miras',
url='https://github.com/AndreMiras/pyetheroll',
packages=['pyetheroll'],
install_requires=[])
30 changes: 30 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tox]
envlist = pep8,isort,py3
# no setup.py to be ran
skipsdist = True
# trick to enable pre-installation modules
# https://stackoverflow.com/a/50081741/185510
# used to downgrade to setuptools 37, see:
# https://github.com/ethereum/pyethereum/pull/831
indexserver =
preinstall = https://pypi.python.org/simple

[testenv]
deps =
:preinstall: setuptools<=37.0.0
pytest
-r{toxinidir}/requirements.txt
commands =
pytest tests/
python setup.py install

[testenv:pep8]
deps = flake8
commands = flake8 pyetheroll/ tests/

[testenv:isort]
# isort needs to know the requirements to properly sort
deps =
:preinstall: setuptools<=37.0.0
-r{toxinidir}/requirements.txt
commands = isort --check-only --recursive --diff pyetheroll/ tests/

0 comments on commit 34b0545

Please sign in to comment.