Skip to content

Instantly share code, notes, and snippets.

@yaronvel yaronvel/PizzaStore.sol
Last active Dec 6, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.