Contract con_spange_game_1


Contract Code


  
1 random.seed()
2 I = importlib
3 metadata = Hash()
4 maxStack = Variable()
5 gameStack = Variable()
6
7
8 @construct
9 def seed():
10 metadata['owner'] = ctx.caller
11 metadata['operator'] = ctx.caller
12 maxStack.set(0)
13 gameStack.set(0)
14
15
16 @export
17 def rpsPlay(throw: str, stack: float):
18 gameStack = ForeignHash(foreign_contract='con_spange',
19 foreign_name='balances')
20 maxStack = gameStack[ctx.this]
21
22 assert not ctx.caller.startswith('con_'), 'bad robot'
23 assert throw == "r" or throw == "p" or throw == "s", 'r, p or s; to represent rock, paper or scissors.'
24 assert stack > 0, 'stack must be some spange.'
25 assert stack < maxStack, 'whoa big spender! less than ' + str(maxStack)
26 I.import_module('con_spange').transfer_from(
27 amount=stack,
28 to=ctx.this,
29 main_account=ctx.caller)
30 play = rpsRound(throw, stack)
31 return play
32
33
34 def rpsRound(p1: str, stack: float):
35 b1 = botThrow()
36 if p1 == b1:
37 I.import_module('con_spange').transfer(
38 amount=stack*0.99,
39 to=ctx.caller)
40 result = 'Tie. bot = ' + b1
41 return result
42 elif (b1 == 'r' and p1 == 's') or (b1 == 's' and p1 == 'p') or (b1 == 'p' and p1 == 'r'):
43 result = 'Bot wins! bot = ' + b1
44 return result
45 else:
46 I.import_module('con_spange').transfer(
47 amount=stack*2,
48 to=ctx.caller)
49 result = 'Human wins! bot = ' + b1
50 return result
51
52
53 def botThrow():
54 x = random.randint(0, 2)
55 if x == 0:
56 b1 = 'r'
57 elif x == 1:
58 b1 = 'p'
59 else:
60 b1 = 's'
61 return b1
62
63
64 @export
65 def change_metadata(key: str, value: Any):
66 assert ctx.caller == metadata['operator'], 'No'
67 metadata[key] = value
68
69
70 @export
71 def top_up(amount: float):
72 assert ctx.caller == metadata['operator'], 'No'
73 assert amount > 0, 'No Zero'
74 I.import_module('con_spange').transfer_from(
75 amount=amount,
76 to=ctx.this,
77 main_account=ctx.caller)
78
79
80 @export
81 def tap_out(amount: float):
82 assert ctx.caller == metadata['operator'], 'No'
83 assert amount > 0, 'No Zero'
84 I.import_module('con_spange').transfer(
85 amount=amount,
86 to=ctx.caller)

Byte Code

e3000000000000000000000000040000004000000073b000000065006a018300010065025a0365046400640164028d025a0565066400640364028d025a0765066400640464028d025a086405640684005a09650a64008301650b650c64079c0264086409840483015a0d650b650c640a9c02640b640c84045a0e640d640e84005a0f650a64008301650b6510640f9c0264106411840483015a11650a64008301650c64129c0164136414840483015a12650a64008301650c64129c0164156416840483015a13641753002918da11636f6e5f7370616e67655f67616d655f31da086d657461646174612902da08636f6e7472616374da046e616d65da086d6178537461636bda0967616d65537461636b630000000000000000000000000300000043000000732c00000074006a01740264013c0074006a01740264023c0074036a0464038301010074056a046403830101006400530029044eda056f776e6572da086f70657261746f72e9000000002906da03637478da0663616c6c6572da0a5f5f6d65746164617461da0a5f5f6d6178537461636bda03736574da0b5f5f67616d65537461636ba90072100000007210000000da00da045f5f5f5f08000000730800000000010a010a010a0172120000002902da057468726f77da05737461636b63020000000000000005000000060000004300000073a00000007400640164026403640464058d047d027c0274016a0219007d0374016a036a04640683010c00733074056407830182017c0064086b0273507c0064096b0273507c00640a6b0273507405640b830182017c01640c6b0473607405640d830182017c017c036b0073787405640e74067c03830117008301820174076a08640183016a097c0174016a0274016a03640f8d030100740a7c007c0183027d047c04530029104eda0a636f6e5f7370616e6765da0862616c616e636573720100000072060000002904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572030000007204000000da04636f6e5f7a0962616420726f626f74da0172da0170da01737a30722c2070206f7220733b20746f20726570726573656e7420726f636b2c207061706572206f722073636973736f72732e72090000007a1a737461636b206d75737420626520736f6d65207370616e67652e7a1c77686f6120626967207370656e64657221206c657373207468616e202903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74290bda0b466f726569676e48617368720a000000da0474686973720b000000da0a73746172747377697468da0e417373657274696f6e4572726f72da03737472da0149da0d696d706f72745f6d6f64756c65da0d7472616e736665725f66726f6dda0a5f5f727073526f756e64290572130000007214000000720f000000720d000000da04706c6179721000000072100000007211000000da07727073506c61790f0000007316000000000204010c010a01160120011001180110010a010a01722a0000002902da0270317214000000630200000000000000040000000400000043000000739e000000740083007d027c007c026b02723874016a02640183016a037c01740464028301140074056a0664038d02010064047c0217007d037c0353007c0264056b0272487c0064066b0273687c0264066b0272587c0064076b0273687c0264076b0272747c0064056b02727464087c0217007d037c03530074016a02640183016a037c016409140074056a0664038d020100640a7c0217007d037c03530064005300290b4e72150000007a04302e39392902721d000000721e0000007a0b5469652e20626f74203d20721a000000721c000000721b0000007a10426f742077696e732120626f74203d20e9020000007a1248756d616e2077696e732120626f74203d202907da0a5f5f626f745468726f7772250000007226000000da087472616e73666572da07646563696d616c720a000000720b0000002904722b0000007214000000da026231da06726573756c7472100000007210000000721100000072280000001e00000073180000000001060108010e011001080104013001080104021a0108017228000000630000000000000000020000000300000043000000733000000074006a016401640283027d007c0064016b02721a64037d016e127c0064046b02722864057d016e0464067d017c01530029074e7209000000722c000000721a000000e901000000721b000000721c0000002902da0672616e646f6dda0772616e64696e742902da01787230000000721000000072100000007211000000722d0000002e000000730e00000000010c0108010601080106020401722d0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e7208000000da024e6f2904720a000000720b000000720c0000007223000000290272360000007237000000721000000072100000007211000000da0f6368616e67655f6d657461646174613900000073040000000002160172390000002901721d000000630100000000000000010000000500000043000000734400000074006a017402640119006b02731674036402830182017c0064036b047326740364048301820174046a05640583016a067c0074006a0774006a0164068d0301006400530029074e7208000000723800000072090000007a074e6f205a65726f72150000002903721d000000721e000000721f0000002908720a000000720b000000720c000000722300000072250000007226000000722700000072210000002901721d000000721000000072100000007211000000da06746f705f75703f00000073080000000002160110011001723a000000630100000000000000010000000400000043000000734000000074006a017402640119006b02731674036402830182017c0064036b047326740364048301820174046a05640583016a067c0074006a0164068d0201006400530029074e7208000000723800000072090000007a074e6f205a65726f72150000002902721d000000721e0000002907720a000000720b000000720c000000722300000072250000007226000000722e0000002901721d000000721000000072100000007211000000da077461705f6f7574470000007306000000000216011001723b0000004e29147233000000da0473656564da09696d706f72746c69627225000000da0448617368720c000000da085661726961626c65720d000000720f0000007212000000da085f5f6578706f72747224000000da05666c6f6174722a0000007228000000722d000000da03416e797239000000723a000000723b0000007210000000721000000072100000007211000000da083c6d6f64756c653e01000000731e000000080104010c010c010c0308070601120e1010080b06011205060110070601