Skip to content

Instantly share code, notes, and snippets.

@mcj90
Last active April 16, 2019 23:01
Show Gist options
  • Save mcj90/91c5db8c492696a4d0f82231f18698f4 to your computer and use it in GitHub Desktop.
Save mcj90/91c5db8c492696a4d0f82231f18698f4 to your computer and use it in GitHub Desktop.
[SimpleCarContract_issue] #solidity
pragma solidity >=0.4.22 <0.6.0;
contract CarContract {
struct Car {
string name;
uint productionYear;
}
address owner;
mapping(address => Car) carOwner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier onlyNewOwners() {
require(carOwner[msg.sender].productionYear == 0);
_;
}
function addCar(string memory _name, uint _productionYear) public onlyNewOwners {
Car memory currentCar = Car(_name, _productionYear);
carOwner[msg.sender] = currentCar;
}
function getCar() public view returns (string memory) {
address owner = msg.sender;
return carOwner[owner].name;
}
function deleteCar(address _address) public onlyOwner {
delete carOwner[_address];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment