diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 00000000..dcfa3db4 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/bitcoin/__init__.py b/bitcoin/__init__.py index dcb02de9..8af1b1bb 100644 --- a/bitcoin/__init__.py +++ b/bitcoin/__init__.py @@ -25,6 +25,7 @@ class MainParams(bitcoin.core.CoreMainParams): ('bluematt.me', 'dnsseed.bluematt.me'), ('dashjr.org', 'dnsseed.bitcoin.dashjr.org'), ('bitcoinstats.com', 'seed.bitcoinstats.com'), + ('petertodd.org', 'seed.btc.petertodd.net'), ('xf2.org', 'bitseed.xf2.org'), ('bitcoin.jonasschnelli.ch', 'seed.bitcoin.jonasschnelli.ch')) BASE58_PREFIXES = {'PUBKEY_ADDR':0, @@ -37,7 +38,7 @@ class TestNetParams(bitcoin.core.CoreTestNetParams): DEFAULT_PORT = 18333 RPC_PORT = 18332 DNS_SEEDS = (('testnetbitcoin.jonasschnelli.ch', 'testnet-seed.bitcoin.jonasschnelli.ch'), - ('petertodd.org', 'seed.tbtc.petertodd.org'), + ('petertodd.org', 'seed.tbtc.petertodd.net'), ('bluematt.me', 'testnet-seed.bluematt.me'), ('bitcoin.schildbach.de', 'testnet-seed.bitcoin.schildbach.de')) BASE58_PREFIXES = {'PUBKEY_ADDR':111, diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py index 355d2a85..0f902c8c 100644 --- a/bitcoin/core/key.py +++ b/bitcoin/core/key.py @@ -26,6 +26,7 @@ _ssl = ctypes.cdll.LoadLibrary( ctypes.util.find_library('ssl.35') or ctypes.util.find_library('ssl') or ctypes.util.find_library('libeay32') + or ctypes.util.find_library('libcrypto') ) _libsecp256k1_path = ctypes.util.find_library('secp256k1') diff --git a/bitcoin/core/serialize.py b/bitcoin/core/serialize.py index ac75da34..ae82d503 100644 --- a/bitcoin/core/serialize.py +++ b/bitcoin/core/serialize.py @@ -26,7 +26,7 @@ def Hash(msg): - """SHA256^2)(msg) -> bytes""" + """SHA256^2(msg) -> bytes""" return hashlib.sha256(hashlib.sha256(msg).digest()).digest() def Hash160(msg): diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index 417dc533..25310c71 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -205,11 +205,14 @@ def __init__(self, self.__service_url = service_url self.__url = urlparse.urlparse(service_url) - if self.__url.scheme not in ('http',): + if self.__url.scheme not in ('http', 'https'): raise ValueError('Unsupported URL scheme %r' % self.__url.scheme) if self.__url.port is None: - port = httplib.HTTP_PORT + if self.__url.scheme == 'https': + port = httplib.HTTPS_PORT + else: + port = httplib.HTTP_PORT else: port = self.__url.port self.__id_count = 0 @@ -223,8 +226,12 @@ def __init__(self, if connection: self.__conn = connection else: - self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port, - timeout=timeout) + if self.__url.scheme == 'https': + self.__conn = httplib.HTTPSConnection(self.__url.hostname, port=port, + timeout=timeout) + else: + self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port, + timeout=timeout) def _call(self, service_name, *args): self.__id_count += 1 @@ -783,6 +790,25 @@ def unlockwallet(self, password, timeout=60): r = self._call('walletpassphrase', password, timeout) return r + def createwallet(self, name): + """create a new wallet. + + name - The wallet name. + + """ + r = self._call('createwallet', name) + return r + + def loadwallet(self, name, load_on_startup=False): + """load a wallet. + + name - The wallet name. + load_on_startup - whether to remember to load it automatically next time bitcoind starts. + + """ + r = self._call('loadwallet', name, load_on_startup) + return r + def _addnode(self, node, arg): r = self._call('addnode', node, arg) return r diff --git a/bitcoin/tests/fakebitcoinproxy.py b/bitcoin/tests/fakebitcoinproxy.py index ac111615..effabf4a 100644 --- a/bitcoin/tests/fakebitcoinproxy.py +++ b/bitcoin/tests/fakebitcoinproxy.py @@ -97,6 +97,7 @@ def make_blocks_from_blockhashes(blockhashes): instantiation. """ blocks = [] + previousblockhash = None for (height, blockhash) in enumerate(blockhashes): block = {"hash": blockhash, "height": height, "tx": []}