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

@@ -264,18 +264,8 @@ class Commands:
def sweep(self, privkey, to_address, fee = 0.0001):
pubkey = public_key_from_private_key(privkey)
address = address_from_private_key(privkey)
pay_script = Transaction.pay_script(address)
unspent = self.network.synchronous_get([ ('blockchain.address.listunspent',[address])])[0]
if not unspent:
return
total = sum( map(lambda x:int(x.get('value')), unspent) ) - int(Decimal(fee)*100000000)
inputs = map(lambda i: {'prevout_hash': i['tx_hash'], 'prevout_n':i['tx_pos'], 'scriptPubKey':pay_script, 'redeemPubkey':pubkey}, unspent)
outputs = [(to_address, total)]
tx = Transaction.from_io(inputs, outputs)
tx.sign({ pubkey:privkey })
return tx
fee = int(Decimal(fee)*100000000)
return Transaction.sweep([privkey], self.network, to_address, fee)
def signmessage(self, address, message):

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)