add command for offline tx
This commit is contained in:
@@ -567,7 +567,7 @@ class Wallet:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def send(self, to_address, amount, label, password):
|
def send(self, to_address, amount, label, password, do_send):
|
||||||
try:
|
try:
|
||||||
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, self.fee, password )
|
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, self.fee, password )
|
||||||
except InvalidPassword: return False, "Wrong password"
|
except InvalidPassword: return False, "Wrong password"
|
||||||
@@ -579,15 +579,18 @@ class Wallet:
|
|||||||
tx = raw_tx( s_inputs, outputs )
|
tx = raw_tx( s_inputs, outputs )
|
||||||
tx = filter( tx )
|
tx = filter( tx )
|
||||||
tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex')
|
tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex')
|
||||||
out = self.send_tx(tx)
|
if do_send:
|
||||||
if out != tx_hash:
|
out = self.send_tx(tx)
|
||||||
return False, "error: hash mismatch"
|
if out != tx_hash:
|
||||||
|
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:
|
||||||
wallet.labels[tx_hash] = label
|
wallet.labels[tx_hash] = label
|
||||||
wallet.save()
|
wallet.save()
|
||||||
return True, tx_hash
|
return True, out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -600,7 +603,7 @@ if __name__ == '__main__':
|
|||||||
except:
|
except:
|
||||||
cmd = "gui"
|
cmd = "gui"
|
||||||
|
|
||||||
known_commands = ['balance', 'sendtoaddress', 'password', 'getnewaddress', 'addresses', 'history', 'label', 'gui', 'all_addresses']
|
known_commands = ['balance', 'sendtoaddress', 'password', 'getnewaddress', 'addresses', 'history', 'label', 'gui', 'all_addresses', 'gentx']
|
||||||
if cmd not in known_commands:
|
if cmd not in known_commands:
|
||||||
print "Known commands:", ', '.join(known_commands)
|
print "Known commands:", ', '.join(known_commands)
|
||||||
exit(0)
|
exit(0)
|
||||||
@@ -651,11 +654,12 @@ if __name__ == '__main__':
|
|||||||
# generate first key
|
# generate first key
|
||||||
wallet.create_new_address(False, None)
|
wallet.create_new_address(False, None)
|
||||||
|
|
||||||
wallet.new_session()
|
if cmd not in ['password', 'gentx', 'history', 'label']:
|
||||||
wallet.update()
|
wallet.new_session()
|
||||||
wallet.save()
|
wallet.update()
|
||||||
|
wallet.save()
|
||||||
|
|
||||||
if cmd in ['sendtoaddress', 'password', 'getnewaddress']:
|
if cmd in ['sendtoaddress', 'password', 'getnewaddress','gentx']:
|
||||||
password = getpass.getpass('Password:') if wallet.use_encryption else None
|
password = getpass.getpass('Password:') if wallet.use_encryption else None
|
||||||
|
|
||||||
if cmd == 'balance':
|
if cmd == 'balance':
|
||||||
@@ -707,7 +711,7 @@ if __name__ == '__main__':
|
|||||||
wallet.labels[tx] = label
|
wallet.labels[tx] = label
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
||||||
elif cmd == 'sendtoaddress':
|
elif cmd in ['sendtoaddress', 'gentx']:
|
||||||
try:
|
try:
|
||||||
to_address = sys.argv[2]
|
to_address = sys.argv[2]
|
||||||
amount = float(sys.argv[3])
|
amount = float(sys.argv[3])
|
||||||
@@ -715,7 +719,7 @@ if __name__ == '__main__':
|
|||||||
except:
|
except:
|
||||||
print "syntax: send <recipient> <amount> [label]"
|
print "syntax: send <recipient> <amount> [label]"
|
||||||
exit(1)
|
exit(1)
|
||||||
r, h = wallet.send( to_address, amount, label, password )
|
r, h = wallet.send( to_address, amount, label, password, cmd=='sendtoaddress' )
|
||||||
print h
|
print h
|
||||||
|
|
||||||
elif cmd == 'getnewaddress':
|
elif cmd == 'getnewaddress':
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ 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 )
|
status, msg = self.wallet.send( to_address, amount, label, password, True )
|
||||||
if status:
|
if status:
|
||||||
show_message( "payment sent.\n" + msg )
|
show_message( "payment sent.\n" + msg )
|
||||||
payto_entry.set_text("")
|
payto_entry.set_text("")
|
||||||
|
|||||||
Reference in New Issue
Block a user