fix sweep

This commit is contained in:
ThomasV 2017-10-05 20:08:16 +02:00
parent 3dabb94046
commit 15ab48aaa8
3 changed files with 7 additions and 6 deletions

View File

@ -509,7 +509,7 @@ def deserialize_privkey(key):
compressed = len(vch) == 34 compressed = len(vch) == 34
return txin_type, vch[1:33], compressed return txin_type, vch[1:33], compressed
else: else:
return False raise BaseException("cannot deserialize", key)
def regenerate_key(pk): def regenerate_key(pk):
assert len(pk) == 32 assert len(pk) == 32

View File

@ -388,7 +388,7 @@ class Commands:
privkey to a destination address. The transaction is not privkey to a destination address. The transaction is not
broadcasted.""" broadcasted."""
tx_fee = satoshis(tx_fee) tx_fee = satoshis(tx_fee)
privkeys = privkey if type(privkey) is list else [privkey] privkeys = privkey.split()
self.nocheck = nocheck self.nocheck = nocheck
dest = self._resolver(destination) dest = self._resolver(destination)
tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee, imax) tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee, imax)

View File

@ -874,15 +874,16 @@ class Abstract_Wallet(PrintError):
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 privkey in privkeys: for sec in privkeys:
pubkey = public_key_from_private_key(privkey) txin_type, privkey, compressed = bitcoin.deserialize_privkey(sec)
address = address_from_private_key(privkey) pubkey = bitcoin.public_key_from_private_key(privkey, compressed)
address = bitcoin.pubkey_to_address(txin_type, pubkey)
u = network.synchronous_get(('blockchain.address.listunspent', [address])) u = network.synchronous_get(('blockchain.address.listunspent', [address]))
pay_script = bitcoin.address_to_script(address) pay_script = bitcoin.address_to_script(address)
for item in u: for item in u:
if len(inputs) >= imax: if len(inputs) >= imax:
break break
item['type'] = 'p2pkh' item['type'] = txin_type
item['scriptPubKey'] = pay_script item['scriptPubKey'] = pay_script
item['redeemPubkey'] = pubkey item['redeemPubkey'] = pubkey
item['address'] = address item['address'] = address