Skip to content

Instantly share code, notes, and snippets.

@abramsymons
Created May 12, 2020 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abramsymons/c5fed677ce28d06fe50088b500dfeb65 to your computer and use it in GitHub Desktop.
Save abramsymons/c5fed677ce28d06fe50088b500dfeb65 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.3;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
contract BrightID {
mapping(address => bool) public verifications;
mapping(address => address) public history;
}
contract Distribution is Ownable {
using SafeMath for uint256;
uint256 claimable = 0;
BrightID brightid;
mapping(address => uint256) public claimed;
receive () external payable {}
function setClaimable(uint256 _claimable) public onlyOwner
{
claimable = _claimable;
}
function setBrightid(address addr) public onlyOwner
{
brightid = BrightID(addr);
}
function claim(address payable beneficiary, uint256 amount) public
{
require(brightid.verifications(beneficiary), "beneficiary is not verified");
uint256 sum = 0;
address tmpAddress = beneficiary;
while (tmpAddress != address(0)) {
sum = sum.add(claimed[tmpAddress]);
tmpAddress = brightid.history(tmpAddress);
}
require(claimable >= sum.add(amount), "total claimed amount is more than claimable");
claimed[beneficiary] = claimed[beneficiary].add(amount);
beneficiary.transfer(amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment