|
|
|
|
@ -870,27 +870,38 @@ class Abstract_Wallet(PrintError):
|
|
|
|
|
self.sign_transaction(tx, password) |
|
|
|
|
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): |
|
|
|
|
inputs = [] |
|
|
|
|
keypairs = {} |
|
|
|
|
for sec in privkeys: |
|
|
|
|
txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec) |
|
|
|
|
pubkey = bitcoin.public_key_from_private_key(privkey, compressed) |
|
|
|
|
address = bitcoin.pubkey_to_address(txin_type, pubkey) |
|
|
|
|
sh = bitcoin.address_to_scripthash(address) |
|
|
|
|
u = network.synchronous_get(('blockchain.scripthash.listunspent', [sh])) |
|
|
|
|
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) |
|
|
|
|
self._append_utxos_to_inputs(inputs, network, pubkey, txin_type, imax) |
|
|
|
|
if txin_type == 'p2pkh': # WIF serialization is ambiguous :( |
|
|
|
|
self._append_utxos_to_inputs(inputs, network, pubkey, 'p2pk', imax) |
|
|
|
|
keypairs[pubkey] = privkey, compressed |
|
|
|
|
|
|
|
|
|
if not inputs: |
|
|
|
|
|