|
Revision 296, 1.5 kB
(checked in by ocjhb, 3 years ago)
|
|
algorithm to get values for exchange
|
-
Property svn:mime-type set to
text/plain
-
Property svn:eol-style set to
native
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | from entity import * |
|---|
| 2 | import messages |
|---|
| 3 | class Authorizer(Entity): |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | def __init__(self,storage=None): |
|---|
| 7 | Entity.__init__(self,storage) |
|---|
| 8 | self.deny = False |
|---|
| 9 | |
|---|
| 10 | def createKeys(self): |
|---|
| 11 | priv,pub = occrypto.KeyFactory(1024) |
|---|
| 12 | self.setKeys((priv,pub)) |
|---|
| 13 | return pub |
|---|
| 14 | |
|---|
| 15 | def setKeys(self,keys): |
|---|
| 16 | self.storage.setdefault('keys',[]).append(keys) |
|---|
| 17 | |
|---|
| 18 | def _getKeys(self): |
|---|
| 19 | return self.storage['keys'][-1] |
|---|
| 20 | |
|---|
| 21 | def denominationToValue(self,denomination): |
|---|
| 22 | return int(denomination) |
|---|
| 23 | |
|---|
| 24 | def authorize(self,message): |
|---|
| 25 | |
|---|
| 26 | target = message.target |
|---|
| 27 | blinds = message.blinds |
|---|
| 28 | coins = message.coins |
|---|
| 29 | |
|---|
| 30 | amount = 0 |
|---|
| 31 | |
|---|
| 32 | if self.deny: |
|---|
| 33 | answer = messages.Error() |
|---|
| 34 | answer.text = 'authorizer was told to deny' |
|---|
| 35 | return answer |
|---|
| 36 | |
|---|
| 37 | for keyid,blind in blinds: |
|---|
| 38 | mkc = self.getMKCById(keyid) |
|---|
| 39 | amount += self.denominationToValue(mkc.denomination) |
|---|
| 40 | if amount > 10000000: |
|---|
| 41 | error = messages.Error() |
|---|
| 42 | error.text = 'way too much' |
|---|
| 43 | return error |
|---|
| 44 | |
|---|
| 45 | answer = messages.AuthorizedMessage() |
|---|
| 46 | answer.message = message |
|---|
| 47 | priv,pub = self._getKeys() |
|---|
| 48 | answer.keyId = pub.hash() |
|---|
| 49 | priv.signContainer(answer) |
|---|
| 50 | return answer |
|---|
| 51 | |
|---|
| 52 | def setMKCs(self,mkcs): |
|---|
| 53 | mkclist = self.storage.setdefault('mkcs',{}) |
|---|
| 54 | for mkc in mkcs: |
|---|
| 55 | mkclist[mkc.keyId] = mkc |
|---|
| 56 | |
|---|
| 57 | def getMKCById(self,keyid): |
|---|
| 58 | return self.storage['mkcs'][keyid] |
|---|