I have a smart contract that holds the details of a person. Each new person gets a new smart contract that they 'own'.
I have a regulator/ admin who wants to see the number of such smart contracts existing on the system and see the person who owns it. He will not be able to view any of the private data stored on them (data will be encrypted). Only the owner name (public variable) will be in unencrypted form. Is it possible to write a function that does this? I have considered making a registry that stores the address
vs the owner name
on a database but am looking for a solution just using smart contracts.
contract People{
bool public isActive = false;
uint public objectId;
string public ownerName;
string somePrivateData;
mapping (address => bool) owned;
function initPeopleContract(string name){
if (!isActive) {
isActive = true;
ownerName = name;
}
}
function getOwnerName() returns (string val) {
if (!isActive) {
val = ownerName;
}else {
val = "Account Deactivated";
}
}
function getPrivateData() returns (string data) {
if (msg.sender == address){
// Send the data back
} else {
// Reject due to un-authorized request
}
}
}
The last function is incomplete, I will add parts that check whether the person who request the transaction is really the owner of the smart contract or not. The ownerName
is a public variable that the admin should be able to query and view.
I am using web3.js , browser solidity to compile abi
code and a private block chain run using geth
console commands.