3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2011 thomasv@gitorious
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #from bitcoin import *
22 from decimal
import Decimal
24 #from transaction import Transaction
27 def __init__(self
, name
, min_args
, max_args
, requires_network
, requires_wallet
, requires_password
, description
, syntax
= '', options_syntax
= ''):
29 self
.min_args
=min_args
30 self
.max_args
= max_args
31 self
.requires_network
= requires_network
32 self
.requires_wallet
= requires_wallet
33 self
.requires_password
= requires_password
34 self
.description
= description
36 self
.options
= options_syntax
39 def register_command(*args
):
42 known_commands
[name
] = Command(*args
)
46 payto_options
= ' --fee, -f: set transaction fee\n --fromaddr, -F: send from address -\n --changeaddr, -c: send change to address'
47 listaddr_options
= " -a: show all addresses, including change addresses\n -l: include labels in results"
48 restore_options
= " accepts a seed or master public key."
49 mksendmany_syntax
= 'mksendmanytx <recipient> <amount> [<recipient> <amount> ...]'
50 payto_syntax
= "payto <recipient> <amount> [label]\n<recipient> can be a bitcoin address or a label"
51 paytomany_syntax
= "paytomany <recipient> <amount> [<recipient> <amount> ...]\n<recipient> can be a bitcoin address or a label"
52 signmessage_syntax
= 'signmessage <address> <message>\nIf you want to lead or end a message with spaces, or want double spaces inside the message make sure you quote the string. I.e. " Hello This is a weird String "'
53 verifymessage_syntax
= 'verifymessage <address> <signature> <message>\nIf you want to lead or end a message with spaces, or want double spaces inside the message make sure you quote the string. I.e. " Hello This is a weird String "'
60 register_command('history', 0, 0, True, True, False, 'Returns the transaction history of your wallet')
61 register_command('help', 0, 1, False, False, False, 'Prints this help')
68 def __init__(self
, wallet
, callback
= None):
70 #self.network = network
71 self
._callback
= callback
75 def _run(self
, method
, args
, password_getter
):
76 cmd
= known_commands
[method
]
77 if cmd
.requires_password
and self
.wallet
.use_encryption
:
78 self
.password
= apply(password_getter
,())
79 f
= getattr(self
, method
)
83 apply(self
._callback
, ())
87 def help(self
, cmd
=None):
88 if cmd
not in known_commands
:
89 print_msg("\nList of commands:", ', '.join(sorted(known_commands
)))
91 cmd
= known_commands
[cmd
]
92 print_msg(cmd
.description
)
93 if cmd
.syntax
: print_msg("Syntax: " + cmd
.syntax
)
94 if cmd
.options
: print_msg("options:\n" + cmd
.options
)
102 for item
in self
.wallet
.get_tx_history():
103 tx_hash
, conf
, is_mine
, value
, fee
, balance
, timestamp
= item
105 time_str
= datetime
.datetime
.fromtimestamp( timestamp
).isoformat(' ')[:-3]
109 label
, is_default_label
= self
.wallet
.get_label(tx_hash
)
111 out
.append({'txid':tx_hash
, 'date':"%16s"%time_str
, 'label':label
, 'value':format_satoshis(value
)})