Page MenuHomePhabricator

[electrum] move some methods from Transaction to TxInput
ClosedPublic

Authored by PiRK on Sep 15 2023, 16:00.

Details

Summary

Remove some code duplication and move code that works purely on inputs to the TxInput class.
Keep some shortcuts/helpers in Transaction. We can remove them (and avoid a dict -> TxInput conversion) when Transaction entirely works with TxInputs instead of coin dicts.

The multisig_script function can be converted to using and returning bytes to reduce the number of needed conversions, now that it is mainly called in TxInput

Depends on D14493

Test Plan

python test_runner.py

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Sep 15 2023, 16:00

do we need to preserve sign_schnorr as a param in so many places? could we just have electrumabc always sign schnorr unless there was some tx type that didn't support it?

electrum/electrumabc/transaction.py
946 ↗(On Diff #42231)

are we ultimately converting everything away from .hex() and to bytes? Is this change a consequence of the specific improvement targeted in this diff? Is it a general benefit?

Still some other instances of .hex() in this file.

electrum/electrumabc/transaction.py
946 ↗(On Diff #42231)

Yes, we are ultimately removing the use of hex strings in the codebase, and only converting hex <-> bytes when reading/writing json or saving transactions to files.

bytes use only half as much memory and are faster to work with, so this will improve the performance.

Also there is already a lot of places that do internal conversions back and forth, because currently the codebase is not consistent, so picking one everywhere is a benefit in itself, no matter which one we pick.

do we need to preserve sign_schnorr as a param in so many places? could we just have electrumabc always sign schnorr unless there was some tx type that didn't support it?

There are still some wallet types that don't support schnorr signing, such as hardware wallets and multisig wallets.

This revision is now accepted and ready to land.Sep 16 2023, 14:27