Guest User

Untitled

a guest
Aug 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. // Seguro de vida de viajero
  2.  
  3. // 1.- Comprar un seguro y asignar a un beneficiario
  4.  
  5. // 2.- El "gobierno" valida si falleció y se cobra el seguro
  6.  
  7. // 3.- La "agencia" declara si estaba viajando
  8.  
  9. // 4.- Se paga al beneficiario 2x
  10.  
  11. // 5.- La agencia retira el sobrante
  12.  
  13. pragma solidity ^0.4.24;
  14.  
  15. contract Assurance {
  16. // Declaracion de variables
  17. address assurer;
  18. address government;
  19. uint price = 1 ether;
  20. mapping (address => assured) public users;
  21.  
  22. struct assured {
  23. address beneficiario;
  24. bool wasTraveling;
  25. bool isAssured;
  26. bool isLegallyDead;
  27. }
  28.  
  29. constructor(address _government){
  30. assurer = msg.sender;
  31. government = _government;
  32. }
  33.  
  34. modifier onlyGovernment(){
  35. if(government != msg.sender)
  36. revert();
  37. _;
  38. }
  39.  
  40. modifier onlyAssurer(){
  41. if(assurer != msg.sender)
  42. revert();
  43. _;
  44. }
  45.  
  46. // Comprar Seguro y asignar beneficiario
  47. function BuyAssurance(address _beneficiario) payable {
  48. if(msg.value < price || users[msg.sender].isLegallyDead != false || users[msg.sender].isAssured != false) {
  49. revert();
  50. }
  51. if (msg.value > price) {
  52. msg.sender.transfer(msg.value - price);
  53. }
  54. users[msg.sender].isAssured = true;
  55. users[msg.sender].beneficiario = _beneficiario;
  56. }
  57.  
  58. // Registra que alguien está muerto (no lo mata)
  59. function certifyDead(address _deadGuy) onlyGovernment(){
  60. users[_deadGuy].isLegallyDead = true;
  61. }
  62.  
  63. // Comprueba si estaba viajando
  64. function certifyTraveling(address _traveler) onlyAssurer() {
  65. users[_traveler].wasTraveling = true;
  66. }
  67.  
  68. // Cobrar el seguro si estaba viajando, si estaba asegurado y si esta muerto
  69. function collect(address _supposedDeadGuy) payable onlyAssurer(){
  70. if(!users[_supposedDeadGuy].isLegallyDead || !users[_supposedDeadGuy].wasTraveling || !users[_supposedDeadGuy].isAssured){
  71. revert();
  72. }
  73. users[_supposedDeadGuy].beneficiario.transfer(2*price);
  74. }
  75.  
  76. // Regresa la utilidad a la aseguradora
  77. function cashOut() payable onlyAssurer() {
  78. msg.sender.transfer(this.balance);
  79. }
  80.  
  81. // Checa las variables de usuariis
  82. function infoUser(address _user) public view returns(address, bool, bool, bool){
  83. return (users[_user].beneficiario, users[_user].isAssured, users[_user].isLegallyDead, users[_user].wasTraveling);
  84. }
  85.  
  86. // Checa el balance del contrato
  87. function checkContractBalance() public view returns(uint){
  88. return (this.balance);
  89. }
  90. }
Add Comment
Please, Sign In to add comment