Skip to content

Instantly share code, notes, and snippets.

@alecchampaign
Last active December 5, 2017 22:11
Show Gist options
  • Select an option

  • Save alecchampaign/f066e25e99ed0f09e3fca17990211e62 to your computer and use it in GitHub Desktop.

Select an option

Save alecchampaign/f066e25e99ed0f09e3fca17990211e62 to your computer and use it in GitHub Desktop.
Smart contract for storing a database of identities
pragma solidity ^0.4.18;
contract ID {
address creator;
struct identity {
string name;
uint age;
uint height;
uint weight;
string occupation;
}
mapping(address => identity) people;
modifier onlyCreator() {
require(msg.sender == creator);
_;
}
event personAdded(address _person, string _name, string _occupation, uint _age, uint _height, uint _weight);
event personRemoved(address _person, string _name, string _occupation, uint _age, uint _height, uint _weight);
function ID() public {
creator = msg.sender;
}
function addIdentity(string _name, string _occupation, uint _age, uint _height, uint _weight) public {
people[msg.sender].name = _name;
people[msg.sender].occupation = _occupation;
people[msg.sender].age = _age;
people[msg.sender].height = _height;
people[msg.sender].weight = _weight;
personAdded(msg.sender, _name, _occupation, _age, _height, _weight);
}
function removeIdentity() public {
people[msg.sender].name = " ";
people[msg.sender].occupation = " ";
people[msg.sender].age = 0;
people[msg.sender].height = 0;
people[msg.sender].weight = 0;
personRemoved(msg.sender, " ", " ", 0, 0, 0);
}
function killContract() public onlyCreator() {
selfdestruct(creator);
}
function () public {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment