Last active
December 6, 2018 09:59
-
-
Save yaronvel/b4b071de79ab279a35ca3a7517df60b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract PizzaStore { | |
uint constant SLICE_PRICE_IN_ETH = 1e17; | |
uint constant SLICE_PRICE_IN_TOKEN = 1e19; | |
ERC20Interface constant PIZZA_TOKEN = ERC20Interface(0xdd974D5C2e2928deA5F71b9825b8b646686BD200); | |
event ProofOfPayment(address _beneficiary, address _token, uint _amount, bytes32 _data); | |
function buyPizzaWithEther(uint _slices, address _beneficiary, string _homeAddress) public payable { | |
require(msg.value == _slices * SLICE_PRICE_IN_ETH); | |
bytes32 data = keccak256(abi.encodePacked(_slices,_homeAddress)); | |
emit ProofOfPayment(_beneficiary,0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,msg.value,data); | |
} | |
function buyPizzaWithToken(uint _slices, address _beneficiary, string _homeAddress) public { | |
require(PIZZA_TOKEN.transferFrom(msg.sender,this,_slices * SLICE_PRICE_IN_TOKEN)); | |
bytes32 data = keccak256(abi.encodePacked(_slices,_homeAddress)); | |
emit ProofOfPayment(_beneficiary,PIZZA_TOKEN,_slices * SLICE_PRICE_IN_TOKEN,data); | |
} | |
} | |
contract ERC20Interface { | |
function totalSupply() public view returns (uint); | |
function balanceOf(address tokenOwner) public view returns (uint balance); | |
function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
function transfer(address to, uint tokens) public returns (bool success); | |
function approve(address spender, uint tokens) public returns (bool success); | |
function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment