Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2016 16:00
Show Gist options
  • Save anonymous/8f70d2e3b2729ead2015ff4d63349053 to your computer and use it in GitHub Desktop.
Save anonymous/8f70d2e3b2729ead2015ff4d63349053 to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.6+commit.2dabbdf0.js&optimize=false&gist=
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract InsurancePOC is usingOraclize {
address public owner;
address public beneficiary;
string public identifier;
event newOraclizeQuery(string description);
event newOraclizeResponse(string description);
event hasDied(string description);
function InsurancePOC () {
owner = msg.sender;
beneficiary = 0;
identifier = "";
}
function enable ( string ident, address addr ) {
if ( owner != msg.sender ) return;
if ( strCompare(identifier, "") == 0 ) identifier = ident;
if ( beneficiary == 0 ) beneficiary = addr;
}
function redeem() {
if ( msg.sender != owner ) return;
if ( owner != beneficiary ) return;
suicide(owner);
}
function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize_cbAddress()) return;
newOraclizeResponse(strConcat("Oraclize respose received.", result));
if ( strCompare(result, "Dead") == 0 ) {
owner = beneficiary;
hasDied(strConcat("Payment is cleared. Result: ", result));
}
}
function heartbeat() payable {
if ( beneficiary == 0 ) return;
if ( strCompare(identifier, "") == 0 ) return;
newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
oraclize_query('URL', strConcat('html(http://oracle.integritas.net/users/', identifier, ').xpath(/html/body/p/span/text())'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment