forked from miladmostavi/gnosis-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HunchGameToken.sol
101 lines (91 loc) · 2.96 KB
/
HunchGameToken.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
89
90
91
92
93
94
95
96
97
98
99
100
101
pragma solidity ^0.4.0;
import "Tokens/StandardToken.sol";
/// @title Hunch Game token contract - Implements token trading and high-score calculation.
/// @author Stefan George - <stefan.george@consensys.net>
/// @author Martin Koeppelmann - <martin.koeppelmann@consensys.net>
contract HunchGameToken is StandardToken {
/*
* Constants
*/
// Token meta data
string constant public name = "HunchGame Token";
string constant public symbol = "HGT";
uint8 constant public decimals = 18;
/*
* Data structures
*/
address owner;
address hunchGameMarketFactory;
/*
* Modifiers
*/
modifier isOwner() {
if (msg.sender != owner) {
// Only DAO contract is allowed to proceed
throw;
}
_;
}
modifier isHunchGameMarketFactory() {
if (msg.sender != hunchGameMarketFactory) {
// Only HunchGame market factory contract is allowed to proceed
throw;
}
_;
}
/*
* Read and write functions
*/
/// @dev Contract constructor sets initial tokens to contract owner.
function HunchGameToken() {
owner = msg.sender;
uint initialTokens = 2**256 / 2;
balances[msg.sender] += initialTokens;
totalSupply += initialTokens;
}
/// @dev Issues tokens for user.
/// @param user User's address.
/// @param tokenCount Number of tokens to issue.
function issueTokens(address user, uint tokenCount)
public
isHunchGameMarketFactory
{
balances[user] += tokenCount;
totalSupply += tokenCount;
}
/// @dev Setup function sets external contracts' addresses.
/// @param _hunchGameMarketFactory HunchGame market factory address.
function setup(address _hunchGameMarketFactory)
external
isOwner
{
if (hunchGameMarketFactory != 0) {
// Setup was executed already
throw;
}
hunchGameMarketFactory = _hunchGameMarketFactory;
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success.
/// @param _from Address from where tokens are withdrawn.
/// @param _to Address to where tokens are sent.
/// @param _value Number of tokens to transfer.
/// @return success Returns success of function call.
function transferFrom(address _from, address _to, uint256 _value)
public
returns (bool success)
{
if ( balances[_from] < _value
|| (allowed[_from][msg.sender] < _value && msg.sender != hunchGameMarketFactory))
{
// Balance too low or allowance too low and sender is not HunchGame market factory
throw;
}
balances[_to] += _value;
balances[_from] -= _value;
if (msg.sender != hunchGameMarketFactory) {
allowed[_from][msg.sender] -= _value;
}
Transfer(_from, _to, _value);
return true;
}
}