Changeset 271

Show
Ignore:
Timestamp:
04/22/09 18:46:54 (3 years ago)
Author:
ocjhb
Message:

working on it

Location:
trunk/sandbox/jhb/oc2
Files:
3 modified
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/documentation.py

    r270 r271  
    651651>>> bob = protocols.SpendListen(bobwallet) 
    652652>>> transport = transports.YieldTransport(bob.run,[]) 
    653 >>> alice = protocols.SpendRequest(transport, wallet, 'foobar', [coin])  
     653>>> alice = protocols.SpendRequest(bob.run, wallet, 'foobar', [coin])  
    654654>>> alice.run() 
    655655Traceback (most recent call last): 
     
    657657SpendReject: unknown transactionId 
    658658 
    659 >>> alice = protocols.SpendRequest(transport, wallet, alicetid, [])  
     659>>> alice = protocols.SpendRequest(bob.run, wallet, alicetid, [])  
    660660>>> alice.run() 
    661661Traceback (most recent call last): 
     
    663663SpendReject: amount of coins does not match announced one 
    664664 
    665 >>> alice = protocols.SpendRequest(transport, wallet, alicetid, [coin])  
     665>>> alice = protocols.SpendRequest(bob.run, wallet, alicetid, [coin])  
    666666>>> alice.run() 
    667667True 
  • trunk/sandbox/jhb/oc2/mint.py

    r266 r271  
    11from entity import * 
     2import messages 
    23 
    34class Mint(Entity): 
     
    5354        return key.verifyContainerSignature(message) 
    5455 
    55     def handleTransferRequest(self,authorizedMessage): 
     56    def handleMintingRequest(self,authorizedMessage): 
    5657          
    5758        if not self.validateAuthorization(authorizedMessage): 
    58             return ('nonvalid','') 
    59         else:  
    60             message = authorizedMessage.message 
     59            return messages.TransferReject() 
     60         
     61        message = authorizedMessage.message 
    6162        blinds = message.blinds 
    6263        result = [] 
     
    6768 
    6869        if self.delay: 
    69              
    7070            self.addToTransactions(message.transactionId,result) 
    71             return('delayed','mint asked to delay') 
     71            answer =  messages.TransferDelay() 
     72            answer.transactionId = message.transactionId 
     73            answer.reason = 'mint asked to delay' 
    7274        else:             
    73             return ('minted',result) 
     75            answer = messages.TransferAccept() 
     76            answer.signatures = result 
     77         
     78        return answer 
     79     
     80    def handleExchangeRequest(self,message): 
     81        coins = message.coins 
     82        blinds = message.blinds 
     83 
     84 
    7485 
    7586    def addToTransactions(self,transactionId,result): 
  • trunk/sandbox/jhb/oc2/protocols.py

    r270 r271  
    118118        options = dict(message.options) 
    119119        requesttype = options['type'] 
     120         
    120121        if requesttype == 'mint': 
    121122            authorizedMessage = self.authorizer.authorize(message) 
    122123            if type(authorizedMessage) == messages.Error: 
    123124                return messages.TransferReject() 
    124                   
    125             response  = self.mint.handleTransferRequest(authorizedMessage) 
    126             if type(response) == messages.Error: 
    127                 return messages.TransferReject() 
    128  
    129             text,value = response 
    130             if text=='minted': 
    131                 answer = messages.TransferAccept() 
    132                 answer.signatures = value 
    133             elif text =='delayed': 
    134                 answer = messages.TransferDelay() 
    135                 answer.transactionId = message.transactionId 
    136                 answer.reason = value 
    137             else: 
    138                 raise 'something went wrong' 
    139         return answer     
     125            return self.mint.handleMintingRequest(authorizedMessage) 
     126         
     127        elif requesttype == 'exchange': 
     128            return self.mint.handleExchangeRequest(message) 
     129             
     130 
    140131 
    141132class TransferResume(Protocol): 
     
    234225            return True 
    235226 
     227    
    236228class SpendListen(Protocol): 
    237229     
     
    247239            answer = messages.SpendReject() 
    248240            answer.reason = 'unknown transactionId' 
    249             yield answer 
    250             return 
     241            return answer 
    251242        #check sum 
    252243        if amount != int(orig.amount): 
    253244            answer = messages.SpendReject() 
    254245            answer.reason = 'amount of coins does not match announced one' 
    255             yield answer 
    256             return 
    257         yield 'trying to exchange'  
    258         #try to exchange. To yield or not to yield? 
    259         import pdb; pdb.set_trace() 
    260         #return answer 
     246            return answer 
     247        #do exchange 
     248 
     249 
    261250        answer = messages.SpendAccept() 
    262251        answer.transactionId = tid 
    263         yield answer 
     252        return answer 
     253            
     254 
    264255 
    265256class CoinsSpendSender(Protocol):