-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPether.sol
93 lines (76 loc) · 2.66 KB
/
Pether.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
pragma solidity ^0.4.26;
import "./ERC20Interface.sol";
import "./ROFEXStyle.sol";
contract Pether is ERC20Interface, ROFEXStyle {
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
uint price;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
constructor() public {
symbol = "PET";
name = "Pether";
decimals = 18;
_totalSupply = 1000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
price = 1;
emit Transfer(address(0), owner, _totalSupply);
}
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function transfer(address to, uint tokens) public returns (bool success) {
balances[owner] = balances[owner].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(owner, to, tokens);
return true;
}
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
function buyPethers(uint amount) public payable {
require(amount.mul(price) == msg.value);
require(balanceOf(owner) >= amount);
require(transfer(msg.sender, amount));
alterPriceUp();
transactionCount++;
recordNewTransaction(price);
}
function sellPethers(uint amount) public {
require(balances[msg.sender] >= amount);
require(transfer(owner, amount));
uint amountEther = amount.mul(price).div(10**uint(decimals));
msg.sender.transfer(amountEther);
alterPriceDown();
transactionCount++;
recordNewTransaction(price);
}
function alterPriceUp() private {
price++;
}
function alterPriceDown() private {
if (price > 0) {
price--;
}
}
function getCurrentPrice() public view returns (int price) {
return price;
}
}