Skip to content

Commit

Permalink
Fix compilation errors and improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DemiMarie committed Jan 17, 2019
1 parent a0ccadb commit ef5d527
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions contracts/abstracts/ValidatorSetBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
uint256 public constant STAKE_UNIT = 1 ether;

// ================================================ Events ========================================================
/// Emitted by `stake` function to signal that the staker made a stake of the specified
/// @dev Emitted by `stake` function to signal that the staker made a stake of the specified
/// amount for the specified observer during the specified staking epoch.
/// @param toObserver The observer for whom the `staker` made the stake.
/// @param staker The address of staker who made the stake.
Expand All @@ -34,7 +34,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
uint256 amount
);

/// Emitted by `moveStake` function to signal that the staker moved the specified
/// @dev Emitted by `moveStake` function to signal that the staker moved the specified
/// amount of a stake from one observer to another during the specified staking epoch.
/// @param fromObserver The observer from whom the `staker` moved the stake.
/// @param toObserver The observer to whom the `staker` moved the stake.
Expand All @@ -49,7 +49,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
uint256 amount
);

/// Emitted by `withdraw` function to signal that the staker withdrew the specified
/// @dev Emitted by `withdraw` function to signal that the staker withdrew the specified
/// amount of a stake from the specified observer during the specified staking epoch.
/// @param fromObserver The observer from whom the `staker` withdrew `amount`.
/// @param staker The address of staker who withdrew `amount`.
Expand Down Expand Up @@ -298,7 +298,9 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
];
}

// Returns an index of the pool in the `poolsInactive` array
/// @dev Returns an index of the pool in the `poolsInactive` array.
/// @param _who The address to search for.
/// @return `uint256(~0)` if the address is not found, or the index otherwise.
function poolInactiveIndex(address _who) public view returns(uint256) {
// NOTE: the potential overflow is deliberate
return uintStorage[
Expand All @@ -313,7 +315,10 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
];
}

// Returns staker index in `poolStakers` array
/// @dev Returns an index of the pool in the `poolStakers` array.
/// @param _pool The pool to search in.
/// @param _staker The address to search for.
/// @return `uint256(~0)` if the address is not found, or the index otherwise.
function poolStakerIndex(address _pool, address _staker) public view returns(uint256) {
return uintStorage[
keccak256(abi.encode(POOL_STAKER_INDEX, _pool, _staker))
Expand Down Expand Up @@ -404,7 +409,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
function _addToPoolsInactive(address _who) internal {
address[] storage poolsInactive = addressArrayStorage[POOLS_INACTIVE];
uint256 index = poolInactiveIndex(_who);
if (index + 1 > 0 && poolsInactive[index] != _who) {
if (index != uint256(~0) && poolsInactive[index] != _who) {
_setPoolInactiveIndex(_who, poolsInactive.length);
poolsInactive.push(_who);
}
Expand All @@ -430,7 +435,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
function _removeFromPoolsInactive(address _who) internal {
address[] storage poolsInactive = addressArrayStorage[POOLS_INACTIVE];
uint256 indexToRemove = poolInactiveIndex(_who);
if (indexToRemove + 1 && poolsInactive[indexToRemove] == _who) {
if (indexToRemove != uint256(~0) && poolsInactive[indexToRemove] == _who) {
poolsInactive[indexToRemove] = poolsInactive[poolsInactive.length - 1];
_setPoolInactiveIndex(poolsInactive[indexToRemove], indexToRemove);
poolsInactive.length--;
Expand Down Expand Up @@ -653,7 +658,7 @@ contract ValidatorSetBase is EternalStorage, IValidatorSet {
keccak256(abi.encode(POOL_STAKERS, _pool))
];
uint256 indexToRemove = poolStakerIndex(_pool, _staker);
if (!(indexToRemove + 1)) return;
if (indexToRemove == uint256(~0)) return;
stakers[indexToRemove] = stakers[stakers.length - 1];
_setPoolStakerIndex(_pool, stakers[indexToRemove], indexToRemove);
stakers.length--;
Expand Down

0 comments on commit ef5d527

Please sign in to comment.