Guest User

Untitled

a guest
Jun 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. pragma solidity ^0.4.16;
  2.  
  3. contract BikeContract {
  4. address bikeOwner;
  5. Condition bikeCondition;
  6. address[] riders;
  7. Battery bikeBattery;
  8.  
  9. struct Battery{
  10. uint capacity;
  11. uint chargeLevel;
  12. }
  13.  
  14. enum Condition{
  15. in_use,
  16. broken,
  17. repaired,
  18. available
  19. }
  20.  
  21. function changeStatus(Condition s) public returns (string) {
  22. if (bikeCondition == Condition.broken && (s == Condition.in_use || s == Condition.available)) {
  23. bikeBattery.chargeLevel -= 20;
  24. return "bike must be repaired first";
  25. } else {
  26. bikeCondition = s;
  27. bikeBattery.chargeLevel -= 20;
  28. return "color changed";
  29. }
  30. }
  31.  
  32. constructor() public {
  33. bikeCondition = Condition.available;
  34. bikeBattery.chargeLevel = 100;
  35. riders.push(msg.sender);
  36. bikeOwner = msg.sender;
  37. }
  38. }
Add Comment
Please, Sign In to add comment