Created
September 13, 2018 20:01
-
-
Save crazybuster/44fcbaa47da48071811e2ac8543884c2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains 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; | |
// | |
// Selector for create in TestMarketplace: | |
// "10a9ee58": "dispatched_createListing(address,bytes32,uint256)" | |
// call_params: | |
// _listing: 0xAB01 deposit: 8 | |
// ab010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 | |
contract DispatcherContract { | |
function approve_and_dispatch( | |
address token_address, | |
uint256 token_amount, | |
address dispatched, | |
bytes4 selector, | |
bytes call_params) public payable returns (bool) { | |
if ( DispatchableToken(token_address).dispatched_approve(msg.sender, dispatched, token_amount) ) | |
{ | |
bytes memory call_data = abi.encodePacked(selector, uint256(msg.sender), call_params); | |
return dispatched.call.value(msg.value)(call_data); | |
} | |
return false; | |
} | |
} | |
contract TrustedCallee { | |
address trusted_dispatcher; | |
function setTrustedDispatcher(address trusted) public | |
{ | |
// should be an internal function... | |
// require the owner of the token sets this. | |
trusted_dispatcher = trusted; | |
} | |
} | |
contract DispatchableToken is TrustedCallee { // Our token would have to inheret from this... | |
event Approval( | |
address indexed owner, | |
address indexed spender, | |
uint256 value | |
); | |
function dispatched_approve(address sender, address spender, uint256 value) public returns (bool) { | |
require(trusted_dispatcher == msg.sender); | |
//_allowed[sender][spender] = value; | |
emit Approval(sender, spender, value); | |
return true; | |
} | |
} | |
contract TestMarketplace is TrustedCallee { | |
event Listed( | |
address seller, | |
bytes32 _listing, | |
uint256 deposit, | |
uint256 value | |
); | |
function dispatched_createListing(address seller, bytes32 _listing, uint256 deposit) public payable { | |
require(trusted_dispatcher == msg.sender); | |
emit Listed(seller, _listing, deposit, msg.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment