Contract con_oracle


Contract Code


  
1 import con_otoken
2 import currency
3 __tau_price_in_cents = Variable(contract='con_oracle', name=
4 'tau_price_in_cents')
5 __frozen = Variable(contract='con_oracle', name='frozen')
6 __cost_enabled = Variable(contract='con_oracle', name='cost_enabled')
7 __operator = Hash(default_value=False, contract='con_oracle', name='operator')
8 __price = Hash(default_value=decimal('2.56'), contract='con_oracle', name=
9 'price')
10
11
12 def ____():
13 __tau_price_in_cents.set(decimal('2.56'))
14 __operator['list'] = [
15 '96474552a93330e5af51d8a4ec22177d7b57eb1d776eeaa73a049a1830064542',
16 'd3b192f8d65375e1c5e80c306a99c3ae7979a98f90c92776db7914cc1b3ec181',
17 '0000803efd5df09c75c0c6670742db5074e5a011b829dfd8a0c50726d263a345']
18 __operator[ctx.caller] = True
19
20
21 @__export('con_oracle')
22 def set_price(new_price: float):
23 assert __operator[ctx.caller] is True
24 assert new_price < decimal('1.2') * __tau_price_in_cents.get() + decimal(
25 '0.1')
26 assert new_price > 0
27 __price[ctx.caller] = new_price
28
29
30 @__export('con_oracle')
31 def calculate_price():
32 assert __frozen.get() != True
33 oracle_count = 0
34 total_price = 0
35 for x in __operator['list']:
36 oracle_count += 1
37 total_price += __price[x]
38 __tau_price_in_cents.set(total_price / oracle_count)
39
40
41 @__export('con_oracle')
42 def replace_oracle(new_oracle: str):
43 assert __operator[ctx.caller] is True
44 __operator[ctx.caller] = False
45 __operator['list'] = __operator['list'].remove(ctx.caller)
46 __operator['list'] = __operator['list'].append(new_oracle)
47 __price[new_oracle] = __tau_price_in_cents.get()
48
49
50 @__export('con_oracle')
51 def get_price():
52 if __cost_enabled.get() is True:
53 con_otoken.transfer_from(1, ctx.this, ctx.caller)
54 return __tau_price_in_cents.get()
55
56
57 @__export('con_oracle')
58 def disperse_token():
59 amount = con_otoken.balance_of(ctx.this) / len(__operator['list'])
60 for x in __operator['list']:
61 con_otoken.transfer(amount, x)
62 amount = currency.balance_of(ctx.this) / len(__operator['list'])
63 for x in __operator['list']:
64 currency.transfer(amount, x)
65
66
67 @__export('con_oracle')
68 def is_frozen():
69 return __frozen.get()
70
71
72 @__export('con_oracle')
73 def freeze_vote(vote: bool):
74 assert __operator[ctx.caller] is True
75 __operator[ctx.caller, 'freeze'] = vote
76
77
78 @__export('con_oracle')
79 def freeze():
80 oracle_count = 0
81 yes_votes = 0
82 for x in __operator['list']:
83 oracle_count += 1
84 if __operator[x, 'freeze'] is True:
85 yes_votes += 1
86 if yes_votes / oracle_count > decimal('0.5'):
87 __frozen.set(True)
88 return True
89 else:
90 __frozen.set(False)
91 return False
92
93
94 @__export('con_oracle')
95 def enable_cost():
96 assert __operator[ctx.caller] is True
97 __cost_enabled.set(True)
98

Byte Code

e300000000000000000000000005000000400000007302010000640064016c005a00640064016c015a0165026402640364048d025a0365026402640564048d025a0465026402640664048d025a05650664076402640864098d035a0765066508640a83016402640b64098d035a09640c640d84005a0a650b64028301650c640e9c01640f6410840483015a0d650b6402830164116412840083015a0e650b64028301650f64139c0164146415840483015a10650b6402830164166417840083015a11650b6402830164186419840083015a12650b64028301641a641b840083015a13650b640283016514641c9c01641d641e840483015a15650b64028301641f6420840083015a16650b6402830164216422840083015a17640153002923e9000000004eda0a636f6e5f6f7261636c65da127461755f70726963655f696e5f63656e74732902da08636f6e7472616374da046e616d65da0666726f7a656eda0c636f73745f656e61626c656446da086f70657261746f722903da0d64656661756c745f76616c7565720400000072050000007a04322e3536da057072696365630000000000000000000000000300000043000000732a00000074006a01740264018301830101006402640364046703740364053c006406740374046a053c006400530029074e7a04322e3536da4039363437343535326139333333306535616635316438613465633232313737643762353765623164373736656561613733613034396131383330303634353432da4064336231393266386436353337356531633565383063333036613939633361653739373961393866393063393237373664623739313463633162336563313831da4030303030383033656664356466303963373563306336363730373432646235303734653561303131623832396466643861306335303732366432363361333435da046c697374542906da145f5f7461755f70726963655f696e5f63656e7473da03736574da07646563696d616cda0a5f5f6f70657261746f72da03637478da0663616c6c6572a90072150000007215000000da00da045f5f5f5f0c000000730a00000000010e02020102010a0172170000002901da096e65775f7072696365630100000000000000010000000400000043000000734c000000740074016a02190064016b087312740382017c0074046402830174056a068300140074046403830117006b007332740382017c0064046b04733e740382017c00740774016a023c006400530029054e547a03312e327a03302e3172010000002908721200000072130000007214000000da0e417373657274696f6e4572726f727211000000720f000000da03676574da075f5f707269636529017218000000721500000072150000007216000000da097365745f707269636515000000730a0000000002120112010e010c01721c000000630000000000000000030000000400000043000000735000000074006a01830064016b0373107402820164027d0064027d01782474036403190044005d187d027c00640437007d007c0174047c02190037007d017122570074056a067c017c001b00830101006400530029054e547201000000720e000000e9010000002907da085f5f66726f7a656e721a00000072190000007212000000721b000000720f00000072100000002903da0c6f7261636c655f636f756e74da0b746f74616c5f7072696365da0178721500000072150000007216000000da0f63616c63756c6174655f70726963651e000000730e00000000021001040104010e010801100172220000002901da0a6e65775f6f7261636c656301000000000000000100000003000000430000007352000000740074016a02190064016b087312740382016402740074016a023c007400640319006a0474016a028301740064033c007400640319006a057c008301740064033c0074066a07830074087c003c006400530029044e5446720e00000029097212000000721300000072140000007219000000da0672656d6f7665da06617070656e64720f000000721a000000721b00000029017223000000721500000072150000007216000000da0e7265706c6163655f6f7261636c6529000000730a000000000212010a01140112017226000000630000000000000000000000000400000043000000732600000074006a01830064016b08721e74026a03640274046a0574046a068303010074076a018300530029034e54721d0000002908da0e5f5f636f73745f656e61626c6564721a000000da0a636f6e5f6f746f6b656eda0d7472616e736665725f66726f6d7213000000da04746869737214000000720f0000007215000000721500000072150000007216000000da096765745f707269636532000000730600000000020c011201722b000000630000000000000000020000000400000043000000737000000074006a0174026a038301740474056401190083011b007d00781c74056401190044005d107d0174006a067c007c01830201007122570074076a0174026a038301740474056401190083011b007d00781c74056401190044005d107d0174076a067c007c0183020100715857006400530029024e720e00000029087228000000da0a62616c616e63655f6f667213000000722a000000da036c656e7212000000da087472616e73666572da0863757272656e63792902da06616d6f756e747221000000721500000072150000007216000000da0e64697370657273655f746f6b656e39000000730c000000000218010e01100118010e017231000000630000000000000000000000000100000043000000730800000074006a018300530029014e2902721e000000721a0000007215000000721500000072150000007216000000da0969735f66726f7a656e430000007302000000000272320000002901da04766f74656301000000000000000100000004000000430000007324000000740074016a02190064016b087312740382017c00740074016a02640266023c006400530029034e54da06667265657a652904721200000072130000007214000000721900000029017233000000721500000072150000007216000000da0b667265657a655f766f7465480000007304000000000212017235000000630000000000000000030000000400000043000000736a00000064017d0064017d01783074006402190044005d247d027c00640337007d0074007c0264046602190064056b0872127c01640337007d01711257007c017c001b007401640683016b04725874026a036405830101006405530074026a03640783010100640753006400530029084e7201000000720e000000721d0000007234000000547a03302e3546290472120000007211000000721e00000072100000002903721f000000da097965735f766f746573722100000072150000007215000000721600000072340000004e00000073160000000002040104010e01080110010c0110010a0104020a0172340000006300000000000000000000000002000000430000007320000000740074016a02190064016b0873127403820174046a056401830101006400530029024e5429067212000000721300000072140000007219000000722700000072100000007215000000721500000072150000007216000000da0b656e61626c655f636f73745e000000730400000000021201723700000029187228000000722f000000da085661726961626c65720f000000721e0000007227000000da044861736872120000007211000000721b0000007217000000da085f5f6578706f7274da05666c6f6174721c0000007222000000da037374727226000000722b00000072310000007232000000da04626f6f6c7235000000723400000072370000007215000000721500000072150000007216000000da083c6d6f64756c653e01000000732a00000008010801040108010c010c010e010a010803080906011008100b060110081007100a1005060110051010