MCPcopy Create free account
hub / github.com/ElementsProject/elements / getnewdestination

Function getnewdestination

test/functional/test_framework/wallet.py:225–246  ·  view source on GitHub ↗

Generate a random destination of the specified type and return the corresponding public key, scriptPubKey and address. Supported types are 'legacy', 'p2sh-segwit' and 'bech32'. Can be used when a random destination is needed, but no compiled wallet is available (e.g. as r

(address_type='bech32', hrp='ert', version=235, prefix=75)

Source from the content-addressed store, hash-verified

223
224
225def getnewdestination(address_type='bech32', hrp='ert', version=235, prefix=75):
226 """Generate a random destination of the specified type and return the
227 corresponding public key, scriptPubKey and address. Supported types are
228 'legacy', 'p2sh-segwit' and 'bech32'. Can be used when a random
229 destination is needed, but no compiled wallet is available (e.g. as
230 replacement to the getnewaddress/getaddressinfo RPCs)."""
231 key = ECKey()
232 key.generate()
233 pubkey = key.get_pubkey().get_bytes()
234 if address_type == 'legacy':
235 scriptpubkey = key_to_p2pkh_script(pubkey)
236 address = key_to_p2pkh(pubkey, version=version)
237 elif address_type == 'p2sh-segwit':
238 scriptpubkey = key_to_p2sh_p2wpkh_script(pubkey)
239 address = key_to_p2sh_p2wpkh(pubkey, prefix=prefix)
240 elif address_type == 'bech32':
241 scriptpubkey = key_to_p2wpkh_script(pubkey)
242 address = key_to_p2wpkh(pubkey, hrp=hrp)
243 # TODO: also support bech32m (need to generate x-only-pubkey)
244 else:
245 assert False
246 return pubkey, scriptpubkey, address
247
248
249def address_to_scriptpubkey(address):

Callers 3

run_testMethod · 0.90
test_filterMethod · 0.90
run_testMethod · 0.90

Calls 10

generateMethod · 0.95
get_pubkeyMethod · 0.95
ECKeyClass · 0.90
key_to_p2pkh_scriptFunction · 0.90
key_to_p2pkhFunction · 0.90
key_to_p2sh_p2wpkhFunction · 0.90
key_to_p2wpkh_scriptFunction · 0.90
key_to_p2wpkhFunction · 0.90
get_bytesMethod · 0.45

Tested by 1

test_filterMethod · 0.72