Contract con_optic_gov_v3


Contract Code


  
1 import currency
2 import con_xoptic_lst001
3
4 S = Hash(default_value=0)
5 P = Hash(default_value=0)
6 LIST = Hash()
7 metadata = Hash(default_value=0)
8 xOPTIC_BALANCE = ForeignHash(foreign_contract='con_xoptic_lst001', foreign_name='balances')
9
10 @construct
11 def seed():
12 metadata['gov_wallet'] = '1d9c6a41b0e0de799b5cba6250a0525add486a06eb667089a1d458aa32ab42d4'
13 metadata['create_cost'] = 50_000
14 metadata['poll_time'] = 3
15 metadata['threshold'] = 20
16 metadata['operator'] = ctx.caller
17 metadata['master_contract'] = 'con_optic_protocol_v2'
18
19 @export
20 def register_poll(poll: str, data: dict):
21 user = ctx.caller
22 assert xOPTIC_BALANCE[user] >= metadata['create_cost'], 'Not enough coins to create poll!'
23 assert P[poll, 'id'] != poll, 'ID exist enough coins to create poll!'
24
25 con_xoptic_lst001.transfer_from(metadata['create_cost'], metadata['gov_wallet'], user)
26
27 P[poll, 'title'] = data['title']
28 P[poll, 'id'] = poll
29 P[poll, 'text'] = data['text']
30 P[poll, 'start'] = now
31 P[poll, 'creator'] = user
32 P[poll, 'end'] = now + datetime.timedelta(days=metadata['poll_time'])
33 P[poll, 'close'] = False
34 P[poll, 'remove'] = False
35
36 P[poll, 'option', 'YES'] += metadata['create_cost']
37 P[poll, 'vote_count'] += metadata['create_cost']
38 P[poll, 'vote_threshold'] += 1
39 S[user, poll, 'voted'] = True
40 S[user, poll, 'amount'] += 0
41
42
43 @export
44 def close_poll(poll: str):
45 assert ctx.caller == metadata['operator'
46 ], 'Only operator can set metadata!'
47
48 if P[poll, 'vote_threshold'] < metadata['threshold'] and P[poll, 'close'] == False:
49 con_xoptic_lst001.transfer_from(metadata['create_cost'], P[poll, 'creator'], metadata['gov_wallet'])
50
51 P[poll, 'close'] = True
52
53 @export
54 def remove_poll(poll: str):
55 assert ctx.caller == metadata['operator'
56 ], 'Only operator can set metadata!'
57
58 P[poll, 'remove'] = True
59
60 @export
61 def change_text(poll: str, text: str):
62 assert ctx.caller == metadata['operator'
63 ], 'Only operator can set metadata!'
64
65 P[poll, 'text'] = text
66
67 @export
68 def vote(poll: str, option: int, amount:float):
69 user = ctx.caller
70
71 xOPTIC = ForeignHash(foreign_contract= metadata['master_contract'], foreign_name='S')
72 user_balance = xOPTIC[user,'xoptic_pledge'] - S[user, poll, 'amount']
73 assert amount > 0, 'You must send something.'
74 assert user_balance >= amount, 'Not enough coins to send!'
75 assert P[poll, 'close'] == False, 'Poll close'
76 assert P[poll, 'end'] > now, 'Poll close'
77 assert option >= 0, 'Invalid option'
78 assert option < 2, 'Invalid option'
79
80
81 if S[user, poll, 'voted'] == True:
82 """none"""
83 else:
84 S[user, poll, 'voted'] = True
85 P[poll, 'vote_threshold'] += 1
86
87 if option == 0:
88 P[poll, 'option', 'NO'] += amount
89
90 if option == 1:
91 P[poll, 'option', 'YES'] += amount
92
93 P[poll, 'vote_count'] += amount
94 S[user, poll, 'amount'] += amount
95
96 @export
97 def claim(poll: str):
98 user = ctx.caller
99 assert P[poll, 'close'] == True, 'Poll not close'
100 assert P[poll, 'end'] >= now, 'Poll not close'
101 assert S[user, poll, 'amount'] > 0, 'You must send something.'
102
103 amount = S[user, poll,'amount']
104
105 S[user, poll,'amount'] = 0
106
107 #participation
108 if P[poll, 'vote_threshold'] >= metadata['threshold']:
109 PART = (amount * 100) / P[poll, 'vote_count']
110 REWARDS = metadata['create_cost'] * (PART/100)
111 else:
112 REWARDS = 0
113
114 con_xoptic_lst001.transfer_from(REWARDS, user, metadata['gov_wallet'])
115
116
117
118 @export
119 def change_meta(meta: str, value: Any):
120 assert ctx.caller == metadata['operator'
121 ], 'Only operator can set metadata!'
122 metadata[meta] = value
123

Byte Code

e300000000000000000000000006000000400000007306010000640064016c005a00640064016c015a01650264006402640364048d035a03650264006402640564048d035a0465026402640664078d025a05650264006402640864048d035a0665076409640a6402640b640c8d045a08640d640e84005a09650a64028301650b650c640f9c0264106411840483015a0d650a64028301650b64129c0164136414840483015a0e650a64028301650b64129c0164156416840483015a0f650a64028301650b650b64179c0264186419840483015a10650a64028301650b65116512641a9c03641b641c840483015a13650a64028301650b64129c01641d641e840483015a14650a64028301650b6515641f9c0264206421840483015a16640153002922e9000000004eda10636f6e5f6f707469635f676f765f7633da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0150da044c495354290272050000007206000000da086d65746164617461da11636f6e5f786f707469635f6c7374303031da0862616c616e636573da0e784f505449435f42414c414e43452904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d657205000000720600000063000000000000000000000000030000004300000073360000006401740064023c006403740064043c006405740064063c006407740064083c0074016a02740064093c00640a7400640b3c0064005300290c4eda4031643963366134316230653064653739396235636261363235306130353235616464343836613036656236363730383961316434353861613332616234326434da0a676f765f77616c6c65746950c30000da0b6372656174655f636f7374e903000000da09706f6c6c5f74696d65e914000000da097468726573686f6c64da086f70657261746f72da15636f6e5f6f707469635f70726f746f636f6c5f7632da0f6d61737465725f636f6e74726163742903da0a5f5f6d65746164617461da03637478da0663616c6c6572a900721c000000721c000000da00da045f5f5f5f0d000000730c000000000208010801080108010a01721e0000002902da04706f6c6cda0464617461630200000000000000030000000500000043000000733201000074006a017d0274027c0219007403640119006b05731e740464028301820174057c006403660219007c006b037336740464048301820174066a077403640119007403640519007c02830301007c016406190074057c00640666023c007c0074057c00640366023c007c016407190074057c00640766023c00740874057c00640866023c007c0274057c00640966023c00740874096a0a7403640a1900640b8d01170074057c00640c66023c00640d74057c00640e66023c00640d74057c00640f66023c0074057c0064106411660305001900740364011900370003003c0074057c006412660205001900740364011900370003003c0074057c0064136602050019006414370003003c006415740b7c027c00641666033c00740b7c027c0064176603050019006418370003003c006400530029194e72110000007a204e6f7420656e6f75676820636f696e7320746f2063726561746520706f6c6c21da0269647a25494420657869737420656e6f75676820636f696e7320746f2063726561746520706f6c6c217210000000da057469746c65da0474657874da057374617274da0763726561746f7272130000002901da0464617973da03656e6446da05636c6f7365da0672656d6f7665da066f7074696f6eda03594553da0a766f74655f636f756e74da0e766f74655f7468726573686f6c64e90100000054da05766f746564da06616d6f756e747201000000290c721a000000721b000000da105f5f784f505449435f42414c414e43457219000000da0e417373657274696f6e4572726f72da035f5f50720a000000da0d7472616e736665725f66726f6dda036e6f77da086461746574696d65da0974696d6564656c7461da035f5f532903721f0000007220000000da0475736572721c000000721c000000721d000000da0d72656769737465725f706f6c6c170000007326000000000206011201060118010c010a0110010c0110010c010c011c010c010c011a01180114010e01723a0000002901721f000000630100000000000000010000000500000043000000736800000074006a017402640119006b027316740364028301820174047c006403660219007402640419006b00725874047c0064056602190064066b02725874056a0674026407190074047c0064086602190074026409190083030100640a74047c00640566023c0064005300290b4e72160000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121722d0000007215000000722800000046721100000072250000007210000000542907721a000000721b000000721900000072320000007233000000720a00000072340000002901721f000000721c000000721c000000721d000000da0a636c6f73655f706f6c6c2e000000730e00000000021001060118010c010e011001723b000000630100000000000000010000000400000043000000732600000074006a017402640119006b0273167403640283018201640374047c00640466023c006400530029054e72160000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461215472290000002905721a000000721b0000007219000000723200000072330000002901721f000000721c000000721c000000721d000000da0b72656d6f76655f706f6c6c390000007306000000000210010601723c0000002902721f0000007223000000630200000000000000020000000400000043000000732600000074006a017402640119006b02731674036402830182017c0174047c00640366023c006400530029044e72160000007a1f4f6e6c79206f70657261746f722063616e20736574206d657461646174612172230000002905721a000000721b0000007219000000723200000072330000002902721f0000007223000000721c000000721c000000721d000000da0b6368616e67655f74657874400000007306000000000210010601723d0000002903721f000000722a0000007230000000630300000000000000060000000600000043000000734601000074006a017d03740274036401190064026403640464058d047d047c047c0364066602190074047c037c0064076603190018007d057c0264086b04734474056409830182017c057c026b0573547405640a8301820174067c00640b66021900640c6b02736c7405640d8301820174067c00640e6602190074076b0473847405640d830182017c0164086b0573947405640f830182017c0164106b0073a47405640f8301820174047c037c0064116603190064126b0272b86e22641274047c037c00641166033c0074067c0064136602050019006414370003003c007c0164086b0272f874067c00641564166603050019007c02370003003c007c0164146b029001721874067c00641564176603050019007c02370003003c0074067c0064186602050019007c02370003003c0074047c037c0064076603050019007c02370003003c006400530029194e721800000072030000007202000000da06784f505449432904720d000000720e00000072050000007206000000da0d786f707469635f706c65646765723000000072010000007a18596f75206d7573742073656e6420736f6d657468696e672e7a194e6f7420656e6f75676820636f696e7320746f2073656e64217228000000467a0a506f6c6c20636c6f736572270000007a0e496e76616c6964206f7074696f6ee902000000722f00000054722d000000722e000000722a000000da024e4f722b000000722c0000002908721a000000721b000000da0b466f726569676e48617368721900000072380000007232000000723300000072350000002906721f000000722a00000072300000007239000000da085f5f784f50544943da0c757365725f62616c616e6365721c000000721c000000721d000000da04766f74654700000073280000000002060108010c011a01100110011801180110011001120102020e011401080116010a0116011401724500000063010000000000000005000000050000004300000073c000000074006a017d0174027c0064016602190064026b02731e740364038301820174027c0064046602190074046b057336740364038301820174057c017c0064056603190064066b047350740364078301820174057c017c006405660319007d02640674057c017c00640566033c0074027c006408660219007406640919006b0572a67c02640a140074027c00640b660219001b007d037406640c19007c03640a1b0014007d046e0464067d0474076a087c047c017406640d19008303010064005300290e4e7228000000547a0e506f6c6c206e6f7420636c6f73657227000000723000000072010000007a18596f75206d7573742073656e6420736f6d657468696e672e722d0000007215000000e964000000722c000000721100000072100000002909721a000000721b00000072330000007232000000723500000072380000007219000000720a00000072340000002905721f00000072390000007230000000da0450415254da0752455741524453721c000000721c000000721d000000da05636c61696d60000000731600000000020601180118011a010e010e01140114011202040172490000002902da046d657461da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e72160000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721a000000721b000000721900000072320000002902724a000000724b000000721c000000721c000000721d000000da0b6368616e67655f6d657461700000007306000000000210010601724c0000002917da0863757272656e6379720a000000da044861736872380000007233000000da065f5f4c495354721900000072420000007231000000721e000000da085f5f6578706f7274da03737472da0464696374723a000000723b000000723c000000723d000000da03696e74da05666c6f617472450000007249000000da03416e79724c000000721c000000721c000000721c000000721d000000da083c6d6f64756c653e01000000732c000000080108010e010e010c010e0204010c04080a060112160601100a0601100606011206060114180601100f0601