Created
April 19, 2022 16:16
-
-
Save C2OO13/16da6894a9d9af9750339be0abf9f1ca to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.11+commit.d7f03943.js&optimize=false&runs=200&gist=
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
contract AadharCardContract { | |
struct AadharCard { | |
string name; | |
string number; | |
string ipfsHash; | |
string description; | |
string accName; | |
uint state; // 0=Requested Approval / 1= WIP / 2= Approved / 3= Denied | |
} | |
mapping (string => AadharCard) private aadharCards; | |
struct AadharCardQueue{ | |
uint state; | |
string accName; | |
} | |
mapping(uint => AadharCardQueue) private queueAadharCard; | |
uint private firstAadharCard; | |
uint private lastAadharCard; | |
constructor(){ | |
lastAadharCard = 0; | |
firstAadharCard = 1; | |
} | |
function enqueueAadharCard(AadharCardQueue memory data) internal { | |
lastAadharCard += 1; | |
queueAadharCard[lastAadharCard] = data; | |
} | |
function dequeueAadharCard() internal returns (AadharCardQueue memory data) { | |
require(lastAadharCard >= firstAadharCard); | |
data = queueAadharCard[firstAadharCard]; | |
delete queueAadharCard[firstAadharCard]; | |
firstAadharCard += 1; | |
} | |
function getCountOfPendingAadharCard() public view returns(uint){ | |
return ((lastAadharCard + 1) - firstAadharCard); | |
} | |
function newAadharCard(string memory accName, string memory _name, string memory _number, string memory _ipfsHash, string memory _description) public { | |
AadharCard memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.number = _number; | |
c.state = 0; | |
c.accName = accName; | |
aadharCards[accName] = c; | |
AadharCardQueue memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueueAadharCard(b); | |
} | |
function setAadharCard(string memory accName, string memory _name, string memory _number, string memory _ipfsHash, string memory _description) public{ | |
AadharCard memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.number = _number; | |
c.state = 0; | |
c.accName = accName; | |
aadharCards[accName] = c; | |
AadharCardQueue memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueueAadharCard(b); | |
} | |
function approveAadharCard(string memory accName) public { | |
AadharCard memory c = aadharCards[accName]; | |
if(c.state != 0) return; | |
c.state = 2; | |
aadharCards[accName] = c; | |
updateAadharQueue(); | |
} | |
function rejectAadharCard(string memory accName) public { | |
AadharCard memory c = aadharCards[accName]; | |
if(c.state == 3) return; | |
c.state = 3; | |
aadharCards[accName] = c; | |
updateAadharQueue(); | |
} | |
function getAadharCard(string memory accName) public view returns (AadharCard memory) { | |
return aadharCards[accName]; | |
} | |
function updateAadharQueue() private{ | |
require(lastAadharCard >= firstAadharCard); | |
uint i=firstAadharCard; | |
while(i<=lastAadharCard && getAadharCard(queueAadharCard[i++].accName).state != 0){ | |
AadharCard memory temp = getAadharCard(queueAadharCard[i++].accName); | |
if(temp.state != 0) dequeueAadharCard(); | |
else return; | |
} | |
} | |
function getAllPendingAadharCards() public view returns(AadharCard[] memory b){ | |
require(lastAadharCard >= firstAadharCard, "No pending aadhar cards"); | |
uint i=firstAadharCard; | |
uint j=lastAadharCard-firstAadharCard; | |
b = new AadharCard[](j+1); | |
j=0; | |
AadharCard memory temp; | |
while(i<=lastAadharCard){ | |
AadharCardQueue memory c = queueAadharCard[i++]; | |
temp = getAadharCard(c.accName); | |
if(temp.state == 0) b[j++] = temp; | |
} | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
contract BirthCertiContract { | |
struct BirthCertificate { | |
string name; | |
string dob; | |
string ipfsHash; | |
string description; | |
string accName; | |
uint state; // 0=Requested Approval / 1= WIP / 2= Approved / 3= Denied | |
} | |
mapping (string => BirthCertificate) private birthCertificates; | |
struct BirthCerti{ | |
uint state; | |
string accName; | |
} | |
mapping(uint => BirthCerti) private queueBirthCertificate; | |
uint private firstBirthCertificate; | |
uint private lastBirthCertificate; | |
constructor(){ | |
lastBirthCertificate = 0; | |
firstBirthCertificate = 1; | |
} | |
function enqueueBirthCertificate(BirthCerti memory data) internal { | |
lastBirthCertificate += 1; | |
queueBirthCertificate[lastBirthCertificate] = data; | |
} | |
function dequeueBirthCertificate() internal returns (BirthCerti memory data) { | |
require(lastBirthCertificate >= firstBirthCertificate); | |
data = queueBirthCertificate[firstBirthCertificate]; | |
delete queueBirthCertificate[firstBirthCertificate]; | |
firstBirthCertificate += 1; | |
} | |
function getCountOfPendingBirthCertificate() public view returns(uint){ | |
return ((lastBirthCertificate + 1) - firstBirthCertificate); | |
} | |
function newBirthCerti(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public { | |
BirthCertificate memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.dob = _dob; | |
c.state = 0; | |
c.accName = accName; | |
birthCertificates[accName] = c; | |
BirthCerti memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueueBirthCertificate(b); | |
} | |
function setBirthCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public { | |
BirthCertificate memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.dob = _dob; | |
c.state = 0; | |
c.accName = accName; | |
birthCertificates[accName] = c; | |
BirthCerti memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueueBirthCertificate(b); | |
} | |
function approveBirthCertificate(string memory accName) public { | |
BirthCertificate memory c = birthCertificates[accName]; | |
if(c.state != 0) return; | |
c.state = 2; | |
birthCertificates[accName] = c; | |
updateBirthQueue(); | |
} | |
function rejectBirthCertificate(string memory accName) public { | |
BirthCertificate memory c = birthCertificates[accName]; | |
if(c.state == 3) return; | |
c.state = 3; | |
birthCertificates[accName] = c; | |
updateBirthQueue(); | |
} | |
function getBirthCertificate(string memory accName) public view returns (BirthCertificate memory) { | |
return birthCertificates[accName]; | |
} | |
function updateBirthQueue() private{ | |
require(lastBirthCertificate >= firstBirthCertificate); | |
uint i=firstBirthCertificate; | |
while(i<=lastBirthCertificate){ | |
BirthCertificate memory temp = getBirthCertificate(queueBirthCertificate[i++].accName); | |
if(temp.state != 0) dequeueBirthCertificate(); | |
else return; | |
} | |
} | |
function getAllPendingBirthCertificates() public view returns(BirthCertificate[] memory b){ | |
require(lastBirthCertificate >= firstBirthCertificate, "No pending birth certis"); | |
uint i=firstBirthCertificate; | |
uint j=lastBirthCertificate-firstBirthCertificate; | |
b = new BirthCertificate[](j+1); | |
j=0; | |
BirthCertificate memory temp; | |
while(i<=lastBirthCertificate){ | |
BirthCerti memory c = queueBirthCertificate[i++]; | |
temp = getBirthCertificate(c.accName); | |
if(temp.state == 0) b[j++] = temp; | |
} | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
import "./Login.sol"; | |
import "./NotificationContract.sol"; | |
import "./BirthCertiContract.sol"; | |
import "./AadharCardContract.sol"; | |
import "./ShareCertificateContract.sol"; | |
import "./PassportCertiContract.sol"; | |
contract Dashboard is Login, BirthCertiContract, AadharCardContract, ShareCertificateContract, PassportCertiContract, NotificationContract{ | |
address public owner; | |
constructor(){ | |
owner = msg.sender; | |
} | |
modifier isOwner() { | |
require(msg.sender == owner, "Caller is not Owner"); | |
_; | |
} | |
function getId(string memory accName) public view returns(uint){ | |
return accountName_userId[accName]; | |
} | |
function getUser(string memory accName) public view returns(User memory){ | |
return userId_user[getId(accName)]; | |
} | |
function isAdmin(string memory accName) public view returns(bool){ | |
User memory u = getUser(accName); | |
if(u.profile == 3) return true; | |
return false; | |
} | |
function isApprover(string memory accName) public view returns(bool){ | |
User memory u = getUser(accName); | |
if(u.profile == 2 || isAdmin(accName)) return true; | |
return false; | |
} | |
function login(string memory name, string memory pwd) public view returns(bool){ | |
uint id = openLogin(name, pwd); | |
if(id>0){ | |
return true; | |
} | |
return false; | |
} | |
function registerApprover(string memory _accNameAdmin, string memory _passwordAdmin, string memory _accountName, string memory _name, string memory _password) public { | |
bool check = login(_accNameAdmin,_passwordAdmin); | |
if(!check) return; | |
User memory u = getUser(_accNameAdmin); | |
require(isAdmin(u.accountName) == true, "Admin rights required"); | |
signUpApprover(_accountName,_name,_password); | |
} | |
function registerAdmin(string memory _accountName, string memory _name, string memory _password) public isOwner { | |
signUpAdmin(_accountName,_name,_password); | |
} | |
// function getApprovers() public view returns(User[] memory u){} | |
// function getAdmins() public view returns(User[] memory u){} | |
// function registerApplicant(string memory _accountName, string memory _name, string memory _password) public returns(uint) {} | |
// function changePassword(string memory _accountName, string memory _password, string memory _newPassword) public returns(bool){} | |
// ======> Notification functions <======== | |
// function addNotification(string memory accountName, string memory message, string memory redirectLink) public {} | |
// function getUserNotifications(string memory accountName) public view returns(Notification[] memory n) {} | |
// ======> Share Certificates functions <======== | |
// function shareCertificate(string memory sharerAccName, string memory sharedToAccName, uint typeOfCerti, uint time, string memory timeOfSharing) public{} | |
// function getSharedCertis(string memory accName) public view returns(SharedCertis[] memory b){} | |
// ======> Birth Certificate functions <======== | |
// function getCountOfPendingBirthCertificate() public view returns(uint){} | |
// function newBirthCerti(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public {} | |
// function setBirthCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public {} | |
// function approveBirthCertificate(string memory accName) public {} | |
// function rejectBirthCertificate(string memory accName) public {} | |
// function getBirthCertificate(string memory accName) public view returns (BirthCertificate memory) {} | |
// function getAllPendingBirthCertificates() public view returns(BirthCertificate[] memory b){} | |
// ======> Aadhar Card functions <======== | |
// function getCountOfPendingAadharCard() public view returns(uint){} | |
// function newAadharCard(string memory accName, string memory _name, string memory _number, string memory _ipfsHash, string memory _description) public {} | |
// function setAadharCard(string memory accName, string memory _name, string memory _number, string memory _ipfsHash, string memory _description) public{} | |
// function approveAadharCard(string memory accName) public {} | |
// function rejectAadharCard(string memory accName) public {} | |
// function getAadharCard(string memory accName) public view returns (AadharCard memory) {} | |
// function getAllPendingAadharCards() public view returns(AadharCard[] memory b){} | |
// ======> Passport Certificate functions <======== | |
// function getCountOfPendingPassportCertificate() internal view returns(uint){} | |
// function newPassportCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public {} | |
// function setPassportCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public {} | |
// function approvePassportCertificate(string memory accName) public{} | |
// function rejectPassportCertificate(string memory accName) public {} | |
// function getPassportCertificate(string memory accName) public view returns (PassportCertificate memory) {} | |
// function getAllPendingPassportCertis() public view returns(PassportCertificate[] memory b){} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
contract Login { | |
struct User{ | |
string name; | |
string accountName;// unique | |
string password; | |
uint profile;// 1 - Applicant / 2 - Approver / 3 - Admin | |
uint userId; | |
} | |
uint private lastId; | |
User[] internal approvers; | |
User[] internal admins; | |
mapping(uint => User) internal userId_user; | |
mapping(string => uint) internal accountName_userId; | |
constructor(){ | |
lastId = 0; | |
} | |
function checkUniqueAccountName(string memory accountName) private view returns(bool){ | |
if(accountName_userId[accountName]>0) return true; | |
return false; | |
} | |
function registerApplicant(string memory _accountName, string memory _name, string memory _password) public returns(uint) { | |
require(checkUniqueAccountName(_accountName) == false, "Account Name already in use! Try another one"); | |
User memory u; | |
lastId += 1; | |
u.userId = lastId; | |
u.name = _name; | |
u.accountName = _accountName; | |
u.profile = 1; | |
u.password = _password; | |
accountName_userId[_accountName] = lastId; | |
userId_user[lastId] = u; | |
return lastId; | |
} | |
function signUpApprover(string memory _accountName, string memory _name, string memory _password) internal returns(uint) { | |
require(checkUniqueAccountName(_accountName) == false, "Account Name already in use! Try another one"); | |
User memory u; | |
lastId += 1; | |
u.userId = lastId; | |
u.name = _name; | |
u.accountName = _accountName; | |
u.profile = 2; | |
u.password = _password; | |
accountName_userId[_accountName] = lastId; | |
userId_user[lastId] = u; | |
approvers.push(u); | |
return lastId; | |
} | |
function signUpAdmin(string memory _accountName, string memory _name, string memory _password) internal returns(uint) { | |
require(checkUniqueAccountName(_accountName) == false, "Account Name already in use! Try another one"); | |
User memory u; | |
lastId += 1; | |
u.userId = lastId; | |
u.name = _name; | |
u.accountName = _accountName; | |
u.profile = 3; | |
u.password = _password; | |
accountName_userId[_accountName] = lastId; | |
userId_user[lastId] = u; | |
admins.push(u); | |
return lastId; | |
} | |
function openLogin(string memory _accountName, string memory _password) internal view returns (uint) { | |
uint userId = accountName_userId[_accountName]; | |
User memory u = userId_user[userId]; | |
if (keccak256(bytes(u.password)) == keccak256(bytes(_password))) { | |
return userId; | |
} | |
return 0; | |
} | |
function changePassword(string memory _accountName, string memory _password, string memory _newPassword) public returns(bool){ | |
uint userId = accountName_userId[_accountName]; | |
User memory u = userId_user[userId]; | |
if (keccak256(bytes(u.password)) == keccak256(bytes(_password))) { | |
userId_user[userId].password = _newPassword; | |
return true; | |
} | |
return false; | |
} | |
function getApprovers() public view returns(User[] memory u){ | |
u = approvers; | |
} | |
function getAdmins() public view returns(User[] memory u){ | |
u = admins; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
contract NotificationContract{ | |
struct Notification{ | |
string accountName; | |
string message; | |
string redirectLink; | |
} | |
mapping(string => Notification[]) internal userNotifications; | |
constructor(){ | |
} | |
function addNotification(string memory accountName, string memory message, string memory redirectLink) public { | |
Notification memory n; | |
n.accountName = accountName; | |
n.message = message; | |
n.redirectLink = redirectLink; | |
userNotifications[accountName].push(n); | |
} | |
function getUserNotifications(string memory accountName) public view returns(Notification[] memory n){ | |
n = userNotifications[accountName]; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.11; | |
contract PassportCertiContract { | |
struct PassportCertificate { | |
string name; | |
string dob; | |
string ipfsHash; | |
string description; | |
string accName; | |
uint state; // 0=Requested Approval / 1= WIP / 2= Approved / 3= Denied | |
} | |
mapping (string => PassportCertificate) private passportCertificates; | |
struct PassportCerti{ | |
uint state; | |
string accName; | |
} | |
mapping(uint => PassportCerti) private queuePassportCertificate; | |
uint private firstPassportCertificate; | |
uint private lastPassportCertificate; | |
constructor(){ | |
lastPassportCertificate = 0; | |
firstPassportCertificate = 1; | |
} | |
function enqueuePassportCertificate(PassportCerti memory data) internal { | |
lastPassportCertificate += 1; | |
queuePassportCertificate[lastPassportCertificate] = data; | |
} | |
function dequeuePassportCertificate() internal returns (PassportCerti memory data) { | |
require(lastPassportCertificate >= firstPassportCertificate); | |
data = queuePassportCertificate[firstPassportCertificate]; | |
delete queuePassportCertificate[firstPassportCertificate]; | |
firstPassportCertificate += 1; | |
} | |
function getCountOfPendingPassportCertificate() public view returns(uint){ | |
return ((lastPassportCertificate + 1) - firstPassportCertificate); | |
} | |
function newPassportCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public { | |
PassportCertificate memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.dob = _dob; | |
c.state = 0; | |
c.accName = accName; | |
passportCertificates[accName] = c; | |
PassportCerti memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueuePassportCertificate(b); | |
} | |
function setPassportCertificate(string memory accName, string memory _name, string memory _dob, string memory _ipfsHash, string memory _description) public { | |
PassportCertificate memory c; | |
c.ipfsHash = _ipfsHash; | |
c.description = _description; | |
c.name = _name; | |
c.dob = _dob; | |
c.state = 0; | |
c.accName = accName; | |
passportCertificates[accName] = c; | |
PassportCerti memory b; | |
b.state = 0; | |
b.accName = accName; | |
enqueuePassportCertificate(b); | |
} | |
function approvePassportCertificate(string memory accName) public{ | |
PassportCertificate memory c = passportCertificates[accName]; | |
if(c.state != 0) return; | |
c.state = 2; | |
passportCertificates[accName] = c; | |
updatePassportQueue(); | |
} | |
function rejectPassportCertificate(string memory accName) public { | |
PassportCertificate memory c = passportCertificates[accName]; | |
if(c.state == 3) return; | |
c.state = 3; | |
passportCertificates[accName] = c; | |
updatePassportQueue(); | |
} | |
function getPassportCertificate(string memory accName) public view returns (PassportCertificate memory) { | |
return passportCertificates[accName]; | |
} | |
function updatePassportQueue() private{ | |
require(lastPassportCertificate >= firstPassportCertificate); | |
uint i=firstPassportCertificate; | |
while(i<=lastPassportCertificate){ | |
PassportCertificate memory temp = getPassportCertificate(queuePassportCertificate[i++].accName); | |
if(temp.state != 0) dequeuePassportCertificate(); | |
else return; | |
} | |
} | |
function getAllPendingPassportCertis() public view returns(PassportCertificate[] memory b){ | |
require(lastPassportCertificate >= firstPassportCertificate, "No pending passports!"); | |
uint i=firstPassportCertificate; | |
uint j=lastPassportCertificate-firstPassportCertificate; | |
b = new PassportCertificate[](j+1); | |
j=0; | |
PassportCertificate memory temp; | |
while(i<=lastPassportCertificate){ | |
PassportCerti memory c = queuePassportCertificate[i++]; | |
temp = getPassportCertificate(c.accName); | |
if(temp.state == 0) b[j++] = temp; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment