-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathExampleTokensRecipient.sol
More file actions
65 lines (55 loc) · 2.35 KB
/
Copy pathExampleTokensRecipient.sol
File metadata and controls
65 lines (55 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This code has not been reviewed.
* Do not use or deploy this code before reviewing it personally first.
*/
pragma solidity ^0.4.24;
import { ERC820Implementer } from "eip820/contracts/ERC820Implementer.sol";
import { ERC820ImplementerInterface } from "eip820/contracts/ERC820ImplementerInterface.sol";
import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import { ERC777TokensRecipient } from "../ERC777TokensRecipient.sol";
import { ERC777Token } from "../ERC777Token.sol";
contract ExampleTokensRecipient is ERC820Implementer, ERC820ImplementerInterface, ERC777TokensRecipient, Ownable {
bool private allowTokensReceived;
mapping(address => address) public token;
mapping(address => address) public operator;
mapping(address => address) public from;
mapping(address => address) public to;
mapping(address => uint256) public amount;
mapping(address => bytes) public data;
mapping(address => bytes) public operatorData;
mapping(address => uint256) public balanceOf;
constructor(bool _setInterface) public {
if (_setInterface) { setInterfaceImplementation("ERC777TokensRecipient", this); }
allowTokensReceived = true;
}
function tokensReceived(
address _operator,
address _from,
address _to,
uint256 _amount,
bytes _data,
bytes _operatorData
)
public
{
require(allowTokensReceived, "Receive not allowed");
token[_to] = msg.sender;
operator[_to] = _operator;
from[_to] = _from;
to[_to] = _to;
amount[_to] = _amount;
data[_to] = _data;
operatorData[_to] = _operatorData;
balanceOf[_from] = ERC777Token(msg.sender).balanceOf(_from);
balanceOf[_to] = ERC777Token(msg.sender).balanceOf(_to);
}
function acceptTokens() public onlyOwner { allowTokensReceived = true; }
function rejectTokens() public onlyOwner { allowTokensReceived = false; }
// solhint-disable-next-line no-unused-vars
function canImplementInterfaceForAddress(address addr, bytes32 interfaceHash) public view returns(bytes32) {
return ERC820_ACCEPT_MAGIC;
}
}