Skip to content

Instantly share code, notes, and snippets.

@crazybuster
Last active September 14, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crazybuster/4821a42b45f6385e6720f97a3ecb1c8f to your computer and use it in GitHub Desktop.
Save crazybuster/4821a42b45f6385e6720f97a3ecb1c8f 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