Contract con_pixelcity_master_1


Contract Code


  
1 # Controller Contract for PixelCity
2 # This contract will get a rework at some point (long lists suck), and its not a problem. nothing is locked in here.
3 import currency
4 I = importlib
5
6 pixelwhale_contract = Variable()
7 pixelwhale_info_contract = Variable()
8 plots = Hash(default_value=0)
9
10 rewards = Hash(default_value=0)
11 valid_build_nfts = Variable()
12 valid_plot_nfts = Variable()
13
14 in_use_building_nfts = Variable()
15
16 @construct
17 def seed():
18 pixelwhale_contract.set("con_pixel_whale_master_v1")
19 pixelwhale_info_contract.set("con_pixel_whale_info_v1")
20 valid_build_nfts.set([])
21 valid_plot_nfts.set([])
22 in_use_building_nfts.set([])
23
24 @export
25 def connect_built_to_plot(plot_thing: str, build_thing: str):
26 remove_non_build_owners()
27 remove_non_plot_owners()
28 assert build_thing not in in_use_building_nfts.get(), 'This building is already in use'
29 assert plot_thing in valid_plot_nfts.get(), 'Not a valid PixelCity NFT!'
30 assert build_thing in valid_build_nfts.get(), 'Not a valid PixelCity NFT!'
31 thing_info_owners = ForeignHash(foreign_contract=pixelwhale_info_contract.get(), foreign_name='S')
32 owner_plot = thing_info_owners[plot_thing, 'owner']
33 owner_build = thing_info_owners[build_thing, 'owner']
34 assert owner_plot == ctx.caller, "You are not the owner of this plot"
35 assert owner_build == ctx.caller, "You are not the owner of this build"
36 plots[plot_thing] = {"current_plot_owner":ctx.caller, "current_build_owner": ctx.caller, "built": build_thing}
37 old_in_use_building_nfts = in_use_building_nfts.get()
38 old_in_use_building_nfts.append(build_thing)
39 in_use_building_nfts.set(old_in_use_building_nfts)
40
41 def remove_non_plot_owners():
42 thing_info_owners = ForeignHash(foreign_contract=pixelwhale_info_contract.get(), foreign_name='S')
43 old_in_use_building_nfts = in_use_building_nfts.get()
44 for plot_thing in valid_plot_nfts.get():
45 if(plots[plot_thing] != 0):
46 if thing_info_owners[plot_thing, 'owner'] != plots[plot_thing]["current_plot_owner"]:
47 if(plots[plot_thing]["built"] in old_in_use_building_nfts):
48 old_in_use_building_nfts.remove(plots[plot_thing]["built"])
49 plots[plot_thing] = {"current_plot_owner": "", "current_build_owner": "", "built": ""}
50 in_use_building_nfts.set(old_in_use_building_nfts)
51
52 def remove_non_build_owners():
53 thing_info_owners = ForeignHash(foreign_contract=pixelwhale_info_contract.get(), foreign_name='S')
54 old_in_use_building_nfts = in_use_building_nfts.get()
55 for plot_thing in valid_plot_nfts.get():
56 if(plots[plot_thing] != 0):
57 if thing_info_owners[plots[plot_thing]["built"], 'owner'] != plots[plot_thing]["current_build_owner"]:
58 old_plot = plots[plot_thing]
59 if(old_plot["built"] in old_in_use_building_nfts):
60 old_in_use_building_nfts.remove(old_plot["built"])
61 plots[plot_thing] = {"current_plot_owner":old_plot["current_plot_owner"], "current_build_owner": old_plot["current_build_owner"], "built": ""}
62 in_use_building_nfts.set(old_in_use_building_nfts)
63
64 @export
65 def deposit_rewards(currency_amount:float):
66 assert currency_amount > 0, "Cant deposit negative amounts"
67 currency.transfer_from(amount=currency_amount, to=ctx.this, main_account=ctx.caller)
68 for plot_thing in valid_plot_nfts.get():
69 if(plots[plot_thing] != 0):
70 if(plots[plot_thing]["built"] != ""):
71 rewards[plots[plot_thing]["current_build_owner"]] += currency_amount / (len(in_use_building_nfts.get()))
72
73 @export
74 def claim_rewards():
75 remove_non_build_owners()
76 remove_non_plot_owners()
77 amount_to_claim = rewards[ctx.caller]
78 if(amount_to_claim > 0):
79 rewards[ctx.caller] = 0
80 currency.transfer(amount=amount_to_claim, to=ctx.caller)
81
82 @export
83 def set_valid_plot_nfts(list_of_nfts: list):
84 assert ctx.caller == "ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89", 'You are not allowed to do that'
85 valid_plot_nfts.set(list_of_nfts)
86
87 @export
88 def set_valid_build_nfts(list_of_nfts: list):
89 assert ctx.caller == "ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89", 'You are not allowed to do that'
90 valid_build_nfts.set(list_of_nfts)
91

Byte Code

e3000000000000000000000000050000004000000073ea000000640064016c005a0065015a0265036402640364048d025a0465036402640564048d025a05650664006402640664078d035a07650664006402640864078d035a0865036402640964048d025a0965036402640a64048d025a0a65036402640b64048d025a0b640c640d84005a0c650d64028301650e650e640e9c02640f6410840483015a0f6411641284005a106413641484005a11650d64028301651264159c0164166417840483015a13650d6402830164186419840083015a14650d640283016515641a9c01641b641c840483015a16650d640283016515641a9c01641d641e840483015a1764015300291fe9000000004eda16636f6e5f706978656c636974795f6d61737465725f31da13706978656c7768616c655f636f6e74726163742902da08636f6e7472616374da046e616d65da18706978656c7768616c655f696e666f5f636f6e7472616374da05706c6f74732903da0d64656661756c745f76616c756572040000007205000000da0772657761726473da1076616c69645f6275696c645f6e667473da0f76616c69645f706c6f745f6e667473da14696e5f7573655f6275696c64696e675f6e667473630000000000000000000000000200000043000000733600000074006a0164018301010074026a0164028301010074036a0167008301010074046a0167008301010074056a016700830101006400530029034eda19636f6e5f706978656c5f7768616c655f6d61737465725f7631da17636f6e5f706978656c5f7768616c655f696e666f5f76312906da155f5f706978656c7768616c655f636f6e7472616374da03736574da1a5f5f706978656c7768616c655f696e666f5f636f6e7472616374da125f5f76616c69645f6275696c645f6e667473da115f5f76616c69645f706c6f745f6e667473da165f5f696e5f7573655f6275696c64696e675f6e667473a90072150000007215000000da00da045f5f5f5f13000000730a00000000010a010a010a010a0172170000002902da0a706c6f745f7468696e67da0b6275696c645f7468696e6763020000000000000006000000060000004300000073cc0000007400830001007401830001007c0174026a0383006b07732074046401830182017c0074056a0383006b06733474046402830182017c0174066a0383006b0673487404640283018201740774086a03830064036404640564068d047d027c027c006407660219007d037c027c016407660219007d047c0374096a0a6b02738674046408830182017c0474096a0a6b027398740464098301820174096a0a74096a0a7c01640a9c03740b7c003c0074026a0383007d057c056a0c7c018301010074026a0d7c058301010064005300290b4e7a1f54686973206275696c64696e6720697320616c726561647920696e207573657a1a4e6f7420612076616c696420506978656c43697479204e465421da01537202000000da117468696e675f696e666f5f6f776e6572732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000da056f776e65727a22596f7520617265206e6f7420746865206f776e6572206f66207468697320706c6f747a23596f7520617265206e6f7420746865206f776e6572206f662074686973206275696c642903da1263757272656e745f706c6f745f6f776e6572da1363757272656e745f6275696c645f6f776e6572da056275696c74290eda195f5f72656d6f76655f6e6f6e5f6275696c645f6f776e657273da185f5f72656d6f76655f6e6f6e5f706c6f745f6f776e6572737214000000da03676574da0e417373657274696f6e4572726f7272130000007212000000da0b466f726569676e486173687211000000da03637478da0663616c6c6572da075f5f706c6f7473da06617070656e647210000000290672180000007219000000da135f5f7468696e675f696e666f5f6f776e657273da0a6f776e65725f706c6f74da0b6f776e65725f6275696c64da186f6c645f696e5f7573655f6275696c64696e675f6e667473721500000072150000007216000000da15636f6e6e6563745f6275696c745f746f5f706c6f741b00000073260000000002060106010e01060114010e010601020108010a010c010c01120112010401100108010a01722f0000006300000000000000000300000006000000430000007392000000740074016a02830064016402640364048d047d0074036a0283007d01786674046a02830044005d5a7d0274057c02190064056b0372267c007c0264066602190074057c021900640719006b03722674057c021900640819007c016b0672707c016a0674057c0219006408190083010100640964096409640a9c0374057c023c007126570074036a077c018301010064005300290b4e721a0000007202000000721b0000002904721c000000721d000000720400000072050000007201000000721e000000721f000000722100000072160000002903721f000000722000000072210000002908722600000072110000007224000000721400000072130000007229000000da0672656d6f766572100000002903722b000000722e0000007218000000721500000072150000007216000000722300000032000000731c0000000001020108010a0108010e010c011001080110010a01080102011201722300000063000000000000000004000000060000004300000073a2000000740074016a02830064016402640364048d047d0074036a0283007d01787674046a02830044005d6a7d0274057c02190064056b0372267c0074057c0219006406190064076602190074057c021900640819006b03722674057c0219007d037c03640619007c016b0672787c016a067c0364061900830101007c03640919007c0364081900640a640b9c0374057c023c007126570074036a077c018301010064005300290c4e721a0000007202000000721b0000002904721c000000721d0000007204000000720500000072010000007221000000721e0000007220000000721f00000072160000002903721f000000722000000072210000002908722600000072110000007224000000721400000072130000007229000000723000000072100000002904722b000000722e0000007218000000da086f6c645f706c6f74721500000072150000007216000000722200000043000000731e0000000001020108010a0108010e010c0112010e0108010c010e0102010601140172220000002901da0f63757272656e63795f616d6f756e74630100000000000000020000000700000043000000737a0000007c0064016b047310740064028301820174016a027c0074036a0474036a0564038d030100785074066a07830044005d447d0174087c01190064016b03722e74087c0119006404190064056b03722e740974087c01190064061900050019007c00740a740b6a07830083011b00370003003c00712e57006400530029074e72010000007a1d43616e74206465706f736974206e6567617469766520616d6f756e74732903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74722100000072160000007220000000290c7225000000da0863757272656e6379da0d7472616e736665725f66726f6d7227000000da04746869737228000000721300000072240000007229000000da095f5f72657761726473da036c656e7214000000290272320000007218000000721500000072150000007216000000da0f6465706f7369745f72657761726473550000007310000000000210010a010a010e010c0110011001723b000000630000000000000000010000000400000043000000733c000000740083000100740183000100740274036a0419007d007c0064016b0472386401740274036a043c0074056a067c0074036a0464028d0201006400530029034e72010000002902723300000072340000002907722200000072230000007239000000722700000072280000007236000000da087472616e736665722901da0f616d6f756e745f746f5f636c61696d721500000072150000007216000000da0d636c61696d5f7265776172647361000000730c0000000002060106010a0108010a01723e0000002901da0c6c6973745f6f665f6e667473630100000000000000010000000200000043000000732000000074006a0164016b027312740264028301820174036a047c00830101006400530029034eda40666636313534346561393465616165623564663038656438363363346139333865393132396162613663656565356633316236363831626465646531316238397a1e596f7520617265206e6f7420616c6c6f77656420746f20646f20746861742905722700000072280000007225000000721300000072100000002901723f000000721500000072150000007216000000da137365745f76616c69645f706c6f745f6e6674736b0000007304000000000212017241000000630100000000000000010000000200000043000000732000000074006a0164016b027312740264028301820174036a047c00830101006400530029034e72400000007a1e596f7520617265206e6f7420616c6c6f77656420746f20646f20746861742905722700000072280000007225000000721200000072100000002901723f000000721500000072150000007216000000da147365745f76616c69645f6275696c645f6e66747371000000730400000000021201724200000029187236000000da09696d706f72746c6962da0149da085661726961626c65720f0000007211000000da0448617368722900000072390000007212000000721300000072140000007217000000da085f5f6578706f7274da03737472722f00000072230000007222000000da05666c6f6174723b000000723e000000da046c697374724100000072420000007215000000721500000072150000007216000000da083c6d6f64756c653e0100000073340000000801040104010801040108010e0206010801040108010401080104010803080806011216081108120601100b100a060110050601