-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/utils/Address.sol"; | ||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/access/Ownable.sol"; | ||
import "./IdentityVerification.sol"; | ||
|
||
contract UserRegistry { | ||
using SafeMath for uint256; | ||
using Address for address; | ||
|
||
// Mapping of user addresses to their corresponding user data | ||
mapping (address => UserData) public userData; | ||
|
||
// Struct to represent user data | ||
struct UserData { | ||
string name; | ||
string email; | ||
uint256 balance; | ||
bool isVerified; | ||
} | ||
|
||
// Event emitted when a new user is registered | ||
event UserRegistered(address indexed user, string name, string email); | ||
|
||
// Event emitted when a user's data is updated | ||
event UserDataUpdated(address indexed user, string name, string email); | ||
|
||
// Modifier to restrict access to only the owner of the contract | ||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Only the owner can call this function"); | ||
_; | ||
} | ||
|
||
// Constructor function to initialize the contract | ||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
// Function to register a new user | ||
function registerUser(address user, string memory name, string memory email) public { | ||
// Create a new user data struct | ||
UserData storage userDataStorage = userData[user]; | ||
userDataStorage.name = name; | ||
userDataStorage.email = email; | ||
userDataStorage.balance = 0; | ||
userDataStorage.isVerified = false; | ||
|
||
// Emit the UserRegistered event | ||
emit UserRegistered(user, name, email); | ||
} | ||
|
||
// Function to update a user's data | ||
function updateUserData(address user, string memory name, string memory email) public { | ||
// Update the user data struct | ||
userDataStorage.name = name; | ||
userDataStorage.email = email; | ||
|
||
// Emit the UserDataUpdated event | ||
emit UserDataUpdated(user, name, email); | ||
} | ||
|
||
// Function to get a user's data | ||
function getUserData(address user) public view returns (string memory, string memory, uint256, bool) { | ||
UserData storage userDataStorage = userData[user]; | ||
return (userDataStorage.name, userDataStorage.email, userDataStorage.balance, userDataStorage.isVerified); | ||
} | ||
|
||
// Function to update a user's balance | ||
function updateBalance(address user, uint256 amount) public { | ||
UserData storage userDataStorage = userData[user]; | ||
userDataStorage.balance = userDataStorage.balance.add(amount); | ||
} | ||
|
||
// Function to verify a user's identity using the IdentityVerification contract | ||
function verifyIdentity(address user) public { | ||
IdentityVerification identityVerification = IdentityVerification(address); | ||
require(identityVerification.getVerificationStatus(user), "User's identity is not verified"); | ||
userData[user].isVerified = true; | ||
} | ||
} | ||
|