From 173a73e74781dcd2edce120d8685550a88a73189 Mon Sep 17 00:00:00 2001
From: Peter Todd <pete@petertodd.org>
Date: Fri, 8 Dec 2023 10:33:55 +0000
Subject: [PATCH 1/9] Update petertodd DNS seeds

---
 bitcoin/__init__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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,

From 2fabb36e9c5f6951392ae9074eec63127fbd48a6 Mon Sep 17 00:00:00 2001
From: mhh <mike.hukiewitz@robotter.ai>
Date: Mon, 6 May 2024 15:38:05 +0200
Subject: [PATCH 2/9] Add HTTPS to supported RPC Proxy protocols

---
 bitcoin/rpc.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py
index 417dc533..7bd45a2c 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

From fc46e335e24e2aa9414ad1d1177196ff8e55ffce Mon Sep 17 00:00:00 2001
From: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Date: Tue, 4 Jun 2024 13:46:44 +0200
Subject: [PATCH 3/9] core: support openssl 3

In modern version of openssl (iirc from 1.1) the
library `libeay32` is removed in favor of libcrypto.

See for more info https://github.com/openssl/openssl/issues/10332

This commit is adding the possibility to include libcrypto too

Fixing the following error on a nix shell

/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/_pytest/config/__init__.py:325: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
Plugin: helpconfig, Hook: pytest_cmdline_parse
ConftestImportFailure: OSError: libeay32: cannot open shared object file: No such file or directory (from /home/vincent/gittea/work/lampo.rs/tests/lnprototest/tests/conftest.py)
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
  config = pluginmanager.hook.pytest_cmdline_parse(
ImportError while loading conftest '/home/vincent/gittea/work/lampo.rs/tests/lnprototest/tests/conftest.py'.
tests/conftest.py:3: in <module>
    import lnprototest
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/__init__.py:15: in <module>
    from .event import (
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/event.py:16: in <module>
    from .namespace import namespace
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/namespace.py:6: in <module>
    from .signature import SigType
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/signature.py:5: in <module>
    from .utils import check_hex, privkey_expand
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/utils/__init__.py:18: in <module>
    from .bitcoin_utils import (
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/utils/bitcoin_utils.py:14: in <module>
    from bitcoin.wallet import CBitcoinSecret
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/bitcoin/wallet.py:23: in <module>
    import bitcoin.core.key
/home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/bitcoin/core/key.py:27: in <module>
    _ssl = ctypes.cdll.LoadLibrary(
/nix/store/sxr2igfkwhxbagri49b8krmcqz168sim-python3-3.11.8/lib/python3.11/ctypes/__init__.py:454: in LoadLibrary
    return self._dlltype(name)
/nix/store/sxr2igfkwhxbagri49b8krmcqz168sim-python3-3.11.8/lib/python3.11/ctypes/__init__.py:376: in __init__
    self._handle = _dlopen(self._name, mode)
E   OSError: libeay32: cannot open shared object file: No such file or directory
make[1]: *** [Makefile:11: check] Error 4

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
---
 bitcoin/core/key.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py
index 355d2a85..a7c9cf4f 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.cdll.LoadLibrary("libcrypto")
 )
 
 _libsecp256k1_path = ctypes.util.find_library('secp256k1')

From d2fe2ad2507a9d0060947615ce85b1afeeb0a454 Mon Sep 17 00:00:00 2001
From: aviv57 <aviv57@gmail.com>
Date: Wed, 30 Oct 2024 03:06:54 +0200
Subject: [PATCH 4/9] core: Fix a bug with loading libcrypto

Looks like the fix in https://github.com/petertodd/python-bitcoinlib/pull/301 was not working.

I got the following error while trying to run `from bitcoin.rpc import Proxy` on my machine

```
File ~\OneDrive\Documents\GitHub\python-bitcoinlib\bitcoin\rpc.py:38
     36 from bitcoin.core import COIN, x, lx, b2lx, CBlock, CBlockHeader, CTransaction, COutPoint, CTxOut
     37 from bitcoin.core.script import CScript
---> 38 from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret
     40 DEFAULT_USER_AGENT = "AuthServiceProxy/0.1"
     42 DEFAULT_HTTP_TIMEOUT = 30

File ~\OneDrive\Documents\GitHub\python-bitcoinlib\bitcoin\wallet.py:23
     21 import bitcoin.bech32
     22 import bitcoin.core
---> 23 import bitcoin.core.key
     24 import bitcoin.core.script as script
     27 class CBitcoinAddress(object):

File ~\OneDrive\Documents\GitHub\python-bitcoinlib\bitcoin\core\key.py:27
     23 import bitcoin.signature
     25 import bitcoin.core.script
---> 27 _ssl = ctypes.cdll.LoadLibrary(
     28     ctypes.util.find_library('ssl.35') or ctypes.util.find_library('ssl') or ctypes.util.find_library('libeay32')
     29     or ctypes.cdll.LoadLibrary("libcrypto")
     30 )
     32 _libsecp256k1_path = ctypes.util.find_library('secp256k1')
     33 _libsecp256k1_enable_signing = False

File ~\.pyenv\pyenv-win\versions\3.12.7\Lib\ctypes\__init__.py:460, in LibraryLoader.LoadLibrary(self, name)
    459 def LoadLibrary(self, name):
--> 460     return self._dlltype(name)

File ~\.pyenv\pyenv-win\versions\3.12.7\Lib\ctypes\__init__.py:348, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    343 def __init__(self, name, mode=DEFAULT_MODE, handle=None,
    344              use_errno=False,
    345              use_last_error=False,
    346              winmode=None):
    347     if name:
--> 348         name = _os.fspath(name)
    349     self._name = name
    350     flags = self._func_flags_

TypeError: expected str, bytes or os.PathLike object, not CDLL
---
 bitcoin/core/key.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py
index a7c9cf4f..0f902c8c 100644
--- a/bitcoin/core/key.py
+++ b/bitcoin/core/key.py
@@ -26,7 +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.cdll.LoadLibrary("libcrypto")
+    or ctypes.util.find_library('libcrypto')
 )
 
 _libsecp256k1_path = ctypes.util.find_library('secp256k1')

From e5beddaba860c3af228e220801ca6f01189f52f3 Mon Sep 17 00:00:00 2001
From: ZZiigguurraatt <ZZiigguurraatt>
Date: Mon, 25 Nov 2024 08:40:47 -0500
Subject: [PATCH 5/9] add createwallet rpc command

---
 bitcoin/rpc.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py
index 7bd45a2c..41f6c991 100644
--- a/bitcoin/rpc.py
+++ b/bitcoin/rpc.py
@@ -790,6 +790,15 @@ 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 _addnode(self, node, arg):
         r = self._call('addnode', node, arg)
         return r

From 65e8f15ad71be0f5349a4145ed81a3301b09ef02 Mon Sep 17 00:00:00 2001
From: ZZiigguurraatt <ZZiigguurraatt>
Date: Mon, 25 Nov 2024 09:00:27 -0500
Subject: [PATCH 6/9] add loadwallet rpc command

---
 bitcoin/rpc.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py
index 41f6c991..25310c71 100644
--- a/bitcoin/rpc.py
+++ b/bitcoin/rpc.py
@@ -799,6 +799,16 @@ def createwallet(self, 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

From 5c0ff08f7067b172c43ad4c730d1849b366e14d4 Mon Sep 17 00:00:00 2001
From: Jesus Christ <120573631+Gudnessuche@users.noreply.github.com>
Date: Tue, 3 Dec 2024 14:35:37 +0000
Subject: [PATCH 7/9] Update serialize.py (Docstring Typo:)

The closing parenthesis in the docstring should be removed.
---
 bitcoin/core/serialize.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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):

From 5ca448572279b131b32d557b06009aa98757a5c5 Mon Sep 17 00:00:00 2001
From: Peter Todd <pete@petertodd.org>
Date: Fri, 14 Mar 2025 19:50:59 +0000
Subject: [PATCH 8/9] Create python-package.yml

---
 .github/workflows/python-package.yml | 40 ++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 .github/workflows/python-package.yml

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

From 91e334d831fd16c60c932ad7df42c88fd6567c02 Mon Sep 17 00:00:00 2001
From: Peter Todd <pete@petertodd.org>
Date: Fri, 14 Mar 2025 19:54:07 +0000
Subject: [PATCH 9/9] Fix flake8 fail

---
 bitcoin/tests/fakebitcoinproxy.py | 1 +
 1 file changed, 1 insertion(+)

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": []}