Skip to content

Instantly share code, notes, and snippets.

@kirillsurkov
Created April 17, 2018 17:41
Show Gist options
  • Select an option

  • Save kirillsurkov/380f17d59b2ebbf14becf0a813b5573d to your computer and use it in GitHub Desktop.

Select an option

Save kirillsurkov/380f17d59b2ebbf14becf0a813b5573d to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.20;
contract Store {
address private owner;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function Store() public {
owner = msg.sender;
}
function deposit() public payable onlyOwner {
}
function withdraw(address to, uint value) public onlyOwner {
to.transfer(value);
}
}
contract Main {
mapping(address => mapping(address => uint)) public allowed;
Store private store;
function Main() public {
store = new Store();
}
function send(address to) public payable {
require(msg.value > 0);
allowed[msg.sender][to] += msg.value;
store.deposit.value(msg.value)();
}
function receive(address from, uint amount) public {
require(allowed[from][msg.sender] >= amount && amount > 0);
allowed[from][msg.sender] -= amount;
store.withdraw(msg.sender, amount);
}
function takeBack(address from, uint amount) public {
require(allowed[msg.sender][from] >= amount && amount > 0);
allowed[msg.sender][from] -= amount;
store.withdraw(msg.sender, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment