Last active
April 16, 2019 23:01
-
-
Save mcj90/91c5db8c492696a4d0f82231f18698f4 to your computer and use it in GitHub Desktop.
[SimpleCarContract_issue] #solidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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