btclib-org / btclib

btclib: a python3 library for 'bitcoin cryptography'
https://btclib.org
MIT License
100 stars 40 forks source link

Add `joinpsbts` functionality #76

Closed St333p closed 1 year ago

St333p commented 1 year ago

Bitcoin Core has a function that allows to merge multiple unsigned PSBTs into one which contains the union of inputs and outputs from the input PSBTs. This is relevant for every usecase in which the set of inputs and outputs of a transaction is collaboratively defined by a set of entities that do not necessarily have a coordinator; for instance it is often used in coinjoin/payjoin transactions.

This PR aims to bring a similar functionality to btclib, choosing flexibility where possible but striving to keep compliance with bitcoin core as the default behavior.

fametrano commented 1 year ago

please rebase and check that all new 5 GitHib actions succed

sourcery-ai[bot] commented 1 year ago

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 1.35%.

Quality metrics Before After Change
Complexity 1.96 ⭐ 2.08 ⭐ 0.12 👎
Method Length 85.88 🙂 93.24 🙂 7.36 👎
Working memory 7.51 🙂 7.71 🙂 0.20 👎
Quality 68.86% 🙂 67.51% 🙂 -1.35% 👎
Other metrics Before After Change
Lines 1728 2205 477
Changed files Quality Before Quality After Quality Change
btclib/bip32/key_origin.py 88.58% ⭐ 88.02% ⭐ -0.56% 👎
btclib/psbt/__init__.py 80.59% ⭐ 69.66% 🙂 -10.93% 👎
btclib/psbt/psbt.py 60.51% 🙂 61.12% 🙂 0.61% 👍
btclib/tx/__init__.py 94.23% ⭐ 91.08% ⭐ -3.15% 👎
btclib/tx/tx.py 80.51% ⭐ 74.62% 🙂 -5.89% 👎
tests/bip32/test_key_origin.py 68.39% 🙂 68.53% 🙂 0.14% 👍
tests/psbt/test_psbt.py 74.03% 🙂 71.98% 🙂 -2.05% 👎
tests/tx/test_tx.py 60.10% 🙂 59.35% 🙂 -0.75% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
btclib/psbt/psbt.py Psbt.assert_signable 22 😞 163 😞 11 😞 40.42% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
btclib/psbt/psbt.py Psbt.parse 10 🙂 188 😞 15 😞 41.77% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/tx/test_tx.py test_tx 0 ⭐ 697 ⛔ 12 😞 46.17% 😞 Try splitting into smaller methods. Extract out complex expressions
btclib/psbt/psbt.py join_psbts 5 ⭐ 158 😞 16 ⛔ 48.14% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/psbt/test_psbt.py test_vectors_bip174 5 ⭐ 208 ⛔ 12 😞 49.23% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!