forked from runtimeverification/verified-smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandardToken.inlined.sol
207 lines (158 loc) · 5.13 KB
/
StandardToken.inlined.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
pragma solidity ^0.4.2;
/*
* Token - is a smart contract interface
* for managing common functionality of
* a token.
*
* ERC.20 Token standard: https://github.com/eth ereum/EIPs/issues/20
*/
contract TokenInterface {
// total amount of tokens
uint totalSupply;
/**
*
* balanceOf() - constant function check concrete tokens balance
*
* @param owner - account owner
*
* @return the value of balance
*/
function balanceOf(address owner) constant returns (uint256 balance);
function transfer(address to, uint256 value) returns (bool success);
function transferFrom(address from, address to, uint256 value) returns (bool success);
/**
*
* approve() - function approves to a person to spend some tokens from
* owner balance.
*
* @param spender - person whom this right been granted.
* @param value - value to spend.
*
* @return true in case of succes, otherwise failure
*
*/
function approve(address spender, uint256 value) returns (bool success);
/**
*
* allowance() - constant function to check how much is
* permitted to spend to 3rd person from owner balance
*
* @param owner - owner of the balance
* @param spender - permitted to spend from this balance person
*
* @return - remaining right to spend
*
*/
function allowance(address owner, address spender) constant returns (uint256 remaining);
// events notifications
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/*
* StandardToken - is a smart contract
* for managing common functionality of
* a token.
*
* ERC.20 Token standard:
* https://github.com/eth ereum/EIPs/issues/20
*/
contract StandardToken is TokenInterface {
// token ownership
mapping (address => uint256) balances;
// spending permision management
mapping (address => mapping (address => uint256)) allowed;
function StandardToken(){
}
/**
* transfer() - transfer tokens from msg.sender balance
* to requested account
*
* @param to - target address to transfer tokens
* @param value - ammount of tokens to transfer
*
* @return - success / failure of the transaction
*/
function transfer(address to, uint256 value) returns (bool success) {
if (balances[msg.sender] >= value && value > 0) {
// do actual tokens transfer
balances[msg.sender] -= value;
balances[to] += value;
// rise the Transfer event
Transfer(msg.sender, to, value);
return true;
} else {
return false;
}
}
/**
* transferFrom() - used to move allowed funds from other owner
* account
*
* @param from - move funds from account
* @param to - move funds to account
* @param value - move the value
*
* @return - return true on success false otherwise
*/
function transferFrom(address from, address to, uint256 value) returns (bool success) {
if ( balances[from] >= value &&
allowed[from][msg.sender] >= value &&
value > 0) {
// do the actual transfer
balances[from] -= value;
balances[to] += value;
// addjust the permision, after part of
// permited to spend value was used
allowed[from][msg.sender] -= value;
// rise the Transfer event
Transfer(from, to, value);
return true;
} else {
return false;
}
}
/**
*
* balanceOf() - constant function check concrete tokens balance
*
* @param owner - account owner
*
* @return the value of balance
*/
function balanceOf(address owner) constant returns (uint256 balance) {
return balances[owner];
}
/**
*
* approve() - function approves to a person to spend some tokens from
* owner balance.
*
* @param spender - person whom this right been granted.
* @param value - value to spend.
*
* @return true in case of succes, otherwise failure
*
*/
function approve(address spender, uint256 value) returns (bool success) {
// now spender can use balance in
// ammount of value from owner balance
allowed[msg.sender][spender] = value;
// rise event about the transaction
Approval(msg.sender, spender, value);
return true;
}
/**
*
* allowance() - constant function to check how mouch is
* permited to spend to 3rd person from owner balance
*
* @param owner - owner of the balance
* @param spender - permited to spend from this balance person
*
* @return - remaining right to spend
*
*/
function allowance(address owner, address spender) constant returns (uint256 remaining) {
return allowed[owner][spender];
}
}