@@ -37,15 +37,13 @@ def parse(line):
37
37
class Command (object ):
38
38
'''A command that is sent to the component.'''
39
39
40
- def __init__ (self , action , arguments = [], target = None , username = '' ):
41
- '''Constructor. action is the command to perform. arguments is an array
42
- of words, target is the involved Address if any, and username is
43
- the involved username if any.
44
- '''
40
+ def __init__ (self , action , arguments = [], target = None ):
41
+ '''Constructor. action is the command to perform. arguments is an
42
+ array of words or phrases, target is the Addressable object the
43
+ command is targetted at.'''
45
44
self .action = action .lower ()
46
45
self .arguments = arguments
47
46
self .target = target
48
- self .username = username
49
47
50
48
def usage (self ):
51
49
"""Return an explanation message about how to use the command. Raise an
@@ -67,14 +65,14 @@ def execute(self, user):
67
65
"""Actually execute the command, on behalf of the given user."""
68
66
debug ("A command was sent: %s" % self .action )
69
67
if COMMAND_PAY == self .action :
70
- if ( self .target is None ) and ( 0 == len ( self . username )) :
68
+ if self .target is None :
71
69
raise CommandTargetError , 'You can only send coins to a user or an address.'
72
70
try :
73
71
amount = self .arguments .pop (0 )
74
72
except IndexError :
75
73
raise CommandSyntaxError , 'You must specify an amount.'
76
74
comment = ' ' .join (self .arguments )
77
- return self ._executePay (user , amount , self .target , self . username , comment )
75
+ return self ._executePay (user , amount , self .target , comment )
78
76
elif COMMAND_CANCEL == self .action :
79
77
try :
80
78
code = self .arguments .pop (0 )
@@ -98,23 +96,23 @@ def execute(self, user):
98
96
else :
99
97
raise UnknownCommandError , self .action
100
98
101
- def _executePay (self , sender , amount , address , username , comment = '' ):
99
+ def _executePay (self , sender , amount , target , comment = '' ):
102
100
"""Called internally. Actually place the payment order in the pending
103
101
list and generate the reply."""
104
- debug ("Pay order (BTC %s to %s from %s, %s)" % (amount , address , sender , comment ))
102
+ debug ("Pay order (BTC %s to %s from %s, %s)" % (amount , target , sender , comment ))
105
103
try :
106
104
amount = int (amount )
107
105
except ValueError :
108
106
raise CommandSyntaxError , 'The amount must be a number.'
109
107
if amount <= 0 :
110
108
raise CommandSyntaxError , 'The amount must be positive.'
111
109
try :
112
- order = PaymentOrder (sender , address , username , amount , comment )
110
+ order = PaymentOrder (sender , target , amount , comment )
113
111
except PaymentToSelfError :
114
112
raise CommandSyntaxError , 'You know, I\' m your own address. It doesn\' t make sense.'
115
113
order .queue ()
116
- info ("Payment order valid, queued: %s -> %s/%s (BTC %s, %s)" % \
117
- (sender , address , username , amount , order .code ))
114
+ info ("Payment order valid, queued: %s -> %s (BTC %s, %s)" % \
115
+ (sender , target , amount , order .code ))
118
116
reply = "You want to pay BTC %s to %s" % (amount , order .recipient )
119
117
if 0 != len (comment ):
120
118
reply += ' (%s)' % comment
@@ -159,11 +157,7 @@ def _executeCancel(self, user, code=None):
159
157
debug ("Payment %s (BTC %s to %s) was cancelled by %s" % \
160
158
(code , payment .amount , payment .recipient , user ))
161
159
target = self .target
162
- if self .target is not None :
163
- target = self .target .address
164
- elif 0 != len (self .username ):
165
- target = self .username
166
- if target == payment .recipient :
160
+ if target == payment .target :
167
161
reply = "Cancelled payment of BTC %s to me" % payment .amount
168
162
if 0 != len (payment .comment ):
169
163
reply += " (%s)" % payment .comment
@@ -203,27 +197,20 @@ def _executeConfirm(self, user, code=None):
203
197
def _executeListPending (self , user ):
204
198
"""Called internally. Generate the listing of all pending payments."""
205
199
reply = ''
206
- if self .target is not None :
207
- label = "Pending payments to this address:"
208
- empty = "No pending payments to this address."
209
- for row in user .pendingPayments (self .target .address ):
210
- reply += "\n [%s] (%s): BTC %s" % (row ['confirmation_code' ], row ['date' ].date ().isoformat (), row ['amount' ])
211
- if 0 != len (row ['comment' ]):
212
- reply += ' (%s)' % row ['comment' ]
213
- elif 0 != len (self .username ):
214
- label = "Pending payments to this user:"
215
- empty = "No pending payments to this user."
216
- for row in user .pendingPayments (self .username ):
217
- reply += "\n [%s] (%s): BTC %s" % (row ['confirmation_code' ], row ['date' ].date ().isoformat (), row ['amount' ])
218
- if 0 != len (row ['comment' ]):
219
- reply += ' (%s)' % row ['comment' ]
220
- else :
200
+ if self .target is None :
221
201
label = "Pending payments:"
222
202
empty = "No pending payments."
223
203
for row in user .pendingPayments ():
224
204
reply += "\n [%s] (%s): BTC %s to %s" % (row ['confirmation_code' ], row ['date' ].date ().isoformat (), row ['amount' ], row ['recipient' ])
225
205
if 0 != len (row ['comment' ]):
226
206
reply += ' (%s)' % row ['comment' ]
207
+ else :
208
+ label = "Pending payments to me:"
209
+ empty = "No pending payments to me."
210
+ for row in user .pendingPayments (self .target ):
211
+ reply += "\n [%s] (%s): BTC %s" % (row ['confirmation_code' ], row ['date' ].date ().isoformat (), row ['amount' ])
212
+ if 0 != len (row ['comment' ]):
213
+ reply += ' (%s)' % row ['comment' ]
227
214
if 0 == len (reply ):
228
215
return empty
229
216
else :
0 commit comments