Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/wallet_util.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin Core developers | # Copyright (c) 2018 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Useful util functions for testing the wallet""" | """Useful util functions for testing the wallet""" | ||||
from collections import namedtuple | from collections import namedtuple | ||||
from test_framework.address import ( | from test_framework.address import ( | ||||
key_to_p2pkh, | key_to_p2pkh, | ||||
script_to_p2sh, | script_to_p2sh, | ||||
) | ) | ||||
from test_framework.key import ( | |||||
bytes_to_wif, | |||||
ECKey, | |||||
) | |||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
OP_2, | OP_2, | ||||
OP_3, | OP_3, | ||||
OP_CHECKMULTISIG, | OP_CHECKMULTISIG, | ||||
OP_CHECKSIG, | OP_CHECKSIG, | ||||
OP_DUP, | OP_DUP, | ||||
OP_EQUAL, | OP_EQUAL, | ||||
Show All 24 Lines | def get_key(node): | ||||
pkh = hash160(hex_str_to_bytes(pubkey)) | pkh = hash160(hex_str_to_bytes(pubkey)) | ||||
return Key(privkey=node.dumpprivkey(addr), | return Key(privkey=node.dumpprivkey(addr), | ||||
pubkey=pubkey, | pubkey=pubkey, | ||||
p2pkh_script=CScript( | p2pkh_script=CScript( | ||||
[OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), | [OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), | ||||
p2pkh_addr=key_to_p2pkh(pubkey)) | p2pkh_addr=key_to_p2pkh(pubkey)) | ||||
def get_generate_key(): | |||||
"""Generate a fresh key | |||||
Returns a named tuple of privkey, pubkey and all address and scripts.""" | |||||
eckey = ECKey() | |||||
eckey.generate() | |||||
privkey = bytes_to_wif(eckey.get_bytes()) | |||||
pubkey = eckey.get_pubkey().get_bytes().hex() | |||||
pkh = hash160(hex_str_to_bytes(pubkey)) | |||||
return Key(privkey=privkey, | |||||
pubkey=pubkey, | |||||
p2pkh_script=CScript( | |||||
[OP_DUP, OP_HASH160, pkh, OP_EQUALVERIFY, OP_CHECKSIG]).hex(), | |||||
p2pkh_addr=key_to_p2pkh(pubkey)) | |||||
def get_multisig(node): | def get_multisig(node): | ||||
"""Generate a fresh 2-of-3 multisig on node | """Generate a fresh 2-of-3 multisig on node | ||||
Returns a named tuple of privkeys, pubkeys and all address and scripts.""" | Returns a named tuple of privkeys, pubkeys and all address and scripts.""" | ||||
addrs = [] | addrs = [] | ||||
pubkeys = [] | pubkeys = [] | ||||
for _ in range(3): | for _ in range(3): | ||||
addr = node.getaddressinfo(node.getnewaddress()) | addr = node.getaddressinfo(node.getnewaddress()) | ||||
Show All 24 Lines |