Contract con_game_manager_v1


Contract Code


  
1 # con_game_manager_v1
2
3 import con_phi_lst001 as phi
4 I = importlib
5
6 owner = Variable()
7 metadata = Hash(default_value=None)
8 contracts_list = Variable()
9 actions = Hash()
10
11 S = {
12 'metadata': metadata,
13 'owner': owner
14 }
15
16 # Policy interface
17 action_interface = [
18 I.Func('interact', args=('payload', 'state', 'caller')),
19 ]
20
21
22 @construct
23 def seed():
24 owner.set(ctx.caller)
25 contracts_list.set([])
26
27
28 @export
29 def register_action(action: str, contract: str):
30 assert ctx.caller == owner.get(), 'Only owner can call!'
31 assert actions[action] is None, 'Action already registered!'
32 # Attempt to import the contract to make sure it is already submitted
33 p = I.import_module(contract)
34
35 # Assert ownership is election_house and interface is correct
36 assert I.owner_of(p) == ctx.this, \
37 'This contract must control the action contract!'
38
39 assert I.enforce_interface(p, action_interface), \
40 'Action contract does not follow the correct interface!'
41
42 contracts = contracts_list.get()
43 contracts.append(contract)
44 contracts_list.set(contracts)
45 actions[action] = contract
46
47
48 @export
49 def override_action(action: str, contract: str):
50 assert ctx.caller == owner.get(), 'Only owner can call!'
51 original_contract = actions[action]
52 assert original_contract is not None, 'Action not already registered!'
53 # Attempt to import the contract to make sure it is already submitted
54 p = I.import_module(contract)
55
56 # Assert ownership is election_house and interface is correct
57 assert I.owner_of(p) == ctx.this, \
58 'This contract must control the action contract!'
59
60 assert I.enforce_interface(p, action_interface), \
61 'Action contract does not follow the correct interface!'
62
63 contracts = contracts_list.get()
64 if original_contract in contracts:
65 contracts.remove(original_contract)
66 contracts.append(contract)
67 contracts_list.set(contracts)
68 actions[action] = contract
69
70
71 @export
72 def unregister_action(action: str):
73 assert ctx.caller == owner.get(), 'Only owner can call!'
74 contract = actions[action]
75 assert contract is not None, 'Action does not exist!'
76
77 contracts = contracts_list.get()
78 if contract in contracts:
79 contracts.remove(contract)
80 contracts_list.set(contracts)
81 actions[action] = None
82
83
84 @export
85 def interact(action: str, payload: dict) -> Any:
86 contract = actions[action]
87 assert contract is not None, 'Invalid action!'
88
89 module = I.import_module(contract)
90
91 result = module.interact(payload, S, ctx.caller)
92 return result
93
94 @export
95 def bulk_interact(action: str, payloads: list):
96 for payload in payloads:
97 interact(action, payload)
98
99
100 @export
101 def change_ownership(new_owner: str):
102 assert ctx.caller == owner.get(), 'Only the owner can change ownership!'
103
104 owner.set(new_owner)
105
106
107 @export
108 def force_withdraw(player: str, amount: float):
109 assert ctx.caller in contracts_list.get(), 'You cannot call this method.'
110 phi.transfer(
111 amount=amount,
112 to=player
113 )
114
115 @export
116 def force_deposit(main_account: str, amount: float):
117 assert ctx.caller in contracts_list.get(), 'You cannot call this method.'
118 phi.transfer_from(
119 to=ctx.this,
120 amount=amount,
121 main_account=main_account
122 )

Byte Code

e300000000000000000000000005000000400000007322010000640064016c005a0165025a0365046402640364048d025a05650664016402640564068d035a0765046402640764048d025a0865066402640864048d025a096507650564099c025a0a65036a0b640a6427640e8d0267015a0c640f641084005a0d650e64028301650f650f64119c0264126413840483015a10650e64028301650f650f64119c0264146415840483015a11650e64028301650f64169c0164176418840483015a12650e64028301650f6513651464199c03641a640a840483015a15650e64028301650f6516641b9c02641c641d840483015a17650e64028301650f641e9c01641f6420840483015a18650e64028301650f651964219c0264226423840483015a1a650e64028301650f651964249c0264256426840483015a1b640153002928e9000000004eda13636f6e5f67616d655f6d616e616765725f7631da056f776e65722902da08636f6e7472616374da046e616d65da086d657461646174612903da0d64656661756c745f76616c756572040000007205000000da0e636f6e7472616374735f6c697374da07616374696f6e73290272060000007203000000da08696e746572616374da077061796c6f6164da057374617465da0663616c6c65722901da0461726773630000000000000000000000000200000043000000731a00000074006a0174026a038301010074046a016700830101006400530029014e2905da075f5f6f776e6572da03736574da03637478720d000000da105f5f636f6e7472616374735f6c697374a90072130000007213000000da00da045f5f5f5f0d000000730400000000010c0172150000002902da06616374696f6e7204000000630200000000000000040000000300000043000000738800000074006a0174026a0383006b027316740464018301820174057c00190064006b08732a740464028301820174066a077c0183017d0274066a087c02830174006a096b02734c740464038301820174066a0a7c02740b830273607404640483018201740c6a0383007d037c036a0d7c0183010100740c6a0e7c03830101007c0174057c003c006400530029054e7a144f6e6c79206f776e65722063616e2063616c6c217a1a416374696f6e20616c72656164792072656769737465726564217a2f5468697320636f6e7472616374206d75737420636f6e74726f6c2074686520616374696f6e20636f6e7472616374217a36416374696f6e20636f6e747261637420646f6573206e6f7420666f6c6c6f772074686520636f727265637420696e7465726661636521290f7211000000720d000000720f000000da03676574da0e417373657274696f6e4572726f72da095f5f616374696f6e73da0149da0d696d706f72745f6d6f64756c65da086f776e65725f6f66da0474686973da11656e666f7263655f696e74657266616365da10616374696f6e5f696e746572666163657212000000da06617070656e647210000000290472160000007204000000da0170da09636f6e747261637473721300000072130000007214000000da0f72656769737465725f616374696f6e1200000073160000000002160114010a01080110010e01060108010a010a017223000000630200000000000000050000000300000043000000739e00000074006a0174026a0383006b027316740464018301820174057c0019007d027c0264006b09732e740464028301820174066a077c0183017d0374066a087c03830174006a096b027350740464038301820174066a0a7c03740b830273647404640483018201740c6a0383007d047c027c046b06727e7c046a0d7c02830101007c046a0e7c0183010100740c6a0f7c04830101007c0174057c003c006400530029054e7a144f6e6c79206f776e65722063616e2063616c6c217a1e416374696f6e206e6f7420616c72656164792072656769737465726564217a2f5468697320636f6e7472616374206d75737420636f6e74726f6c2074686520616374696f6e20636f6e7472616374217a36416374696f6e20636f6e747261637420646f6573206e6f7420666f6c6c6f772074686520636f727265637420696e746572666163652129107211000000720d000000720f000000721700000072180000007219000000721a000000721b000000721c000000721d000000721e000000721f0000007212000000da0672656d6f766572200000007210000000290572160000007204000000da116f726967696e616c5f636f6e747261637472210000007222000000721300000072130000007214000000da0f6f766572726964655f616374696f6e21000000731c00000000021601080110010a01080110010e010601080108010a010a010a01722600000029017216000000630100000000000000030000000300000043000000735e00000074006a0174026a0383006b027316740464018301820174057c0019007d017c0164006b09732e740464028301820174066a0383007d027c017c026b0672487c026a077c018301010074066a087c0283010100640074057c003c006400530029034e7a144f6e6c79206f776e65722063616e2063616c6c217a16416374696f6e20646f6573206e6f742065786973742129097211000000720d000000720f0000007217000000721800000072190000007212000000722400000072100000002903721600000072040000007222000000721300000072130000007214000000da11756e72656769737465725f616374696f6e3300000073100000000002160108011001080108010a010a01722700000029037216000000720b000000da0672657475726e630200000000000000050000000400000043000000733600000074007c0019007d027c0264006b097318740164018301820174026a037c0283017d037c036a047c01740574066a0783037d047c04530029024e7a0f496e76616c696420616374696f6e21290872190000007218000000721a000000721b000000720a000000da01537211000000720d00000029057216000000720b0000007204000000da066d6f64756c65da06726573756c74721300000072130000007214000000720a0000003f000000730a0000000002080110010a01100129027216000000da087061796c6f616473630200000000000000030000000400000043000000731c00000078167c0144005d0e7d0274007c007c0283020100710657006400530029014e2901720a00000029037216000000722c000000720b000000721300000072130000007214000000da0d62756c6b5f696e74657261637448000000730400000000020a01722d0000002901da096e65775f6f776e6572630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174026a057c00830101006400530029024e7a244f6e6c7920746865206f776e65722063616e206368616e6765206f776e6572736869702129067211000000720d000000720f0000007217000000721800000072100000002901722e000000721300000072130000007214000000da106368616e67655f6f776e6572736869704e000000730400000000021601722f0000002902da06706c61796572da06616d6f756e74630200000000000000020000000400000043000000732800000074006a0174026a0383006b067316740464018301820174056a067c017c0064028d0201006400530029034e7a1c596f752063616e6e6f742063616c6c2074686973206d6574686f642e29027231000000da02746f29077211000000720d000000721200000072170000007218000000da03706869da087472616e73666572290272300000007231000000721300000072130000007214000000da0e666f7263655f77697468647261775400000073040000000002160172350000002902da0c6d61696e5f6163636f756e747231000000630200000000000000020000000500000043000000732c00000074006a0174026a0383006b067316740464018301820174056a0674006a077c017c0064028d0301006400530029034e7a1c596f752063616e6e6f742063616c6c2074686973206d6574686f642e290372320000007231000000723600000029087211000000720d0000007212000000721700000072180000007233000000da0d7472616e736665725f66726f6d721d000000290272360000007231000000721300000072130000007214000000da0d666f7263655f6465706f7369745a00000073040000000002160172380000002903720b000000720c000000720d000000291cda0e636f6e5f7068695f6c73743030317233000000da09696d706f72746c6962721a000000da085661726961626c65720f000000da0448617368da0a5f5f6d65746164617461721200000072190000007229000000da0446756e63721f0000007215000000da085f5f6578706f7274da03737472722300000072260000007227000000da0464696374da03416e79720a000000da046c697374722d000000722f000000da05666c6f6174723500000072380000007213000000721300000072130000007214000000da083c6d6f64756c653e010000007334000000080104010c0106010801040108010c010a01100308050601120e060112110601100b060114080601120506011005060112050601