Contract con_soccer_balls


Contract Code


  
1 __S = Hash(default_value='', contract='con_soccer_balls', name='S')
2
3
4 @__export('con_soccer_balls')
5 def add_thing(thing_string: str, name: str, title: str, description: str,
6 category: str, meta: dict, 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 __S[uid] = ['thing', 'type', 'name', 'title', 'description', 'category',
15 'owner', 'creator', 'likes', 'price:amount', 'price:soccer_point',
16 'meta_items']
17 __S[uid, 'thing'] = thing_string
18 __S[uid, 'type'] = 'text/plain'
19 __S[uid, 'name'] = name
20 __S[uid, 'title'] = title
21 __S[uid, 'description'] = description
22 __S[uid, 'category'] = category
23 __S[uid, 'owner'] = creator
24 __S[uid, 'creator'] = creator
25 __S[uid, 'likes'] = 0
26 __S[uid, 'price', 'amount'] = 0
27 __S[uid, 'price', 'soccer_point'] = 0
28 __S[uid, 'meta_items'] = ['url', 'accuracy', 'multiplier',
29 'out_multiplier_back']
30 __S[uid, 'meta', 'url'] = meta['url']
31 __S[uid, 'meta', 'accuracy'] = meta['accuracy']
32 __S[uid, 'meta', 'multiplier'] = meta['multiplier']
33 __S[uid, 'meta', 'out_multiplier_back'] = meta['out_multiplier_back']
34 return uid
35
36
37 def __enforce_thing_standards(thing_string: str, name: str, description:
38 str, meta: dict):
39 assert len(thing_string) > 0, 'Thing string cannot be empty.'
40 assert len(name) > 0, 'No Name provided.'
41 assert len(name) <= 80, 'Name too long (25 chars max).'
42 assert len(description) > 0, 'No description provided.'
43 assert len(description) <= 300, 'Description too long (128 chars max).'
44 __custom_meta_validations(meta)
45
46
47 def __custom_meta_validations(meta):
48 assert 'accuracy' in meta, "Missing meta value 'accuracy'."
49 assert meta['accuracy'] >= 0 and meta['accuracy'
50 ] <= 10, 'accuracy value ' + str(meta['accuracy']
51 ) + ' is out of range (1-15).'
52 assert 'multiplier' in meta, "Missing meta value 'multiplier'."
53 assert meta['multiplier'] <= 1, 'multiplier value ' + str(meta[
54 'multiplier']) + ' is out of range (0.01-1).'
55 assert 'out_multiplier_back' in meta, "Missing meta value 'out_multiplier_back'."
56 assert meta['out_multiplier_back'] >= 0 and meta['out_multiplier_back'
57 ] <= 50, 'multiplier value ' + str(meta['out_multiplier_back']
58 ) + ' is out of range (0-50).'
59
60
61 @__export('con_soccer_balls')
62 def thing_exists(thing_string: str):
63 uid = hashlib.sha256(thing_string)
64 return __S[uid]
65
66
67 @__export('con_soccer_balls')
68 def get_owner(uid: str):
69 return __S[uid, 'owner']
70
71
72 @__export('con_soccer_balls')
73 def set_price(uid: str, amount: int):
74 assert amount >= 0, 'Cannot set a negative price'
75 __S[uid, 'price', 'amount'] = amount
76
77
78 @__export('con_soccer_balls')
79 def set_price_soccer_point(uid: str, amount: int):
80 assert amount >= 0, 'Cannot set a negative price'
81 __S[uid, 'price', 'soccer_point'] = amount
82
83
84 @__export('con_soccer_balls')
85 def get_price_amount(uid: str):
86 return __S[uid, 'price', 'amount']
87
88
89 @__export('con_soccer_balls')
90 def get_price_amount_soccer_point(uid: str):
91 return __S[uid, 'price', 'soccer_point']
92
93
94 @__export('con_soccer_balls')
95 def get_accuracy(uid: str):
96 return __S[uid, 'meta', 'accuracy']
97
98
99 @__export('con_soccer_balls')
100 def get_multiplier(uid: str):
101 return __S[uid, 'meta', 'multiplier']
102
103
104 @__export('con_soccer_balls')
105 def get_out_multiplier_back(uid: str):
106 return __S[uid, 'meta', 'out_multiplier_back']
107
108
109 @__export('con_soccer_balls')
110 def get_category(uid: str):
111 return __S[uid, 'category']
112
113
114 @__export('con_soccer_balls')
115 def set_owner(uid: str, owner: str):
116 __S[uid, 'owner'] = owner
117
118
119 @__export('con_soccer_balls')
120 def like_thing(uid: str):
121 likes = __S[uid, 'likes']
122 __S[uid, 'likes'] = likes + 1
123

Byte Code

e30000000000000000000000000900000040000000735e010000650064006401640264038d035a01650264018301650365036503650365036504650364049c0764056406840483015a05650365036503650464079c046408640984045a06640a640b84005a076502640183016503640c9c01640d640e840483015a086502640183016503640f9c0164106411840483015a096502640183016503650a64129c0264136414840483015a0b6502640183016503650a64129c0264156416840483015a0c6502640183016503640f9c0164176418840483015a0d6502640183016503640f9c016419641a840483015a0e6502640183016503640f9c01641b641c840483015a0f6502640183016503640f9c01641d641e840483015a106502640183016503640f9c01641f6420840483015a116502640183016503640f9c0164216422840483015a126502640183016503650364239c0264246425840483015a136502640183016503640f9c0164266427840483015a14642853002929da00da10636f6e5f736f636365725f62616c6c73da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d652907da0c7468696e675f737472696e677206000000da057469746c65da0b6465736372697074696f6eda0863617465676f7279da046d657461da0763726561746f72630700000000000000090000000c00000043000000737a01000074007c007c017c037c058304010074016a027c0083017d0774037c0719000c00732e74047c00640117008301820174016a027c016a0583006a0664026403830283017d08740364047c08660219000c00736674046405740364047c08660219001700830182017c07740364047c0866023c006406640764086409640a640b640c640d640e640f64106411670c74037c073c007c0074037c07640666023c00641274037c07640766023c007c0174037c07640866023c007c0274037c07640966023c007c0374037c07640a66023c007c0474037c07640b66023c007c0674037c07640c66023c007c0674037c07640d66023c00641374037c07640e66023c00641374037c076414641566033c00641374037c076414641666033c00641764186419641a670474037c07641166023c007c056417190074037c07641b641766033c007c056418190074037c07641b641866033c007c056419190074037c07641b641966033c007c05641a190074037c07641b641a66033c007c075300291c4e7a0f20616c726561647920657869737473fa01207201000000da056e616d65737a274120666f726d206f662074686973206e616d6520616c72656164792062656c6f6e677320746f20da057468696e67da0474797065720600000072080000007209000000720a000000da056f776e6572720c000000da056c696b65737a0c70726963653a616d6f756e747a1270726963653a736f636365725f706f696e74da0a6d6574615f6974656d737a0a746578742f706c61696ee900000000da057072696365da06616d6f756e74da0c736f636365725f706f696e74da0375726cda086163637572616379da0a6d756c7469706c696572da136f75745f6d756c7469706c6965725f6261636b720b0000002907da195f5f656e666f7263655f7468696e675f7374616e6461726473da07686173686c6962da06736861323536da035f5f53da0e417373657274696f6e4572726f72da056c6f776572da077265706c61636529097207000000720600000072080000007209000000720a000000720b000000720c000000da03756964da096e616d65735f756964a90072250000007201000000da096164645f7468696e6704000000733800000000030e010a0116011601100112010c010c010a010a010c010c010c010c010c010c010c010c010c010e010e0106010e01120112011201120172260000002904720700000072060000007209000000720b000000630400000000000000040000000200000043000000737000000074007c00830164016b047314740164028301820174007c01830164016b047328740164038301820174007c01830164046b01733c740164058301820174007c02830164016b047350740164068301820174007c02830164076b017364740164088301820174027c03830101006400530029094e72140000007a1d5468696e6720737472696e672063616e6e6f7420626520656d7074792e7a114e6f204e616d652070726f76696465642ee9500000007a1d4e616d6520746f6f206c6f6e6720283235206368617273206d6178292e7a184e6f206465736372697074696f6e2070726f76696465642e692c0100007a254465736372697074696f6e20746f6f206c6f6e672028313238206368617273206d6178292e2903da036c656e7220000000da195f5f637573746f6d5f6d6574615f76616c69646174696f6e732904720700000072060000007209000000720b000000722500000072250000007201000000721c00000025000000730c000000000214011401140114011401721c00000063010000000000000001000000050000004300000073b800000064017c006b06731074006402830182017c006401190064036b0572287c006401190064046b0173407400640574017c006401190083011700640617008301820164077c006b06735074006408830182017c006407190064096b0173747400640a74017c006407190083011700640b170083018201640c7c006b0673847400640d830182017c00640c190064036b05729c7c00640c1900640e6b0173b47400640a74017c00640c190083011700640f1700830182016400530029104e72190000007a1e4d697373696e67206d6574612076616c756520276163637572616379272e7214000000e90a0000007a0f61636375726163792076616c7565207a18206973206f7574206f662072616e67652028312d3135292e721a0000007a204d697373696e67206d6574612076616c756520276d756c7469706c696572272ee9010000007a116d756c7469706c6965722076616c7565207a1a206973206f7574206f662072616e67652028302e30312d31292e721b0000007a294d697373696e67206d6574612076616c756520276f75745f6d756c7469706c6965725f6261636b272ee9320000007a18206973206f7574206f662072616e67652028302d3530292e29027220000000da037374722901720b00000072250000007225000000720100000072290000002f00000073160000000001100112010801160110010e011601100112010801722900000029017207000000630100000000000000020000000200000043000000731200000074006a017c0083017d0174027c011900530029014e2903721d000000721e000000721f000000290272070000007223000000722500000072250000007201000000da0c7468696e675f6578697374733d000000730400000000020a01722e00000029017223000000630100000000000000010000000300000043000000730c00000074007c00640166021900530029024e72110000002901721f00000029017223000000722500000072250000007201000000da096765745f6f776e65724300000073020000000002722f00000029027223000000721600000063020000000000000002000000050000004300000073220000007c0164016b05731074006402830182017c0174017c006403640466033c006400530029054e72140000007a1b43616e6e6f74207365742061206e656761746976652070726963657215000000721600000029027220000000721f000000290272230000007216000000722500000072250000007201000000da097365745f707269636548000000730400000000021001723000000063020000000000000002000000050000004300000073220000007c0164016b05731074006402830182017c0174017c006403640466033c006400530029054e72140000007a1b43616e6e6f74207365742061206e656761746976652070726963657215000000721700000029027220000000721f000000290272230000007216000000722500000072250000007201000000da167365745f70726963655f736f636365725f706f696e744e0000007304000000000210017231000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e721500000072160000002901721f00000029017223000000722500000072250000007201000000da106765745f70726963655f616d6f756e7454000000730200000000027232000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e721500000072170000002901721f00000029017223000000722500000072250000007201000000da1d6765745f70726963655f616d6f756e745f736f636365725f706f696e7459000000730200000000027233000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e720b00000072190000002901721f00000029017223000000722500000072250000007201000000da0c6765745f61636375726163795e000000730200000000027234000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e720b000000721a0000002901721f00000029017223000000722500000072250000007201000000da0e6765745f6d756c7469706c69657263000000730200000000027235000000630100000000000000010000000400000043000000730e00000074007c006401640266031900530029034e720b000000721b0000002901721f00000029017223000000722500000072250000007201000000da176765745f6f75745f6d756c7469706c6965725f6261636b68000000730200000000027236000000630100000000000000010000000300000043000000730c00000074007c00640166021900530029024e720a0000002901721f00000029017223000000722500000072250000007201000000da0c6765745f63617465676f72796d00000073020000000002723700000029027223000000721100000063020000000000000002000000040000004300000073100000007c0174007c00640166023c006400530029024e72110000002901721f000000290272230000007211000000722500000072250000007201000000da097365745f6f776e657272000000730200000000027238000000630100000000000000020000000400000043000000732000000074007c006401660219007d017c016402170074007c00640166023c006400530029034e7212000000722b0000002901721f000000290272230000007212000000722500000072250000007201000000da0a6c696b655f7468696e6777000000730400000000020c0172390000004e2915da0448617368721f000000da085f5f6578706f7274722d000000da04646963747226000000721c0000007229000000722e000000722f000000da03696e7472300000007231000000723200000072330000007234000000723500000072360000007237000000723800000072390000007225000000722500000072250000007201000000da083c6d6f64756c653e01000000733c0000000e0306010801141f04011009080e06011005060110040601120506011205060110040601100406011004060110040601100406011004060112040601