/* * Create smart contract for tracking cars repair history. * Fill up the code blocks in Solidity for: * - getCar() * - createCar() * - updateKilometers() * - transferOwnership() */ pragma solidity ^0.4.21; /** * Contract to store the mileage of a car */ contract Odometer { event Creation( address indexed from, string indexed vin ); event Transfer( address indexed from, address indexed to, string indexed vin ); struct Car { string vin; address owner; uint kilometers; } mapping (string => Car) cars; function Odometer() public {} /** * Returns the current data of the given car */ function getCar(string vin) public constant returns(address owner, uint kilometers) { /* -- Your code here -- */ owner = cars[vin].owner; kilometers = cars[vin].kilometers; asser (car) } /** * Creates a track record of a new car. * Transaction will fail (and burn gas!) if the car already exists. */ function createCar(string vin) public { /* -- Your code here -- */ assert(cars[vin].owner == 0x0); cars[vin].vin = vin; cars[vin].owner = msg.sender; cars[vin].kilometers = 0; emit Creation(msg.sender, vin); } /** * Updates the current kilometers of the car. Transactions fails and burns gas if * the new kilometer value is lower than the old one. */ function updateKilometers(string vin, uint kilometers) public { /* -- Your code here -- */ } /** * Transfers the ownership of a car to a different address. * Transaction fails and burns gas if the car is not owned by the caller or if the kilometers are * less than the last known state. */ function transferOwnership(string vin, address owner, uint kilometers) public { /* -- Your code here -- */ } }
0.4.18