-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0x9c9891f7795eb127ba4783b671573275ff3a83a9-B2X-BtcSegwit2X.sol
172 lines (140 loc) · 6.86 KB
/
0x9c9891f7795eb127ba4783b671573275ff3a83a9-B2X-BtcSegwit2X.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
pragma solidity ^0.4.17;
library SafeMathMod {// Partial SafeMath Library
function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
require((c = a - b) < a);
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
require((c = a + b) > a);
}
}
contract B2X {//is inherently ERC20
using SafeMathMod for uint256;
/**
* @constant name The name of the token
* @constant symbol The symbol used to display the currency
* @constant decimals The number of decimals used to dispay a balance
* @constant totalSupply The total number of tokens times 10^ of the number of decimals
* @constant MAX_UINT256 Magic number for unlimited allowance
* @storage balanceOf Holds the balances of all token holders
* @storage allowed Holds the allowable balance to be transferable by another address.
*/
string constant public name = "BtcSegwit2X";
string constant public symbol = "B2X";
uint8 constant public decimals = 8;
uint256 constant public totalSupply = 21000000e8;
uint256 constant private MAX_UINT256 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowed;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event TransferFrom(address indexed _spender, address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
function B2X() public {balanceOf[msg.sender] = totalSupply;}
/**
* @notice send `_value` token to `_to` from `msg.sender`
*
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
/* Ensures that tokens are not sent to address "0x0" */
require(_to != address(0));
/* Prevents sending tokens directly to contracts. */
require(isNotContract(_to));
/* SafeMathMOd.sub will throw if there is not enough balance and if the transfer value is 0. */
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_to] = balanceOf[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value The amount of token to be transferred
* @return Whether the transfer was successful or not
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
/* Ensures that tokens are not sent to address "0x0" */
require(_to != address(0));
/* Ensures tokens are not sent to this contract */
require(_to != address(this));
uint256 allowance = allowed[_from][msg.sender];
/* Ensures sender has enough available allowance OR sender is balance holder allowing single transsaction send to contracts*/
require(_value <= allowance || _from == msg.sender);
/* Use SafeMathMod to add and subtract from the _to and _from addresses respectively. Prevents under/overflow and 0 transfers */
balanceOf[_to] = balanceOf[_to].add(_value);
balanceOf[_from] = balanceOf[_from].sub(_value);
/* Only reduce allowance if not MAX_UINT256 in order to save gas on unlimited allowance */
/* Balance holder does not need allowance to send from self. */
if (allowed[_from][msg.sender] != MAX_UINT256 && _from != msg.sender) {
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
}
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Transfer the specified amounts of tokens to the specified addresses.
* @dev Be aware that there is no check for duplicate recipients.
*
* @param _toAddresses Receiver addresses.
* @param _amounts Amounts of tokens that will be transferred.
*/
function multiPartyTransfer(address[] _toAddresses, uint256 _amounts) public {
/* Ensures _toAddresses array is less than or equal to 255 */
require(_toAddresses.length <= 255);
for (uint8 i = 0; i < _toAddresses.length; i++) {
transfer(_toAddresses[i], _amounts);
}
}
/**
* @dev Transfer the specified amounts of tokens to the specified addresses from authorized balance of sender.
* @dev Be aware that there is no check for duplicate recipients.
*
* @param _from The address of the sender
* @param _toAddresses The addresses of the recipients (MAX 255)
* @param _amounts The amounts of tokens to be transferred
*/
function multiPartyTransferFrom(address _from, address[] _toAddresses, uint256[] _amounts) public {
/* Ensures _toAddresses array is less than or equal to 255 */
require(_toAddresses.length <= 255);
/* Ensures _toAddress and _amounts have the same number of entries. */
require(_toAddresses.length == _amounts.length);
for (uint8 i = 0; i < _toAddresses.length; i++) {
transferFrom(_from, _toAddresses[i], _amounts[i]);
}
}
/**
* @notice `msg.sender` approves `_spender` to spend `_value` tokens
*
* @param _spender The address of the account able to transfer the tokens
* @param _value The amount of tokens to be approved for transfer
* @return Whether the approval was successful or not
*/
function approve(address _spender, uint256 _value) public returns (bool success) {
/* Ensures address "0x0" is not assigned allowance. */
require(_spender != address(0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @param _owner The address of the account owning tokens
* @param _spender The address of the account able to transfer the tokens
* @return Amount of remaining tokens allowed to spent
*/
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
remaining = allowed[_owner][_spender];
}
function isNotContract(address _addr) private view returns (bool) {
uint length;
assembly {
/* retrieve the size of the code on target address, this needs assembly */
length := extcodesize(_addr)
}
return (length == 0);
}
// revert on eth transfers to this contract
function() public payable {revert();}
}