Contract con_uw_master_season_1_


Contract Code

1 import currency
2 import con_uwarriors_lst001
3
4 I = importlib
5 S = Hash(default_value='')
6 balances = Hash(default_value=0)
7 metadata = Hash(default_value=0)
8 nicks = Hash(default_value=0)
9 wp = ForeignHash(foreign_contract='con_uwarriors_lst001', foreign_name='balances')
10
11 @construct
12 def seed():
13 metadata['operator'] = ctx.caller
14 metadata['withdrawal'] = False
15 metadata['starter_pack_price'] = 1500
16 metadata['game_cost'] = 2
17 metadata['time'] = 14
18 metadata['fees'] = decimal('0.15')
19 metadata['fees_withdrawal'] = decimal('0.20')
20
21 @export
22 def set_nick_name(nickname: str):
23 caller = ctx.caller
24 assert len(nickname) <= 25, 'Nickname too long (25 chars max).'
25 assert len(nickname) > 0, 'Nickname too short.'
26 names_uid = hashlib.sha256(nickname.lower().replace(' ', ''))
27 assert not nicks['nicknames', names_uid], 'A form of this name already belongs to ' + nicks['nicknames', names_uid]
28 nicks[caller, 'nickname'] = nickname
29 nicks['nicknames', names_uid] = nickname
30
31
32 @export
33 def change_nick_name(nickname: str, change: str):
34 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
35 assert len(nickname) <= 25, 'Nickname too long (25 chars max).'
36 assert len(nickname) > 0, 'Nickname too short.'
37 names_uid = hashlib.sha256(nickname.lower().replace(' ', ''))
38 assert not nicks['nicknames', names_uid], 'A form of this name already belongs to ' + nicks['nicknames', names_uid]
39 nicks[nickname, 'nickname'] = change
40 nicks['nicknames', names_uid] = change
41
42
43 @export
44 def play():
45 sender = ctx.caller
46 amount = metadata['game_cost']
47 operator = metadata['operator']
48 assert wp[sender] > amount , 'Not enough coins to send!'
49 con_uwarriors_lst001.transfer_from(amount, metadata['operator'], sender)
50 balances[sender, 'can_play'] = True
51
52
53 @export
54 def buy_character():
55 sender = ctx.caller
56 amount = metadata['starter_pack_price']
57 operator = metadata['operator']
58 assert wp[sender] > amount , 'Not enough coins to send!'
59 con_uwarriors_lst001.transfer_from(amount, metadata['operator'], sender)
60
61
62 @export
63 def change_thing_meta(uid: str, meta: dict, contract: str):
64 assert ctx.caller == metadata['operator'] or metadata['operator_thing_meta'] == ctx.caller, 'Only operator can set metadata!'
65 thing_info = I.import_module(contract)
66 thing_uid = thing_info.change_meta(uid, meta)
67 return thing_uid
68
69 @export
70 def rewards(uid: str, amount: float):
71 assert ctx.caller == metadata['operator'], 'Only operator'
72 assert balances[uid, 'can_play'] == true, 'No can Play'
73
74 if metadata['withdrawal'] == True:
75 balances[uid, 'rewards'] += amount
76 balances[uid, 'total_rewards'] += amount
77 if balances[uid, 'rewards', 'time'] is None:
78 balances[uid, 'rewards', 'time'] = now
79 else:
80 balances[uid, 'total_rewards'] += amount
81 con_uwarriors_lst001.transfer_from(amount, uid, metadata['operator'])
82
83 balances[uid, 'can_play'] = False
84
85
86 @export
87 def withdrawal():
88 sender = ctx.caller
89 assert balances[sender, 'rewards'] > 0, 'Cannot send negative balances!'
90
91 amount = balances[sender, 'rewards']
92 if metadata['withdrawal'] == True:
93 if (now - balances[sender, 'rewards', 'time']).days > metadata['time']:
94
95 con_uwarriors_lst001.transfer_from(amount, sender, metadata['operator'])
96 balances[sender, 'rewards'] = 0
97 balances[uid, 'rewards', 'time'] = now
98 else:
99 con_uwarriors_lst001.transfer_from(amount - (amount * metadata['fees_withdrawal']), sender, metadata['operator'])
100 balances[sender, 'rewards'] = 0
101 balances[uid, 'rewards', 'time'] = now
102
103 @export
104 def add_thing_meta(uid: str, meta:str, contract: str, value: Any):
105 assert ctx.caller == metadata['operator'] or metadata['operator_thing_meta'] == ctx.caller, 'Only operator can set metadata!'
106 thing_info = I.import_module(contract)
107 thing_uid = thing_info.add_meta(uid, meta, value)
108
109 return thing_uid
110
111
112 @export
113 def add_user_data(uid: str, meta: str, data:str, value: Any):
114 assert ctx.caller == metadata['operator'] or metadata['operator_user_data'] == ctx.caller, 'Only operator can set metadata!'
115 balances[key, data] = value
116
117 @export
118 def change_metadata(key: str, value: Any):
119 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
120 metadata[key] = value
121
122
123 @export
124 def create_thing(contract: str, thing_string: str, name: str, owner: str, meta: dict = {}):
125 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
126 thing_info = I.import_module(contract)
127 sender = ctx.caller
128 thing_uid = thing_info.add_thing(thing_string, name, meta, owner)
129
130 return thing_uid
131
132 @export
133 def buy_thing(uid: str, contract:str):
134 thing_info = I.import_module(contract)
135 sender = ctx.caller
136 owner = thing_info.get_owner(uid)
137 creator = thing_info.get_creator(uid)
138
139 assert_already_owned(uid, sender, contract)
140
141 price_amount = thing_info.get_price_amount(uid)
142
143 assert price_amount, uid + ' is not for sale'
144 assert price_amount > 0, uid + ' is not for sale'
145
146 price_amount_pay = price_amount - (price_amount * metadata['fees'])
147
148 con_uwarriors_lst001.transfer_from(price_amount_pay, owner, sender)
149 con_uwarriors_lst001.transfer_from((price_amount * metadata['fees']), metadata['operator'], sender)
150
151 transfer_ownership(uid, sender, contract)
152
153 return price_amount
154
155
156 @export
157 def sell_thing(uid: str, amount: float, description: str, contract:str):
158 thing_info = I.import_module(contract)
159 auction = thing_info.get_auction(uid)
160
161 assert auction == False, ' is on auction'
162
163 assert_ownership(uid, ctx.caller, contract)
164
165 thing_info.set_price(uid, amount)
166
167 @export
168 def transfer(uid: str, new_owner: str, contract:str):
169 sender = ctx.caller
170 assert_ownership(uid, sender, contract)
171 assert_already_owned(uid, new_owner, contract)
172 transfer_ownership(uid, new_owner, contract)
173
174 @export
175 def approve(uid: str, to: str, contract:str):
176 sender = ctx.caller
177 assert_ownership(uid, sender, contract)
178 balances[sender, uid, to] = True
179
180
181 @export
182 def revoke(uid: str, to: str):
183 balances[ctx.caller, uid, to] = None
184
185
186 @export
187 def transfer_from(uid: str, to: str, main_account: str, contract: str):
188 sender = ctx.caller
189
190 assert balances[main_account, uid, sender], f"You have not been given approval to transfer this user's item. {main_account} {sender}"
191 assert_ownership(uid, main_account, contract)
192 assert_already_owned(uid, to, contract)
193 transfer_ownership(uid, to, contract)
194
195 balances[main_account, uid, sender] = None
196
197
198 def assert_already_owned(uid: str, sender: str, contract: str):
199 thing_info = I.import_module(contract)
200 owner = thing_info.get_owner(uid)
201 assert owner != sender, uid + ' already owned by ' + sender
202
203
204 def assert_ownership(uid: str, sender, contract: str):
205 thing_info = I.import_module(contract)
206 owner = thing_info.get_owner(uid)
207 assert owner == sender, uid + ' not owned by ' + sender
208
209
210 def transfer_ownership(uid:str, new_owner: str, contract: str):
211 thing_info = I.import_module(contract)
212 old_owner = thing_info.get_owner(uid)
213 thing_info.set_owner(uid, new_owner)
214 if thing_info.get_price_amount(uid) > 0:
215 thing_info.set_price(uid, 0)
216
217
218
219
220
221

Byte Code

e30000000000000000000000000800000040000000733a020000640064016c005a00640064016c015a0165025a03650464026403640464058d035a05650464006403640664058d035a06650464006403640764058d035a07650464006403640864058d035a086509640964066403640a640b8d045a0a640c640d84005a0b650c64038301650d640e9c01640f6410840483015a0e650c64038301650d650d64119c0264126413840483015a0f650c6403830164146415840083015a10650c6403830164166417840083015a11650c64038301650d6512650d64189c036419641a840483015a13650c64038301650d6514641b9c02641c641d840483015a15650c64038301641e641f840083015a16650c64038301650d650d650d651764209c0464216422840483015a18650c64038301650d650d650d651764239c0464246425840483015a19650c64038301650d651764269c0264276428840483015a1a650c6403830169006601650d650d650d650d651264299c05642a642b840583015a1b650c64038301650d650d642c9c02642d642e840483015a1c650c64038301650d6514650d650d642f9c0464306431840483015a1d650c64038301650d650d650d64329c0364336434840483015a1e650c64038301650d650d650d64359c0364366437840483015a1f650c64038301650d650d64389c026439643a840483015a20650c64038301650d650d650d650d643b9c04643c643d840483015a21650d650d650d643e9c03643f644084045a22650d650d642c9c026441644284045a23650d650d650d64329c036443644484045a24640153002945e9000000004eda00da17636f6e5f75775f6d61737465725f736561736f6e5f315fda01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d65746164617461da056e69636b73da14636f6e5f7577617272696f72735f6c7374303031da0277702904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572060000007207000000630000000000000000000000000300000043000000734600000074006a01740264013c006402740264033c006404740264053c006406740264073c006408740264093c007403640a83017402640b3c007403640c83017402640d3c0064005300290e4eda086f70657261746f7246da0a7769746864726177616c69dc050000da12737461727465725f7061636b5f7072696365e902000000da0967616d655f636f7374e90e000000da0474696d657a04302e3135da04666565737a04302e3230da0f666565735f7769746864726177616c2904da03637478da0663616c6c6572da0a5f5f6d65746164617461da07646563696d616ca900721c000000721c0000007202000000da045f5f5f5f0f000000730e00000000010a0108010801080108010c01721d0000002901da086e69636b6e616d65630100000000000000030000000500000043000000738200000074006a017d0174027c00830164016b01731a740364028301820174027c00830164036b04732e740364048301820174046a057c006a0683006a0764056406830283017d02740864077c02660219000c00736674036408740864077c02660219001700830182017c0074087c01640966023c007c00740864077c0266023c0064005300290a4ee9190000007a214e69636b6e616d6520746f6f206c6f6e6720283235206368617273206d6178292e72010000007a134e69636b6e616d6520746f6f2073686f72742efa01207202000000da096e69636b6e616d65737a274120666f726d206f662074686973206e616d6520616c72656164792062656c6f6e677320746f20721e000000290972180000007219000000da036c656eda0e417373657274696f6e4572726f72da07686173686c6962da06736861323536da056c6f776572da077265706c616365da075f5f6e69636b732903721e0000007219000000da096e616d65735f756964721c000000721c0000007202000000da0d7365745f6e69636b5f6e616d6519000000731200000000020601140114011601100106010c010c01722a0000002902721e000000da066368616e6765630200000000000000030000000500000043000000739200000074006a017402640119006b027316740364028301820174047c00830164036b01732a740364048301820174047c00830164056b04733e740364068301820174056a067c006a0783006a0864076408830283017d02740964097c02660219000c0073767403640a740964097c02660219001700830182017c0174097c00640b66023c007c01740964097c0266023c0064005300290c4e720f0000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121721f0000007a214e69636b6e616d6520746f6f206c6f6e6720283235206368617273206d6178292e72010000007a134e69636b6e616d6520746f6f2073686f72742e7220000000720200000072210000007a274120666f726d206f662074686973206e616d6520616c72656164792062656c6f6e677320746f20721e000000290a72180000007219000000721a00000072230000007222000000722400000072250000007226000000722700000072280000002903721e000000722b0000007229000000721c000000721c0000007202000000da106368616e67655f6e69636b5f6e616d65260000007314000000000210010601140114011601100106010c010c01722c000000630000000000000000030000000400000043000000734c00000074006a017d007402640119007d017402640219007d0274037c0019007c016b04732a740464038301820174056a067c017402640219007c0083030100640474077c00640566023c006400530029064e7213000000720f0000007a194e6f7420656e6f75676820636f696e7320746f2073656e642154da0863616e5f706c6179290872180000007219000000721a000000da045f5f77707223000000720b000000da0d7472616e736665725f66726f6dda0a5f5f62616c616e6365732903da0673656e646572da06616d6f756e74720f000000721c000000721c0000007202000000da04706c617934000000730c0000000002060108010801140112017233000000630000000000000000030000000400000043000000734000000074006a017d007402640119007d017402640219007d0274037c0019007c016b04732a740464038301820174056a067c017402640219007c00830301006400530029044e7211000000720f0000007a194e6f7420656e6f75676820636f696e7320746f2073656e6421290772180000007219000000721a000000722e0000007223000000720b000000722f000000290372310000007232000000720f000000721c000000721c0000007202000000da0d6275795f6368617261637465723e000000730a0000000002060108010801140172340000002903da03756964da046d6574617206000000630300000000000000050000000300000043000000733e00000074006a017402640119006b02732474026402190074006a016b027324740364038301820174046a057c0283017d037c036a067c007c0183027d047c04530029044e720f000000da136f70657261746f725f7468696e675f6d6574617a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290772180000007219000000721a0000007223000000da0149da0d696d706f72745f6d6f64756c65da0b6368616e67655f6d6574612905723500000072360000007206000000da0a7468696e675f696e666fda097468696e675f756964721c000000721c0000007202000000da116368616e67655f7468696e675f6d65746147000000730a0000000002100114010a010c01723d00000029027235000000723200000063020000000000000002000000050000004300000073ba00000074006a017402640119006b027316740364028301820174047c0064036602190074056b02732e740364048301820174026405190064066b02728474047c0064076602050019007c01370003003c0074047c0064086602050019007c01370003003c0074047c00640764096603190064006b0872aa740674047c006407640966033c006e2674047c0064086602050019007c01370003003c0074076a087c017c0074026401190083030100640a74047c00640366023c0064005300290b4e720f0000007a0d4f6e6c79206f70657261746f72722d0000007a0b4e6f2063616e20506c6179721000000054da0772657761726473da0d746f74616c5f72657761726473721500000046290972180000007219000000721a00000072230000007230000000da0474727565da036e6f77720b000000722f000000290272350000007232000000721c000000721c0000007202000000723e0000005000000073140000000002160118010c01140114011201100214011201723e00000063000000000000000002000000050000004300000073bc00000074006a017d0074027c0064016602190064026b04731e740364038301820174027c006401660219007d0174046404190064056b0272b8740574027c00640164066603190018006a067404640619006b04728074076a087c017c0074046407190083030100640274027c00640166023c007405740274096401640666033c006e3874076a087c017c01740464081900140018007c0074046407190083030100640274027c00640166023c007405740274096401640666033c006400530029094e723e00000072010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217210000000547215000000720f0000007217000000290a7218000000721900000072300000007223000000721a0000007241000000da0464617973720b000000722f0000007235000000290272310000007232000000721c000000721c000000720200000072100000005f000000731c0000000002060118010c010c01140108010a0108010c0110020a0114010c0172100000002904723500000072360000007206000000da0576616c7565630400000000000000060000000400000043000000734000000074006a017402640119006b02732474026402190074006a016b027324740364038301820174046a057c0283017d047c046a067c007c017c0383037d057c05530029044e720f00000072370000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290772180000007219000000721a000000722300000072380000007239000000da086164645f6d65746129067235000000723600000072060000007243000000723b000000723c000000721c000000721c0000007202000000da0e6164645f7468696e675f6d65746172000000730a0000000002100114010a010e017245000000290472350000007236000000da04646174617243000000630400000000000000040000000400000043000000733400000074006a017402640119006b02732474026402190074006a016b02732474036403830182017c03740474057c0266023c006400530029044e720f000000da126f70657261746f725f757365725f646174617a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290672180000007219000000721a00000072230000007230000000da036b657929047235000000723600000072460000007243000000721c000000721c0000007202000000da0d6164645f757365725f646174617b00000073060000000002100114017249000000290272480000007243000000630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720f0000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290472180000007219000000721a0000007223000000290272480000007243000000721c000000721c0000007202000000da0f6368616e67655f6d65746164617461820000007306000000000210010601724a00000029057206000000da0c7468696e675f737472696e677207000000da056f776e65727236000000630500000000000000080000000500000043000000733a00000074006a017402640119006b027316740364028301820174046a057c0083017d0574006a017d067c056a067c017c027c047c0383047d077c07530029034e720f0000007a1f4f6e6c79206f70657261746f722063616e20736574206d6574616461746121290772180000007219000000721a000000722300000072380000007239000000da096164645f7468696e6729087206000000724b0000007207000000724c0000007236000000723b0000007231000000723c000000721c000000721c0000007202000000da0c6372656174655f7468696e6789000000730c0000000003100106010a0106011001724e00000029027235000000720600000063020000000000000008000000040000004300000073a600000074006a017c0183017d0274026a037d037c026a047c0083017d047c026a057c0083017d0574067c007c037c01830301007c026a077c0083017d067c06734a74087c0064011700830182017c0664026b04735e74087c0064011700830182017c067c06740964031900140018007d07740a6a0b7c077c047c0383030100740a6a0b7c0674096403190014007409640419007c0383030100740c7c007c037c01830301007c06530029054e7a10206973206e6f7420666f722073616c6572010000007216000000720f000000290d7238000000723900000072180000007219000000da096765745f6f776e6572da0b6765745f63726561746f72da165f5f6173736572745f616c72656164795f6f776e6564da106765745f70726963655f616d6f756e747223000000721a000000720b000000722f000000da145f5f7472616e736665725f6f776e657273686970290872350000007206000000723b0000007231000000724c000000da0763726561746f72da0c70726963655f616d6f756e74da1070726963655f616d6f756e745f706179721c000000721c0000007202000000da096275795f7468696e6794000000731c00000000020a0106010a010a010c010a011001140110010e010e010c010c017257000000290472350000007232000000da0b6465736372697074696f6e7206000000630400000000000000060000000400000043000000734200000074006a017c0383017d047c046a027c0083017d057c0564016b027324740364028301820174047c0074056a067c03830301007c046a077c007c01830201006400530029034e467a0e206973206f6e2061756374696f6e290872380000007239000000da0b6765745f61756374696f6e7223000000da125f5f6173736572745f6f776e65727368697072180000007219000000da097365745f707269636529067235000000723200000072580000007206000000723b000000da0761756374696f6e721c000000721c0000007202000000da0a73656c6c5f7468696e67a6000000730a00000000020a010a0110010e01725d00000029037235000000da096e65775f6f776e65727206000000630300000000000000040000000400000043000000732e00000074006a017d0374027c007c037c028303010074037c007c017c028303010074047c007c017c02830301006400530029014e290572180000007219000000725a0000007251000000725300000029047235000000725e00000072060000007231000000721c000000721c0000007202000000da087472616e73666572af0000007308000000000206010c010c01725f00000029037235000000da02746f7206000000630300000000000000040000000500000043000000732400000074006a017d0374027c007c037c0283030100640174037c037c007c0166033c006400530029024e54290472180000007219000000725a000000723000000029047235000000726000000072060000007231000000721c000000721c0000007202000000da07617070726f7665b70000007306000000000206010c01726100000029027235000000726000000063020000000000000002000000050000004300000073140000006400740074016a027c007c0166033c006400530029014e2903723000000072180000007219000000290272350000007260000000721c000000721c0000007202000000da067265766f6b65be000000730200000000027262000000290472350000007260000000da0c6d61696e5f6163636f756e747206000000630400000000000000050000000500000043000000735e00000074006a017d0474027c027c007c04660319007328740364017c029b0064027c049b009d048301820174047c007c027c038303010074057c007c017c038303010074067c007c017c0383030100640074027c027c007c0466033c006400530029034e7a3f596f752068617665206e6f74206265656e20676976656e20617070726f76616c20746f207472616e73666572207468697320757365722773206974656d2e20722000000029077218000000721900000072300000007223000000725a00000072510000007253000000290572350000007260000000726300000072060000007231000000721c000000721c0000007202000000722f000000c3000000730e00000000020601100112010c010c010c01722f0000002903723500000072310000007206000000630300000000000000050000000300000043000000733000000074006a017c0283017d037c036a027c0083017d047c047c016b03732c74037c00640117007c011700830182016400530029024e7a1220616c7265616479206f776e656420627920290472380000007239000000724f00000072230000002905723500000072310000007206000000723b000000724c000000721c000000721c00000072020000007251000000ce000000730600000000010a010a017251000000630300000000000000050000000300000043000000733000000074006a017c0283017d037c036a027c0083017d047c047c016b02732c74037c00640117007c011700830182016400530029024e7a0e206e6f74206f776e656420627920290472380000007239000000724f00000072230000002905723500000072310000007206000000723b000000724c000000721c000000721c0000007202000000725a000000d4000000730600000000010a010a01725a000000630300000000000000050000000300000043000000733e00000074006a017c0283017d037c036a027c0083017d047c036a037c007c01830201007c036a047c00830164016b04723a7c036a057c006401830201006400530029024e7201000000290672380000007239000000724f000000da097365745f6f776e65727252000000725b00000029057235000000725e0000007206000000723b000000da096f6c645f6f776e6572721c000000721c00000072020000007253000000da000000730a00000000010a010a010c010e0172530000002925da0863757272656e6379720b000000da09696d706f72746c69627238000000da0448617368da035f5f537230000000721a0000007228000000da0b466f726569676e48617368722e000000721d000000da085f5f6578706f7274da03737472722a000000722c00000072330000007234000000da0464696374723d000000da05666c6f6174723e0000007210000000da03416e7972450000007249000000724a000000724e0000007257000000725d000000725f00000072610000007262000000722f0000007251000000725a0000007253000000721c000000721c000000721c0000007202000000da083c6d6f64756c653e01000000735c0000000801080104010e0106010801060108010601080104010c03080a0601100c0601120d100a1009060114080601120e101306011608060116060601120606021c0906011211060116080601140706011406060112040601160a12061006