Last active
November 28, 2020 18:53
-
-
Save eum602/5b93595febef13ba57a45a1743d16401 to your computer and use it in GitHub Desktop.
A method to add a struct in a smart contract - solidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addNewUser(bytes32 hash, bytes32 id, uint startDate, uint exp, uint sex, uint8 age, bytes6 user_hash, StatusCode code, Hobbies hbobbies) external returns(bool) { | |
CustomDataType storage user = registry[hash][msg.sender]; | |
require(user.id==0,"User already exists"); | |
//******This is only an example ****** | |
user.id = id; | |
user.startDate = startDate; | |
user.iat = now*1000; | |
user.exp = exp; | |
user.sex = sex; | |
user.age = age; | |
user.hash = user_hash; | |
user.code = code; | |
user.hobbies = hobbies; | |
user.status = true; | |
user[hash][msg.sender] = user; | |
emit UserRegistered(hash, msg.sender, id, startDate, user.iat, sex, user_hash, code, hobbies); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment