register commands, check for their arguments
This commit is contained in:
93
electrum
93
electrum
@@ -297,20 +297,6 @@ if __name__ == '__main__':
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
# open session
|
||||
if cmd not in offline_commands and not options.offline:
|
||||
interface = Interface(config)
|
||||
interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
|
||||
interface.start()
|
||||
wallet.interface = interface
|
||||
verifier = WalletVerifier(interface, config)
|
||||
wallet.set_verifier(verifier)
|
||||
synchronizer = WalletSynchronizer(wallet, config)
|
||||
synchronizer.start()
|
||||
wallet.update()
|
||||
wallet.save()
|
||||
|
||||
|
||||
|
||||
# important warning
|
||||
if cmd in ['dumpprivkey', 'dumpprivkeys']:
|
||||
@@ -338,38 +324,13 @@ if __name__ == '__main__':
|
||||
password = None
|
||||
|
||||
|
||||
# check and format the arguments
|
||||
# add missing arguments
|
||||
if cmd == 'importprivkey':
|
||||
# See if they specificed a key on the cmd line, if not prompt
|
||||
if len(args) == 1:
|
||||
args[1] = prompt_password('Enter PrivateKey (will not echo):', False)
|
||||
|
||||
elif cmd == 'signmessage':
|
||||
if len(args) < 3:
|
||||
print_msg("Error: Invalid usage of signmessage.")
|
||||
print_msg(known_commands[cmd])
|
||||
sys.exit(1)
|
||||
address = args[1]
|
||||
message = ' '.join(args[2:])
|
||||
if len(args) > 3:
|
||||
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
|
||||
args = [ cmd, address, message ]
|
||||
|
||||
elif cmd == 'verifymessage':
|
||||
try:
|
||||
address = args[1]
|
||||
signature = args[2]
|
||||
message = ' '.join(args[3:])
|
||||
except:
|
||||
print_msg("Error: Not all parameters were given, displaying help instead.")
|
||||
print_msg(known_commands[cmd])
|
||||
sys.exit(1)
|
||||
if len(args) > 4:
|
||||
print_msg("Warning: Message was reconstructed from several arguments:", repr(message))
|
||||
args = [ cmd, address, signature, message]
|
||||
|
||||
elif cmd == 'signrawtransaction':
|
||||
import json
|
||||
args = [ cmd, args[1], json.loads(args[2]) if len(args)>2 else [], json.loads(args[3]) if len(args)>3 else []]
|
||||
|
||||
elif cmd == 'createmultisig':
|
||||
@@ -380,15 +341,6 @@ if __name__ == '__main__':
|
||||
|
||||
elif cmd=='listaddresses':
|
||||
args = [cmd, options.show_all, options.show_balance, options.show_labels]
|
||||
|
||||
elif cmd == 'setlabel':
|
||||
try:
|
||||
tx = args[1]
|
||||
label = ' '.join(args[2:])
|
||||
except:
|
||||
print_msg("Error. Syntax: label <tx_hash> <text>")
|
||||
sys.exit(1)
|
||||
args = [ cmd, tx, label ]
|
||||
|
||||
elif cmd in ['payto', 'mktx']:
|
||||
|
||||
@@ -434,6 +386,44 @@ if __name__ == '__main__':
|
||||
# del(wallet.history[from_addr])
|
||||
#wallet.save()
|
||||
|
||||
|
||||
|
||||
# check the number of arguments
|
||||
min_args, max_args, description, syntax, options_syntax = known_commands[cmd]
|
||||
if len(args) - 1 < min_args:
|
||||
print_msg("Not enough arguments")
|
||||
print_msg("Syntax:", syntax)
|
||||
sys.exit(1)
|
||||
|
||||
if max_args >= 0 and len(args) - 1 > max_args:
|
||||
print_msg("too many arguments", args)
|
||||
print_msg("Syntax:", syntax)
|
||||
sys.exit(1)
|
||||
|
||||
if max_args < 0:
|
||||
if len(args) > min_args:
|
||||
message = ' '.join(args[min_args:])
|
||||
print_msg("Warning: Final argument was reconstructed from several arguments:", repr(message))
|
||||
args = args[0:min_args] + [ message ]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# open session
|
||||
if cmd not in offline_commands and not options.offline:
|
||||
interface = Interface(config)
|
||||
interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
|
||||
interface.start()
|
||||
wallet.interface = interface
|
||||
verifier = WalletVerifier(interface, config)
|
||||
wallet.set_verifier(verifier)
|
||||
synchronizer = WalletSynchronizer(wallet, config)
|
||||
synchronizer.start()
|
||||
wallet.update()
|
||||
wallet.save()
|
||||
|
||||
|
||||
# run the command
|
||||
@@ -445,7 +435,10 @@ if __name__ == '__main__':
|
||||
print_msg("Type 'electrum --help' to see the list of options")
|
||||
print_msg("List of commands:", ', '.join(known_commands))
|
||||
else:
|
||||
print_msg(known_commands[cmd2])
|
||||
_, _, description, syntax, options_syntax = known_commands[cmd2]
|
||||
print_msg(description)
|
||||
if syntax: print_msg("Syntax: " + syntax)
|
||||
if options_syntax: print_msg("options:\n" + options_syntax)
|
||||
|
||||
elif cmd == 'deseed':
|
||||
if not wallet.seed:
|
||||
|
||||
Reference in New Issue
Block a user