Changeset 294
- Timestamp:
- 04/30/09 21:15:23 (3 years ago)
- Location:
- trunk/sandbox/jhb/oc2
- Files:
-
- 3 modified
-
coinsplitting.py (modified) (1 diff)
-
testissuer.py (modified) (3 diffs)
-
wallet.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/oc2/coinsplitting.py
r287 r294 28 28 if rest > 0 and token <= rest: 29 29 picked.append(token) 30 return picked 30 return picked 31 31 32 if __name__ == '__main__': 32 33 dl = [[1,2,5,10,20,50,100],[1,3,9,27],[1,3,5,7,11,13,17,19,23],[1,17,33]] -
trunk/sandbox/jhb/oc2/testissuer.py
r290 r294 23 23 24 24 print 'issuer: setup currency discription' 25 denominations=[ 0,1,2,5,10,20]25 denominations=[1,2,5,10,20] 26 26 cdd = issuer.makeCDD('TestCent','tc',[str(d) for d in denominations],'http://192.168.2.101:%s/' % port,'') 27 27 mint.setCDD(cdd) … … 47 47 authorizerstorage.save() 48 48 49 50 def address_string(self): 51 host, port = self.client_address[:2] 52 return host 53 49 54 print 'Starting up server' 50 55 Handler.issuer = issuer … … 52 57 Handler.authorizer = authorizer 53 58 httpd = BaseHTTPServer.HTTPServer(("", port), Handler) 59 httpd.address_string = address_string 54 60 httpd.serve_forever() -
trunk/sandbox/jhb/oc2/wallet.py
r290 r294 170 170 return coinsplitting.tokenizer([int(d) for d in denominations],amount) 171 171 172 172 def pickForSpending(self,amount,coins): 173 tmp = [(c.denomination,c) for c in coins] 174 tmp.sort() 175 tmp.reverse() 176 coins = [t[1] for t in tmp] 177 picked = [] 178 for coin in coins: 179 sumpicked = sum([int(c.denomination) for c in picked]) 180 if sumpicked < amount: 181 if int(coin.denomination) <= (amount - sumpicked): 182 picked.append(coin) 183 else: 184 break 185 return picked 186 173 187 174 188 #################################higher level############################# … … 181 195 currency['cdds'].append(cdd) 182 196 183 def buyCoins(self,transport,amount,target):197 def mintCoins(self,transport,amount,target): 184 198 cdd = self.askLatestCDD(transport) 185 199 currency = self.getCurrency(cdd.currencyId) … … 217 231 i += 1 218 232 self.storage.save() 233 234 def getAllCoins(self,currencyId): 235 currency = self.getCurrency(currencyId) 236 return currency['coins'] 237 238 239 240 def redeemCoins(self,transport,amount,target): 241 cdd = self.askLatestCDD(transport) 242 currency = self.getCurrency(cdd.currencyId) 243 coins = currency['coins'] 244 picked = self.pickForSpending(amount,coins) 245 tid = self.makeSerial() 246 response = self.requestTransfer(transport,tid,target,[],picked) 247 newcoins = [c for c in coins if c not in picked] 248 currency['coins'] = newcoins 249 250
