Guest User

Untitled

a guest
Oct 9th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. contract Organ {
  4. struct kidney {
  5. uint id;
  6. uint date;
  7. string ipfsAddress;
  8. string author;
  9. bool active;
  10. }
  11.  
  12. uint lastKidneyId;
  13. uint[] kidneyIds;
  14. mapping(uint => kidney) kidneys;
  15.  
  16. event KidneyCreated(
  17. uint id,
  18. uint date,
  19. string ipfsAddress,
  20. string author);
  21.  
  22. constructor() public {
  23. lastKidneyId = 0;
  24. }
  25.  
  26. function createKidney(string _ipfsAddress, string _author) public {
  27. kidneys[lastKidneyId] = kidney(lastKidneyId, now, _ipfsAddress, _author,true);
  28. kidneyIds.push(lastKidneyId);
  29. lastKidneyId++;
  30. emit KidneyCreated(lastKidneyId, now, _ipfsAddress, _author);
  31. }
  32.  
  33. function getKidneyIds() public view returns (uint[]) {
  34. return kidneyIds;
  35. }
  36.  
  37. function getKidney(uint id) public kidneyExists(id) view
  38. returns (
  39. uint,
  40. uint,
  41. string,
  42. string,
  43. bool
  44. ) {
  45. return (id,
  46. kidneys[id].date,
  47. kidneys[id].ipfsAddress,
  48. kidneys[id].author,
  49. kidneys[id].active
  50. );
  51. }
  52.  
  53. function toggleActive(uint id) public kidneyExists(id) {
  54. kidneys[id].active = false;
  55. }
  56.  
  57. modifier kidneyExists(uint id) {
  58. if (kidneys[id].id == 0) {
  59. revert();
  60. }
  61. _;
  62. }
  63. }
Add Comment
Please, Sign In to add comment