Contract con_pixel_whale_info_v1


Contract Code


  
1 __S = Hash(default_value='', contract='con_pixel_whale_info_v1', name='S')
2
3
4 @__export('con_pixel_whale_info_v1')
5 def add_thing(thing_string: str, name: str, description: str, meta: dict,
6 creator: str):
7 __enforce_thing_standards(thing_string, name, description, meta)
8 uid = hashlib.sha256(thing_string)
9 assert not __S[uid], thing_string + ' already exists'
10 names_uid = hashlib.sha256(name.lower().replace(' ', ''))
11 assert not __S['names', names_uid
12 ], 'A form of this name already belongs to ' + __S['names', names_uid]
13 __S['names', names_uid] = uid
14 __custom_string_validations(thing_string, meta['num_of_frames'])
15 __S[uid] = ['thing', 'type', 'name', 'description', 'owner', 'creator',
16 'likes', 'price:amount', 'price:hold', 'meta_items']
17 __S[uid, 'thing'] = thing_string
18 __S[uid, 'type'] = 'text/plain'
19 __S[uid, 'name'] = name
20 __S[uid, 'description'] = description
21 __S[uid, 'owner'] = creator
22 __S[uid, 'creator'] = creator
23 __S[uid, 'likes'] = 0
24 __S[uid, 'price', 'amount'] = 0
25 __S[uid, 'meta_items'] = ['speed', 'num_of_frames', 'royalty_percent']
26 __S[uid, 'meta', 'speed'] = meta['speed']
27 __S[uid, 'meta', 'num_of_frames'] = meta['num_of_frames']
28 __S[uid, 'meta', 'royalty_percent'] = meta['royalty_percent']
29 return uid
30
31
32 def __enforce_thing_standards(thing_string: str, name: str, description:
33 str, meta: dict):
34 assert len(thing_string) > 0, 'Thing string cannot be empty.'
35 assert len(name) > 0, 'No Name provided.'
36 assert len(name) <= 25, 'Name too long (25 chars max).'
37 assert len(description) > 0, 'No description provided.'
38 assert len(description) <= 128, 'Description too long (128 chars max).'
39 __custom_meta_validations(meta)
40
41
42 def __custom_string_validations(thing_string: str, num_of_frames: int):
43 assert num_of_frames >= 1 and num_of_frames <= 8, 'num_of_frames value ' + str(
44 num_of_frames) + ' is out of range (1-4).'
45 assert len(thing_string
46 ) % num_of_frames == 0, 'num_of_frames value is invalid.'
47 assert len(thing_string
48 ) / num_of_frames == 625, 'Frames Data is Invalid, must be 625 pixels/frame.'
49 __assertPixelValues(thing_string)
50
51
52 def __assertPixelValues(thing_string):
53 for pixel in thing_string:
54 assert (ord(pixel) >= 65 and ord(pixel) <= 122) and ord(pixel
55 ) != 92, 'Frames Data contains invalid pixel {}.'.format(pixel)
56
57
58 def __custom_meta_validations(meta):
59 assert 'speed' in meta, "Missing meta value 'speed' (int)."
60 assert isinstance(meta['speed'], int), 'Speed value is not an integer.'
61 assert meta['speed'] >= 100 and meta['speed'
62 ] <= 2000, 'Speed value ' + str(meta['speed']
63 ) + ' is out of range (100ms-2000ms).'
64 assert 'num_of_frames' in meta, "Missing meta value 'num_of_frames' (int)."
65 assert isinstance(meta['num_of_frames'], int
66 ), 'num_of_frames value is not an integer.'
67 assert 'royalty_percent' in meta, "Missing meta value 'royalty_percent' (int)."
68 assert isinstance(meta['royalty_percent'], int
69 ), 'royalty_percent value is not an integer.'
70 assert meta['royalty_percent'] >= 0 and meta['royalty_percent'
71 ] <= 100, 'royalty_percent value ' + str(meta['royalty_percent']
72 ) + ' is out of range (0-100).'
73
74
75 @__export('con_pixel_whale_info_v1')
76 def thing_exists(thing_string: str):
77 uid = hashlib.sha256(thing_string)
78 return __S[uid]
79
80
81 @__export('con_pixel_whale_info_v1')
82 def get_owner(uid: str):
83 return __S[uid, 'owner']
84
85
86 @__export('con_pixel_whale_info_v1')
87 def get_creator(uid: str):
88 return __S[uid, 'creator']
89
90
91 @__export('con_pixel_whale_info_v1')
92 def set_price(uid: str, amount: float, hold: str):
93 assert amount >= 0, 'Cannot set a negative price'
94 __S[uid, 'price', 'amount'] = amount
95 if not hold == None:
96 __S[uid, 'price', 'hold'] = hold
97
98
99 @__export('con_pixel_whale_info_v1')
100 def get_price_amount(uid: str):
101 return __S[uid, 'price', 'amount']
102
103
104 @__export('con_pixel_whale_info_v1')
105 def get_royalty_amount(uid: str):
106 return __S[uid, 'meta', 'royalty_percent']
107
108
109 @__export('con_pixel_whale_info_v1')
110 def get_price_hold(uid: str):
111 return __S[uid, 'price', 'hold']
112
113
114 @__export('con_pixel_whale_info_v1')
115 def set_owner(uid: str, owner: str):
116 __S[uid, 'owner'] = owner
117
118
119 @__export('con_pixel_whale_info_v1')
120 def like_thing(uid: str):
121 likes = __S[uid, 'likes']
122 __S[uid, 'likes'] = likes + 1
123
124
125 @__export('con_pixel_whale_info_v1')
126 def set_proof(uid: str, code: str):
127 __S[uid, 'proof'] = code
128

Byte Code

e300000000000000000000000007000000400000007348010000650064006401640264038d035a016502640183016503650365036504650364049c0564056406840483015a05650365036503650464079c046408640984045a0665036507640a9c02640b640c84045a08640d640e84005a09640f641084005a0a650264018301650364119c0164126413840483015a0b650264018301650364149c0164156416840483015a0c650264018301650364149c0164176418840483015a0d6502640183016503650e650364199c03641a641b840483015a0f650264018301650364149c01641c641d840483015a10650264018301650364149c01641e641f840483015a11650264018301650364149c0164206421840483015a126502640183016503650364229c0264236424840483015a13650264018301650364149c0164256426840483015a146502640183016503650364279c0264286429840483015a15642a5300292bda00da17636f6e5f706978656c5f7768616c655f696e666f5f7631da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d652905da0c7468696e675f737472696e677206000000da0b6465736372697074696f6eda046d657461da0763726561746f72630500000000000000070000000a00000043000000734a01000074007c007c017c027c038304010074016a027c0083017d0574037c0519000c00732e74047c00640117008301820174016a027c016a0583006a0664026403830283017d06740364047c06660219000c00736674046405740364047c06660219001700830182017c05740364047c0666023c0074077c007c036406190083020100640764086409640a640b640c640d640e640f6410670a74037c053c007c0074037c05640766023c00641174037c05640866023c007c0174037c05640966023c007c0274037c05640a66023c007c0474037c05640b66023c007c0474037c05640c66023c00641274037c05640d66023c00641274037c056413641466033c00641564066416670374037c05641066023c007c036415190074037c056417641566033c007c036406190074037c056417640666033c007c036416190074037c056417641666033c007c05530029184e7a0f20616c726561647920657869737473fa01207201000000da056e616d65737a274120666f726d206f662074686973206e616d6520616c72656164792062656c6f6e677320746f20da0d6e756d5f6f665f6672616d6573da057468696e67da047479706572060000007208000000da056f776e6572720a000000da056c696b65737a0c70726963653a616d6f756e747a0a70726963653a686f6c64da0a6d6574615f6974656d737a0a746578742f706c61696ee900000000da057072696365da06616d6f756e74da057370656564da0f726f79616c74795f70657263656e7472090000002908da195f5f656e666f7263655f7468696e675f7374616e6461726473da07686173686c6962da06736861323536da035f5f53da0e417373657274696f6e4572726f72da056c6f776572da077265706c616365da1b5f5f637573746f6d5f737472696e675f76616c69646174696f6e7329077207000000720600000072080000007209000000720a000000da03756964da096e616d65735f756964a90072220000007201000000da096164645f7468696e6704000000732e00000000030e010a0116011601100112010c010e010c0110010c010c010c010c010c010c010c010e011201120112011201722300000029047207000000720600000072080000007209000000630400000000000000040000000200000043000000737000000074007c00830164016b047314740164028301820174007c01830164016b047328740164038301820174007c01830164046b01733c740164058301820174007c02830164016b047350740164068301820174007c02830164076b017364740164088301820174027c03830101006400530029094e72130000007a1d5468696e6720737472696e672063616e6e6f7420626520656d7074792e7a114e6f204e616d652070726f76696465642ee9190000007a1d4e616d6520746f6f206c6f6e6720283235206368617273206d6178292e7a184e6f206465736372697074696f6e2070726f76696465642ee9800000007a254465736372697074696f6e20746f6f206c6f6e672028313238206368617273206d6178292e2903da036c656e721c000000da195f5f637573746f6d5f6d6574615f76616c69646174696f6e7329047207000000720600000072080000007209000000722200000072220000007201000000721800000020000000730c000000000214011401140114011401721800000029027207000000720d00000063020000000000000002000000040000004300000073600000007c0164016b0572107c0164026b0173247400640374017c0183011700640417008301820174027c0083017c01160064056b02733c740064068301820174027c0083017c011b0064076b027354740064088301820174037c00830101006400530029094ee901000000e9080000007a146e756d5f6f665f6672616d65732076616c7565207a17206973206f7574206f662072616e67652028312d34292e72130000007a1f6e756d5f6f665f6672616d65732076616c756520697320696e76616c69642e69710200007a314672616d6573204461746120697320496e76616c69642c206d7573742062652036323520706978656c732f6672616d652e2904721c000000da037374727226000000da135f5f617373657274506978656c56616c75657329027207000000720d000000722200000072220000007201000000721f0000002a000000730e0000000001120112010601120106011201721f0000006301000000000000000200000004000000430000007344000000783e7c0044005d367d0174007c01830164016b05722e74007c01830164026b01722e74007c01830164036b037306740164046a027c01830183018201710657006400530029054ee941000000e97a000000e95c0000007a264672616d6573204461746120636f6e7461696e7320696e76616c696420706978656c207b7d2e2903da036f7264721c000000da06666f726d617429027207000000da05706978656c722200000072220000007201000000722b00000034000000730600000000010a011e01722b00000063010000000000000001000000050000004300000073d600000064017c006b067310740064028301820174017c006401190074028302732674006403830182017c006401190064046b05723e7c006401190064056b0173567400640674037c006401190083011700640717008301820164087c006b067366740064098301820174017c006408190074028302737c7400640a83018201640b7c006b06738c7400640c8301820174017c00640b19007402830273a27400640d830182017c00640b1900640e6b0572ba7c00640b190064046b0173d27400640f74037c00640b19008301170064101700830182016400530029114e72160000007a214d697373696e67206d6574612076616c756520277370656564272028696e74292e7a1e53706565642076616c7565206973206e6f7420616e20696e74656765722ee96400000069d00700007a0c53706565642076616c7565207a20206973206f7574206f662072616e676520283130306d732d323030306d73292e720d0000007a294d697373696e67206d6574612076616c756520276e756d5f6f665f6672616d6573272028696e74292e7a266e756d5f6f665f6672616d65732076616c7565206973206e6f7420616e20696e74656765722e72170000007a2b4d697373696e67206d6574612076616c75652027726f79616c74795f70657263656e74272028696e74292e7a28726f79616c74795f70657263656e742076616c7565206973206e6f7420616e20696e74656765722e72130000007a16726f79616c74795f70657263656e742076616c7565207a19206973206f7574206f662072616e67652028302d313030292e2904721c000000da0a6973696e7374616e6365da03696e74722a0000002901720900000072220000007222000000720100000072270000003a000000731c00000000011001160112010801160110011001060110011001060112010801722700000029017207000000630100000000000000020000000200000043000000731200000074006a017c0083017d0174027c011900530029014e29037219000000721a000000721b000000290272070000007220000000722200000072220000007201000000da0c7468696e675f6578697374734b000000730400000000020a01723500000029017220000000630100000000000000010000000300000043000000730c00000074007c00640166021900530029024e72100000002901721b00000029017220000000722200000072220000007201000000da096765745f6f776e657251000000730200000000027236000000630100000000000000010000000300000043000000730c00000074007c00640166021900530029024e720a0000002901721b00000029017220000000722200000072220000007201000000da0b6765745f63726561746f7256000000730200000000027237000000290372200000007215000000da04686f6c6463030000000000000003000000050000004300000073380000007c0164016b05731074006402830182017c0174017c006403640466033c007c0264006b0273347c0274017c006403640566033c006400530029064e72130000007a1b43616e6e6f74207365742061206e656761746976652070726963657214000000721500000072380000002902721c000000721b0000002903722000000072150000007238000000722200000072220000007201000000da097365745f70726963655b0000007308000000000210010e0108017239000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e721400000072150000002901721b00000029017220000000722200000072220000007201000000da106765745f70726963655f616d6f756e746300000073020000000002723a000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e720900000072170000002901721b00000029017220000000722200000072220000007201000000da126765745f726f79616c74795f616d6f756e746800000073020000000002723b000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e721400000072380000002901721b00000029017220000000722200000072220000007201000000da0e6765745f70726963655f686f6c646d00000073020000000002723c00000029027220000000721000000063020000000000000002000000040000004300000073100000007c0174007c00640166023c006400530029024e72100000002901721b000000290272200000007210000000722200000072220000007201000000da097365745f6f776e65727200000073020000000002723d000000630100000000000000020000000400000043000000732000000074007c006401660219007d017c016402170074007c00640166023c006400530029034e721100000072280000002901721b000000290272200000007211000000722200000072220000007201000000da0a6c696b655f7468696e6777000000730400000000020c01723e00000029027220000000da04636f646563020000000000000002000000040000004300000073100000007c0174007c00640166023c006400530029024eda0570726f6f662901721b00000029027220000000723f000000722200000072220000007201000000da097365745f70726f6f667d0000007302000000000272410000004e2916da0448617368721b000000da085f5f6578706f7274722a000000da0464696374722300000072180000007234000000721f000000722b0000007227000000723500000072360000007237000000da05666c6f61747239000000723a000000723b000000723c000000723d000000723e00000072410000007222000000722200000072220000007201000000da083c6d6f64756c653e0100000073380000000e0306010801101a04011009100a080608110601100506011004060110040601140706011004060110040601100406011204060110050601