Changeset 320 for trunk/sandbox/jhb/oc2/wallet.py
- Timestamp:
- 05/28/09 14:30:52 (3 years ago)
- Files:
-
- 1 modified
-
trunk/sandbox/jhb/oc2/wallet.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/oc2/wallet.py
r319 r320 39 39 self.feedback('Talking to issuer: fetching latest CDD') 40 40 response = transport(messages.AskLatestCDD()) 41 if not isinstance(response,messages.GiveLatestCDD): 42 raise Exception, 'Not a valid message' 43 if not response.cdd.masterPubKey.verifyContainerSignature(response.cdd): 44 raise Exception, 'Could not verify cdd' 41 45 return response.cdd 42 46 43 47 44 def fetchMintKeys(self,transport, denominations=None,keyids=None):48 def fetchMintKeys(self,transport,cdd,denominations=None,keyids=None): 45 49 if denominations and keyids: 46 raise "you can't ask for denominations and keyids at the same time"50 raise Exception, "you can't ask for denominations and keyids at the same time" 47 51 if not (denominations or keyids): 48 raise "you need to ask at least for one"52 raise Exception, "you need to ask at least for one" 49 53 message = messages.FetchMintKeys() 50 message.denominations = [str(d) for d in denominations] 54 denominations = [str(d) for d in denominations] 55 message.denominations = denominations 51 56 message.keyids = keyids 52 57 self.feedback('Talking to issuer: fetching mintkeys') 53 58 response = transport(message) 59 54 60 if response.header == 'MINTING_KEY_FAILURE': 55 61 raise message 56 else: 57 return response.keys 62 63 if not isinstance(response,messages.GiveMintKeys): 64 raise Exception, 'Not a valid message' 65 66 if set(denominations).difference(set([key.denomination for key in response.keys])): 67 raise Exception, 'Not all denominations met' 68 69 for key in response.keys: 70 if not cdd.masterPubKey.verifyContainerSignature(key): 71 raise Exception, 'Could not verify key' 72 return response.keys 73 58 74 59 75 … … 119 135 120 136 121 def listenSpend(self, message,transport=None):137 def listenSpend(self,transport,message): 122 138 tid = message.transactionId 123 139 amount = sum([int(m.denomination) for m in message.coins]) … … 174 190 175 191 def pickForSpending(self,amount,coins): 176 tmp = [( c.denomination,c) for c in coins]192 tmp = [(int(c.denomination),c) for c in coins] 177 193 tmp.sort() 178 194 tmp.reverse() 179 coins = [t[1] for t in tmp]195 mycoins = [t[1] for t in tmp] 180 196 picked = [] 181 for coin in coins:197 for coin in mycoins: 182 198 sumpicked = sum([int(c.denomination) for c in picked]) 183 199 if sumpicked < amount: … … 220 236 def prepareBlanks(self,transport,cdd,values): 221 237 wanted = list(set(values)) #what mkcs do we want 222 keys = self.fetchMintKeys(transport, denominations=wanted)238 keys = self.fetchMintKeys(transport,cdd,denominations=wanted) 223 239 mkcs = {} 224 240 for mkc in keys: 225 241 if not cdd.masterPubKey.verifyContainerSignature(mkc): 226 raise 'Invalid signature onmkc'242 raise Exception, 'Could not verify mkc' 227 243 mkcs[mkc.denomination] = mkc 228 244
