Skip to content

Instantly share code, notes, and snippets.

@franz101
Created May 16, 2018 17:19
Show Gist options
  • Save franz101/c2c3559af70e743ff1684d6803083725 to your computer and use it in GitHub Desktop.
Save franz101/c2c3559af70e743ff1684d6803083725 to your computer and use it in GitHub Desktop.
SmartCity
pragma solidity ^0.4.15;
import "./Stromanbieter.sol";
contract SmartCity is Stromanbieter{
address public owner; // owner of the contract
struct Citizen { // User structure
uint id;
bool exists;
address citizenAddress;
string fullName;
string personalAddress;
uint income;
string status;
}
uint totalCitizens=0; // count of total loans
mapping(address => Citizen) citizens; // mapping address to loan
// constructor executed when deploying the contract into network
// `msg.sender` is the account creating this contract.
constructor() public payable {
owner = msg.sender;
}
// transaction to registerCitizen
function registerCitizen(string fullname, string personaladdress, uint income) public {
//require(!citizens[msg.sender])
Citizen memory c = citizens[msg.sender];
if(c.exists){
citizens[msg.sender] = Citizen(totalCitizens, true, msg.sender, fullname, personaladdress,income, "Registered"); // add Loan object to mapping
}
else{totalCitizens++;
citizens[msg.sender] = Citizen(totalCitizens, true,msg.sender, fullname, personaladdress,income, "Registered"); // add Loan object to mapping
}
}
// get citizen details
function getCitizen(address addr) public constant returns(uint, string, string, uint, string) {
Citizen memory c = citizens[addr];
return (c.id, c.fullName, c.personalAddress, c.income, c.status);
}
function getTotal() public constant returns(uint)
{return totalCitizens;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment