Skip to content

Conversation

JAGADISHSUNILPEDNEKAR
Copy link
Contributor

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.py module with the UnifiedAddress class
  • 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
Screenshot 2025-03-30 at 12 59 05 AM

@JAGADISHSUNILPEDNEKAR
Copy link
Contributor Author

HI @karask
Just checking on this PR

@karask
Copy link
Owner

karask commented May 8, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants