Skip to content

Instantly share code, notes, and snippets.

@nick
Forked from crazybuster/ERC827Test.sol
Created September 14, 2018 20:10
Show Gist options
  • Save nick/8fe6ef16bdd4635615813c58510f811a to your computer and use it in GitHub Desktop.
Save nick/8fe6ef16bdd4635615813c58510f811a to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
import "./openzeppelin-solidity/ownership/Ownable.sol";
import "./openzeppelin-solidity/token/ERC20/StandardToken";
contract Token is StandardToken, Ownable {
uint256 public constant decimals = 0;
string public constant name = "ERC827 Token";
string public constant symbol = "TOK";
mapping (address => bool) erc827Whitelist;
constructor(uint256 initialSupply) public {
owner = msg.sender;
totalSupply_ = initialSupply;
balances[msg.sender] = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
}
function addToERC827Whitelist(address _spender) public onlyOwner {
erc827Whitelist[_spender] = true;
}
function approveAndCallWithSender(
address _spender,
uint256 _value,
bytes4 selector,
bytes call_params
)
public
payable
returns (bool)
{
require(_spender != address(this) && erc827Whitelist[_spender]);
super.approve(_spender, _value);
bytes memory call_data = abi.encodePacked(selector, uint256(msg.sender), call_params);
require(_spender.call.value(msg.value)(call_data));
return true;
}
// TODO: similarly wrapped versions of increaseApprovalAndCall, etc.
}
contract Marketplace {
event Listing(address _seller, uint256 _deposit, bytes32 ipfshHash);
Token token;
constructor(Token _token) public {
token = _token;
}
function proxiedCreateListing(address _seller, uint256 _deposit, bytes32 _ipfsHash) public payable {
// msg.sender would be token address here
require(msg.sender == address(token), "proxied function must be called by token");
require(_seller != address(token), "token can't be the seller");
require(address(this) != address(token), "marketplace can't be the seller");
require(token.transferFrom(_seller, address(this), _deposit));
emit Listing(_seller, _deposit, _ipfsHash);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment