This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoken_receiver.sol
88 lines (70 loc) · 2.11 KB
/
token_receiver.sol
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pragma solidity ^0.5.0;
import {ERC20Interface} from "./ERC20.sol";
contract TokenReciever {
bool public locked = false;
address owner;
constructor() public {
owner = msg.sender;
}
modifier OnlyUnlock {
require(!locked);
_;
}
modifier OnlyOwner {
require(msg.sender == owner);
_;
}
function Send(address token, address to, uint value)
public
OnlyOwner
OnlyUnlock
{
ERC20Interface(token).transfer(to, value);
}
function SendFrom(address token, address from, address to, uint tokens)
public
OnlyOwner
OnlyUnlock
{
ERC20Interface(token).transferFrom(from, to, tokens);
}
function balanceOf(address token) public view returns (uint256) {
return ERC20Interface(token).balanceOf(address(this));
}
function Unlock() public OnlyOwner {
locked = false;
}
function Lock() public OnlyOwner {
locked = true;
}
}
contract Token {
mapping(address => address) internal tokens;
constructor() public {}
function NewTokenReceiver() public {
require(
address(tokens[msg.sender]) == address(0x0),
"Has been created receiver address"
);
// TokenReciever token = new TokenReciever();
tokens[msg.sender] = address(new TokenReciever());
}
function WithdrawToken(address token, address _to, uint256 value) public {
TokenReciever(tokens[msg.sender]).Send(token, _to, value);
}
function SendToken(address token, address from, address to, uint256 value)
internal
{
TokenReciever(tokens[from]).Send(token, to, value);
}
function Balance(address token) public view returns (uint256) {
return TokenReciever(tokens[msg.sender]).balanceOf(token);
}
function SetLock(address user, bool locked) internal {
TokenReciever tr = TokenReciever(tokens[user]);
return locked ? tr.Lock() : tr.Unlock();
}
function MyToken() public view returns (address token) {
return address(tokens[msg.sender]);
}
}