From 676ea9e17e825f31155a799f20e4791dbcf589df Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Mon, 2 Dec 2024 13:26:25 +0700 Subject: [PATCH] Create DecentralizedIdentity.sol --- .../smart_contracts/DecentralizedIdentity.sol | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 blockchain_development_integration/pi_network/smart_contracts/DecentralizedIdentity.sol diff --git a/blockchain_development_integration/pi_network/smart_contracts/DecentralizedIdentity.sol b/blockchain_development_integration/pi_network/smart_contracts/DecentralizedIdentity.sol new file mode 100644 index 000000000..4712384cb --- /dev/null +++ b/blockchain_development_integration/pi_network/smart_contracts/DecentralizedIdentity.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract DecentralizedIdentity { + struct Identity { + string name; + string email; + string phone; + bool exists; + } + + mapping(address => Identity) public identities; + + function createIdentity(string memory name, string memory email, string memory phone) external { + require(!identities[msg.sender].exists, "Identity already exists"); + identities[msg.sender] = Identity(name, email, phone, true); + } + + function updateIdentity(string memory name, string memory email, string memory phone) external { + require(identities[msg.sender].exists, "Identity does not exist"); + identities[msg.sender].name = name; + identities[msg.sender].email = email; + identities[msg.sender].phone = phone; + } + + function getIdentity(address user) external view returns (string memory, string memory, string memory) { + require(identities[user].exists, "Identity does not exist"); + Identity memory identity = identities[user]; + return (identity.name, identity.email, identity.phone); + } +}