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

Method from_pubkey

bitcoin/wallet.py:198–216  ·  view source on GitHub ↗

Create a P2PKH bitcoin address from a pubkey Raises CBitcoinAddressError if pubkey is invalid, unless accept_invalid is True. The pubkey must be a bytes instance; CECKey instances are not accepted.

(cls, pubkey, accept_invalid=False)

Source from the content-addressed store, hash-verified

196
197 @classmethod
198 def from_pubkey(cls, pubkey, accept_invalid=False):
199 """Create a P2PKH bitcoin address from a pubkey
200
201 Raises CBitcoinAddressError if pubkey is invalid, unless accept_invalid
202 is True.
203
204 The pubkey must be a bytes instance; CECKey instances are not accepted.
205 """
206 if not isinstance(pubkey, bytes):
207 raise TypeError('pubkey must be bytes instance; got %r' % pubkey.__class__)
208
209 if not accept_invalid:
210 if not isinstance(pubkey, bitcoin.core.key.CPubKey):
211 pubkey = bitcoin.core.key.CPubKey(pubkey)
212 if not pubkey.is_fullyvalid:
213 raise CBitcoinAddressError('invalid pubkey')
214
215 pubkey_hash = bitcoin.core.Hash160(pubkey)
216 return P2PKHBitcoinAddress.from_bytes(pubkey_hash)
217
218 @classmethod
219 def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, accept_bare_checksig=True):

Callers 6

from_scriptPubKeyMethod · 0.80
VerifyMessageFunction · 0.80
TMethod · 0.80
print_verboseFunction · 0.80

Calls 2

from_bytesMethod · 0.45

Tested by 2

TMethod · 0.64