fix(#272): expose get_stake_amount and get_all_stakers as query endpoints - #384
Merged
cypriannwokolo2-creator merged 1 commit intoAug 31, 2026
Conversation
…uery endpoints
The staking contract had no way for clients to query (a) the plain token
amount staked by a user without receiving the full StakePosition struct,
or (b) the list of all currently active stakers.
Changes:
- types.rs: add StakerList variant to DataKey enum — persistent storage
key for the ordered list of active staker addresses.
- contract.rs:
* init(): initialise StakerList to an empty Vec<Address>.
* stake(): append user to StakerList after a successful stake.
* unstake(): remove user from StakerList when stake is moved to
unbonding — unbonding addresses are not in the list.
* get_stake_amount(): new query that returns just the i128 staked
amount (0 if no active stake). Convenience alternative to
get_stake() for callers that don't need the full StakePosition.
* get_all_stakers(): new query that returns Vec<Address> of all
addresses with an active stake. Useful for governance snapshots
and leaderboard queries.
- lib.rs: expose both new functions as public contract entry points.
Closes cocor-tech#272
|
@FaveTeamz Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Option A from the issue: exposes
get_stake_amountandget_all_stakersas proper public contract entry points in the staking contract, replacing what was previously dead/missing code.What was implemented
packages/staking/src/types.rsStakerListvariant toDataKeyenum — persistent storage key for the ordered list of active staker addresses.packages/staking/src/contract.rsinit(): initialisesStakerListto an emptyVec<Address>on deployment.stake(): appends the user toStakerListafter a successful stake. Uses persistent storage so the list survives instance storage TTL expiry.unstake(): removes the user fromStakerListwhen the stake moves to unbonding — addresses in the unbonding period are intentionally excluded from the list.get_stake_amount(env, user)(new): returns only the rawi128staked token amount for a user (returns0if no active stake). Convenience query for clients that don't need the fullStakePositionstruct.get_all_stakers(env)(new): returnsVec<Address>of all addresses with an active stake. Useful for governance snapshots, leaderboard queries, and off-chain indexing.packages/staking/src/lib.rs#[contractimpl]entry points with doc comments.Design notes
StakerListuses persistent storage (not instance) so it survives ledger TTL expiry for contracts with many stakers.stake/unstaketransactions — no separate maintenance transaction is needed.get_stake_amountis O(1) — reads a single instance storage entry.get_all_stakersis O(n) in the number of stakers — callers should be aware of this for large lists.Closes #272