Skip to content

Instantly share code, notes, and snippets.

@rpaskin
Created July 11, 2021 03:40
Show Gist options
  • Save rpaskin/c632f74c66169e6fa15a3563cbb2ec68 to your computer and use it in GitHub Desktop.
Save rpaskin/c632f74c66169e6fa15a3563cbb2ec68 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.8.0;
contract Strings {
string myString;
function store(string memory _entrada) public {
myString = _entrada;
}
function retrieve() public view returns (string memory){
return myString;
}
}
contract StoreWeather {
enum Weather { sunny, cloudy, rainy, snow }
Weather myWeather;
address public owner;
constructor() {
owner = msg.sender;
}
function store(Weather _weather) public {
require (msg.sender == owner, "Only the owner can store!");
myWeather = _weather;
}
function retrieve() public view returns (Weather){
return myWeather;
}
function isItRaining() public view returns (bool){
return (myWeather == Weather.rainy);
}
}
contract SnowInsurance {
address payable public insured;
address payable public insurer;
address public oracle;
constructor() payable {
require (msg.value > 1000 wei, "Must deposit at least 1000 wei");
insurer = payable(msg.sender);
oracle = 0x0fC5025C764cE34df352757e82f7B5c4Df39A836;
}
function getBalance() public view returns(uint){
return address(this).balance;
}
function insureMe() public payable {
require (insured == address(0), "Contract already in use!");
require (msg.value >= (address(this).balance / 10), "Must send 10% of contract balance to insure!");
insured = payable(msg.sender);
uint change = msg.value - (address(this).balance / 10);
insured.transfer(change);
}
function claim() public {
require (msg.sender == insured, "Only insured can claim!");
StoreWeather w = StoreWeather(oracle);
require (w.retrieve() == StoreWeather.Weather.snow, "Can only claim when snowing!");
insurer.transfer(address(this).balance/10);
insured.transfer(address(this).balance);
}
function cancel() public {
require (msg.sender == insurer, "Only insurer can cancel!");
if (insured != address(0)){
insured.transfer(address(this).balance/10);
}
insurer.transfer(address(this).balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment