Contract con_pixel_whale_master_v1


Contract Code

1 import currency
2 I = importlib
3 S = Hash(default_value='', contract='con_pixel_whale_master_v1', name='S')
4 balances = Hash(default_value=0, contract='con_pixel_whale_master_v1',
5 name='balances')
6 metadata = Hash(default_value=0, contract='con_pixel_whale_master_v1',
7 name='metadata')
8
9
10 def ():
11 S['thing_info_contract'] = 'con_pixel_whale_info_v1'
12 metadata['operator'] = ctx.caller
13 metadata['things_name'] = 'Pixel Whales v1'
14 metadata['things_description'
15 ] = 'On-chain Pixel Animations you can BUY and SELL!'
16
17
18 @export('con_pixel_whale_master_v1')
19 def change_metadata(key: str, value: Any):
20 assert ctx.caller == metadata['operator'
21 ], 'Only operator can set metadata!'
22 metadata[key] = value
23
24
25 @export('con_pixel_whale_master_v1')
26 def create_thing(thing_string: str, name: str, description: str, meta: dict={}
27 ):
28 thing_info = I.import_module(S['thing_info_contract'])
29 sender = ctx.caller
30 thing_uid = thing_info.add_thing(thing_string, name, description, meta,
31 sender)
32 add_to_balance(sender)
33 return thing_uid
34
35
36 @export('con_pixel_whale_master_v1')
37 def buy_thing(uid: str):
38 thing_info = I.import_module(S['thing_info_contract'])
39 sender = ctx.caller
40 owner = thing_info.get_owner(uid)
41 creator = thing_info.get_creator(uid)
42 assert_already_owned(uid, sender)
43 price_amount = thing_info.get_price_amount(uid)
44 royalty_percent = thing_info.get_royalty_amount(uid)
45 assert price_amount, uid + ' is not for sale'
46 assert price_amount > 0, uid + ' is not for sale'
47 price_hold = thing_info.get_price_hold(uid)
48 if price_hold != '':
49 assert sender == price_hold, uid + ' is being held for ' + price_hold
50 if royalty_percent > 0:
51 royalty_amount = price_amount * (royalty_percent / 100)
52 net_amount = price_amount - royalty_amount
53 currency.transfer_from(royalty_amount, creator, sender)
54 else:
55 net_amount = price_amount
56 currency.transfer_from(net_amount, owner, sender)
57 transfer_ownership(uid, sender)
58
59
60 @export('con_pixel_whale_master_v1')
61 def sell_thing(uid: str, amount: float):
62 assert_ownership(uid, ctx.caller)
63 thing_info = I.import_module(S['thing_info_contract'])
64 thing_info.set_price(uid, amount, '')
65
66
67 @export('con_pixel_whale_master_v1')
68 def sell_thing_to(uid: str, amount: float, hold: str):
69 assert_ownership(uid, ctx.caller)
70 thing_info = I.import_module(S['thing_info_contract'])
71 thing_info.set_price(uid, amount, hold)
72
73
74 @export('con_pixel_whale_master_v1')
75 def transfer(uid: str, new_owner: str):
76 sender = ctx.caller
77 assert_ownership(uid, sender)
78 assert_already_owned(uid, new_owner)
79 transfer_ownership(uid, new_owner)
80
81
82 @export('con_pixel_whale_master_v1')
83 def approve(uid: str, to: str):
84 sender = ctx.caller
85 assert_ownership(uid, sender)
86 balances[sender, uid, to] = True
87
88
89 @export('con_pixel_whale_master_v1')
90 def revoke(uid: str, to: str):
91 balances[ctx.caller, uid, to] = None
92
93
94 @export('con_pixel_whale_master_v1')
95 def transfer_from(uid: str, to: str, main_account: str):
96 sender = ctx.caller
97 assert balances[main_account, uid, sender
98 ], "You have not been given approval to transfer this user's item."
99 assert_ownership(uid, main_account)
100 assert_already_owned(uid, to)
101 transfer_ownership(uid, to)
102 balances[main_account, uid, sender] = None
103
104
105 @export('con_pixel_whale_master_v1')
106 def like_thing(uid: str):
107 sender = ctx.caller
108 assert S['liked', uid, sender] == '', sender + ' already liked ' + uid
109 thing_info = I.import_module(S['thing_info_contract'])
110 thing_info.like_thing(uid)
111 S['liked', uid, sender] = True
112
113
114 @export('con_pixel_whale_master_v1')
115 def prove_ownership(uid: str, code: str):
116 sender = ctx.caller
117 assert_ownership(uid, sender)
118 thing_info = I.import_module(S['thing_info_contract'])
119 thing_info.set_proof(uid, code)
120
121
122 def assert_ownership(uid: str, sender):
123 thing_info = I.import_module(S['thing_info_contract'])
124 owner = thing_info.get_owner(uid)
125 assert owner == sender, uid + ' not owned by ' + sender
126
127
128 def assert_already_owned(uid: str, sender):
129 thing_info = I.import_module(S['thing_info_contract'])
130 owner = thing_info.get_owner(uid)
131 assert owner != sender, uid + ' already owned by ' + sender
132
133
134 def transfer_ownership(uid: str, new_owner: str):
135 thing_info = I.import_module(S['thing_info_contract'])
136 old_owner = thing_info.get_owner(uid)
137 thing_info.set_owner(uid, new_owner)
138 if thing_info.get_price_amount(uid) > 0:
139 thing_info.set_price(uid, 0, '')
140 add_to_balance(new_owner)
141 subtract_from_balance(old_owner)
142
143
144 def add_to_balance(holder: str):
145 if balances[holder] is None:
146 balances[holder] = 1
147 else:
148 balances[holder] = balances[holder] + 1
149
150
151 def subtract_from_balance(holder: str):
152 if balances[holder] is None:
153 balances[holder] = 0
154 else:
155 balances[holder] = balances[holder] - 1
156

Byte Code

e30000000000000000000000000700000040000000739a010000640064016c005a0065015a02650364026403640464058d035a04650364006403640664058d035a05650364006403640764058d035a066408640984005a076508640383016509650a640a9c02640b640c840483015a0b65086403830169006601650965096509650c640d9c04640e640f840583015a0d650864038301650964109c0164116412840483015a0e6508640383016509650f64139c0264146415840483015a106508640383016509650f650964169c0364176418840483015a116508640383016509650964199c02641a641b840483015a1265086403830165096509641c9c02641d641e840483015a1365086403830165096509641c9c02641f6420840483015a1465086403830165096509650964219c0364226423840483015a15650864038301650964109c0164246425840483015a166508640383016509650964269c0264276428840483015a17650964109c016429642a84045a18650964109c01642b642c84045a196509650964199c02642d642e84045a1a6509642f9c016430643184045a1b6509642f9c016432643384045a1c640153002934e9000000004eda00da19636f6e5f706978656c5f7768616c655f6d61737465725f7631da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da0862616c616e636573da086d6574616461746163000000000000000000000000030000004300000073260000006401740064023c0074016a02740364033c006404740364053c006406740364073c006400530029084eda17636f6e5f706978656c5f7768616c655f696e666f5f7631da137468696e675f696e666f5f636f6e7472616374da086f70657261746f727a0f506978656c205768616c6573207631da0b7468696e67735f6e616d657a2f4f6e2d636861696e20506978656c20416e696d6174696f6e7320796f752063616e2042555920616e642053454c4c21da127468696e67735f6465736372697074696f6e2904da035f5f53da03637478da0663616c6c6572da0a5f5f6d65746164617461a900721300000072130000007202000000da045f5f5f5f0a0000007308000000000108010a01080272140000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720c0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721000000072110000007212000000da0e417373657274696f6e4572726f72290272150000007216000000721300000072130000007202000000da0f6368616e67655f6d6574616461746112000000730600000000021001060172180000002904da0c7468696e675f737472696e677207000000da0b6465736372697074696f6eda046d657461630400000000000000070000000600000043000000733200000074006a0174026401190083017d0474036a047d057c046a057c007c017c027c037c0583057d0674067c05830101007c06530029024e720b0000002907da0149da0d696d706f72745f6d6f64756c65720f00000072100000007211000000da096164645f7468696e67da105f5f6164645f746f5f62616c616e6365290772190000007207000000721a000000721b000000da0a7468696e675f696e666fda0673656e646572da097468696e675f756964721300000072130000007202000000da0c6372656174655f7468696e6719000000730c00000000030e0106010c010601080172230000002901da037569646301000000000000000a000000040000004300000073e000000074006a0174026401190083017d0174036a047d027c016a057c0083017d037c016a067c0083017d0474077c007c02830201007c016a087c0083017d057c016a097c0083017d067c057356740a7c0064021700830182017c0564036b04736a740a7c0064021700830182017c016a0b7c0083017d077c0764046b0372947c027c076b027394740a7c00640517007c071700830182017c0664036b0472c07c057c0664061b0014007d087c057c0818007d09740c6a0d7c087c047c02830301006e047c057d09740c6a0d7c097c037c0283030100740e7c007c02830201006400530029074e720b0000007a10206973206e6f7420666f722073616c65720100000072020000007a13206973206265696e672068656c6420666f7220e964000000290f721c000000721d000000720f00000072100000007211000000da096765745f6f776e6572da0b6765745f63726561746f72da165f5f6173736572745f616c72656164795f6f776e6564da106765745f70726963655f616d6f756e74da126765745f726f79616c74795f616d6f756e747217000000da0e6765745f70726963655f686f6c64da0863757272656e6379da0d7472616e736665725f66726f6dda145f5f7472616e736665725f6f776e657273686970290a722400000072200000007221000000da056f776e6572da0763726561746f72da0c70726963655f616d6f756e74da0f726f79616c74795f70657263656e74da0a70726963655f686f6c64da0e726f79616c74795f616d6f756e74da0a6e65745f616d6f756e74721300000072130000007202000000da096275795f7468696e6724000000732600000000020e0106010a010a010a010a010a01100114010a010801180108010c010801100204010e01723600000029027224000000da06616d6f756e74630200000000000000030000000400000043000000732c00000074007c0074016a028302010074036a0474056401190083017d027c026a067c007c016402830301006400530029034e720b00000072020000002907da125f5f6173736572745f6f776e65727368697072100000007211000000721c000000721d000000720f000000da097365745f70726963652903722400000072370000007220000000721300000072130000007202000000da0a73656c6c5f7468696e673c000000730600000000020c010e01723a000000290372240000007237000000da04686f6c64630300000000000000040000000400000043000000732c00000074007c0074016a028302010074036a0474056401190083017d037c036a067c007c017c02830301006400530029024e720b0000002907723800000072100000007211000000721c000000721d000000720f0000007239000000290472240000007237000000723b0000007220000000721300000072130000007202000000da0d73656c6c5f7468696e675f746f43000000730600000000020c010e01723c00000029027224000000da096e65775f6f776e6572630200000000000000030000000300000043000000732800000074006a017d0274027c007c028302010074037c007c018302010074047c007c01830201006400530029014e29057210000000721100000072380000007228000000722e00000029037224000000723d0000007221000000721300000072130000007202000000da087472616e736665724a0000007308000000000206010a010a01723e00000029027224000000da02746f630200000000000000030000000500000043000000732200000074006a017d0274027c007c0283020100640174037c027c007c0166033c006400530029024e542904721000000072110000007238000000da0a5f5f62616c616e63657329037224000000723f0000007221000000721300000072130000007202000000da07617070726f7665520000007306000000000206010a01724100000063020000000000000002000000050000004300000073140000006400740074016a027c007c0166033c006400530029014e290372400000007210000000721100000029027224000000723f000000721300000072130000007202000000da067265766f6b655900000073020000000002724200000029037224000000723f000000da0c6d61696e5f6163636f756e74630300000000000000040000000500000043000000734c00000074006a017d0374027c027c007c0366031900731c740364018301820174047c007c028302010074057c007c018302010074067c007c0183020100640074027c027c007c0366033c006400530029024e7a3e596f752068617665206e6f74206265656e20676976656e20617070726f76616c20746f207472616e73666572207468697320757365722773206974656d2e2907721000000072110000007240000000721700000072380000007228000000722e00000029047224000000723f00000072430000007221000000721300000072130000007202000000722d0000005e000000730e00000000020601100106010a010a010a01722d000000630100000000000000030000000500000043000000735200000074006a017d01740264017c007c016603190064026b02732874037c01640317007c0017008301820174046a0574026404190083017d027c026a067c00830101006405740264017c007c0166033c006400530029064eda056c696b656472020000007a0f20616c7265616479206c696b656420720b00000054290772100000007211000000720f0000007217000000721c000000721d000000da0a6c696b655f7468696e672903722400000072210000007220000000721300000072130000007202000000724500000069000000730a0000000002060122010e010a01724500000029027224000000da04636f6465630200000000000000040000000300000043000000732e00000074006a017d0274027c007c028302010074036a0474056401190083017d037c036a067c007c01830201006400530029024e720b0000002907721000000072110000007238000000721c000000721d000000720f000000da097365745f70726f6f6629047224000000724600000072210000007220000000721300000072130000007202000000da0f70726f76655f6f776e657273686970720000007308000000000206010a010e017248000000630200000000000000040000000300000043000000733400000074006a0174026401190083017d027c026a037c0083017d037c037c016b02733074047c00640217007c011700830182016400530029034e720b0000007a0e206e6f74206f776e6564206279202905721c000000721d000000720f000000722600000072170000002904722400000072210000007220000000722f00000072130000007213000000720200000072380000007a000000730600000000010e010a017238000000630200000000000000040000000300000043000000733400000074006a0174026401190083017d027c026a037c0083017d037c037c016b03733074047c00640217007c011700830182016400530029034e720b0000007a1220616c7265616479206f776e6564206279202905721c000000721d000000720f000000722600000072170000002904722400000072210000007220000000722f000000721300000072130000007202000000722800000080000000730600000000010e010a017228000000630200000000000000040000000400000043000000735400000074006a0174026401190083017d027c026a037c0083017d037c026a047c007c01830201007c026a057c00830164026b0472407c026a067c00640264038303010074077c018301010074087c03830101006400530029044e720b000000720100000072020000002909721c000000721d000000720f0000007226000000da097365745f6f776e657272290000007239000000721f000000da175f5f73756274726163745f66726f6d5f62616c616e636529047224000000723d0000007220000000da096f6c645f6f776e6572721300000072130000007202000000722e00000086000000730e00000000010e010a010c010e010e010801722e0000002901da06686f6c646572630100000000000000010000000300000043000000732a00000074007c00190064006b087216640174007c003c006e1074007c0019006401170074007c003c006400530029024ee901000000290172400000002901724c000000721300000072130000007202000000721f00000090000000730600000000010c010a02721f000000630100000000000000010000000300000043000000732a00000074007c00190064006b087216640174007c003c006e1074007c0019006402180074007c003c006400530029034e7201000000724d000000290172400000002901724c000000721300000072130000007202000000724a00000097000000730600000000010c010a02724a000000291d722c000000da09696d706f72746c6962721c000000da0448617368720f000000724000000072120000007214000000da085f5f6578706f7274da03737472da03416e797218000000da046469637472230000007236000000da05666c6f6174723a000000723c000000723e00000072410000007242000000722d0000007245000000724800000072380000007228000000722e000000721f000000724a0000007213000000721300000072130000007202000000da083c6d6f64756c653e010000007344000000080104010e01060108010601080308080601120606011a0a0601101706011206060114060601120706011206060112040601140a06011008060112070e060e06100a0e07