-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorites.vy
37 lines (29 loc) · 993 Bytes
/
favorites.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Forked from Cyfrin Updraft https://github.com/Cyfrin/web3py-favorites-cu
# pragma version 0.4.0
# @license MIT
struct Person:
favorite_number: uint256
name: String[100]
my_favorite_number: uint256
# Static Array/List
list_of_numbers: public(uint256[5])
list_of_people: public(Person[5])
list_of_people_index: uint256
name_to_favorite_number: HashMap[String[100], uint256]
@deploy
def __init__():
self.my_favorite_number = 0
@external
def store(favorite_number: uint256):
self.my_favorite_number = favorite_number
@external
@view
def retrieve() -> uint256:
return self.my_favorite_number
@external
def add_person(name: String[100], favorite_number: uint256):
new_person: Person = Person(favorite_number = favorite_number, name = name)
self.list_of_people[self.list_of_people_index] = new_person
self.list_of_numbers[self.list_of_people_index] = favorite_number
self.list_of_people_index += 1
self.name_to_favorite_number[name] = favorite_number