Changeset 274

Show
Ignore:
Timestamp:
04/23/09 16:25:24 (3 years ago)
Author:
ocjhb
Message:

first dsdb

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

Legend:

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

    r272 r274  
    6868        Field('transactionId'), 
    6969        Field('reason'), 
     70        Field('blinds'), 
     71        Field('coins'), 
    7072    ] 
    7173 
  • trunk/sandbox/jhb/oc2/mint.py

    r272 r274  
    6262        blinds = message.blinds 
    6363        return self._mintBlinds(message) 
     64 
     65 
     66    def validateCoins(self,coins): 
     67        problems = [] 
     68 
     69        for coin in coins: 
     70            if self.inDSDB(coin): 
     71                problems.append('double spent') 
     72                continue 
     73             
     74            priv,pub,denomination,version = self.getMintKeyById(coin.keyId) 
     75             
     76            if not pub.verifyContainerSignature(coin): 
     77                problems.append('no valid signature') 
     78                continue 
     79 
     80            if not denomination == coin.denomination: 
     81                problems.append('wrong denomination') 
     82                continue 
     83 
     84        if [p for p in problems if p]: #there are problems 
     85            return problems 
     86        else: 
     87            return True 
     88 
     89 
     90 
     91 
    6492     
    6593    def handleExchangeRequest(self,message): 
    66         #import pdb; pdb.set_trace() 
    6794        coins = message.coins 
    6895        blinds = message.blinds 
     96 
     97        #check coins 
     98        
     99        result = self.validateCoins(coins) 
     100        if result != True: 
     101            reject = messages.TransferReject() 
     102            reject.reason = 'coins' 
     103            reject.coins = result 
     104            return reject 
     105 
    69106        payed = sum([int(coin.denomination) for coin in coins]) 
    70          
    71107        amount = 0 
    72108        for keyid,blind in blinds: 
     
    78114            reject.reason = 'mismatch' 
    79115            return reject 
     116         
    80117 
    81118        return self._mintBlinds(message) 
     
    103140    def addToTransactions(self,transactionId,result): 
    104141        self.storage.setdefault('transactions',{})[transactionId]=result 
     142 
     143 
     144    def addToDSDB(self,coin): 
     145        dsdb = self.storage.setdefault('dsdb',[]) 
     146        if coin.serial in dsdb: 
     147            return False 
     148        else: 
     149            dsdb.append(coin.serial) 
     150            return True 
     151 
     152    def inDSDB(self,coin): 
     153        return coin.serial in self.storage.setdefault('dsdb',[])