Contract con_optic_flip_coin_v5


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

Byte Code

e30000000000000000000000000600000040000000737c000000640064016c005a0065015a0265036a04830001006505640264036404640564068d045a06650764006404640764088d035a08650764006404640964088d035a09640a640b84005a0a650b64048301650c650c640c9c02640d640e840483015a0d650b64048301650e650f640f9c0264106411840483015a10640153002912e9000000004eda10636f6e5f6f707469635f6c7374303031da0862616c616e636573da16636f6e5f6f707469635f666c69705f636f696e5f7635da054f505449432904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da01532903da0d64656661756c745f76616c756572080000007209000000da086d65746164617461630000000000000000000000000300000043000000735e00000074006a01740264013c006402740264033c006404740264053c006406740264073c006408740264093c00640a7402640b3c00640c7402640d3c00640e7402640f3c006410740264113c006410740264123c006408740264133c006400530029144eda086f70657261746f72da15636f6e5f6f707469635f70726f746f636f6c5f7633da0870726f746f636f6c720a000000da0c70726f746f636f6c5f7661726910270000da044c454e537201000000da0a4d41585f53545245414bda00da0f4d41585f53545245414b5f5553455269a8610000da06414d4f554e5469a0252600da03504f54e905000000da0653545245414bda094d41585f4d554c5449da0a474c4f42415f4c454e532903da03637478da0663616c6c6572da0a5f5f6d65746164617461a900721e000000721e0000007213000000da045f5f5f5f0b000000731600000000010a01080108010801080108010801080108010801721f0000002902da056d756c7469da066f7074696f6e630200000000000000090000000600000043000000730202000074006a017d027c0064016b04731674026402830182017c007403640319006b01732a740264028301820174047403640419007403640519006406640764088d047d0374056a0674036404190083017d047c037c026409660219007d057c057403640a19007c0014006b0573747402640b8301820174076a086401640c83027d067403640a19007c0014007d07640d7d087c067c016b0290017284640e7d0874097c02640f6602050019007c07370003003c0074097c0264106602050019007c07370003003c007c046a0a7c027c0764118d02010074097c026412660205001900640c370003003c0074036413050019007c07370003003c0074097c02641266021900740364141900160064016b02900172547403641505001900740364161900380003003c0074097c026417660205001900740364161900370003003c00740b6a0c7403641619007c027403641819008303010074097c026412660219007403641919006b04900172d674097c02641266021900740364193c007c027403641a3c006e5274036413050019007c07380003003c0074097c02641b6602050019007c07380003003c0074097c0264106602050019007c07380003003c007c046a0d7c027c0764118d020100640174097c02641266023c00740e7c088301740e74097c026412660219008301740e7c058301740e7c068301740e7c078301641c9c055300291d4e72010000007a0c4d756c7469204572726f722e7219000000720f00000072100000007204000000da0c50524f544f434f4c4c454e5329047206000000720700000072080000007209000000da046c656e7372110000007a1c596f7520646f6e742068617665204c454e5320666f7220706c61792ee9010000004654da0377696eda05746f74616c2902da02746fda06616d6f756e74da0673747265616b721a000000721800000072160000007215000000da0a77696e5f616d6f756e74720d00000072120000007214000000da046c6f73652905da0357494e7218000000da014cda04464c4950da05544f54414c290f721b000000721c000000da0e417373657274696f6e4572726f72721d000000da0b466f726569676e48617368da0149da0d696d706f72745f6d6f64756c65da0672616e646f6dda0772616e64696e74da035f5f53da0d696e6372656173655f6c656e737202000000da0d7472616e736665725f66726f6dda0b7265647563655f6c656e73da03737472290972200000007221000000da0673656e646572da0e5f5f50524f544f434f4c4c454e53da0850524f544f434f4cda09555345525f4c454e53722e000000722f000000722c000000721e000000721e0000007213000000da09636f696e5f666c69701900000073460000000002060110011401080106010a010e010c01080110010c010c0104010a010401140114010e01140110011a01140118010c010a01160110010a021001140114010e010c011601723f0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732600000074006a017402640119006b027316740364028301820174027c007c016602190001006400530029034e720d0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721b000000721c000000721d0000007230000000290272400000007241000000721e000000721e0000007213000000da0b6368616e67655f6d657461410000007306000000000210010601724200000029117202000000da09696d706f72746c696272320000007234000000da04736565647231000000da075f5f4f50544943da04486173687236000000721d000000721f000000da085f5f6578706f7274da03696e74723f000000723a000000da03416e797242000000721e000000721e000000721e0000007213000000da083c6d6f64756c653e01000000731800000008010401080104010c010e0106010803080e060112270601