Contract con_optic_flip_coin_v1


Contract Code


  
1 import con_optic_lst001
2 I = importlib
3
4
5 random.seed()
6 OPTIC = ForeignHash(foreign_contract='con_optic_lst001', foreign_name='balances')
7
8 S = Hash(default_value=0)
9 TEST = Hash(default_value=0)
10 metadata = Hash(default_value=0)
11
12 @construct
13 def seed():
14 metadata['operator'] = ctx.caller
15 metadata['protocol'] = 'con_optic_protocol_v3'
16 metadata['protocol_var'] = 'S'
17 metadata['LENS'] = 10000
18 metadata['MAX_STREAK'] = 0
19 metadata['MAX_STREAK_USER'] = ''
20 metadata['AMOUNT'] = 25_000
21 metadata['POT'] = 2_500_000
22 metadata['STREAK'] = 5
23 metadata['MAX_MULTI'] = 5
24 metadata['GLOBA_LENS'] = 0
25
26
27 @export
28 def coin_flip(multi: int, option: int):
29 sender = ctx.caller
30
31 assert multi > 0, 'Multi Error.'
32 assert multi <= metadata['MAX_MULTI'], 'Multi Error.'
33
34 LENS = ForeignHash(foreign_contract=metadata['protocol'], foreign_name=metadata['protocol_var'])
35 PROTOCOL = I.import_module(metadata['protocol'])
36
37 USER_LENS = (LENS[sender,'lens'] + S[sender,'lens'])
38
39 assert USER_LENS >= metadata['LENS'] * multi, 'You dont have LENS for play.'
40
41 FLIP = random.randint(0, 1)
42 TOTAL = metadata['LENS'] * multi
43 WIN = False
44
45 if FLIP == option:
46 WIN = True
47 S[sender,'lens_win'] += TOTAL
48 S[sender,'total_lens'] += TOTAL
49 PROTOCOL.increase_lens(to=sender , amount= TOTAL)
50 S[sender,'streak'] += 1
51 metadata['GLOBA_LENS'] += TOTAL
52
53 if S[sender,'streak'] % metadata['STREAK'] == 0:
54 metadata['POT'] -= metadata['AMOUNT']
55 S[sender,'win_amount'] += metadata['AMOUNT']
56 con_optic_lst001.transfer_from(metadata['AMOUNT'], sender, metadata['operator'])
57
58 if S[sender,'streak'] > metadata['MAX_STREAK']:
59 metadata['MAX_STREAK'] = S[sender,'streak']
60 metadata['MAX_STREAK_USER'] = sender
61 else:
62
63 metadata['GLOBA_LENS'] -= TOTAL
64 S[sender,'lens_lose'] -= TOTAL
65 S[sender,'total_lens'] -= TOTAL
66 PROTOCOL.reduce_lens(to=sender , amount=TOTAL)
67 S[sender,'streak'] = 0
68
69 return {'WIN':str(WIN), 'STREAK':str(S[sender,'streak']), 'LENS': str(USER_LENS), 'FLIP': str(FLIP), 'TOTAL': str(TOTAL)}
70
71
72 @export
73 def change_meta(key: str, value: Any):
74 assert ctx.caller == metadata['operator'
75 ], 'Only operator can set metadata!'
76
77 metadata[key,value]

Byte Code

e30000000000000000000000000600000040000000738a000000640064016c005a0065015a0265036a04830001006505640264036404640564068d045a06650764006404640764088d035a08650764006404640964088d035a09650764006404640a64088d035a0a640b640c84005a0b650c64048301650d650d640d9c02640e640f840483015a0e650c64048301650f651064109c0264116412840483015a11640153002913e9000000004eda10636f6e5f6f707469635f6c7374303031da0862616c616e636573da16636f6e5f6f707469635f666c69705f636f696e5f7631da054f505449432904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da01532903da0d64656661756c745f76616c756572080000007209000000da0454455354da086d65746164617461630000000000000000000000000300000043000000735e00000074006a01740264013c006402740264033c006404740264053c006406740264073c006408740264093c00640a7402640b3c00640c7402640d3c00640e7402640f3c006410740264113c006410740264123c006408740264133c006400530029144eda086f70657261746f72da15636f6e5f6f707469635f70726f746f636f6c5f7633da0870726f746f636f6c720a000000da0c70726f746f636f6c5f7661726910270000da044c454e537201000000da0a4d41585f53545245414bda00da0f4d41585f53545245414b5f5553455269a8610000da06414d4f554e5469a0252600da03504f54e905000000da0653545245414bda094d41585f4d554c5449da0a474c4f42415f4c454e532903da03637478da0663616c6c6572da0a5f5f6d65746164617461a900721f000000721f0000007214000000da045f5f5f5f0c000000731600000000010a0108010801080108010801080108010801080172200000002902da056d756c7469da066f7074696f6e630200000000000000090000000600000043000000730e02000074006a017d027c0064016b04731674026402830182017c007403640319006b01732a740264028301820174047403640419007403640519006406640764088d047d0374056a0674036404190083017d047c037c0264096602190074077c0264096602190017007d057c057403640719007c0014006b0573807402640a8301820174086a096401640b83027d067403640719007c0014007d07640c7d087c067c016b0290017290640d7d0874077c02640e6602050019007c07370003003c0074077c02640f6602050019007c07370003003c007c046a0a7c027c0764108d02010074077c026411660205001900640b370003003c0074036412050019007c07370003003c0074077c02641166021900740364131900160064016b02900172607403641405001900740364151900380003003c0074077c026416660205001900740364151900370003003c00740b6a0c7403641519007c027403641719008303010074077c026411660219007403641819006b04900172e274077c02641166021900740364183c007c02740364193c006e5274036412050019007c07380003003c0074077c02641a6602050019007c07380003003c0074077c02640f6602050019007c07380003003c007c046a0d7c027c0764108d020100640174077c02641166023c00740e7c088301740e74077c026411660219008301740e7c058301740e7c068301740e7c078301641b9c055300291c4e72010000007a0c4d756c7469204572726f722e721a000000721000000072110000007204000000721200000029047206000000720700000072080000007209000000da046c656e737a1c596f7520646f6e742068617665204c454e5320666f7220706c61792ee9010000004654da086c656e735f77696eda0a746f74616c5f6c656e732902da02746fda06616d6f756e74da0673747265616b721b000000721900000072170000007216000000da0a77696e5f616d6f756e74720e00000072130000007215000000da096c656e735f6c6f73652905da0357494e72190000007212000000da04464c4950da05544f54414c290f721c000000721d000000da0e417373657274696f6e4572726f72721e000000da0b466f726569676e48617368da0149da0d696d706f72745f6d6f64756c65da035f5f53da0672616e646f6dda0772616e64696e74da0d696e6372656173655f6c656e737202000000da0d7472616e736665725f66726f6dda0b7265647563655f6c656e73da03737472290972210000007222000000da0673656e646572da065f5f4c454e53da0850524f544f434f4cda09555345525f4c454e53722d000000722e000000722c000000721f000000721f0000007214000000da09636f696e5f666c69701a00000073460000000002060110011401080106010a010e011801080110010c010c0104010a010401140114010e01140110011a01140118010c010a01160110010a021001140114010e010c011401723e0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732600000074006a017402640119006b027316740364028301820174027c007c016602190001006400530029034e720e0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721c000000721d000000721e000000722f0000002902723f0000007240000000721f000000721f0000007214000000da0b6368616e67655f6d657461420000007306000000000210010601724100000029127202000000da09696d706f72746c696272310000007234000000da04736565647230000000da075f5f4f50544943da04486173687233000000da065f5f54455354721e0000007220000000da085f5f6578706f7274da03696e74723e0000007239000000da03416e797241000000721f000000721f000000721f0000007214000000da083c6d6f64756c653e01000000731a00000008010401080104010c010e010e0106010803080e060112270601