mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-09 20:19:50 +00:00
separate mktx and sendtx
This commit is contained in:
parent
8687c63226
commit
321970c7a9
2 changed files with 41 additions and 27 deletions
|
@ -302,18 +302,20 @@ class Wallet:
|
||||||
self.private_keys = self.pw_encode( repr(private_keys), password)
|
self.private_keys = self.pw_encode( repr(private_keys), password)
|
||||||
self.addresses.append(address)
|
self.addresses.append(address)
|
||||||
if for_change: self.change_addresses.append( len(self.addresses) - 1 )
|
if for_change: self.change_addresses.append( len(self.addresses) - 1 )
|
||||||
h = self.retrieve_history(address)
|
self.history[address] = []
|
||||||
self.history[address] = h
|
self.status[address] = None
|
||||||
self.status[address] = h[-1]['blk_hash'] if h else None
|
self.save()
|
||||||
return address
|
return address
|
||||||
|
|
||||||
|
|
||||||
def recover(self, password):
|
def recover(self, password):
|
||||||
seed = self.pw_decode( self.seed, password)
|
seed = self.pw_decode( self.seed, password)
|
||||||
|
|
||||||
# todo: recover receiving addresses from tx
|
# todo: recover receiving addresses from tx
|
||||||
is_found = False
|
is_found = False
|
||||||
while True:
|
while True:
|
||||||
addr = self.create_new_address(True, password)
|
addr = self.create_new_address(True, password)
|
||||||
|
self.history[addr] = h = self.retrieve_history(addr)
|
||||||
|
self.status[addr] = h[-1]['blk_hash'] if h else None
|
||||||
#print "recovering", addr
|
#print "recovering", addr
|
||||||
if self.status[addr] is not None:
|
if self.status[addr] is not None:
|
||||||
is_found = True
|
is_found = True
|
||||||
|
@ -323,6 +325,8 @@ class Wallet:
|
||||||
num_gap = 0
|
num_gap = 0
|
||||||
while True:
|
while True:
|
||||||
addr = self.create_new_address(False, password)
|
addr = self.create_new_address(False, password)
|
||||||
|
self.history[addr] = h = self.retrieve_history(addr)
|
||||||
|
self.status[addr] = h[-1]['blk_hash'] if h else None
|
||||||
#print "recovering", addr
|
#print "recovering", addr
|
||||||
if self.status[addr] is None:
|
if self.status[addr] is None:
|
||||||
num_gap += 1
|
num_gap += 1
|
||||||
|
@ -595,27 +599,23 @@ class Wallet:
|
||||||
default_label = 'at: ' + o_addr
|
default_label = 'at: ' + o_addr
|
||||||
tx['default_label'] = default_label
|
tx['default_label'] = default_label
|
||||||
|
|
||||||
|
def mktx(self, to_address, amount, label, password, fee=None):
|
||||||
|
|
||||||
def send(self, to_address, amount, label, password, do_send, fee=None):
|
|
||||||
if fee is None: fee = self.fee
|
if fee is None: fee = self.fee
|
||||||
try:
|
try:
|
||||||
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password )
|
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password )
|
||||||
except InvalidPassword: return False, "Wrong password"
|
if not inputs:
|
||||||
if not inputs: return False, "Not enough funds"
|
return False, "Not enough funds"
|
||||||
try:
|
|
||||||
s_inputs = wallet.sign_inputs( inputs, outputs, password )
|
s_inputs = wallet.sign_inputs( inputs, outputs, password )
|
||||||
except InvalidPassword:
|
except InvalidPassword:
|
||||||
return False, "Wrong password"
|
return False, "Wrong password"
|
||||||
tx = raw_tx( s_inputs, outputs )
|
tx = filter( raw_tx( s_inputs, outputs ) )
|
||||||
tx = filter( tx )
|
return True, tx
|
||||||
|
|
||||||
|
def sendtx(self, tx):
|
||||||
tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex')
|
tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex')
|
||||||
if do_send:
|
out = self.send_tx(tx)
|
||||||
out = self.send_tx(tx)
|
if out != tx_hash:
|
||||||
if out != tx_hash:
|
return False, "error: " + out
|
||||||
return False, "error: hash mismatch"
|
|
||||||
else:
|
|
||||||
out = tx
|
|
||||||
if to_address not in self.addressbook:
|
if to_address not in self.addressbook:
|
||||||
self.addressbook.append(to_address)
|
self.addressbook.append(to_address)
|
||||||
if label:
|
if label:
|
||||||
|
@ -631,7 +631,7 @@ class Wallet:
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
known_commands = ['balance', 'contacts', 'sendto', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed']
|
known_commands = ['balance', 'contacts', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed']
|
||||||
|
|
||||||
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands))
|
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands))
|
||||||
|
|
||||||
|
@ -701,14 +701,14 @@ if __name__ == '__main__':
|
||||||
wallet.create_new_address(False, None)
|
wallet.create_new_address(False, None)
|
||||||
|
|
||||||
# check syntax
|
# check syntax
|
||||||
if cmd in ['sendto', 'mktx']:
|
if cmd in ['payto', 'mktx']:
|
||||||
try:
|
try:
|
||||||
to_address = args[1]
|
to_address = args[1]
|
||||||
amount = float(args[2])
|
amount = float(args[2])
|
||||||
label = ' '.join(args[3:])
|
label = ' '.join(args[3:])
|
||||||
if options.tx_fee: options.tx_fee = float(options.tx_fee)
|
if options.tx_fee: options.tx_fee = float(options.tx_fee)
|
||||||
except:
|
except:
|
||||||
print "syntax: sendto <recipient> <amount> [label]"
|
print "syntax: payto <recipient> <amount> [label]"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# open session
|
# open session
|
||||||
|
@ -718,14 +718,14 @@ if __name__ == '__main__':
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
||||||
# commands needing password
|
# commands needing password
|
||||||
if cmd in ['sendto', 'password', 'newaddress','mktx','seed'] or ( cmd=='addresses' and options.show_keys):
|
if cmd in ['payto', 'password', 'newaddress','mktx','seed'] or ( cmd=='addresses' and options.show_keys):
|
||||||
password = getpass.getpass('Password:') if wallet.use_encryption else None
|
password = getpass.getpass('Password:') if wallet.use_encryption else None
|
||||||
|
|
||||||
if cmd == 'seed':
|
if cmd == 'seed':
|
||||||
import mnemonic
|
import mnemonic
|
||||||
print wallet.seed, '"'+' '.join(mnemonic.mn_encode(wallet.seed))+'"'
|
print wallet.seed, '"'+' '.join(mnemonic.mn_encode(wallet.seed))+'"'
|
||||||
|
|
||||||
if cmd == 'balance':
|
elif cmd == 'balance':
|
||||||
c, u = wallet.get_balance()
|
c, u = wallet.get_balance()
|
||||||
if u:
|
if u:
|
||||||
print c*1e-8, u*1e-8
|
print c*1e-8, u*1e-8
|
||||||
|
@ -783,14 +783,23 @@ if __name__ == '__main__':
|
||||||
wallet.labels[tx] = label
|
wallet.labels[tx] = label
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
||||||
elif cmd in ['sendto', 'mktx']:
|
elif cmd in ['payto', 'mktx']:
|
||||||
for k, v in wallet.labels.items():
|
for k, v in wallet.labels.items():
|
||||||
if v == to_address:
|
if v == to_address:
|
||||||
to_address = k
|
to_address = k
|
||||||
break
|
break
|
||||||
print "alias", to_address
|
print "alias", to_address
|
||||||
r, h = wallet.send( to_address, amount, label, password, cmd=='sendto', fee = options.tx_fee )
|
r, h = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee )
|
||||||
print h
|
if r and cmd=='payto':
|
||||||
|
r, h = wallet.sendtx( tx )
|
||||||
|
print h
|
||||||
|
else:
|
||||||
|
print h
|
||||||
|
|
||||||
|
elif cmd=='sendtx':
|
||||||
|
tx = args[1]
|
||||||
|
r, h = wallet.sendtx( tx )
|
||||||
|
print h
|
||||||
|
|
||||||
elif cmd == 'newaddress':
|
elif cmd == 'newaddress':
|
||||||
a = wallet.get_new_address()
|
a = wallet.get_new_address()
|
||||||
|
|
|
@ -556,8 +556,13 @@ class BitcoinGUI:
|
||||||
|
|
||||||
password = password_dialog() if self.wallet.use_encryption else None
|
password = password_dialog() if self.wallet.use_encryption else None
|
||||||
|
|
||||||
status, msg = self.wallet.send( to_address, amount, label, password, True )
|
status, tx = self.wallet.mktx( to_address, amount, label, password )
|
||||||
self.wallet.new_session() # we created a new change address
|
self.wallet.new_session() # we created a new change address
|
||||||
|
if not status:
|
||||||
|
show_message(tx)
|
||||||
|
return
|
||||||
|
|
||||||
|
status, msg = self.wallet.sendtx( tx )
|
||||||
if status:
|
if status:
|
||||||
show_message( "payment sent.\n" + msg )
|
show_message( "payment sent.\n" + msg )
|
||||||
payto_entry.set_text("")
|
payto_entry.set_text("")
|
||||||
|
|
Loading…
Add table
Reference in a new issue