1
- pragma solidity ^ 0.5.11 ;
1
+ pragma solidity 0.5.13 ;
2
2
3
3
import "openzeppelin-solidity/contracts/ownership/Ownable.sol " ;
4
4
@@ -11,7 +11,6 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
11
11
* The Reputation contract maintain a map of address to reputation value.
12
12
* It provides an onlyOwner functions to mint and burn reputation _to (or _from) a specific address.
13
13
*/
14
-
15
14
contract Reputation is Ownable {
16
15
17
16
uint8 public decimals = 18 ; //Number of decimals of the smallest unit
@@ -35,60 +34,10 @@ contract Reputation is Ownable {
35
34
// `balances` is the map that tracks the balance of each address, in this
36
35
// contract when the balance changes the block number that the change
37
36
// occurred is also included in the map
38
- mapping (address => Checkpoint[]) balances;
37
+ mapping (address => Checkpoint[]) private balances;
39
38
40
39
// Tracks the history of the `totalSupply` of the reputation
41
- Checkpoint[] totalSupplyHistory;
42
-
43
- /// @notice Constructor to create a Reputation
44
- constructor (
45
- ) public
46
- {
47
- }
48
-
49
- /// @dev This function makes it easy to get the total number of reputation
50
- /// @return The total number of reputation
51
- function totalSupply () public view returns (uint256 ) {
52
- return totalSupplyAt (block .number );
53
- }
54
-
55
- ////////////////
56
- // Query balance and totalSupply in History
57
- ////////////////
58
- /**
59
- * @dev return the reputation amount of a given owner
60
- * @param _owner an address of the owner which we want to get his reputation
61
- */
62
- function balanceOf (address _owner ) public view returns (uint256 balance ) {
63
- return balanceOfAt (_owner, block .number );
64
- }
65
-
66
- /// @dev Queries the balance of `_owner` at a specific `_blockNumber`
67
- /// @param _owner The address from which the balance will be retrieved
68
- /// @param _blockNumber The block number when the balance is queried
69
- /// @return The balance at `_blockNumber`
70
- function balanceOfAt (address _owner , uint256 _blockNumber )
71
- public view returns (uint256 )
72
- {
73
- if ((balances[_owner].length == 0 ) || (balances[_owner][0 ].fromBlock > _blockNumber)) {
74
- return 0 ;
75
- // This will return the expected balance during normal situations
76
- } else {
77
- return getValueAt (balances[_owner], _blockNumber);
78
- }
79
- }
80
-
81
- /// @notice Total amount of reputation at a specific `_blockNumber`.
82
- /// @param _blockNumber The block number when the totalSupply is queried
83
- /// @return The total amount of reputation at `_blockNumber`
84
- function totalSupplyAt (uint256 _blockNumber ) public view returns (uint256 ) {
85
- if ((totalSupplyHistory.length == 0 ) || (totalSupplyHistory[0 ].fromBlock > _blockNumber)) {
86
- return 0 ;
87
- // This will return the expected totalSupply during normal situations
88
- } else {
89
- return getValueAt (totalSupplyHistory, _blockNumber);
90
- }
91
- }
40
+ Checkpoint[] private totalSupplyHistory;
92
41
93
42
/// @notice Generates `_amount` reputation that are assigned to `_owner`
94
43
/// @param _user The address that will be assigned the new reputation
@@ -122,6 +71,49 @@ contract Reputation is Ownable {
122
71
return true ;
123
72
}
124
73
74
+ /// @dev This function makes it easy to get the total number of reputation
75
+ /// @return The total number of reputation
76
+ function totalSupply () public view returns (uint256 ) {
77
+ return totalSupplyAt (block .number );
78
+ }
79
+
80
+ ////////////////
81
+ // Query balance and totalSupply in History
82
+ ////////////////
83
+ /**
84
+ * @dev return the reputation amount of a given owner
85
+ * @param _owner an address of the owner which we want to get his reputation
86
+ */
87
+ function balanceOf (address _owner ) public view returns (uint256 balance ) {
88
+ return balanceOfAt (_owner, block .number );
89
+ }
90
+
91
+ /// @notice Total amount of reputation at a specific `_blockNumber`.
92
+ /// @param _blockNumber The block number when the totalSupply is queried
93
+ /// @return The total amount of reputation at `_blockNumber`
94
+ function totalSupplyAt (uint256 _blockNumber ) public view returns (uint256 ) {
95
+ if ((totalSupplyHistory.length == 0 ) || (totalSupplyHistory[0 ].fromBlock > _blockNumber)) {
96
+ return 0 ;
97
+ // This will return the expected totalSupply during normal situations
98
+ } else {
99
+ return getValueAt (totalSupplyHistory, _blockNumber);
100
+ }
101
+ }
102
+
103
+ /// @dev Queries the balance of `_owner` at a specific `_blockNumber`
104
+ /// @param _owner The address from which the balance will be retrieved
105
+ /// @param _blockNumber The block number when the balance is queried
106
+ /// @return The balance at `_blockNumber`
107
+ function balanceOfAt (address _owner , uint256 _blockNumber )
108
+ public view returns (uint256 )
109
+ {
110
+ if ((balances[_owner].length == 0 ) || (balances[_owner][0 ].fromBlock > _blockNumber)) {
111
+ return 0 ;
112
+ // This will return the expected balance during normal situations
113
+ } else {
114
+ return getValueAt (balances[_owner], _blockNumber);
115
+ }
116
+ }
125
117
////////////////
126
118
// Internal helper functions to query and set a value in a snapshot array
127
119
////////////////
@@ -148,7 +140,7 @@ contract Reputation is Ownable {
148
140
uint256 max = checkpoints.length -1 ;
149
141
while (max > min) {
150
142
uint256 mid = (max + min + 1 ) / 2 ;
151
- if (checkpoints[mid].fromBlock<= _block) {
143
+ if (checkpoints[mid].fromBlock <= _block) {
152
144
min = mid;
153
145
} else {
154
146
max = mid-1 ;
0 commit comments