diff --git a/electrum b/electrum index 46ac69da..34d382a9 100755 --- a/electrum +++ b/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 ") - 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: diff --git a/lib/commands.py b/lib/commands.py index a991b146..e8372c01 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -22,85 +22,60 @@ from bitcoin import * from decimal import Decimal import bitcoin -known_commands = { - 'help':'Prints this help', - 'validateaddress':'Check that the address is valid', - 'getbalance': "Display the balance of your wallet or of an address.\nSyntax: getbalance [
]", - 'contacts': "Show your list of contacts", - 'create':'Create a wallet', - 'restore':'Restore a wallet', - 'payto':"""Create and broadcast a transaction. -Syntax: payto [label] - can be a bitcoin address or a label -options:\n --fee, -f: set transaction fee\n --fromaddr, -s: send from address -\n --changeaddr, -c: send change to address - """, - 'sendrawtransaction': - 'Broadcasts a transaction to the network. \nSyntax: sendrawtransaction ', - 'password': - "Changes your password", - 'listaddresses': - """Shows your list of addresses. -options: - -a: show all addresses, including change addresses - -b: include balance in results - -l: include labels in results - """, +known_commands = {} +offline_commands = [] +protected_commands = [] - 'history':"Shows the transaction history", - 'setlabel':'Assign a label to an item\nSyntax: label