- Timestamp:
- 04/21/09 18:16:11 (3 years ago)
- Location:
- trunk/sandbox/jhb/oc2
- Files:
-
- 5 modified
-
containerbase.py (modified) (2 diffs)
-
documentation.py (modified) (1 diff)
-
messages.py (modified) (2 diffs)
-
protocols.py (modified) (1 diff)
-
wallet.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/oc2/containerbase.py
r259 r269 97 97 fields = [] 98 98 99 def __init__(self,data={}): 99 def __init__(self,data={},**kwargs): 100 if not data and kwargs: 101 data = kwargs 100 102 self.fromData(data) 101 103 … … 116 118 if type(data) != type({}): 117 119 data = dict(data) 120 118 121 for field in self.fields: 119 122 if data.has_key(field.name): -
trunk/sandbox/jhb/oc2/documentation.py
r266 r269 603 603 or SUM_REJECT( transaction_id, "Reason" ) 604 604 605 ############################################################################### 606 607 >>> bobport = 9091 608 >>> bobwallet = Wallet({}) 609 610 >>> aclicetid = wallet.makeSerial() 611 >>> bob = protocols.SumAnnounceListen(bobwallet) 612 >>> alice = protocols.SumAnnounce(bob.run, wallet, 5, 'foobar') 613 >>> bobwallet.approval = "I don't like odd sums" 614 >>> alice.run() 615 "I don't like odd sums" 616 617 >>> bobwallet.approval = True 618 >>> alice.run() 619 True 620 621 ############################################################################### 605 622 606 623 * Wallet Alice sends tokens to Wallet Bob (this time including their clear -
trunk/sandbox/jhb/oc2/messages.py
r266 r269 51 51 Field('signature',signing=False) 52 52 ] 53 class Error(Message ):53 class Error(Message, Exception): 54 54 fields = Message.fields + [ 55 55 Field('text'), … … 73 73 ] 74 74 75 class TransferResume(Message): 76 fields = Message.fields + [ 77 Field('transactionId'), 78 ] 75 79 80 class TransferResume(Message): 81 fields = Message.fields + [ 82 Field('transactionId'), 83 ] 84 85 class SumAnnounce(Message): 86 fields = Message.fields + [ 87 Field('transactionId'), 88 Field('sum'), 89 Field('target'), 90 ] 91 92 class SumAccept(Message): 93 fields = Message.fields + [ 94 Field('transactionId'), 95 ] 96 97 98 class SumReject(Message): 99 fields = Message.fields + [ 100 Field('transactionId'), 101 Field('reason'), 102 ] 103 104 105 -
trunk/sandbox/jhb/oc2/protocols.py
r266 r269 178 178 return answer 179 179 180 class SumAnnounce(Protocol): 181 182 def __init__(self,transport,wallet,sum,target): 183 self.transport = transport 184 self.sum = sum 185 self.target = target 186 self.wallet = wallet 187 188 def run(self,message=None): 189 tid = self.wallet.makeSerial() 190 message = messages.SumAnnounce() 191 message.transactionId = tid 192 message.sum = self.sum 193 message.target = self.target 194 self.wallet.addOutgoing(message) 195 response = self.transport(message) 196 if response.header == 'SumAccept': 197 return True 198 else: 199 return response.reason 200 201 202 class SumAnnounceListen(Protocol): 203 204 def __init__(self,wallet): 205 self.wallet = wallet 206 207 def run(self,message=None): 208 approval = self.wallet.getApproval(message) 209 if approval == True: 210 answer = messages.SumAccept() 211 else: 212 answer = messages.SumReject() 213 answer.reason = approval 214 answer.transactionId = message.transactionId 215 return answer 180 216 181 217 class CoinsSpendSender(Protocol): -
trunk/sandbox/jhb/oc2/wallet.py
r259 r269 17 17 def makeSerial(self): 18 18 return occrypto.createSerial() 19 20 def addOutgoing(self,message): 21 self.storage.setdefault('outgoing',{})[message.transactionId] = message 22 23 def addIncoming(self,message): 24 self.storage.setdefault('incoming',{})[message.transactionId] = message 25 26 def getApproval(self,message): 27 sum = message.sum 28 target = message.sum 29 approval = getattr(self,'approval',True) #get that from ui 30 if approval == True: 31 self.addIncoming(message) 32 return approval 33 34
