| | 48 | if method == 'post': |
| | 49 | if action == 'addcurrency': |
| | 50 | self.addCurrency() |
| | 51 | elif action == 'mint': |
| | 52 | self.mintCoins() |
| | 53 | elif action == '': |
| | 54 | pass |
| | 55 | |
| | 56 | elif method == 'get': |
| | 57 | if action == '': |
| | 58 | #basically nothing happened |
| | 59 | self.displayMain() |
| | 60 | elif action == 'addcurrency': |
| | 61 | self.displayAddCurrency() |
| | 62 | elif action == 'mint': |
| | 63 | self.displayMint() |
| | 64 | |
| | 65 | |
| | 66 | def addCurrency(self): |
| | 67 | url = self.form.getfirst('url','') |
| | 68 | if url: |
| | 69 | transport = transports.HTTPTransport(url) |
| | 70 | w.wallet.addCurrency(transport) |
| | 71 | storage.save() |
| | 72 | self.displayMain() |
| | 73 | |
| | 74 | |
| | 75 | def mintCoins(self): |
| | 76 | amount = int(self.form.getfirst('amount',1)) |
| | 77 | reference = self.form.getfirst('reference') |
| | 78 | cdd,wehave = self.getCurrency(self.form.getfirst('currencyId')) |
| | 79 | transport = transports.HTTPTransport(cdd.issuerServiceLocation) |
| | 80 | self.wallet.mintCoins(transport,amount,reference) |
| | 81 | self.storage.save() |
| | 82 | self.displayMain() |
| | 83 | |
| | 84 | |
| | 85 | def displayMain(self): |
| | 86 | tmp = [(cdd.currencyId,cdd,amount) for cdd,amount in self.wallet.listCurrencies()] |
| | 87 | tmp.sort() |
| | 88 | currencies = [(t[1],t[2]) for t in tmp] |
| | 89 | items = [] |
| | 90 | for cdd,amount in currencies: |
| | 91 | entry = """ |
| | 92 | <p>%s <b href='%s'>%ss</b><br/> |
| | 93 | <a href='%s?action=mint¤cyId=%s'>Withdraw</a> |
| | 94 | </p> |
| | 95 | """ % (amount,cdd.issuerServiceLocation,cdd.currencyId,baseurl,cdd.currencyId) |
| | 96 | items.append(entry) |
| | 97 | items = '\n'.join(items) |
| | 98 | html = """ |
| | 99 | <html><body> |
| | 100 | <h2>Wallet content</h2> |
| | 101 | %s |
| | 102 | ----<br/> |
| | 103 | <a href='%s?action=addcurrency'>Add a currency</a> |
| | 104 | </body></html> |
| | 105 | """ % (items,baseurl) |
| | 106 | self.out(html) |
| | 107 | |
| | 108 | def displayAddCurrency(self): |
| | 109 | html=""" |
| | 110 | <html><body> |
| | 111 | <h2>Add a currency</h2> |
| | 112 | <form action='%s' method='post'> |
| | 113 | The url of the issuer:<br> |
| | 114 | <input type='text' name='url' value='http://baach.de:9090' /><br> |
| | 115 | <input type='submit' /> |
| | 116 | <input type='hidden' name='action' value='addcurrency'/> |
| | 117 | </form> |
| | 118 | </body></html> |
| | 119 | """ % baseurl |
| | 120 | self.out(html) |
| | 121 | |
| | 122 | def displayMint(self): |
| | 123 | currencyId = self.form.getfirst('currencyId','coin') |
| | 124 | html=""" |
| | 125 | <html><body> |
| | 126 | <h2>Get new coins</h2> |
| | 127 | <form action='%s' method='post'> |
| | 128 | How many <b>%ss</b><br> |
| | 129 | <input type='text' name='amount' value='1' /><br> |
| | 130 | Reference<br> |
| | 131 | <input type='text' name='reference' value='secret' /><br> |
| | 132 | <input type='submit' /> |
| | 133 | <input type='hidden' name='action' value='mint'/> |
| | 134 | <input type='hidden' name='currencyId' value='%s'/> |
| | 135 | </form> |
| | 136 | </body></html> |
| | 137 | |
| | 138 | """ % (baseurl,currencyId,currencyId) |
| | 139 | self.out(html) |
| | 140 | |
| | 141 | |
| 63 | | |
| 64 | | # |
| 65 | | |
| 66 | | if method=='post' and action == 'addcurrency': |
| 67 | | url = form.getfirst('url','') |
| 68 | | if url: |
| 69 | | transport = transports.HTTPTransport(url) |
| 70 | | w.wallet.addCurrency(transport) |
| 71 | | storage.save() |
| 72 | | action = '' |
| 73 | | elif method=='post' and action == 'mint': |
| 74 | | amount = int(form.getfirst('amount',1)) |
| 75 | | reference = form.getfirst('reference') |
| 76 | | cdd,wehave = w.getCurrency(form.getfirst('currencyId')) |
| 77 | | transport = transports.HTTPTransport(cdd.issuerServiceLocation) |
| 78 | | w.wallet.mintCoins(transport,amount,reference) |
| 79 | | action = '' |
| 80 | | |
| 81 | | elif method == 'post' and action == '': |
| 82 | | #we got stuff posted from a wallet |
| 83 | | pass |
| 84 | | |
| 85 | | |
| 86 | | if action == '': |
| 87 | | tmp = [(cdd.currencyId,cdd,amount) for cdd,amount in w.wallet.listCurrencies()] |
| 88 | | tmp.sort() |
| 89 | | currencies = [(t[1],t[2]) for t in tmp] |
| 90 | | items = [] |
| 91 | | for cdd,amount in currencies: |
| 92 | | entry = """ |
| 93 | | <li>%s %s<br/> |
| 94 | | %s<br> |
| 95 | | <a href='%s?action=mint¤cyId=%s'>Withdraw</a> |
| 96 | | </li> |
| 97 | | """ % (amount,cdd.currencyId,cdd.issuerServiceLocation,baseurl,cdd.currencyId) |
| 98 | | items.append(entry) |
| 99 | | items = '\n'.join(items) |
| 100 | | html = """ |
| 101 | | <html><body> |
| 102 | | <b>Wallet content</b> |
| 103 | | <ul> |
| 104 | | %s |
| 105 | | </ul> |
| 106 | | ----<br/> |
| 107 | | <a href='%s?action=addcurrency'>Add a currency</a> |
| 108 | | </body></html> |
| 109 | | """ % (items,baseurl) |
| 110 | | out(html) |
| 111 | | |
| 112 | | elif action == 'addcurrency': |
| 113 | | html=""" |
| 114 | | <html><body> |
| 115 | | <b>Add a currency</b> |
| 116 | | <form action='%s' method='post'> |
| 117 | | The url of the issuer:<br> |
| 118 | | <input type='text' name='url' value='http://baach.de:9090' /><br> |
| 119 | | <input type='submit' /> |
| 120 | | <input type='hidden' name='action' value='addcurrency'/> |
| 121 | | </form> |
| 122 | | </body></html> |
| 123 | | """ % baseurl |
| 124 | | out(html) |
| 125 | | |
| 126 | | elif action == 'mint': |
| 127 | | currencyId = form.getfirst('currencyId','coin') |
| 128 | | html=""" |
| 129 | | <html><body> |
| 130 | | <b>Get new coins</b> |
| 131 | | <form action='%s' method='post'> |
| 132 | | How many %ss<br> |
| 133 | | <input type='text' name='amount' value='1' /><br> |
| 134 | | Reference<br> |
| 135 | | <input type='text' name='reference' value='secret' /><br> |
| 136 | | <input type='submit' /> |
| 137 | | <input type='hidden' name='action' value='mint'/> |
| 138 | | <input type='hidden' name='currencyId' value='%s'/> |
| 139 | | </form> |
| 140 | | </body></html> |
| 141 | | |
| 142 | | """ % (baseurl,currencyId,currencyId) |
| 143 | | out(html) |
| | 151 | w.dispatchRequest() |