From bd3607dac7ba52d145bd9a87bdb7ae36b4a5f0b9 Mon Sep 17 00:00:00 2001 From: JSwambo Date: Mon, 9 Mar 2020 13:18:39 +0000 Subject: [PATCH 01/17] Fix file location of .cookie when on testnet --- bitcoin/rpc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index 51f24ac9..4ff8fdd2 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -170,7 +170,9 @@ def __init__(self, ('http', conf['rpchost'], conf['rpcport'])) cookie_dir = conf.get('datadir', os.path.dirname(btc_conf_file)) - if bitcoin.params.NAME != "mainnet": + if bitcoin.params.NAME == 'testnet': + cookie_dir = os.path.join(cookie_dir, 'testnet3') + elif bitcoin.params.NAME == 'regtest': cookie_dir = os.path.join(cookie_dir, bitcoin.params.NAME) cookie_file = os.path.join(cookie_dir, ".cookie") try: From e3f1a0383e8ea96a7dafd74403c41c653eb1c4c0 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Wed, 26 Apr 2023 21:34:07 +0000 Subject: [PATCH 02/17] Minor: doc formatting fix --- bitcoin/core/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bitcoin/core/__init__.py b/bitcoin/core/__init__.py index 80cb6367..7c2d5a85 100644 --- a/bitcoin/core/__init__.py +++ b/bitcoin/core/__init__.py @@ -434,9 +434,11 @@ def from_tx(cls, tx): return cls(tx.vin, tx.vout, tx.nLockTime, tx.nVersion, tx.wit) def GetTxid(self): - """Get the transaction ID. This differs from the transactions hash as - given by GetHash. GetTxid excludes witness data, while GetHash - includes it. """ + """Get the transaction ID. + + This differs from the transactions hash as given by GetHash. GetTxid + excludes witness data, while GetHash includes it. + """ if self.wit != CTxWitness(): txid = Hash(CTransaction(self.vin, self.vout, self.nLockTime, self.nVersion).serialize()) From 70d9cb5e7bbfd8e228cbe6878a2517cb3250521d Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 27 Apr 2023 21:04:22 +0000 Subject: [PATCH 03/17] Add calc_weight() to CTransaction --- bitcoin/core/__init__.py | 18 ++++++++++++++++++ bitcoin/tests/test_transactions.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/bitcoin/core/__init__.py b/bitcoin/core/__init__.py index 7c2d5a85..538501af 100644 --- a/bitcoin/core/__init__.py +++ b/bitcoin/core/__init__.py @@ -446,6 +446,24 @@ def GetTxid(self): txid = Hash(self.serialize()) return txid + def calc_weight(self): + """Calculate the transaction weight, as defined by BIP141. + + The transaction must contain at least one input and one output. + """ + # Not clear how calc_weight() should be defined for the zero vin/vout + # cases, so punting on that decision for now. + assert len(self.vin) > 0 + assert len(self.vout) > 0 + + # This special case isn't strictly necessary. But saves on serializing + # the transaction twice in the no-witness case. + if self.wit.is_null(): + return len(self.serialize()) * 4 + else: + stripped = CTransaction(self.vin, self.vout, self.nLockTime, self.nVersion) + return len(stripped.serialize()) * 3 + len(self.serialize()) + @__make_mutable class CMutableTransaction(CTransaction): """A mutable transaction""" diff --git a/bitcoin/tests/test_transactions.py b/bitcoin/tests/test_transactions.py index 2753e9fe..c223b9dd 100644 --- a/bitcoin/tests/test_transactions.py +++ b/bitcoin/tests/test_transactions.py @@ -150,3 +150,24 @@ def test_tx_invalid(self): flags.add(SCRIPT_VERIFY_P2SH) VerifyScript(tx.vin[i].scriptSig, prevouts[tx.vin[i].prevout], tx, i, flags=flags) + + def test_calc_weight(self): + # test vectors taken from rust-bitcoin + txs = [ + # one segwit input (P2WPKH) + ('020000000001018a763b78d3e17acea0625bf9e52b0dc1beb2241b2502185348ba8ff4a253176e0100000000ffffffff0280d725000000000017a914c07ed639bd46bf7087f2ae1dfde63b815a5f8b488767fda20300000000160014869ec8520fa2801c8a01bfdd2e82b19833cd0daf02473044022016243edad96b18c78b545325aaff80131689f681079fb107a67018cb7fb7830e02205520dae761d89728f73f1a7182157f6b5aecf653525855adb7ccb998c8e6143b012103b9489bde92afbcfa85129a82ffa512897105d1a27ad9806bded27e0532fc84e700000000', 565), + # one segwit input (P2WSH) + ('01000000000101a3ccad197118a2d4975fadc47b90eacfdeaf8268adfdf10ed3b4c3b7e1ad14530300000000ffffffff0200cc5501000000001976a91428ec6f21f4727bff84bb844e9697366feeb69f4d88aca2a5100d00000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220548f11130353b3a8f943d2f14260345fc7c20bde91704c9f1cbb5456355078cd0220383ed4ed39b079b618bcb279bbc1f2ca18cb028c4641cb522c9c5868c52a0dc20147304402203c332ecccb3181ca82c0600520ee51fee80d3b4a6ab110945e59475ec71e44ac0220679a11f3ca9993b04ccebda3c834876f353b065bb08f50076b25f5bb93c72ae1016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000', 766), + # one segwit input (P2WPKH) and two legacy inputs (P2PKH) + ('010000000001036b6b6ac7e34e97c53c1cc74c99c7948af2e6aac75d8778004ae458d813456764000000006a473044022001deec7d9075109306320b3754188f81a8236d0d232b44bc69f8309115638b8f02204e17a5194a519cf994d0afeea1268740bdc10616b031a521113681cc415e815c012103488d3272a9fad78ee887f0684cb8ebcfc06d0945e1401d002e590c7338b163feffffffffc75bd7aa6424aee972789ec28ba181254ee6d8311b058d165bd045154d7660b0000000006b483045022100c8641bcbee3e4c47a00417875015d8c5d5ea918fb7e96f18c6ffe51bc555b401022074e2c46f5b1109cd79e39a9aa203eadd1d75356415e51d80928a5fb5feb0efee0121033504b4c6dfc3a5daaf7c425aead4c2dbbe4e7387ce8e6be2648805939ecf7054ffffffff494df3b205cd9430a26f8e8c0dc0bb80496fbc555a524d6ea307724bc7e60eee0100000000ffffffff026d861500000000001976a9145c54ed1360072ebaf56e87693b88482d2c6a101588ace407000000000000160014761e31e2629c6e11936f2f9888179d60a5d4c1f900000247304402201fa38a67a63e58b67b6cfffd02f59121ca1c8a1b22e1efe2573ae7e4b4f06c2b022002b9b431b58f6e36b3334fb14eaecee7d2f06967a77ef50d8d5f90dda1057f0c01210257dc6ce3b1100903306f518ee8fa113d778e403f118c080b50ce079fba40e09a00000000', 1755), + # three legacy inputs (P2PKH) + ('0100000003e4d7be4314204a239d8e00691128dca7927e19a7339c7948bde56f669d27d797010000006b483045022100b988a858e2982e2daaf0755b37ad46775d6132057934877a5badc91dee2f66ff022020b967c1a2f0916007662ec609987e951baafa6d4fda23faaad70715611d6a2501210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff9e22eb1b3f24c260187d716a8a6c2a7efb5af14a30a4792a6eeac3643172379c000000006a47304402207df07f0cd30dca2cf7bed7686fa78d8a37fe9c2254dfdca2befed54e06b779790220684417b8ff9f0f6b480546a9e90ecee86a625b3ea1e4ca29b080da6bd6c5f67e01210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff1123df3bfb503b59769731da103d4371bc029f57979ebce68067768b958091a1000000006a47304402207a016023c2b0c4db9a7d4f9232fcec2193c2f119a69125ad5bcedcba56dd525e02206a734b3a321286c896759ac98ebfd9d808df47f1ce1fbfbe949891cc3134294701210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff0200c2eb0b000000001976a914e5eb3e05efad136b1405f5c2f9adb14e15a35bb488ac88cfff1b000000001976a9144846db516db3130b7a3c92253599edec6bc9630b88ac00000000', 2080), + # one segwit input (P2TR) + ('01000000000101b5cee87f1a60915c38bb0bc26aaf2b67be2b890bbc54bb4be1e40272e0d2fe0b0000000000ffffffff025529000000000000225120106daad8a5cb2e6fc74783714273bad554a148ca2d054e7a19250e9935366f3033760000000000002200205e6d83c44f57484fd2ef2a62b6d36cdcd6b3e06b661e33fd65588a28ad0dbe060141df9d1bfce71f90d68bf9e9461910b3716466bfe035c7dbabaa7791383af6c7ef405a3a1f481488a91d33cd90b098d13cb904323a3e215523aceaa04e1bb35cdb0100000000', 617), + # one legacy input (P2PKH) + ('0100000001c336895d9fa674f8b1e294fd006b1ac8266939161600e04788c515089991b50a030000006a47304402204213769e823984b31dcb7104f2c99279e74249eacd4246dabcf2575f85b365aa02200c3ee89c84344ae326b637101a92448664a8d39a009c8ad5d147c752cbe112970121028b1b44b4903c9103c07d5a23e3c7cf7aeb0ba45ddbd2cfdce469ab197381f195fdffffff040000000000000000536a4c5058325bb7b7251cf9e36cac35d691bd37431eeea426d42cbdecca4db20794f9a4030e6cb5211fabf887642bcad98c9994430facb712da8ae5e12c9ae5ff314127d33665000bb26c0067000bb0bf00322a50c300000000000017a9145ca04fdc0a6d2f4e3f67cfeb97e438bb6287725f8750c30000000000001976a91423086a767de0143523e818d4273ddfe6d9e4bbcc88acc8465003000000001976a914c95cbacc416f757c65c942f9b6b8a20038b9b12988ac00000000', 1396), + ] + + for tx, expected_wu in txs: + tx = CTransaction.deserialize(x(tx)) + self.assertEqual(tx.calc_weight(), expected_wu) From fbbe92452a05b8bed8a02de19442621b9c448562 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 27 Apr 2023 22:48:33 +0000 Subject: [PATCH 04/17] Remove out of date years on copyright notices The notices themselves are for the most part not even required: https://opensource.com/article/20/10/copyright-notices-open-source-software Also duplicative of the information in git, which is the authoritive source. --- bitcoin/__init__.py | 2 +- bitcoin/bech32.py | 2 +- bitcoin/bloom.py | 2 +- bitcoin/core/__init__.py | 2 +- bitcoin/core/_bignum.py | 2 +- bitcoin/core/script.py | 2 +- bitcoin/core/scripteval.py | 2 +- bitcoin/core/serialize.py | 2 +- bitcoin/messages.py | 2 +- bitcoin/net.py | 2 +- bitcoin/signature.py | 2 +- bitcoin/signmessage.py | 4 ++-- bitcoin/tests/__init__.py | 2 +- bitcoin/tests/test_base58.py | 2 +- bitcoin/tests/test_bech32.py | 2 +- bitcoin/tests/test_bloom.py | 2 +- bitcoin/tests/test_checkblock.py | 2 +- bitcoin/tests/test_core.py | 2 +- bitcoin/tests/test_key.py | 2 +- bitcoin/tests/test_messages.py | 2 +- bitcoin/tests/test_net.py | 2 +- bitcoin/tests/test_ripemd160.py | 2 +- bitcoin/tests/test_rpc.py | 2 +- bitcoin/tests/test_script.py | 2 +- bitcoin/tests/test_scripteval.py | 2 +- bitcoin/tests/test_segwit.py | 2 +- bitcoin/tests/test_serialize.py | 2 +- bitcoin/tests/test_signmessage.py | 2 +- bitcoin/tests/test_transactions.py | 2 +- bitcoin/tests/test_wallet.py | 2 +- bitcoin/wallet.py | 2 +- 31 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bitcoin/__init__.py b/bitcoin/__init__.py index 90bc4a15..a8d2250e 100644 --- a/bitcoin/__init__.py +++ b/bitcoin/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2018 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/bech32.py b/bitcoin/bech32.py index f140b0ae..1ef88b57 100644 --- a/bitcoin/bech32.py +++ b/bitcoin/bech32.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/bloom.py b/bitcoin/bloom.py index 50073dc3..d0e3b765 100644 --- a/bitcoin/bloom.py +++ b/bitcoin/bloom.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/core/__init__.py b/bitcoin/core/__init__.py index 538501af..ea578f9b 100644 --- a/bitcoin/core/__init__.py +++ b/bitcoin/core/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2017 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/core/_bignum.py b/bitcoin/core/_bignum.py index 6edd7065..9b9f11ac 100644 --- a/bitcoin/core/_bignum.py +++ b/bitcoin/core/_bignum.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/core/script.py b/bitcoin/core/script.py index aa2cff87..c0058a41 100644 --- a/bitcoin/core/script.py +++ b/bitcoin/core/script.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/core/scripteval.py b/bitcoin/core/scripteval.py index e93e8720..9e38f792 100644 --- a/bitcoin/core/scripteval.py +++ b/bitcoin/core/scripteval.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2017 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/core/serialize.py b/bitcoin/core/serialize.py index b12c0239..ac75da34 100644 --- a/bitcoin/core/serialize.py +++ b/bitcoin/core/serialize.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2018 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/messages.py b/bitcoin/messages.py index edb7beb1..b4d7604f 100644 --- a/bitcoin/messages.py +++ b/bitcoin/messages.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/net.py b/bitcoin/net.py index 4d98fdd9..7348dd74 100644 --- a/bitcoin/net.py +++ b/bitcoin/net.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/signature.py b/bitcoin/signature.py index fd1d7404..89434b7a 100644 --- a/bitcoin/signature.py +++ b/bitcoin/signature.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/signmessage.py b/bitcoin/signmessage.py index 38c20dc8..d893f07a 100644 --- a/bitcoin/signmessage.py +++ b/bitcoin/signmessage.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # @@ -57,4 +57,4 @@ def __str__(self): return self.message.decode('ascii') def __repr__(self): - return 'BitcoinMessage(%s, %s)' % (self.magic, self.message) \ No newline at end of file + return 'BitcoinMessage(%s, %s)' % (self.magic, self.message) diff --git a/bitcoin/tests/__init__.py b/bitcoin/tests/__init__.py index 770ca60a..0ce1c371 100644 --- a/bitcoin/tests/__init__.py +++ b/bitcoin/tests/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_base58.py b/bitcoin/tests/test_base58.py index 74840205..59091034 100644 --- a/bitcoin/tests/test_base58.py +++ b/bitcoin/tests/test_base58.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_bech32.py b/bitcoin/tests/test_bech32.py index 9d7db073..06da1244 100644 --- a/bitcoin/tests/test_bech32.py +++ b/bitcoin/tests/test_bech32.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_bloom.py b/bitcoin/tests/test_bloom.py index f637600d..436a97ea 100644 --- a/bitcoin/tests/test_bloom.py +++ b/bitcoin/tests/test_bloom.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_checkblock.py b/bitcoin/tests/test_checkblock.py index a2bf9ad0..10c1c9a9 100644 --- a/bitcoin/tests/test_checkblock.py +++ b/bitcoin/tests/test_checkblock.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_core.py b/bitcoin/tests/test_core.py index 66ab16dd..ff16ca56 100644 --- a/bitcoin/tests/test_core.py +++ b/bitcoin/tests/test_core.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_key.py b/bitcoin/tests/test_key.py index 2526b948..6cb18b54 100644 --- a/bitcoin/tests/test_key.py +++ b/bitcoin/tests/test_key.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_messages.py b/bitcoin/tests/test_messages.py index b5e115dd..8b201dc2 100644 --- a/bitcoin/tests/test_messages.py +++ b/bitcoin/tests/test_messages.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_net.py b/bitcoin/tests/test_net.py index 80f6d775..74a81325 100644 --- a/bitcoin/tests/test_net.py +++ b/bitcoin/tests/test_net.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_ripemd160.py b/bitcoin/tests/test_ripemd160.py index a135b55e..df1374d9 100644 --- a/bitcoin/tests/test_ripemd160.py +++ b/bitcoin/tests/test_ripemd160.py @@ -21,4 +21,4 @@ def test_ripemd160(self): (b"1234567890" * 8, "9b752e45573d4b39f4dbd3323cab82bf63326bfb"), (b"a" * 1000000, "52783243c1697bdbe16d37f97f68f08325dc1528") ]: - self.assertEqual(ripemd160(msg).hex(), hexout) \ No newline at end of file + self.assertEqual(ripemd160(msg).hex(), hexout) diff --git a/bitcoin/tests/test_rpc.py b/bitcoin/tests/test_rpc.py index 716fb816..743db350 100644 --- a/bitcoin/tests/test_rpc.py +++ b/bitcoin/tests/test_rpc.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_script.py b/bitcoin/tests/test_script.py index ca4598ff..1ca62eb0 100644 --- a/bitcoin/tests/test_script.py +++ b/bitcoin/tests/test_script.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_scripteval.py b/bitcoin/tests/test_scripteval.py index 59f12182..a1762020 100644 --- a/bitcoin/tests/test_scripteval.py +++ b/bitcoin/tests/test_scripteval.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2017 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_segwit.py b/bitcoin/tests/test_segwit.py index b2a0e1c8..76b89de0 100644 --- a/bitcoin/tests/test_segwit.py +++ b/bitcoin/tests/test_segwit.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_serialize.py b/bitcoin/tests/test_serialize.py index cc1056b8..2031b8ac 100644 --- a/bitcoin/tests/test_serialize.py +++ b/bitcoin/tests/test_serialize.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_signmessage.py b/bitcoin/tests/test_signmessage.py index a643f574..bfdc3efb 100644 --- a/bitcoin/tests/test_signmessage.py +++ b/bitcoin/tests/test_signmessage.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_transactions.py b/bitcoin/tests/test_transactions.py index c223b9dd..bdff08f2 100644 --- a/bitcoin/tests/test_transactions.py +++ b/bitcoin/tests/test_transactions.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/tests/test_wallet.py b/bitcoin/tests/test_wallet.py index c178cd51..68ba69f0 100644 --- a/bitcoin/tests/test_wallet.py +++ b/bitcoin/tests/test_wallet.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # diff --git a/bitcoin/wallet.py b/bitcoin/wallet.py index eb5eeb98..292d6592 100644 --- a/bitcoin/wallet.py +++ b/bitcoin/wallet.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 The python-bitcoinlib developers +# Copyright (C) The python-bitcoinlib developers # # This file is part of python-bitcoinlib. # From bca1e7fcc0a086e75e913a57cdf422afa7c7b7e5 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 27 Apr 2023 22:54:25 +0000 Subject: [PATCH 05/17] Update guidance on Core RPC compatibility --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58e11fcb..59c79f05 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ focus on providing tools to manipulate the internals of how Bitcoin works. sudo apt-get install libssl-dev -The RPC interface, `bitcoin.rpc`, is designed to work with Bitcoin Core v0.16.0. +The RPC interface, `bitcoin.rpc`, should work with Bitcoin Core v24.0 or later. Older versions may work but there do exist some incompatibilities. From 88907a8c3b235fe263c3955c449a6cb2802f8fa2 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 27 Apr 2023 22:54:59 +0000 Subject: [PATCH 06/17] Minor: formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 59c79f05..e112c0df 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ system, you can run unit tests for multiple Python versions: HTML coverage reports can then be found in the htmlcov/ subdirectory. + ## Documentation Sphinx documentation is in the "doc" subdirectory. Run "make help" from there From 4ccb7534dff949412ead8ae4bdf5b2adef441b7e Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Thu, 27 Apr 2023 22:59:25 +0000 Subject: [PATCH 07/17] Release v0.12.1 --- bitcoin/__init__.py | 2 +- release-notes.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bitcoin/__init__.py b/bitcoin/__init__.py index a8d2250e..c9330107 100644 --- a/bitcoin/__init__.py +++ b/bitcoin/__init__.py @@ -15,7 +15,7 @@ # Note that setup.py can break if __init__.py imports any external # dependencies, as these might not be installed when setup.py runs. In this # case __version__ could be moved to a separate version.py and imported here. -__version__ = '0.12.0' +__version__ = '0.12.1' class MainParams(bitcoin.core.CoreMainParams): MESSAGE_START = b'\xf9\xbe\xb4\xd9' diff --git a/release-notes.md b/release-notes.md index 91e51cd3..8258fc78 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,5 +1,10 @@ # python-bitcoinlib release notes +## v0.12.1 + +* Added `calc_weight()` method. +* (Hopefully) resolved failure to find `libeay32` on Windows. + ## v0.12.0 * `CECKey` now rejects secrets that aren't exactly 32 bytes From 51eeb58e04b07bf2b25f2be20293fa182cf0f93a Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Sat, 3 Jun 2023 18:27:17 +0000 Subject: [PATCH 08/17] Release v0.12.2 --- bitcoin/__init__.py | 2 +- release-notes.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bitcoin/__init__.py b/bitcoin/__init__.py index c9330107..dcb02de9 100644 --- a/bitcoin/__init__.py +++ b/bitcoin/__init__.py @@ -15,7 +15,7 @@ # Note that setup.py can break if __init__.py imports any external # dependencies, as these might not be installed when setup.py runs. In this # case __version__ could be moved to a separate version.py and imported here. -__version__ = '0.12.1' +__version__ = '0.12.2' class MainParams(bitcoin.core.CoreMainParams): MESSAGE_START = b'\xf9\xbe\xb4\xd9' diff --git a/release-notes.md b/release-notes.md index 8258fc78..5d5b14ee 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,5 +1,9 @@ # python-bitcoinlib release notes +## v0.12.2 + +* Fixed RPC cookie location for testnet + ## v0.12.1 * Added `calc_weight()` method. From 173a73e74781dcd2edce120d8685550a88a73189 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Fri, 8 Dec 2023 10:33:55 +0000 Subject: [PATCH 09/17] 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 Date: Mon, 6 May 2024 15:38:05 +0200 Subject: [PATCH 10/17] 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 Date: Tue, 4 Jun 2024 13:46:44 +0200 Subject: [PATCH 11/17] 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 import lnprototest /home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/__init__.py:15: in from .event import ( /home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/event.py:16: in from .namespace import namespace /home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/namespace.py:6: in from .signature import SigType /home/vincent/.cache/pypoetry/virtualenvs/lampo-lnprototest-IQvPSNpc-py3.11/lib/python3.11/site-packages/lnprototest/signature.py:5: in 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 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 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 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 _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 --- 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 Date: Wed, 30 Oct 2024 03:06:54 +0200 Subject: [PATCH 12/17] 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 Date: Mon, 25 Nov 2024 08:40:47 -0500 Subject: [PATCH 13/17] 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 Date: Mon, 25 Nov 2024 09:00:27 -0500 Subject: [PATCH 14/17] 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 15/17] 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 Date: Fri, 14 Mar 2025 19:50:59 +0000 Subject: [PATCH 16/17] 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 Date: Fri, 14 Mar 2025 19:54:07 +0000 Subject: [PATCH 17/17] 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": []}