- Create a smart contract that stores the name and age of a given person.
- Accounts are not allowed to change the name of other accounts name and age.
It contains the data to be associated to a user that is identified by its address on the Blockchain
struct _user_data
A wrapper for user_data to discriminate if the user has registered before
It uses the fact a lookup for a non existing user returns the default value of each type and for bool is_present it is false
When a user registers, the corresponding bool is_present is set to true
mapping data
The mapping associating the User address with its user_data
This is not public since we want to access this data structure through
Functions
Getter and Setter Functions only
get()
Requires a user has registered before
Returns the user_data associated to the address of the user, via the data mapping and using the ABIEncoderV2 feature to automatically encode the struct user_data into a tuple
set()
It encodes the passed data into a struct user_data that is associated to address of the user via the mapping data and it also sets the is_present flag
Overview
Solidity Exercise - User Data 20210623
Solidity Exercise Description
https://github.com/kevaundray/SmartContractChallenges/blob/master/Ethereum/1/Info.md
Brief Description
Solution 1
Code
Comments
Data Structures
struct user_data
address
on the Blockchainstruct _user_data
user_data
to discriminate if the user has registered beforebool is_present
it isfalse
bool is_present
is set totrue
mapping data
The mapping associating the User
address
with itsuser_data
This is not public since we want to access this data structure through
Functions
get()
user_data
associated to theaddress
of the user, via thedata
mapping and using theABIEncoderV2
feature to automatically encode thestruct user_data
into a tupleset()
struct user_data
that is associated toaddress
of the user via themapping data
and it also sets theis_present
flagAppunto