MCPcopy
hub / github.com/petertodd/python-bitcoinlib / P2WPKHBitcoinAddress

Class P2WPKHBitcoinAddress

bitcoin/wallet.py:304–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302
303
304class P2WPKHBitcoinAddress(CBech32BitcoinAddress):
305
306 @classmethod
307 def from_scriptPubKey(cls, scriptPubKey):
308 """Convert a scriptPubKey to a P2WPKH address
309
310 Raises CBitcoinAddressError if the scriptPubKey isn't of the correct
311 form.
312 """
313 if scriptPubKey.is_witness_v0_keyhash():
314 return cls.from_bytes(0, scriptPubKey[2:22])
315 else:
316 raise CBitcoinAddressError('not a P2WPKH scriptPubKey')
317
318 def to_scriptPubKey(self):
319 """Convert an address to a scriptPubKey"""
320 assert self.witver == 0
321 return script.CScript([0, self])
322
323 def to_redeemScript(self):
324 return script.CScript([script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY, script.OP_CHECKSIG])
325
326class CKey(object):
327 """An encapsulated private key

Callers 1

spend-p2wpkh.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected