Add taproot support
Add Bech32m encoding/decoding for taproot addresses. The decoding was written by Pieter Wuille here: https://github.com/Bytom/python-bytomlib/blob/master/pybtmsdk/segwit_addr.py
The check if a PkScript represents an Bech32m script is done in the following:
- The script must start with 0x01
- The second part of the script must result in a valid taproot address when encoded
Notably, the check for Taproot is the last check before a script would be classifies as unknown, thus avoiding useless computation for checking if a tweaked public key might be encoded into a valid address.
Everything was squashed into one commit.
Hello @Nerolation! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
blockchain_parser/tests/test_taproot.py:
Line 12:35: W291 trailing whitespace Line 17:80: E501 line too long (87 > 79 characters) Line 27:1: E402 module level import not at top of file Line 30:80: E501 line too long (82 > 79 characters) Line 31:80: E501 line too long (90 > 79 characters) Line 32:80: E501 line too long (89 > 79 characters) Line 33:80: E501 line too long (87 > 79 characters) Line 34:80: E501 line too long (89 > 79 characters) Line 47:10: E111 indentation is not a multiple of four Line 47:10: E117 over-indented Line 50:56: E231 missing whitespace after ',' Line 50:80: E501 line too long (83 > 79 characters) Line 55:86: W292 no newline at end of file
- In the file
blockchain_parser/utils_taproot.py:
Line 125:9: E125 continuation line with same indent as next logical line Line 126:13: E117 over-indented
Comment last updated at 2022-08-29 12:40:17 UTC
Hi @alecalve , If you want me to provide further material (e.g. tests or test blk.dat files) I'm happy to help.
Thanks for your contribution, I think some tests would be warranted yes
Thanks for your contribution, I think some tests would be warranted yes
Fine, I will attach some! Best!
Hi @alecalve ! I verified some transactions that I took from here https://bitcoin.stackexchange.com/questions/110995/how-can-i-find-samples-for-p2tr-transactions-on-mainnet I put it into the tests folder. Works fine! Best!
This is the test output:
python3 test_taproot.py
Processing ../../blocks/blk02804.dat Tx ID: 33e794d097969002ee05d336686fc03c9e15a597c1b9827669460fac98799036 Input Tx ID: 5849051cf3ce36257a1d844e28959f368a35adc9520fb9679175f6cdf8c1f1d1 Value: 0 s Value: 67,230 s
Tx ID: 37777defed8717c581b4c0509329550e344bdc14ac38f71fc050096887e535c8 Input Tx ID: e700b7b330e4b56c5883d760f9cbe4fa47e0f62b350e108f1767bc07a4bbc07b Input Tx ID: e700b7b330e4b56c5883d760f9cbe4fa47e0f62b350e108f1767bc07a4bbc07b Address: bc1qzulaxy8fmvk8a92sec8s8u0xcqwcxw4fx037d8 Value: 965,300 s
Tx ID: 83c8e0289fecf93b5a284705396f5a652d9886cbd26236b0d647655ad8a37d82 Input Tx ID: 89654cf2132da47e4e9fae1ae37ba1c1cb09923b85fa351e5cc0a3539c52e21e Input Tx ID: 89654cf2132da47e4e9fae1ae37ba1c1cb09923b85fa351e5cc0a3539c52e21e Input Tx ID: 89654cf2132da47e4e9fae1ae37ba1c1cb09923b85fa351e5cc0a3539c52e21e Input Tx ID: 89654cf2132da47e4e9fae1ae37ba1c1cb09923b85fa351e5cc0a3539c52e21e Value: 10,911,232 s
Tx ID: 905ecdf95a84804b192f4dc221cfed4d77959b81ed66013a7e41a6e61e7ed530 Input Tx ID: 5b79f5d6039c188613342eb13961dd7d1e1a0f90023d3eaed25fc85a29201bb4 Value: 0 s
Tx ID: 2eb8dbaa346d4be4e82fe444c2f0be00654d8cfd8c4a9a61b11aeaab8c00b272 Input Tx ID: 09347a39275641e291dff2d8beded236b6b1bb0f4a6ae40a50f67dce02cf7323 Input Tx ID: 777c998695de4b7ecec54c058c73b2cab71184cf1655840935cd9388923dc288 Value: 0 s Address: 1Taproote7gvQGKz5g982ecSbPvqJhMUf Value: 1,154,670 s
Ready to rumble @alecalve