| 1 | """run this file to run an issuer. If required, it will setup a currency""" |
|---|
| 2 | |
|---|
| 3 | ### minmal config ### |
|---|
| 4 | |
|---|
| 5 | #where can this server be reached? |
|---|
| 6 | baseurl = 'http://10.42.43.1' |
|---|
| 7 | #what port to run on? |
|---|
| 8 | port = 9090 |
|---|
| 9 | |
|---|
| 10 | ### nothing to config below this ### |
|---|
| 11 | |
|---|
| 12 | import BaseHTTPServer |
|---|
| 13 | import issuer, mint,authorizer,storage |
|---|
| 14 | from testutils import Handler |
|---|
| 15 | |
|---|
| 16 | issuerstorage = storage.Storage().setFilename('data/issuerstorage.bin').restore() |
|---|
| 17 | mintstorage = storage.Storage().setFilename('data/mintstorage.bin').restore() |
|---|
| 18 | authorizerstorage = storage.Storage().setFilename('data/authorizerstorage.bin').restore() |
|---|
| 19 | |
|---|
| 20 | issuer = issuer.Issuer(issuerstorage) |
|---|
| 21 | mint = mint.Mint(mintstorage) |
|---|
| 22 | authorizer = authorizer.Authorizer(authorizerstorage) |
|---|
| 23 | |
|---|
| 24 | if not issuerstorage.has_key('masterPrivKey'): |
|---|
| 25 | print 'Issuer: setting up master keys' |
|---|
| 26 | issuer.createMasterKeys() |
|---|
| 27 | |
|---|
| 28 | print 'issuer: setup currency discription' |
|---|
| 29 | denominations=[1,2,5,10,20,50,100,200,500,1000,2000,5000,10000,20000,50000,100000,200000,500000] |
|---|
| 30 | cdd = issuer.makeCDD('TestCent','tc',[str(d) for d in denominations],'%s:%s/' % (baseurl,port),'') |
|---|
| 31 | mint.setCDD(cdd) |
|---|
| 32 | |
|---|
| 33 | print 'mint: setting up mintkeys' |
|---|
| 34 | keys = mint.newMintKeys() |
|---|
| 35 | |
|---|
| 36 | print 'issuer: signing mintkeys' |
|---|
| 37 | mkcs = issuer.signMintKeys(keys=keys,cdd = cdd) |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | print 'authorizer: creating keys' |
|---|
| 41 | authpub = authorizer.createKeys() |
|---|
| 42 | |
|---|
| 43 | print 'mint: add authorizer key' |
|---|
| 44 | mint.addAuthKey(authpub) |
|---|
| 45 | print 'authorizer: set mkcs' |
|---|
| 46 | authorizer.setMKCs(mkcs.values()) #FIXME - signMintKeys and fetchMintKeys return different |
|---|
| 47 | |
|---|
| 48 | print 'saving everything' |
|---|
| 49 | issuerstorage.save() |
|---|
| 50 | mintstorage.save() |
|---|
| 51 | authorizerstorage.save() |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | def address_string(self): |
|---|
| 55 | host, port = self.client_address[:2] |
|---|
| 56 | return host |
|---|
| 57 | |
|---|
| 58 | print 'Starting up server on port %s ' % port |
|---|
| 59 | Handler.issuer = issuer |
|---|
| 60 | Handler.mint = mint |
|---|
| 61 | Handler.authorizer = authorizer |
|---|
| 62 | httpd = BaseHTTPServer.HTTPServer(("", port), Handler) |
|---|
| 63 | httpd.address_string = address_string |
|---|
| 64 | httpd.serve_forever() |
|---|