try to sweep p2pk outputs from old type WIF privkeys
This commit is contained in:
parent
06f18f9078
commit
1c31177d03
|
@ -405,6 +405,9 @@ def address_to_script(addr):
|
||||||
|
|
||||||
def address_to_scripthash(addr):
|
def address_to_scripthash(addr):
|
||||||
script = address_to_script(addr)
|
script = address_to_script(addr)
|
||||||
|
return script_to_scripthash(script)
|
||||||
|
|
||||||
|
def script_to_scripthash(script):
|
||||||
h = sha256(bytes.fromhex(script))[0:32]
|
h = sha256(bytes.fromhex(script))[0:32]
|
||||||
return bh2u(bytes(reversed(h)))
|
return bh2u(bytes(reversed(h)))
|
||||||
|
|
||||||
|
|
|
@ -870,27 +870,38 @@ class Abstract_Wallet(PrintError):
|
||||||
self.sign_transaction(tx, password)
|
self.sign_transaction(tx, password)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
def _append_utxos_to_inputs(self, inputs, network, pubkey, txin_type, imax):
|
||||||
|
address = None
|
||||||
|
if txin_type != 'p2pk':
|
||||||
|
address = bitcoin.pubkey_to_address(txin_type, pubkey)
|
||||||
|
sh = bitcoin.address_to_scripthash(address)
|
||||||
|
else:
|
||||||
|
script = bitcoin.public_key_to_p2pk_script(pubkey)
|
||||||
|
sh = bitcoin.script_to_scripthash(script)
|
||||||
|
u = network.synchronous_get(('blockchain.scripthash.listunspent', [sh]))
|
||||||
|
for item in u:
|
||||||
|
if len(inputs) >= imax:
|
||||||
|
break
|
||||||
|
if address is not None:
|
||||||
|
item['address'] = address
|
||||||
|
item['type'] = txin_type
|
||||||
|
item['prevout_hash'] = item['tx_hash']
|
||||||
|
item['prevout_n'] = item['tx_pos']
|
||||||
|
item['pubkeys'] = [pubkey]
|
||||||
|
item['x_pubkeys'] = [pubkey]
|
||||||
|
item['signatures'] = [None]
|
||||||
|
item['num_sig'] = 1
|
||||||
|
inputs.append(item)
|
||||||
|
|
||||||
def sweep(self, privkeys, network, config, recipient, fee=None, imax=100):
|
def sweep(self, privkeys, network, config, recipient, fee=None, imax=100):
|
||||||
inputs = []
|
inputs = []
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
for sec in privkeys:
|
for sec in privkeys:
|
||||||
txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec)
|
txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec)
|
||||||
pubkey = bitcoin.public_key_from_private_key(privkey, compressed)
|
pubkey = bitcoin.public_key_from_private_key(privkey, compressed)
|
||||||
address = bitcoin.pubkey_to_address(txin_type, pubkey)
|
self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax)
|
||||||
sh = bitcoin.address_to_scripthash(address)
|
if txin_type == 'p2pkh': # WIF serialization is ambiguous :(
|
||||||
u = network.synchronous_get(('blockchain.scripthash.listunspent', [sh]))
|
self._append_utxos_to_inputs(inputs, network, pubkey, 'p2pk', imax)
|
||||||
for item in u:
|
|
||||||
if len(inputs) >= imax:
|
|
||||||
break
|
|
||||||
item['type'] = txin_type
|
|
||||||
item['address'] = address
|
|
||||||
item['prevout_hash'] = item['tx_hash']
|
|
||||||
item['prevout_n'] = item['tx_pos']
|
|
||||||
item['pubkeys'] = [pubkey]
|
|
||||||
item['x_pubkeys'] = [pubkey]
|
|
||||||
item['signatures'] = [None]
|
|
||||||
item['num_sig'] = 1
|
|
||||||
inputs.append(item)
|
|
||||||
keypairs[pubkey] = privkey, compressed
|
keypairs[pubkey] = privkey, compressed
|
||||||
|
|
||||||
if not inputs:
|
if not inputs:
|
||||||
|
|
Loading…
Reference in New Issue