1
0

sweep privkeys in gui

This commit is contained in:
ThomasV
2014-05-01 17:35:01 +02:00
parent b21cfc2746
commit 46c0dda3b9
3 changed files with 54 additions and 13 deletions

View File

@@ -386,7 +386,6 @@ class Transaction:
self.outputs = map(lambda x: (x['address'],x['value']), self.outputs)
self.locktime = self.d['lockTime']
def __str__(self):
return self.raw
@@ -398,6 +397,31 @@ class Transaction:
self.outputs = outputs
return self
@classmethod
def sweep(klass, privkeys, network, to_address, fee):
inputs = []
for privkey in privkeys:
pubkey = public_key_from_private_key(privkey)
address = address_from_private_key(privkey)
u = network.synchronous_get([ ('blockchain.address.listunspent',[address])])[0]
pay_script = klass.pay_script(address)
for item in u:
item['scriptPubKey'] = pay_script
item['redeemPubkey'] = pubkey
item['address'] = address
item['prevout_hash'] = item['tx_hash']
item['prevout_n'] = item['tx_pos']
inputs += u
if not inputs:
return
total = sum( map(lambda x:int(x.get('value')), inputs) ) - fee
outputs = [(to_address, total)]
self = klass.from_io(inputs, outputs)
self.sign({ pubkey:privkey })
return self
@classmethod
def multisig_script(klass, public_keys, num=None):
n = len(public_keys)