python-bitcoin-utils
python-bitcoin-utils copied to clipboard
TODO : Implement Unified Address Object for Multi-Type Address Support
Unified Address Object Implementation
This PR introduces a new UnifiedAddress class that provides a unified way to handle all Bitcoin address types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR) and enables conversion between compatible address types.
Changes:
- Created a new
address.pymodule with theUnifiedAddressclass - Added support for detecting address types automatically
- Implemented conversion logic between compatible address formats
- Added functionality to create addresses from various sources (strings, hashes, scripts, witness programs)
- Added comprehensive tests for all address functionality
Key Features:
- Simplified API for handling different address types uniformly
- Easy conversion between address formats (e.g., P2PKH → P2WPKH)
- Support for nested SegWit addresses (P2SH-P2WPKH, P2SH-P2WSH)
- Complete type-hinting for better development experience
- Comprehensive validation of address formats and conversions
Example Usage:
# Create from existing addresses
unified = UnifiedAddress(p2pkh_address)
# Convert between address types
p2wpkh = unified.to_address_type(P2WPKH_ADDRESS_V0)
# Create from address string with auto-detection
address = UnifiedAddress.from_address("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx")
All the tests pass
HI @karask Just checking on this PR
Not sure that a unified object is required. The TODO mentions that but it was meant to generalise the existing Address object and see how to clean it up. I feel like this change adds more complexity for the user.
I will keep it here and re-examine it later. Thanks for the contribution.