This simplifies the code and makes it more typesafe.
The plan is to use this enum in the TxInput class and eventually in coin dicts to replace the "p2pkh", "p2sh", "p2pk" and "coinbase" strings (utxo["type"]).
Depends on D14434
Differential D14436
[electrum] use an IntEnum for script types PiRK on Aug 30 2023, 14:45. Authored by Tags None Subscribers None
Details
This simplifies the code and makes it more typesafe. The plan is to use this enum in the TxInput class and eventually in coin dicts to replace the "p2pkh", "p2sh", "p2pk" and "coinbase" strings (utxo["type"]). Depends on D14434 python test_runner.py I also ran the new test_privkey_from_WIF_privkey before this commit, to check that the behavior didn't change. Run the application (electrum/electrum-abc), send a transaction to be sure the transaction construction/serialization/deserialization still works.
Diff Detail
Event TimelineComment Actions A short IntEnum demo: $ python Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from enum import IntEnum >>> >>> class ScriptType(IntEnum): ... p2pkh = 0 ... p2sh = 5 ... >>> >>> ScriptType.p2pkh <ScriptType.p2pkh: 0> >>> >>> ScriptType.p2pkh == 0 True >>> ScriptType.p2pkh.name 'p2pkh' >>> >>> ScriptType(5) <ScriptType.p2sh: 5> >>> >>> ScriptType(5) == ScriptType.p2sh True >>> >>> ScriptType["p2sh"] <ScriptType.p2sh: 5> >>> >>> ScriptType["p2sh"] == ScriptType.p2sh True >>> >>> issubclass(ScriptType, int) True >>> >>> isinstance(ScriptType.p2sh, int) True >>> Comment Actions name.lower() is no longer necessary now that I commited to keeping the enum names lowercase |