Contract con_test_f0f3


Contract Code


  
1 # Initialize a state hash that uses a tuple of strings as keys and an empty dictionary as the default value
2 users = Hash(default_value={})
3
4 @export
5 def register_user(username: str):
6 # Ensure the username hasn't already been registered
7 assert username not in users, 'This username is already registered'
8
9 # Create a new entry in the users hash for this username
10 users[username] = {'contacts': [], 'addresses': [], 'documents': [], 'links': []}
11
12 @export
13 def add_data(username: str, category: str, item: str):
14 # Ensure the username has been registered
15 assert username in users, 'This username is not registered'
16
17 # Ensure the category is valid
18 assert category in users[username], 'This category does not exist'
19
20 # Add the new item to the user's specified category
21 users[username][category].append(item)
22
23 @export
24 def remove_data(username: str, category: str, item: str):
25 # Ensure the username has been registered
26 assert username in users, 'This username is not registered'
27
28 # Ensure the category is valid
29 assert category in users[username], 'This category does not exist'
30
31 # Remove the item from the user's specified category
32 users[username][category].remove(item)
33
34 @export
35 def get_data(username: str, category: str):
36 # Ensure the username has been registered
37 assert username in users, 'This username is not registered'
38
39 # Ensure the category is valid
40 assert category in users[username], 'This category does not exist'
41
42 # Return the user's data for the specified category
43 return users[username][category]
44
45 @export
46 def count_users():
47 # Return the total number of registered users
48 return len(users)
49
50 @export
51 def count_category_items(username: str, category: str):
52 # Ensure the username has been registered
53 assert username in users, 'This username is not registered'
54
55 # Ensure the category is valid
56 assert category in users[username], 'This category does not exist'
57
58 # Return the number of items in the user's specified category
59 return len(users[username][category])
60
61 @export
62 def verify_user(username: str):
63 # Check if the username is registered
64 return username in users
65

Byte Code

e3000000000000000000000000050000004000000073b2000000650069006400640164028d035a01650264008301650364039c0164046405840483015a0465026400830165036503650364069c0364076408840483015a0565026400830165036503650364069c036409640a840483015a0665026400830165036503640b9c02640c640d840483015a07650264008301640e640f840083015a0865026400830165036503640b9c0264106411840483015a09650264008301650364039c0164126413840483015a0a641453002915da0d636f6e5f746573745f66306633da0575736572732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d652901da08757365726e616d6563010000000000000001000000050000004300000073260000007c0074006b0773107401640183018201670067006700670064029c0474007c003c006400530029034e7a235468697320757365726e616d6520697320616c726561647920726567697374657265642904da08636f6e7461637473da09616464726573736573da09646f63756d656e7473da056c696e6b732902da075f5f7573657273da0e417373657274696f6e4572726f7229017206000000a900720d000000da00da0d72656769737465725f75736572040000007306000000000210010601720f00000029037206000000da0863617465676f7279da046974656d630300000000000000030000000300000043000000733a0000007c0074006b06731074016401830182017c0174007c0019006b067324740164028301820174007c0019007c0119006a027c02830101006400530029034e7a1f5468697320757365726e616d65206973206e6f7420726567697374657265647a1c546869732063617465676f727920646f6573206e6f742065786973742903720b000000720c000000da06617070656e642903720600000072100000007211000000720d000000720d000000720e000000da086164645f646174610b00000073060000000002100114017213000000630300000000000000030000000300000043000000733a0000007c0074006b06731074016401830182017c0174007c0019006b067324740164028301820174007c0019007c0119006a027c02830101006400530029034e7a1f5468697320757365726e616d65206973206e6f7420726567697374657265647a1c546869732063617465676f727920646f6573206e6f742065786973742903720b000000720c000000da0672656d6f76652903720600000072100000007211000000720d000000720d000000720e000000da0b72656d6f76655f64617461120000007306000000000210011401721500000029027206000000721000000063020000000000000002000000030000004300000073300000007c0074006b06731074016401830182017c0174007c0019006b067324740164028301820174007c0019007c011900530029034e7a1f5468697320757365726e616d65206973206e6f7420726567697374657265647a1c546869732063617465676f727920646f6573206e6f742065786973742902720b000000720c000000290272060000007210000000720d000000720d000000720e000000da086765745f6461746119000000730600000000021001140172160000006300000000000000000000000002000000430000007308000000740074018301530029014e2902da036c656e720b000000720d000000720d000000720d000000720e000000da0b636f756e745f75736572732000000073020000000002721800000063020000000000000002000000030000004300000073340000007c0074006b06731074016401830182017c0174007c0019006b0673247401640283018201740274007c0019007c0119008301530029034e7a1f5468697320757365726e616d65206973206e6f7420726567697374657265647a1c546869732063617465676f727920646f6573206e6f742065786973742903720b000000720c0000007217000000290272060000007210000000720d000000720d000000720e000000da14636f756e745f63617465676f72795f6974656d73250000007306000000000210011401721900000063010000000000000001000000020000004300000073080000007c0074006b06530029014e2901720b00000029017206000000720d000000720d000000720e000000da0b7665726966795f757365722c00000073020000000002721a0000004e290bda0448617368720b000000da085f5f6578706f7274da03737472720f00000072130000007215000000721600000072180000007219000000721a000000720d000000720d000000720d000000720e000000da083c6d6f64756c653e01000000731a0000000e03060110060601140606011406060112061005060112060601