Professional Documents
Culture Documents
Prashant Upadhyaya
Post-Graduate Certificate Program in Blockchain
Indian Institute of Technology, Kanpur
drprashant79@protonmail.com
I. SOURCE CODE
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.10 and less than 0.9.0
contract kycpau {
// Struct Customer
// custName - username of the customer
// custData - customer data
// rating - rating given to customer given based on regularity
// upvotes - number of upvotes recieved from banks
// bank - address of bank that validated the customer account
struct Customer {
string custName;
string custData;
uint rating;
uint upvotes;
address bank;
string password;
}
// Struct Bank
// bankName - bankName of the bank
// ethAddress - ethereum address of the bank
// rating - rating based on number of valid/invalid verified accounts
// KYC_count - number of KYCs verified by the bank
struct Bank {
string bankName;
address ethAddress;
uint rating;
uint KYC_count;
string regNumber;
}
struct Request {
string custName;
address bankAddress;
bool isAllowed;
}
Customer[] allCustomers;
Bank[] allBanks;
Request[] allRequests;
function allowBank(string memory CustName, address bankAddress, bool ifallowed) public payable {
for(uint i = 0; i < allRequests.length; ++ i) {
if(stringsEqual(allRequests[i].custName, CustName) && allRequests[i].bankAddress == bankAddress) {
if(ifallowed) {
allRequests[i].isAllowed = true;
} else {
for(uint j=i;j<allRequests.length-2; ++j) {
allRequests[i] = allRequests[i+1];
}
allRequests.length;
}
return;
}
}
}
function stringsEqual(string storage _a, string memory _b) internal returns (bool) {
bytes storage a = bytes(_a);
bytes memory b = bytes(_b);
if (a.length != b.length)
return false;
// @todo unroll this loop
for (uint i = 0; i < a.length; i ++)
{
if (a[i] != b[i])
return false;
}
return true;
}
function addBank(string memory custName, address eth, string memory regNum) public payable returns(uint) {
if(allBanks.length == 0 || isPartOfOrg()) {
allBanks.length;
allBanks[allBanks.length - 1] = Bank(custName, eth, 200, 0, regNum);
return 0;
}
return 7;
}
function addCustomer(string memory CustName, string memory custData) public payable returns(uint) {
if(!isPartOfOrg())
return 7;
// throw error if userbankName already in use
for(uint i = 0;i < allCustomers.length; ++ i) {
if(stringsEqual(allCustomers[i].custName, CustName))
return 2;
}
allCustomers.length;
// throw error if there is overflow in uint
if(allCustomers.length < 1)
return 1;
allCustomers[allCustomers.length-1] = Customer(CustName, custData, 100, 0, msg.sender, "null");
updateRating(msg.sender,true);
return 0;
}
function checkCustomer(string memory CustName, string memory password) public payable returns(bool) {
for(uint i = 0; i < allCustomers.length; ++ i) {
if(stringsEqual(allCustomers[i].custName, CustName) && stringsEqual(allCustomers[i].password, password)) {
return true;
}
if(stringsEqual(allCustomers[i].custName, CustName)) {
return false;
}
}
return false;
}
function setPassword(string memory CustName, string memory password) public payable returns(bool) {
for(uint i=0;i < allCustomers.length; ++ i) {
if(stringsEqual(allCustomers[i].custName, CustName) && stringsEqual(allCustomers[i].password, "null")) {
allCustomers[i].password = password;
return true;
}
}
return false;
}