Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
c1c0239
Add PSBT (BIP-174) support
JAGADISHSUNILPEDNEKAR Mar 8, 2025
45e90d9
Merge branch 'master' into add-psbt-support
JAGADISHSUNILPEDNEKAR Mar 8, 2025
0b60d97
Address maintainer feedback: clean init.py, revert block.py changes, …
JAGADISHSUNILPEDNEKAR Mar 18, 2025
8e22601
Address PR feedback: Clean up code, revert block.py, add testing docs…
JAGADISHSUNILPEDNEKAR Mar 18, 2025
f9ef8f8
Remove unnecessary files as requested
JAGADISHSUNILPEDNEKAR Mar 19, 2025
0a6cc39
Focus PR on PSBT implementation only, revert unrelated changes
JAGADISHSUNILPEDNEKAR Mar 19, 2025
f1ba68a
Focus PR on PSBT implementation only, reverted unrelated changes
JAGADISHSUNILPEDNEKAR Mar 19, 2025
eb02f2f
Focus PR on PSBT implementation only, reverted many more unrelated c…
JAGADISHSUNILPEDNEKAR Mar 19, 2025
6d1e3ef
Simplify PR to focus on PSBT: remove unnecessary files, revert testin…
JAGADISHSUNILPEDNEKAR Mar 19, 2025
2d2e9b3
Focus PR on PSBT implementation only: keep only necessary changes for…
JAGADISHSUNILPEDNEKAR Mar 19, 2025
9c7e180
Fix test issues with transaction serialization for PSBT implementation
JAGADISHSUNILPEDNEKAR Mar 20, 2025
34b7ea3
Remove non-PSBT related files from PR
JAGADISHSUNILPEDNEKAR Mar 20, 2025
1da9864
Remove remaining non-PSBT files and make PSBT implementation self-con…
JAGADISHSUNILPEDNEKAR Mar 20, 2025
367b714
Removed test files
JAGADISHSUNILPEDNEKAR Mar 20, 2025
a0e1972
Removed some more test files
JAGADISHSUNILPEDNEKAR Mar 20, 2025
d1a3676
Fixed PSBT tests to be fully independent of helper files
JAGADISHSUNILPEDNEKAR Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions bitcoinutils/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,11 @@ def to_hash160(self, compressed: bool = True) -> str:

def get_address(self, compressed: bool = True) -> P2pkhAddress:
"""Returns the corresponding P2PKH Address (default compressed)"""

hash160 = self._to_hash160(compressed)
addr_string_hex = b_to_h(hash160)
return P2pkhAddress(hash160=addr_string_hex)

# Directly create the address using from_hash160 class method
return P2pkhAddress.from_hash160(addr_string_hex)

def get_segwit_address(self) -> P2wpkhAddress:
"""Returns the corresponding P2WPKH address
Expand Down Expand Up @@ -1086,9 +1087,24 @@ class P2pkhAddress(Address):
"""

def __init__(
self, address: Optional[str] = None, hash160: Optional[str] = None
self,
address: Optional[str] = None,
hash160: Optional[str] = None,
script: Optional[Script] = None,
) -> None:
super().__init__(address=address, hash160=hash160)
# Call the parent class initializer with all the expected parameters
super().__init__(address=address, hash160=hash160, script=script)

@classmethod
def from_hash160(cls, hash160: str) -> 'P2pkhAddress':
"""Creates a P2pkhAddress from a hash160 hex string"""
return cls(hash160=hash160)

# Added for PSBT support
@classmethod
def from_public_key(cls, pubkey):
"""Backward compatibility method to create P2pkhAddress from public key."""
return pubkey.get_address()

def to_script_pub_key(self) -> Script:
"""Returns the scriptPubKey (P2PKH) that corresponds to this address"""
Expand Down Expand Up @@ -1323,6 +1339,12 @@ def get_type(self) -> str:
"""Returns the type of address"""
return self.version

# Added for PSBT support
@classmethod
def from_public_key(cls, pubkey):
"""Backward compatibility method to create P2wpkhAddress from public key."""
return pubkey.get_segwit_address()


class P2wshAddress(SegwitAddress):
"""Encapsulates a P2WSH address.
Expand Down Expand Up @@ -1409,4 +1431,4 @@ def main():


if __name__ == "__main__":
main()
main()
Loading