Skip to content

Commit

Permalink
Removed duplicated code election.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol committed Sep 25, 2024
1 parent 708891b commit 0500b3d
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,7 @@ contract Election is
*/
function hasActivatablePendingVotes(address account, address group) external view returns (bool) {
PendingVote storage pendingVote = votes.pending.forGroup[group].byAccount[account];
if (isL2()) {
return pendingVote.epoch < getEpochManager().getCurrentEpochNumber() && pendingVote.value > 0;
}
return pendingVote.epoch < getEpochNumber() && pendingVote.value > 0;
return pendingVote.epoch < _getEpochNumber() && pendingVote.value > 0;
}

/**
Expand Down Expand Up @@ -1010,14 +1007,9 @@ contract Election is

function _activate(address group, address account) internal onlyWhenNotBlocked returns (bool) {
PendingVote storage pendingVote = votes.pending.forGroup[group].byAccount[account];
if (isL2()) {
require(
pendingVote.epoch < getEpochManager().getCurrentEpochNumber(),
"Pending vote epoch not passed"
);
} else {
require(pendingVote.epoch < getEpochNumber(), "Pending vote epoch not passed");
}

require(pendingVote.epoch < _getEpochNumber(), "Pending vote epoch not passed");

uint256 value = pendingVote.value;
require(value > 0, "Vote value cannot be zero");
decrementPendingVotes(group, account, value);
Expand Down Expand Up @@ -1165,11 +1157,7 @@ contract Election is

PendingVote storage pendingVote = groupPending.byAccount[account];
pendingVote.value = pendingVote.value.add(value);
if (isL2()) {
pendingVote.epoch = getEpochManager().getCurrentEpochNumber();
} else {
pendingVote.epoch = getEpochNumber();
}
pendingVote.epoch = _getEpochNumber();
}

/**
Expand Down Expand Up @@ -1290,4 +1278,17 @@ contract Election is
value.mul(votes.active.forGroup[group].total).div(votes.active.forGroup[group].totalUnits);
}
}

/**
* @notice Returns the epoch number.
* @return Current epoch number.
*/
function _getEpochNumber() private view returns (uint256) {
// TODO remove this after L2 is fully implemented
if (isL2()) {
return getEpochManager().getCurrentEpochNumber();
} else {
return getEpochNumber();
}
}
}

0 comments on commit 0500b3d

Please sign in to comment.