-
-
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
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
blockchain_development_integration/pi_network/smart_contracts/DecentralizedIdentity.sol
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,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); | ||
} | ||
} |