Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active May 8, 2021 19:34
Show Gist options
  • Save percybolmer/e8a01d4331a6adade2aacf46873bf5cd to your computer and use it in GitHub Desktop.
Save percybolmer/e8a01d4331a6adade2aacf46873bf5cd to your computer and use it in GitHub Desktop.
/**
* @notice
* hasStake is used to check if a account has stakes and the total amount along with all the seperate stakes
*/
function hasStake(address _staker) public view returns(StakingSummary memory){
// totalStakeAmount is used to count total staked amount of the address
uint256 totalStakeAmount;
// Keep a summary in memory since we need to calculate this
StakingSummary memory summary = StakingSummary(0, stakes[_staker]);
// Itterate all stakes and grab amount of stakes
for (uint256 s = 0; s < summary.stakes.length; s += 1){
totalStakeAmount = totalStakeAmount+summary.stakes[s].amount;
}
// Assign calculate amount to summary
summary.total_amount = totalStakeAmount;
return summary;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment