Skip to content

Instantly share code, notes, and snippets.

@adepanges
Created July 14, 2021 16:24
Show Gist options
  • Save adepanges/2b49f69a32c5da35805c26052e7c35fe to your computer and use it in GitHub Desktop.
Save adepanges/2b49f69a32c5da35805c26052e7c35fe to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.1+commit.df193b15.js&optimize=false&runs=200&gist=
pragma solidity = 0.8.1;
contract Trust {
struct Kid {
uint amount;
uint maturity;
bool paid;
}
mapping(address => Kid) public kids;
address public admin;
constructor(){
admin = msg.sender;
}
function addKid(address kid, uint timeToMaturity) external payable {
require(msg.sender == admin, 'only admin');
require(kids[msg.sender].amount == 0, 'kid already exist');
kids[kid] = Kid(msg.value, block.timestamp + timeToMaturity, false);
}
function withdraw() external {
Kid storage kid = kids[msg.sender];
require(kid.maturity <= block.timestamp, 'too early');
require(kid.amount > 0, 'only kid can withdraw');
require(kid.paid == false, 'paid already');
kid.paid = true;
payable(msg.sender).transfer(kid.amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment