Skip to content
This repository was archived by the owner on Aug 8, 2018. It is now read-only.

Commit f0fbe87

Browse files
committed
Merge branch 'develop' into parallel_block_download
2 parents bdbf137 + 9af6e64 commit f0fbe87

36 files changed

+655
-389
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ omit =
66
*/examples/*
77
*/tests/*
88

9-
[report]
109
exclude_lines =
1110
pragma: no cover
1211
def __repr__

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ sudo: required
33
dist: trusty
44
python:
55
- '2.7'
6+
- '3.6'
67
before_install:
78
- sudo add-apt-repository -y ppa:ethereum/ethereum
89
- sudo apt-get update
910
- sudo apt-get install -y solc
1011
install:
1112
- USE_PYETHEREUM_DEVELOP=1 python setup.py install
12-
- pip install coveralls readme_renderer
13+
- pip install coveralls readme_renderer tox-travis
1314
script:
14-
- coverage run --source pyethapp setup.py test
15-
- python setup.py check --restructuredtext --strict
15+
- tox
1616
after_success:
1717
- coveralls
1818
env:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Introduction
2525

2626
pyethapp is the python based client implementing the Ethereum_ cryptoeconomic state machine.
2727

28-
Ethereum as a platform is focussed on enabling people to build new ideas using blockchain technology.
28+
Ethereum as a platform is focused on enabling people to build new ideas using blockchain technology.
2929

3030
The python implementation aims to provide an easily hackable and extendable codebase.
3131

dev_requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
pytest==2.9.1
1+
pytest
22
mock==2.0.0
33
pytest-mock==1.6.0
4-
ethereum-serpent>=1.8.1
5-
pytest==2.9.1
64
coverage==4.0.3
5+
ethereum-serpent

pyethapp/accounts.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from builtins import hex
2+
from builtins import object
13
import json
24
import os
35
from random import SystemRandom
@@ -7,10 +9,14 @@
79
from ethereum.tools import keys
810
from ethereum.slogging import get_logger
911
from ethereum.utils import privtopub # this is different than the one used in devp2p.crypto
10-
from ethereum.utils import sha3, is_string, decode_hex, remove_0x_head
12+
from ethereum.utils import sha3, is_string, encode_hex, remove_0x_head, to_string
13+
from rlp.utils import decode_hex
14+
15+
from pyethapp.utils import MinType
16+
1117
log = get_logger('accounts')
1218

13-
DEFAULT_COINBASE = 'de0b295669a9fd93d5f28d9ec85e40f4cb697bae'.decode('hex')
19+
DEFAULT_COINBASE = decode_hex('de0b295669a9fd93d5f28d9ec85e40f4cb697bae')
1420

1521
random = SystemRandom()
1622

@@ -22,7 +28,7 @@ def mk_privkey(seed):
2228
def mk_random_privkey():
2329
k = hex(random.getrandbits(256))[2:-1].zfill(64)
2430
assert len(k) == 64
25-
return k.decode('hex')
31+
return decode_hex(k)
2632

2733

2834
class Account(object):
@@ -38,7 +44,7 @@ class Account(object):
3844
def __init__(self, keystore, password=None, path=None):
3945
self.keystore = keystore
4046
try:
41-
self._address = self.keystore['address'].decode('hex')
47+
self._address = decode_hex(self.keystore['address'])
4248
except KeyError:
4349
self._address = None
4450
self.locked = True
@@ -61,6 +67,13 @@ def new(cls, password, key=None, uuid=None, path=None):
6167
"""
6268
if key is None:
6369
key = mk_random_privkey()
70+
71+
# [NOTE]: key and password should be bytes
72+
if not is_string(key):
73+
key = to_string(key)
74+
if not is_string(password):
75+
password = to_string(password)
76+
6477
keystore = keys.make_keystore_json(key, password)
6578
keystore['id'] = uuid
6679
return Account(keystore, password, path)
@@ -94,9 +107,9 @@ def dump(self, include_address=True, include_id=True):
94107
d['crypto'] = self.keystore['crypto']
95108
d['version'] = self.keystore['version']
96109
if include_address and self.address is not None:
97-
d['address'] = self.address.encode('hex')
110+
d['address'] = encode_hex(self.address)
98111
if include_id and self.uuid is not None:
99-
d['id'] = self.uuid
112+
d['id'] = str(self.uuid)
100113
return json.dumps(d)
101114

102115
def unlock(self, password):
@@ -146,7 +159,7 @@ def address(self):
146159
if self._address:
147160
pass
148161
elif 'address' in self.keystore:
149-
self._address = self.keystore['address'].decode('hex')
162+
self._address = decode_hex(self.keystore['address'])
150163
elif not self.locked:
151164
self._address = keys.privtoaddr(self.privkey)
152165
else:
@@ -187,7 +200,7 @@ def sign_tx(self, tx):
187200

188201
def __repr__(self):
189202
if self.address is not None:
190-
address = self.address.encode('hex')
203+
address = encode_hex(self.address)
191204
else:
192205
address = '?'
193206
return '<Account(address={address}, id={id})>'.format(address=address, id=self.uuid)
@@ -257,7 +270,9 @@ def coinbase(self):
257270
return DEFAULT_COINBASE
258271
cb = self.accounts_with_address[0].address
259272
else:
260-
if not is_string(cb_hex):
273+
# [NOTE]: check it!
274+
# if not is_string(cb_hex):
275+
if not isinstance(cb_hex, str):
261276
raise ValueError('coinbase must be string')
262277
try:
263278
cb = decode_hex(remove_0x_head(cb_hex))
@@ -305,8 +320,9 @@ def add_account(self, account, store=True, include_address=True, include_id=True
305320
errno=e.errno)
306321
raise
307322
self.accounts.append(account)
308-
self.accounts.sort(key=lambda account: account.path)
309-
323+
min_value = MinType()
324+
self.accounts.sort(key=lambda account: min_value if account.path is None else account.path)
325+
310326
def update_account(self, account, new_password, include_address=True, include_id=True):
311327
"""Replace the password of an account.
312328
@@ -424,7 +440,7 @@ def find(self, identifier):
424440
except ValueError:
425441
pass
426442
else:
427-
return self.get_by_id(str(uuid))
443+
return self.get_by_id(uuid.hex)
428444

429445
try:
430446
index = int(identifier, 10)
@@ -441,7 +457,7 @@ def find(self, identifier):
441457
if identifier[:2] == '0x':
442458
identifier = identifier[2:]
443459
try:
444-
address = identifier.decode('hex')
460+
address = decode_hex(identifier)
445461
except TypeError:
446462
success = False
447463
else:
@@ -480,16 +496,16 @@ def get_by_address(self, address):
480496
assert len(address) == 20
481497
accounts = [account for account in self.accounts if account.address == address]
482498
if len(accounts) == 0:
483-
raise KeyError('account with address {} not found'.format(address.encode('hex')))
499+
raise KeyError('account with address {} not found'.format(encode_hex(address)))
484500
elif len(accounts) > 1:
485-
log.warning('multiple accounts with same address found', address=address.encode('hex'))
501+
log.warning('multiple accounts with same address found', address=encode_hex(address))
486502
return accounts[0]
487503

488504
def sign_tx(self, address, tx):
489505
self.get_by_address(address).sign_tx(tx)
490506

491507
def propose_path(self, address):
492-
return os.path.join(self.keystore_dir, address.encode('hex'))
508+
return os.path.join(self.keystore_dir, encode_hex(address))
493509

494510
def __contains__(self, address):
495511
assert len(address) == 20

0 commit comments

Comments
 (0)