Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Seguro de vida de viajero
- // 1.- Comprar un seguro y asignar a un beneficiario
- // 2.- El "gobierno" valida si falleció y se cobra el seguro
- // 3.- La "agencia" declara si estaba viajando
- // 4.- Se paga al beneficiario 2x
- // 5.- La agencia retira el sobrante
- pragma solidity ^0.4.24;
- contract Assurance {
- // Declaracion de variables
- address assurer;
- address government;
- uint price = 1 ether;
- mapping (address => assured) public users;
- struct assured {
- address beneficiario;
- bool wasTraveling;
- bool isAssured;
- bool isLegallyDead;
- }
- constructor(address _government){
- assurer = msg.sender;
- government = _government;
- }
- modifier onlyGovernment(){
- if(government != msg.sender)
- revert();
- _;
- }
- modifier onlyAssurer(){
- if(assurer != msg.sender)
- revert();
- _;
- }
- // Comprar Seguro y asignar beneficiario
- function BuyAssurance(address _beneficiario) payable {
- if(msg.value < price || users[msg.sender].isLegallyDead != false || users[msg.sender].isAssured != false) {
- revert();
- }
- if (msg.value > price) {
- msg.sender.transfer(msg.value - price);
- }
- users[msg.sender].isAssured = true;
- users[msg.sender].beneficiario = _beneficiario;
- }
- // Registra que alguien está muerto (no lo mata)
- function certifyDead(address _deadGuy) onlyGovernment(){
- users[_deadGuy].isLegallyDead = true;
- }
- // Comprueba si estaba viajando
- function certifyTraveling(address _traveler) onlyAssurer() {
- users[_traveler].wasTraveling = true;
- }
- // Cobrar el seguro si estaba viajando, si estaba asegurado y si esta muerto
- function collect(address _supposedDeadGuy) payable onlyAssurer(){
- if(!users[_supposedDeadGuy].isLegallyDead || !users[_supposedDeadGuy].wasTraveling || !users[_supposedDeadGuy].isAssured){
- revert();
- }
- users[_supposedDeadGuy].beneficiario.transfer(2*price);
- }
- // Regresa la utilidad a la aseguradora
- function cashOut() payable onlyAssurer() {
- msg.sender.transfer(this.balance);
- }
- // Checa las variables de usuariis
- function infoUser(address _user) public view returns(address, bool, bool, bool){
- return (users[_user].beneficiario, users[_user].isAssured, users[_user].isLegallyDead, users[_user].wasTraveling);
- }
- // Checa el balance del contrato
- function checkContractBalance() public view returns(uint){
- return (this.balance);
- }
- }
Add Comment
Please, Sign In to add comment