diff --git a/.travis.yml b/.travis.yml index ba50b3c..2a9a89d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ install: - pip install git+https://github.com/goacoincore/neoscrypt # command to run tests script: - - pytest --cov=server --cov=lib --cov=wallet - - pycodestyle server/*.py lib/*.py + - pytest --cov=electrumx + - pycodestyle electrumx/server/*.py electrumx/lib/*.py - sh -c "cd docs && make html" # Dont report coverage from nightly after_success: diff --git a/compact_history.py b/compact_history.py index ae2e339..58db9f0 100755 --- a/compact_history.py +++ b/compact_history.py @@ -36,8 +36,8 @@ import sys import traceback from os import environ -from server.env import Env -from server.db import DB +from electrumx.server.env import Env +from electrumx.server.db import DB def compact_history(): diff --git a/docs/conf.py b/docs/conf.py index 7e8ef0a..9be93ac 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,7 +15,7 @@ import os import sys sys.path.insert(0, os.path.abspath('..')) -from server.version import VERSION +from electrumx.server.version import VERSION # -- Project information ----------------------------------------------------- diff --git a/lib/__init__.py b/electrumx/__init__.py similarity index 100% rename from lib/__init__.py rename to electrumx/__init__.py diff --git a/server/__init__.py b/electrumx/lib/__init__.py similarity index 100% rename from server/__init__.py rename to electrumx/lib/__init__.py diff --git a/lib/coins.py b/electrumx/lib/coins.py similarity index 99% rename from lib/coins.py rename to electrumx/lib/coins.py index ba05679..a6359a5 100644 --- a/lib/coins.py +++ b/electrumx/lib/coins.py @@ -38,13 +38,14 @@ from hashlib import sha256 from functools import partial import base64 -import lib.util as util -from lib.hash import Base58, hash160, double_sha256, hash_to_str, HASHX_LEN -from lib.script import ScriptPubKey, OpCodes -import lib.tx as lib_tx -from server.block_processor import BlockProcessor -import server.daemon as daemon -from server.session import ElectrumX, DashElectrumX +import electrumx.lib.util as util +from electrumx.lib.hash import Base58, hash160, double_sha256, hash_to_str +from electrumx.lib.hash import HASHX_LEN +from electrumx.lib.script import ScriptPubKey, OpCodes +import electrumx.lib.tx as lib_tx +from electrumx.server.block_processor import BlockProcessor +import electrumx.server.daemon as daemon +from electrumx.server.session import ElectrumX, DashElectrumX Block = namedtuple("Block", "raw header transactions") diff --git a/lib/enum.py b/electrumx/lib/enum.py similarity index 100% rename from lib/enum.py rename to electrumx/lib/enum.py diff --git a/lib/env_base.py b/electrumx/lib/env_base.py similarity index 100% rename from lib/env_base.py rename to electrumx/lib/env_base.py diff --git a/lib/hash.py b/electrumx/lib/hash.py similarity index 98% rename from lib/hash.py rename to electrumx/lib/hash.py index 8683b1d..bf64848 100644 --- a/lib/hash.py +++ b/electrumx/lib/hash.py @@ -29,7 +29,7 @@ import hashlib import hmac -from lib.util import bytes_to_int, int_to_bytes, hex_to_bytes +from electrumx.lib.util import bytes_to_int, int_to_bytes, hex_to_bytes _sha256 = hashlib.sha256 _sha512 = hashlib.sha512 diff --git a/lib/peer.py b/electrumx/lib/peer.py similarity index 99% rename from lib/peer.py rename to electrumx/lib/peer.py index 2d1e879..e35481e 100644 --- a/lib/peer.py +++ b/electrumx/lib/peer.py @@ -27,8 +27,8 @@ from ipaddress import ip_address -from lib.util import cachedproperty -import lib.util as util +from electrumx.lib.util import cachedproperty +import electrumx.lib.util as util class Peer(object): diff --git a/lib/script.py b/electrumx/lib/script.py similarity index 99% rename from lib/script.py rename to electrumx/lib/script.py index 2741924..94283b1 100644 --- a/lib/script.py +++ b/electrumx/lib/script.py @@ -30,8 +30,8 @@ import struct from collections import namedtuple -from lib.enum import Enumeration -from lib.hash import hash160 +from electrumx.lib.enum import Enumeration +from electrumx.lib.hash import hash160 class ScriptError(Exception): diff --git a/lib/server_base.py b/electrumx/lib/server_base.py similarity index 100% rename from lib/server_base.py rename to electrumx/lib/server_base.py diff --git a/lib/tx.py b/electrumx/lib/tx.py similarity index 98% rename from lib/tx.py rename to electrumx/lib/tx.py index fa94002..3db331b 100644 --- a/lib/tx.py +++ b/electrumx/lib/tx.py @@ -30,10 +30,11 @@ from collections import namedtuple -from lib.hash import double_sha256, hash_to_str -from lib.util import (cachedproperty, unpack_int32_from, unpack_int64_from, - unpack_uint16_from, unpack_uint32_from, - unpack_uint64_from) +from electrumx.lib.hash import double_sha256, hash_to_str +from electrumx.lib.util import ( + cachedproperty, unpack_int32_from, unpack_int64_from, + unpack_uint16_from, unpack_uint32_from, unpack_uint64_from +) class Tx(namedtuple("Tx", "version inputs outputs locktime")): diff --git a/lib/util.py b/electrumx/lib/util.py similarity index 100% rename from lib/util.py rename to electrumx/lib/util.py diff --git a/electrumx/server/__init__.py b/electrumx/server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/block_processor.py b/electrumx/server/block_processor.py similarity index 99% rename from server/block_processor.py rename to electrumx/server/block_processor.py index ad666ed..779e1ff 100644 --- a/server/block_processor.py +++ b/electrumx/server/block_processor.py @@ -16,10 +16,10 @@ from struct import pack, unpack import time from functools import partial -from server.daemon import DaemonError -from lib.hash import hash_to_str, HASHX_LEN -from lib.util import chunks, formatted_time -import server.db +from electrumx.server.daemon import DaemonError +from electrumx.lib.hash import hash_to_str, HASHX_LEN +from electrumx.lib.util import chunks, formatted_time +import electrumx.server.db class Prefetcher(object): @@ -132,7 +132,7 @@ class ChainError(Exception): '''Raised on error processing blocks.''' -class BlockProcessor(server.db.DB): +class BlockProcessor(electrumx.server.db.DB): '''Process blocks and update the DB state to match. Employ a prefetcher to prefetch blocks in batches for processing. diff --git a/server/controller.py b/electrumx/server/controller.py similarity index 98% rename from server/controller.py rename to electrumx/server/controller.py index bd148ef..7e069a0 100644 --- a/server/controller.py +++ b/electrumx/server/controller.py @@ -20,15 +20,16 @@ from functools import partial import pylru from aiorpcx import RPCError, TaskSet, _version as aiorpcx_version -from lib.hash import double_sha256, hash_to_str, hex_str_to_hash, HASHX_LEN -from lib.peer import Peer -from lib.server_base import ServerBase -import lib.util as util -from server.daemon import DaemonError -from server.mempool import MemPool -from server.peers import PeerManager -from server.session import LocalRPC, BAD_REQUEST, DAEMON_ERROR -from server.version import VERSION +from electrumx.lib.hash import double_sha256, hash_to_str, hex_str_to_hash +from electrumx.lib.hash import HASHX_LEN +from electrumx.lib.peer import Peer +from electrumx.lib.server_base import ServerBase +import electrumx.lib.util as util +from electrumx.server.daemon import DaemonError +from electrumx.server.mempool import MemPool +from electrumx.server.peers import PeerManager +from electrumx.server.session import LocalRPC, BAD_REQUEST, DAEMON_ERROR +from electrumx.server.version import VERSION version_string = util.version_string diff --git a/server/daemon.py b/electrumx/server/daemon.py similarity index 99% rename from server/daemon.py rename to electrumx/server/daemon.py index 9bb2f55..f828666 100644 --- a/server/daemon.py +++ b/electrumx/server/daemon.py @@ -18,8 +18,8 @@ from time import strptime import aiohttp -from lib.util import int_to_varint, hex_to_bytes -from lib.hash import hex_str_to_hash +from electrumx.lib.util import int_to_varint, hex_to_bytes +from electrumx.lib.hash import hex_str_to_hash from aiorpcx import JSONRPC diff --git a/server/db.py b/electrumx/server/db.py similarity index 98% rename from server/db.py rename to electrumx/server/db.py index 8f04f42..5146f4c 100644 --- a/server/db.py +++ b/electrumx/server/db.py @@ -17,10 +17,10 @@ from struct import pack, unpack from bisect import bisect_right from collections import namedtuple -import lib.util as util -from lib.hash import hash_to_str, HASHX_LEN -from server.storage import db_class -from server.history import History +import electrumx.lib.util as util +from electrumx.lib.hash import hash_to_str, HASHX_LEN +from electrumx.server.storage import db_class +from electrumx.server.history import History UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value") diff --git a/server/env.py b/electrumx/server/env.py similarity index 98% rename from server/env.py rename to electrumx/server/env.py index add8f19..fc5cd20 100644 --- a/server/env.py +++ b/electrumx/server/env.py @@ -13,9 +13,9 @@ import resource from collections import namedtuple from ipaddress import ip_address -from lib.coins import Coin -from lib.env_base import EnvBase -import lib.util as lib_util +from electrumx.lib.coins import Coin +from electrumx.lib.env_base import EnvBase +import electrumx.lib.util as lib_util NetIdentity = namedtuple('NetIdentity', 'host tcp_port ssl_port nick_suffix') diff --git a/server/history.py b/electrumx/server/history.py similarity index 99% rename from server/history.py rename to electrumx/server/history.py index 29a94cb..52d597e 100644 --- a/server/history.py +++ b/electrumx/server/history.py @@ -16,8 +16,8 @@ from functools import partial import logging from struct import pack, unpack -import lib.util as util -from lib.hash import hash_to_str, HASHX_LEN +import electrumx.lib.util as util +from electrumx.lib.hash import hash_to_str, HASHX_LEN class History(object): diff --git a/server/mempool.py b/electrumx/server/mempool.py similarity index 99% rename from server/mempool.py rename to electrumx/server/mempool.py index fca79bf..e0da9b7 100644 --- a/server/mempool.py +++ b/electrumx/server/mempool.py @@ -13,9 +13,9 @@ import logging import time from collections import defaultdict -from lib.hash import hash_to_str, hex_str_to_hash -from server.daemon import DaemonError -from server.db import UTXO +from electrumx.lib.hash import hash_to_str, hex_str_to_hash +from electrumx.server.daemon import DaemonError +from electrumx.server.db import UTXO class MemPool(object): diff --git a/server/peers.py b/electrumx/server/peers.py similarity index 99% rename from server/peers.py rename to electrumx/server/peers.py index d7062c4..15c3d6c 100644 --- a/server/peers.py +++ b/electrumx/server/peers.py @@ -18,8 +18,8 @@ from functools import partial from aiorpcx import ClientSession, RPCError, SOCKSProxy, ConnectionError -from lib.peer import Peer -from lib.util import ConnectionLogger +from electrumx.lib.peer import Peer +from electrumx.lib.util import ConnectionLogger PEER_GOOD, PEER_STALE, PEER_NEVER, PEER_BAD = range(4) diff --git a/server/session.py b/electrumx/server/session.py similarity index 99% rename from server/session.py rename to electrumx/server/session.py index 44765ab..66640b7 100644 --- a/server/session.py +++ b/electrumx/server/session.py @@ -15,9 +15,9 @@ from functools import partial from aiorpcx import ServerSession, JSONRPCAutoDetect, RPCError -from lib.hash import sha256, hash_to_str -import lib.util as util -from server.daemon import DaemonError +from electrumx.lib.hash import sha256, hash_to_str +import electrumx.lib.util as util +from electrumx.server.daemon import DaemonError BAD_REQUEST = 1 DAEMON_ERROR = 2 diff --git a/server/storage.py b/electrumx/server/storage.py similarity index 99% rename from server/storage.py rename to electrumx/server/storage.py index 6562d33..4f0b251 100644 --- a/server/storage.py +++ b/electrumx/server/storage.py @@ -10,7 +10,7 @@ import os from functools import partial -import lib.util as util +import electrumx.lib.util as util def db_class(name): diff --git a/server/version.py b/electrumx/server/version.py similarity index 100% rename from server/version.py rename to electrumx/server/version.py diff --git a/wallet/bip32.py b/electrumx/wallet/bip32.py similarity index 98% rename from wallet/bip32.py rename to electrumx/wallet/bip32.py index 8215061..37ba2ed 100644 --- a/wallet/bip32.py +++ b/electrumx/wallet/bip32.py @@ -13,9 +13,9 @@ import ecdsa import ecdsa.ellipticcurve as EC import ecdsa.numbertheory as NT -from lib.coins import Coin -from lib.hash import Base58, hmac_sha512, hash160 -from lib.util import cachedproperty, bytes_to_int, int_to_bytes +from electrumx.lib.coins import Coin +from electrumx.lib.hash import Base58, hmac_sha512, hash160 +from electrumx.lib.util import cachedproperty, bytes_to_int, int_to_bytes class DerivationError(Exception): diff --git a/wallet/env.py b/electrumx/wallet/env.py similarity index 95% rename from wallet/env.py rename to electrumx/wallet/env.py index 17da140..1d1b3a0 100644 --- a/wallet/env.py +++ b/electrumx/wallet/env.py @@ -8,7 +8,7 @@ '''Class for handling environment configuration and defaults.''' -from lib.env_base import EnvBase +from electrumx.lib.env_base import EnvBase class Env(EnvBase): diff --git a/electrumx_rpc.py b/electrumx_rpc.py index c5e7d97..3f1172e 100755 --- a/electrumx_rpc.py +++ b/electrumx_rpc.py @@ -17,7 +17,7 @@ from os import environ from aiorpcx import ClientSession -from server.controller import Controller +from electrumx.server.controller import Controller def main(): diff --git a/electrumx_server.py b/electrumx_server.py index fdb0198..3e1c7fb 100755 --- a/electrumx_server.py +++ b/electrumx_server.py @@ -12,8 +12,8 @@ import logging import traceback -from server.env import Env -from server.controller import Controller +from electrumx.server.env import Env +from electrumx.server.controller import Controller def main(): diff --git a/query.py b/query.py index 2e9668d..eadcdc9 100755 --- a/query.py +++ b/query.py @@ -15,9 +15,9 @@ Not currently documented; might become easier to use in future. import sys -from server.env import Env -from server.db import DB -from lib.hash import hash_to_str +from electrumx.server.env import Env +from electrumx.server.db import DB +from electrumx.lib.hash import hash_to_str def count_entries(hist_db, utxo_db): diff --git a/setup.py b/setup.py index 7e4162d..470b8cb 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ import setuptools -from server.version import VERSION +from electrumx.server.version import VERSION setuptools.setup( @@ -13,7 +13,7 @@ setuptools.setup( # "blake256" package is required to sync Decred network. # "xevan_hash" package is required to sync Xuez network. install_requires=['aiorpcX >= 0.5.6', 'plyvel', 'pylru', 'aiohttp >= 1'], - packages=setuptools.find_packages(exclude=['tests']), + packages=setuptools.find_packages(include=('electrumx.*',)), description='ElectrumX Server', author='Neil Booth', author_email='kyuupichan@gmail.com', diff --git a/tests/lib/test_addresses.py b/tests/lib/test_addresses.py index e62e89a..b59edec 100644 --- a/tests/lib/test_addresses.py +++ b/tests/lib/test_addresses.py @@ -26,8 +26,8 @@ import pytest -from lib.coins import Litecoin, BitcoinCash, Zcash, Emercoin, BitcoinGold -from lib.hash import Base58 +from electrumx.lib.coins import Litecoin, BitcoinCash, Zcash, Emercoin, BitcoinGold +from electrumx.lib.hash import Base58 addresses = [ (BitcoinCash, "13xDKJbjh4acmLpNVr6Lc9hFcXRr9fyt4x", diff --git a/tests/lib/test_env_base.py b/tests/lib/test_env_base.py index 22a2084..94d8eb4 100644 --- a/tests/lib/test_env_base.py +++ b/tests/lib/test_env_base.py @@ -4,7 +4,7 @@ import os import pytest -from lib.env_base import EnvBase +from electrumx.lib.env_base import EnvBase os.environ.update({ diff --git a/tests/lib/test_hash.py b/tests/lib/test_hash.py index 87aa355..d4b6014 100644 --- a/tests/lib/test_hash.py +++ b/tests/lib/test_hash.py @@ -5,7 +5,7 @@ from functools import partial import pytest -import lib.hash as lib_hash +import electrumx.lib.hash as lib_hash def test_sha256(): diff --git a/tests/lib/test_util.py b/tests/lib/test_util.py index 7c19360..8414287 100644 --- a/tests/lib/test_util.py +++ b/tests/lib/test_util.py @@ -2,7 +2,7 @@ import os import pytest -from lib import util +from electrumx.lib import util def test_cachedproperty(): diff --git a/tests/server/test_api.py b/tests/server/test_api.py index a6ec461..3d2c319 100644 --- a/tests/server/test_api.py +++ b/tests/server/test_api.py @@ -2,8 +2,8 @@ import asyncio from unittest import mock from aiorpcx import RPCError -from server.env import Env -from server.controller import Controller +from electrumx.server.env import Env +from electrumx.server.controller import Controller loop = asyncio.get_event_loop() diff --git a/tests/server/test_compaction.py b/tests/server/test_compaction.py index d7cae3a..97bba7e 100644 --- a/tests/server/test_compaction.py +++ b/tests/server/test_compaction.py @@ -6,9 +6,9 @@ from os import environ, urandom from struct import pack import random -from lib.hash import hash_to_str, HASHX_LEN -from server.env import Env -from server.db import DB +from electrumx.lib.hash import hash_to_str, HASHX_LEN +from electrumx.server.env import Env +from electrumx.server.db import DB def create_histories(history, hashX_count=100): diff --git a/tests/server/test_env.py b/tests/server/test_env.py index b18a6b5..df27eac 100644 --- a/tests/server/test_env.py +++ b/tests/server/test_env.py @@ -6,8 +6,8 @@ import re import pytest -from server.env import Env, NetIdentity -import lib.coins as lib_coins +from electrumx.server.env import Env, NetIdentity +import electrumx.lib.coins as lib_coins BASE_DAEMON_URL = 'http://username:password@hostname:321/' diff --git a/tests/server/test_storage.py b/tests/server/test_storage.py index 0dcc713..183e01e 100644 --- a/tests/server/test_storage.py +++ b/tests/server/test_storage.py @@ -1,8 +1,8 @@ import pytest import os -from server.storage import Storage, db_class -from lib.util import subclasses +from electrumx.server.storage import Storage, db_class +from electrumx.lib.util import subclasses # Find out which db engines to test # Those that are not installed will be skipped diff --git a/tests/test_blocks.py b/tests/test_blocks.py index d4ba141..d82dc5b 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -30,8 +30,8 @@ from binascii import unhexlify import pytest -from lib.coins import Coin -from lib.hash import hex_str_to_hash +from electrumx.lib.coins import Coin +from electrumx.lib.hash import hex_str_to_hash BLOCKS_DIR = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'blocks') diff --git a/tests/wallet/test_bip32.py b/tests/wallet/test_bip32.py index c5bd967..f9f7b94 100644 --- a/tests/wallet/test_bip32.py +++ b/tests/wallet/test_bip32.py @@ -4,9 +4,9 @@ import pytest -import wallet.bip32 as bip32 -from lib.coins import BitcoinCash as Bitcoin, CoinError -from lib.hash import Base58 +import electrumx.wallet.bip32 as bip32 +from electrumx.lib.coins import BitcoinCash as Bitcoin, CoinError +from electrumx.lib.hash import Base58 MXPRV = 'xprv9s21ZrQH143K2gMVrSwwojnXigqHgm1khKZGTCm7K8w4PmuDEUrudk11ZBxhGPUiUeVcrfGLoZmt8rFNRDLp18jmKMcVma89z7PJd2Vn7R9'