Contract con_dice002


Contract Code


  
1 import currency as tau
2 import con_degen as degen
3
4 random.seed()
5
6 owner = Variable()
7 min_amount = Variable()
8 max_amount = Variable()
9 multiplier = Variable()
10 degen_payout = Variable()
11 degen_balance = Variable()
12
13 @construct
14 def init():
15 owner.set(ctx.caller)
16 min_amount.set(10)
17 max_amount.set(100)
18 multiplier.set(5)
19 degen_payout.set(5)
20 degen_balance.set(0)
21
22 @export
23 def roll(guess: int, amount: float):
24 error = "Not a valid dice number"
25 assert (guess >= 1 and guess <= 6), error
26
27 error = "Min bet amount is " + str(min_amount.get())
28 assert amount >= min_amount.get(), error
29
30 error = "Max bet amount is " + str(max_amount.get())
31 assert amount <= max_amount.get(), error
32
33 balance = tau.balance_of(account=ctx.this)
34
35 error = "Contract balance too low to pay for possible win"
36 assert balance >= amount * multiplier.get(), error
37
38 tau.transfer_from(
39 amount=amount,
40 to=ctx.this,
41 main_account=ctx.caller)
42
43 result = random.randint(1, 6)
44
45 if result == guess:
46 tau.transfer(
47 amount=amount * multiplier.get(),
48 to=ctx.caller)
49 else:
50 if degen_balance.get() >= degen_payout.get():
51 degen.transfer(
52 amount=degen_payout.get(),
53 to=ctx.caller)
54
55 return result
56
57 @export
58 def deposit_tau(amount: float):
59 tau.transfer_from(
60 amount=amount,
61 to=ctx.this,
62 main_account=ctx.caller)
63
64 @export
65 def withdraw_tau(amount: float):
66 error = "Only the owner can request a payout"
67 assert owner.get() == ctx.caller, error
68
69 tau.transfer(
70 amount=amount,
71 to=ctx.caller)
72
73 @export
74 def deposit_degen(amount: int):
75 degen.transfer_from(
76 amount=amount,
77 to=ctx.this,
78 main_account=ctx.caller)
79
80 degen_balance.set(degen_balance.get() + amount)
81
82 @export
83 def withdraw_degen(amount: int):
84 error = "Only the owner can withdraw DEGEN tokens"
85 assert owner.get() == ctx.caller, error
86
87 degen.transfer(
88 amount=amount,
89 to=ctx.caller)
90
91 degen_balance.set(degen_balance.get() - amount)
92
93 @export
94 def set_min(amount: int):
95 error = "Only the owner can adjust the min amount"
96 assert owner.get() == ctx.caller, error
97
98 min_amount.set(amount)
99
100 @export
101 def set_max(amount: int):
102 error = "Only the owner can adjust the max amount"
103 assert owner.get() == ctx.caller, error
104
105 max_amount.set(amount)
106
107 @export
108 def set_loss_payout(amount: int):
109 error = "Only the owner can adjust the loss payout"
110 assert owner.get() == ctx.caller, error
111
112 degen_payout.set(amount)
113

Byte Code

e30000000000000000000000000400000040000000731e010000640064016c005a01640064016c025a0365046a058300010065066402640364048d025a0765066402640564048d025a0865066402640664048d025a0965066402640764048d025a0a65066402640864048d025a0b65066402640964048d025a0c640a640b84005a0d650e64028301650f6510640c9c02640d640e840483015a11650e640283016510640f9c0164106411840483015a12650e640283016510640f9c0164126413840483015a13650e64028301650f640f9c0164146415840483015a14650e64028301650f640f9c0164166417840483015a15650e64028301650f640f9c0164186419840483015a16650e64028301650f640f9c01641a641b840483015a17650e64028301650f640f9c01641c641d840483015a1864015300291ee9000000004eda0b636f6e5f64696365303032da056f776e65722902da08636f6e7472616374da046e616d65da0a6d696e5f616d6f756e74da0a6d61785f616d6f756e74da0a6d756c7469706c696572da0c646567656e5f7061796f7574da0d646567656e5f62616c616e6365630000000000000000000000000200000043000000734200000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a0164038301010074076a0164038301010074086a016404830101006400530029054ee90a000000e964000000e90500000072010000002909da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0c5f5f6d696e5f616d6f756e74da0c5f5f6d61785f616d6f756e74da0c5f5f6d756c7469706c696572da0e5f5f646567656e5f7061796f7574da0f5f5f646567656e5f62616c616e6365a90072170000007217000000da00da045f5f5f5f0c000000730c00000000010c010a010a010a010a0172190000002902da056775657373da06616d6f756e7463020000000000000005000000050000004300000073f800000064017d027c0064026b0572147c0064036b01731c74007c02830182016404740174026a038300830117007d027c0174026a0383006b05734074007c02830182016405740174046a038300830117007d027c0174046a0383006b01736474007c028301820174056a0674076a0864068d017d0364077d027c037c0174096a03830014006b05738e74007c028301820174056a0a7c0174076a0874076a0b64088d030100740c6a0d6402640383027d047c047c006b0272d074056a0e7c0174096a038300140074076a0b64098d0201006e24740f6a03830074106a0383006b0572f474116a0e74106a03830074076a0b64098d0201007c045300290a4e7a174e6f7420612076616c69642064696365206e756d626572e901000000e9060000007a124d696e2062657420616d6f756e74206973207a124d61782062657420616d6f756e74206973202901da076163636f756e747a30436f6e74726163742062616c616e636520746f6f206c6f7720746f2070617920666f7220706f737369626c652077696e2903721b000000da02746fda0c6d61696e5f6163636f756e742902721b000000721f0000002912da0e417373657274696f6e4572726f72da037374727212000000da036765747213000000da03746175da0a62616c616e63655f6f667210000000da04746869737214000000da0d7472616e736665725f66726f6d7211000000da0672616e646f6dda0772616e64696e74da087472616e7366657272160000007215000000da05646567656e2905721a000000721b000000da056572726f72da0762616c616e6365da06726573756c74721700000072170000007218000000da04726f6c6c15000000732000000000020401180110011401100114010e010401180114010c0108011a0110011401722f0000002901721b000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903721b000000721f00000072200000002905722400000072270000007210000000722600000072110000002901721b000000721700000072170000007218000000da0b6465706f7369745f74617529000000730200000000027230000000630100000000000000020000000400000043000000732e00000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d0201006400530029034e7a234f6e6c7920746865206f776e65722063616e20726571756573742061207061796f75742902721b000000721f0000002907720e00000072230000007210000000721100000072210000007224000000722a0000002902721b000000722c000000721700000072170000007218000000da0c77697468647261775f7461752e00000073060000000002040116017231000000630100000000000000010000000500000043000000732a00000074006a017c0074026a0374026a0464018d03010074056a0674056a0783007c001700830101006400530029024e2903721b000000721f00000072200000002908722b00000072270000007210000000722600000072110000007216000000720f00000072230000002901721b000000721700000072170000007218000000da0d6465706f7369745f646567656e350000007304000000000214017232000000630100000000000000020000000400000043000000734000000064017d0174006a01830074026a036b02731a74047c018301820174056a067c0074026a0364028d02010074076a0874076a0183007c001800830101006400530029034e7a284f6e6c7920746865206f776e65722063616e20776974686472617720444547454e20746f6b656e732902721b000000721f0000002909720e0000007223000000721000000072110000007221000000722b000000722a0000007216000000720f0000002902721b000000722c000000721700000072170000007218000000da0e77697468647261775f646567656e3b000000730800000000020401160110017233000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d696e20616d6f756e742907720e00000072230000007210000000721100000072210000007212000000720f0000002902721b000000722c000000721700000072170000007218000000da077365745f6d696e4300000073060000000002040116017234000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a284f6e6c7920746865206f776e65722063616e2061646a75737420746865206d617820616d6f756e742907720e00000072230000007210000000721100000072210000007213000000720f0000002902721b000000722c000000721700000072170000007218000000da077365745f6d61784a00000073060000000002040116017235000000630100000000000000020000000200000043000000732800000064017d0174006a01830074026a036b02731a74047c018301820174056a067c00830101006400530029024e7a294f6e6c7920746865206f776e65722063616e2061646a75737420746865206c6f7373207061796f75742907720e00000072230000007210000000721100000072210000007215000000720f0000002902721b000000722c000000721700000072170000007218000000da0f7365745f6c6f73735f7061796f757451000000730600000000020401160172360000002919da0863757272656e63797224000000da09636f6e5f646567656e722b0000007228000000da0473656564da085661726961626c65720e000000721200000072130000007214000000721500000072160000007219000000da085f5f6578706f7274da03696e74da05666c6f6174722f00000072300000007231000000723200000072330000007234000000723500000072360000007217000000721700000072170000007218000000da083c6d6f64756c653e0100000073320000000801080108010c010c010c010c010c010c030809060112130601100406011006060110050601100706011006060110060601