MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / from_scriptPubKey

Method from_scriptPubKey

bitcoin/wallet.py:84–101  ·  view source on GitHub ↗

Convert a scriptPubKey to a CBech32BitcoinAddress Returns a CBech32BitcoinAddress subclass, either P2WSHBitcoinAddress or P2WPKHBitcoinAddress. If the scriptPubKey is not recognized CBitcoinAddressError will be raised.

(cls, scriptPubKey)

Source from the content-addressed store, hash-verified

82
83 @classmethod
84 def from_scriptPubKey(cls, scriptPubKey):
85 """Convert a scriptPubKey to a CBech32BitcoinAddress
86
87 Returns a CBech32BitcoinAddress subclass, either P2WSHBitcoinAddress or
88 P2WPKHBitcoinAddress. If the scriptPubKey is not recognized
89 CBitcoinAddressError will be raised.
90 """
91 try:
92 return P2WSHBitcoinAddress.from_scriptPubKey(scriptPubKey)
93 except CBitcoinAddressError:
94 pass
95
96 try:
97 return P2WPKHBitcoinAddress.from_scriptPubKey(scriptPubKey)
98 except CBitcoinAddressError:
99 pass
100
101 raise CBitcoinAddressError('scriptPubKey not a valid bech32-encoded address')
102
103
104class CBase58BitcoinAddress(bitcoin.base58.CBase58Data, CBitcoinAddress):

Callers

nothing calls this directly

Calls 2

from_scriptPubKeyMethod · 0.45

Tested by

no test coverage detected