-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrust.sol
31 lines (26 loc) · 870 Bytes
/
Trust.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}
}