Skip to content

Commit

Permalink
Create UserRegistry.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 11, 2024
1 parent a1dc03c commit 3d8a648
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions pi-nexus-blockchain/contracts/UserRegistry.sol
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;
}
}

0 comments on commit 3d8a648

Please sign in to comment.