Skip to content

Commit

Permalink
Solve unittest problems and merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Jan 16, 2024
2 parents ec29267 + 51cc152 commit 79694d3
Show file tree
Hide file tree
Showing 43 changed files with 502 additions and 607 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/unittests-noscrypt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ jobs:
architecture: 'x64'
- name: Install dependencies
run: |
pip install coveralls
pip install psycopg2
pip install mysql-connector
pip install mysqlclient
pip install parameterized
pip install Cython
python setup.py install
python -m pip install .[dev]
pip uninstall -y scrypt
- name: Test with coverage
env:
BCL_CONFIG_FILE: config_encryption.ini.unittest
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ jobs:
architecture: 'x64'
- name: Install dependencies
run: |
pip install coveralls
pip install psycopg2
pip install mysql-connector
pip install mysqlclient
pip install parameterized
pip install scrypt
pip install Cython
python setup.py install
python -m pip install .[dev]
- name: Test with coverage
env:
BCL_CONFIG_FILE: config.ini.unittest
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/unittests_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
python-version: '3.11'
architecture: 'x64'
- name: Install dependencies
run: |
pip install win-unicode-console
pip install coveralls
pip install psycopg2
pip install mysql-connector
pip install mysqlclient
pip install parameterized
pip install scrypt
python setup.py install
python -m pip install .[dev]
- name: Test with coverage
env:
BCL_CONFIG_FILE: config.ini.unittest
UNITTESTS_FULL_DATABASE_TEST: False
PYTHONUTF8: 1
run: coverage run --source=bitcoinlib -m unittest -v
6 changes: 3 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ version: 2
formats: all

build:
image: latest
os: ubuntu-22.04
tools:
python: "3.11"

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: docs/requirements.txt
# - requirements: requirements.txt
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
RELEASE 0.6.14 - Update installation instruction, docker & bugfixes
===================================================================
* Update installation instructions
* Add Docker files for testing and installation testing
* Fix Bitcoind constructors
* Fix issue with hexadecimal passwords for Mnemonics
* Fix regtest address prefix

RELEASE 0.6.13 - Update config & fix some bugs
==============================================
* Rewrite configuration files for easier installation
* Fix issues with bitcoind and litecoind client
* Fix encoding issues with Python3.11 and Windows

RELEASE 0.6.12 - Prepare for Taproot
====================================
* Parse p2tr input scripts
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Then install using pip
For more detailed installation instructions, how to install on other systems or troubleshooting please read https://bitcoinlib.readthedocs.io/en/latest/source/_static/manuals.install.html

If you are using docker you can check some Dockerfiles to create images in the docker directory.

Documentation
-------------
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/config/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.12
0.6.14
8 changes: 4 additions & 4 deletions bitcoinlib/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
1000000000000000000000000: 'Y',
}

if os.name == 'nt' and locale.getpreferredencoding() != 'UTF-8':
# TODO: Find a better windows hack
if os.name == 'nt' and locale.getpreferredencoding().lower() != 'utf-8':
import _locale
_locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8'])
elif locale.getpreferredencoding() != 'UTF-8':
_locale._gdl_bak = _locale._getdefaultlocale
_locale._getdefaultlocale = (lambda *args: (_locale._gdl_bak()[0], 'utf8'))
elif locale.getpreferredencoding().lower() != 'utf-8':
raise EnvironmentError("Locale is currently set to '%s'. "
"This library needs the locale set to UTF-8 to function properly" %
locale.getpreferredencoding())
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"currency_code": "rBTC",
"prefix_address": "00",
"prefix_address_p2sh": "05",
"prefix_bech32": "bc",
"prefix_bech32": "bcrt",
"prefix_wif": "80",
"prefixes_wif": [
["0488B21E", "xpub", "public", false, "legacy", "p2pkh"],
Expand Down
22 changes: 0 additions & 22 deletions bitcoinlib/data/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,27 +405,5 @@
"priority": 10,
"denominator": 1,
"network_overrides": null
},
"blocksmurfer": {
"provider": "blocksmurfer",
"network": "bitcoin",
"client_class": "BlocksmurferClient",
"provider_coin_id": "",
"url": "https://harari.blocksmurfer.io/api/v1/btc/",
"api_key": "",
"priority": 10,
"denominator": 100000000,
"network_overrides": null
},
"blocksmurfer.testnet": {
"provider": "blocksmurfer",
"network": "testnet",
"client_class": "BlocksmurferClient",
"provider_coin_id": "",
"url": "https://harari.blocksmurfer.io/api/v1/tbtc/",
"api_key": "",
"priority": 10,
"denominator": 100000000,
"network_overrides": null
}
}
18 changes: 13 additions & 5 deletions bitcoinlib/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
try:
from Crypto.Hash import RIPEMD160
except ImportError as err:
_logger.warning("Could not import RIPEMD160 from cryptodome, will try do use hashlib but this could lead to errors")
_logger.warning("Could not import RIPEMD160 from cryptodome, will try to use hashlib but this could lead to errors")

try:
from Crypto.Cipher import AES
Expand Down Expand Up @@ -962,12 +962,20 @@ def bip38_decrypt(encrypted_privkey, password):
:return tupple (bytes, bytes): (Private Key bytes, 4 byte address hash for verification)
"""
d = change_base(encrypted_privkey, 58, 256)[2:]
flagbyte = d[0:1]
d = d[1:]
d = change_base(encrypted_privkey, 58, 256)
identifier = d[0:2]
flagbyte = d[2:3]
d = d[3:]
# ec_multiply = False
if identifier == b'\x01\x43':
# ec_multiply = True
raise EncodingError("EC multiply BIP38 keys are not supported at the moment")
elif identifier != b'\x01\x42':
raise EncodingError("Unknown BIP38 identifier, value must be 0x0142 (non-EC-multiplied) or "
"0x0143 (EC-multiplied)")
if flagbyte == b'\xc0':
compressed = False
elif flagbyte == b'\xe0':
elif flagbyte == b'\xe0' or flagbyte == b'\x20':
compressed = True
else:
raise EncodingError("Unrecognised password protected key format. Flagbyte incorrect.")
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def to_seed(self, words, password='', validate=True):
# Check if passphrase is valid
if validate:
self.to_entropy(words)
mnemonic = to_bytes(words)
password = to_bytes(password)
mnemonic = bytes(words, 'utf8')
password = bytes(password, 'utf8')
return hashlib.pbkdf2_hmac(hash_name='sha512', password=mnemonic, salt=b'mnemonic' + password,
iterations=2048)

Expand Down
6 changes: 3 additions & 3 deletions bitcoinlib/services/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BitcoindClient(BaseClient):
"""

@staticmethod
def from_config(configfile=None, network='bitcoin'):
def from_config(configfile=None, network='bitcoin', *args):
"""
Read settings from bitcoind config file
Expand Down Expand Up @@ -113,7 +113,7 @@ def from_config(configfile=None, network='bitcoin'):
server = _read_from_config(config, 'rpc', 'externalip', server)

url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port)
return BitcoindClient(network, url)
return BitcoindClient(network, url, *args)

def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args):
"""
Expand All @@ -123,7 +123,7 @@ def __init__(self, network='bitcoin', base_url='', denominator=100000000, *args)
:type: str
:param base_url: Connection URL in format http(s)://user:password@host:port.
:type: str
:param denominator: Denominator for this currency. Should be always 100000000 (satoshis) for bitcoin
:param denominator: Denominator for this currency. Should be always 100000000 (Satoshi's) for bitcoin
:type: str
"""
if isinstance(network, Network):
Expand Down
8 changes: 4 additions & 4 deletions bitcoinlib/services/dashd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DashdClient(BaseClient):
"""

@staticmethod
def from_config(configfile=None, network='dash'):
def from_config(configfile=None, network='dash', **kargs):
"""
Read settings from dashd config file
Expand Down Expand Up @@ -104,9 +104,9 @@ def from_config(configfile=None, network='dash'):
elif 'externalip' in config['rpc']:
server = config.get('rpc', 'externalip')
url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port)
return DashdClient(network, url)
return DashdClient(network, url, **kargs)

def __init__(self, network='dash', base_url='', denominator=100000000, *args):
def __init__(self, network='dash', base_url='', denominator=100000000, **kargs):
"""
Open connection to dashcore node
Expand All @@ -123,7 +123,7 @@ def __init__(self, network='dash', base_url='', denominator=100000000, *args):
network = bdc.network
_logger.info("Connect to dashd")
self.proxy = AuthServiceProxy(base_url)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs)

def _parse_transaction(self, tx, block_height=None, get_input_values=True):
t = Transaction.parse_hex(tx['hex'], strict=self.strict, network=self.network)
Expand Down
8 changes: 4 additions & 4 deletions bitcoinlib/services/dogecoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DogecoindClient(BaseClient):
"""

@staticmethod
def from_config(configfile=None, network='dogecoin'):
def from_config(configfile=None, network='dogecoin', **kargs):
"""
Read settings from dogecoind config file
Expand Down Expand Up @@ -113,9 +113,9 @@ def from_config(configfile=None, network='dogecoin'):
server = _read_from_config(config, 'rpc', 'externalip', server)

url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port)
return DogecoindClient(network, url)
return DogecoindClient(network, url, **kargs)

def __init__(self, network='dogecoin', base_url='', denominator=100000000, *args):
def __init__(self, network='dogecoin', base_url='', denominator=100000000, **kargs):
"""
Open connection to dogecoin node
Expand All @@ -141,7 +141,7 @@ def __init__(self, network='dogecoin', base_url='', denominator=100000000, *args
"Please replace default password and set url in providers.json or dogecoin.conf file")
_logger.info("Connect to dogecoind")
self.proxy = AuthServiceProxy(base_url)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs)

def getutxos(self, address, after_txid='', max_txs=MAX_TRANSACTIONS):
txs = []
Expand Down
8 changes: 4 additions & 4 deletions bitcoinlib/services/litecoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LitecoindClient(BaseClient):
"""

@staticmethod
def from_config(configfile=None, network='litecoin'):
def from_config(configfile=None, network='litecoin', **kargs):
"""
Read settings from litecoind config file
Expand Down Expand Up @@ -112,9 +112,9 @@ def from_config(configfile=None, network='litecoin'):
server = _read_from_config(config, 'rpc', 'bind', server)
server = _read_from_config(config, 'rpc', 'externalip', server)
url = "http://%s:%s@%s:%s" % (config.get('rpc', 'rpcuser'), config.get('rpc', 'rpcpassword'), server, port)
return LitecoindClient(network, url)
return LitecoindClient(network, url, **kargs)

def __init__(self, network='litecoin', base_url='', denominator=100000000, *args):
def __init__(self, network='litecoin', base_url='', denominator=100000000, **kargs):
"""
Open connection to litecoin node
Expand All @@ -133,7 +133,7 @@ def __init__(self, network='litecoin', base_url='', denominator=100000000, *args
network = bdc.network
_logger.info("Connect to litecoind")
self.proxy = AuthServiceProxy(base_url)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, *args)
super(self.__class__, self).__init__(network, PROVIDERNAME, base_url, denominator, **kargs)

def getbalance(self, addresslist):
balance = 0
Expand Down
14 changes: 1 addition & 13 deletions bitcoinlib/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sqlalchemy import func
from bitcoinlib import services
from bitcoinlib.networks import Network
from bitcoinlib.encoding import to_bytes, int_to_varbyteint, varstr, varbyteint_to_int
from bitcoinlib.encoding import to_bytes, int_to_varbyteint, varstr
from bitcoinlib.db_cache import *
from bitcoinlib.transactions import Transaction, transaction_update_spents
from bitcoinlib.blocks import Block
Expand Down Expand Up @@ -144,12 +144,6 @@ def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, pr
else:
self._blockcount = self.blockcount()

def __exit__(self):
try:
self.cache.session.close()
except Exception:
pass

def _reset_results(self):
self.results = {}
self.errors = {}
Expand Down Expand Up @@ -694,12 +688,6 @@ def __init__(self, network, db_uri=''):
self.session = DbCache(db_uri=db_uri).session
self.network = network

def __exit__(self):
try:
self.session.close()
except Exception:
pass

def cache_enabled(self):
"""
Check if caching is enabled. Returns False if SERVICE_CACHING_ENABLED is False or no session is defined.
Expand Down
8 changes: 5 additions & 3 deletions bitcoinlib/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def __init__(self, prev_txid, output_n, keys=None, signatures=None, public_hash=
b'\0' not in self.witnesses:
self.signatures = [Signature.parse_bytes(self.witnesses[0])]
self.hash_type = self.signatures[0].hash_type
self.keys = [Key(self.witnesses[1], network=self.network)]
self.keys = [Key(self.witnesses[1], network=self.network, strict=self.strict)]

self.update_scripts(hash_type=self.hash_type)

Expand Down Expand Up @@ -1190,7 +1190,7 @@ def __init__(self, value, address='', public_hash=b'', public_key=b'', lock_scri
self.encoding = 'bech32'
self.public_hash = self.script.public_hash
if self.script.keys:
self.public_key = self.script.keys[0].public_hex
self.public_key = self.script.keys[0].public_byte
if self.script_type == 'p2tr':
self.witver = self.script.commands[0] - 80

Expand Down Expand Up @@ -1498,7 +1498,9 @@ def parse_bytesio(cls, rawtx, strict=True, network=DEFAULT_NETWORK):
inputs[n].script = script if not inputs[n].script else inputs[n].script + script
inputs[n].keys = script.keys
inputs[n].signatures = script.signatures
if script.script_types[0][:13] == 'p2sh_multisig' or script.script_types[0] =='signature_multisig':
if not script.script_types:
inputs[n].script_type = 'unknown'
elif script.script_types[0][:13] == 'p2sh_multisig' or script.script_types[0] =='signature_multisig':
inputs[n].script_type = 'p2sh_multisig'
inputs[n].redeemscript = inputs[n].witnesses[-1]
elif script.script_types[0] == 'p2tr_unlock':
Expand Down
Loading

0 comments on commit 79694d3

Please sign in to comment.