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

Port project to Python 3, drop Python 2 support #177

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
86fcc10
Run of the 2to3 script.
JustinTArthur Feb 26, 2016
00130b6
Use bytes for most keys/values in the storage engine. Use binascii pa…
JustinTArthur Mar 1, 2016
2135b58
A unit test for expected results of deserialize module's parse_Transa…
JustinTArthur Mar 4, 2016
ec4fdfc
Use jsonrpc-pelix to get Python 3-compatible jsonrpclib. At some poin…
JustinTArthur Mar 4, 2016
dfdca6a
Fix byte-string compatibility with Python 3 in hashing utilities.
JustinTArthur Mar 4, 2016
094f406
Fix byte-string compatibility with Python 3 in transaction parsing st…
JustinTArthur Mar 4, 2016
9256370
Fix incorrect address being checked by tx parsing test.
JustinTArthur Mar 4, 2016
b589e95
Update test_utils tests to Python 3 hex conversion conventions. Assum…
JustinTArthur Mar 4, 2016
870c202
Base 58 decoding utility function to return bytes instead of characte…
JustinTArthur Mar 4, 2016
97cc9c6
Add `.travis.yml` for continuous integration
bauerj Mar 5, 2016
7c6aec3
Add codecov.io coverage reports
bauerj Mar 5, 2016
f4e9c5e
Add badges for coverage and build status to README
bauerj Mar 5, 2016
1abef45
A couple of benchmarking scripts for comparing approaches and platforms.
JustinTArthur Mar 8, 2016
c23a75e
Unit tests for header transformations.
JustinTArthur Mar 8, 2016
369d3fd
Make int to hex functions Python 3-compatible.
JustinTArthur Mar 8, 2016
9e0051f
leveldb data stored as bytes, not strings.
JustinTArthur Dec 18, 2016
7f6525a
Communication with bitcoind to ported to Python 3. Mostly hex convers…
JustinTArthur Dec 18, 2016
6ae25ee
Fixes to storage for Python 3's bytes vs Python 2's str.
JustinTArthur Dec 18, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The version of libleveldb in 12.04 is too old, better use trusty (14.04)
sudo: required
dist: trusty
language: python

python:
- "3.2"
- "3.3"
- "3.4"
- "pypy3"

before_install:
- pip install codecov
- pip install nose-cov

# command to install dependencies
install:
- sudo apt-get install -y libleveldb-dev python-leveldb
- travis_retry python setup.py install

# command to run tests
script:
- nosetests
- nosetests --with-coverage

after_success:
- codecov

matrix:
fast_finish: true
allow_failures:
- python: pypy3
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![codecov.io](https://codecov.io/github/bauerj/electrum-server/coverage.svg?branch=python3-migration)](https://codecov.io/github/bauerj/electrum-server?branch=python3-migration)
[![Build Status](https://travis-ci.org/bauerj/electrum-server.svg?branch=python3-migration)](https://travis-ci.org/bauerj/electrum-server)

Electrum-server for the Electrum client
=========================================

Expand Down
39 changes: 19 additions & 20 deletions run_electrum_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# SOFTWARE.

import argparse
import ConfigParser
import configparser
import logging
import socket
import sys
Expand All @@ -46,11 +46,11 @@
logging.basicConfig()

if sys.maxsize <= 2**32:
print "Warning: it looks like you are using a 32bit system. You may experience crashes caused by mmap"
print("Warning: it looks like you are using a 32bit system. You may experience crashes caused by mmap")

if os.getuid() == 0:
print "Do not run this program as root!"
print "Run the install script to create a non-privileged user."
print("Do not run this program as root!")
print("Run the install script to create a non-privileged user.")
sys.exit()

def attempt_read_config(config, filename):
Expand Down Expand Up @@ -82,7 +82,7 @@ def setup_network_params(config):
storage.GENESIS_HASH = config.get('network', 'genesis_hash')

def create_config(filename=None):
config = ConfigParser.ConfigParser()
config = configparser.ConfigParser()
# set some defaults, which will be overwritten by the config file
config.add_section('server')
config.set('server', 'banner', 'Welcome to Electrum!')
Expand Down Expand Up @@ -123,7 +123,7 @@ def create_config(filename=None):
break

if not os.path.isfile(filename):
print 'could not find electrum configuration file "%s"' % filename
print('could not find electrum configuration file "%s"' % filename)
sys.exit(1)

attempt_read_config(config, filename)
Expand All @@ -135,24 +135,24 @@ def create_config(filename=None):

def run_rpc_command(params, electrum_rpc_port):
cmd = params[0]
import xmlrpclib
server = xmlrpclib.ServerProxy('http://localhost:%d' % electrum_rpc_port)
import xmlrpc.client
server = xmlrpc.client.ServerProxy('http://localhost:%d' % electrum_rpc_port)
func = getattr(server, cmd)
r = func(*params[1:])
if cmd == 'sessions':
now = time.time()
print 'type address sub version time'
print('type address sub version time')
for item in r:
print '%4s %21s %3s %7s %.2f' % (item.get('name'),
print('%4s %21s %3s %7s %.2f' % (item.get('name'),
item.get('address'),
item.get('subscriptions'),
item.get('version'),
(now - item.get('time')),
)
))
elif cmd == 'debug':
print r
print(r)
else:
print json.dumps(r, indent=4, sort_keys=True)
print(json.dumps(r, indent=4, sort_keys=True))


def cmd_banner_update():
Expand All @@ -169,18 +169,17 @@ def cmd_getinfo():
}

def cmd_sessions():
return map(lambda s: {"time": s.time,
return [{"time": s.time,
"name": s.name,
"address": s.address,
"version": s.version,
"subscriptions": len(s.subscriptions)},
dispatcher.request_dispatcher.get_sessions())
"subscriptions": len(s.subscriptions)} for s in dispatcher.request_dispatcher.get_sessions()]

def cmd_numsessions():
return len(dispatcher.request_dispatcher.get_sessions())

def cmd_peers():
return server_proc.peers.keys()
return list(server_proc.peers.keys())

def cmd_numpeers():
return len(server_proc.peers)
Expand Down Expand Up @@ -290,7 +289,7 @@ def stop_server():
try:
run_rpc_command(args.command, electrum_rpc_port)
except socket.error:
print "server not running"
print("server not running")
sys.exit(1)
sys.exit(0)

Expand All @@ -301,12 +300,12 @@ def stop_server():
is_running = False

if is_running:
print "server already running"
print("server already running")
sys.exit(1)

start_server(config)

from SimpleXMLRPCServer import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCServer
server = SimpleXMLRPCServer(('localhost', electrum_rpc_port), allow_none=True, logRequests=False)
server.register_function(lambda: os.getpid(), 'getpid')
server.register_function(shared.stop, 'stop')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name="electrum-server",
version="1.0",
scripts=['run_electrum_server.py','electrum-server'],
install_requires=['plyvel','jsonrpclib', 'irc >= 11, <=14.0'],
install_requires=['plyvel','jsonrpclib-pelix', 'irc>=11, <=14.0'],
package_dir={
'electrumserver':'src'
},
Expand Down
16 changes: 8 additions & 8 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import utils
import storage
import deserialize
import networks
import blockchain_processor
import processor
import version
from . import utils
from . import storage
from . import deserialize
from . import networks
from . import blockchain_processor
from . import processor
from . import version
import irc
import stratum_tcp
from . import stratum_tcp
Loading