feat(contracts): add bounty_count() total-bounties view function - #1127
Open
Teemi2106 wants to merge 1 commit into
Open
feat(contracts): add bounty_count() total-bounties view function#1127Teemi2106 wants to merge 1 commit into
Teemi2106 wants to merge 1 commit into
Conversation
Adds a dedicated bounty_count() view function that returns the total number of bounties ever created, backed by its own persistent counter (DataKey::TotalBountyCount) that is incremented once per successful create_bounty call. Also adds a doc comment on both bounty_count() and get_next_bounty_id() clarifying the semantic difference between the two: get_next_bounty_id tracks the last-assigned bounty ID (an implementation detail of ID allocation), while bounty_count is a plain, purpose-built running total. Closes ritik4ever#754
|
@Teemi2106 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! 🚀 |
|
@Teemi2106 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
Adds a
bounty_count()view function to the contract that returns the total number of bounties ever created, and clarifies its semantic difference from the existingget_next_bounty_id().Closes #754
Changes
contracts/src/lib.rsDataKey::TotalBountyCount, a dedicated persistent counter separate fromDataKey::NextBountyId.create_bountynow increments this counter by exactly one on every successful call, right after the bounty is written to storage.bounty_count(env: Env) -> u64, a read-only view function that returns the counter's value (defaulting to0if no bounty has ever been created).bounty_count()explaining what it does and how it differs fromget_next_bounty_id().get_next_bounty_id()pointing callers who want a total-bounty count towardbounty_count()instead, sinceget_next_bounty_id's value is really an implementation detail of ID allocation rather than a purpose-built counter.contracts/src/test.rstest_bounty_count, which asserts:bounty_count()is0before any bounty is created.1after the firstcreate_bountycall and2after the second.get_next_bounty_id()given the current sequential ID-assignment scheme (without depending on that being true for the API contract).Design notes
The issue offered two implementation options: a dedicated counter, or deriving the count as
next_id - 1. I went with a dedicated counter rather than deriving fromget_next_bounty_id(), because:DataKey::NextBountyIdis only incremented at creation time and then used directly as the new bounty's ID — so it already equals the total count, not "the ID to be assigned next." Subtracting 1 from it (as literally suggested in the issue) would actually break the "returns 0 before any bounty is created" acceptance criterion (0 - 1underflows for au64).bounty_count()correct and self-contained regardless of any future changes to how bounty IDs are allocated (e.g. if IDs were ever made non-sequential or reused), rather than silently depending on that implementation detail.Acceptance criteria
bounty_count()returns0before any bounty is createdbounty_count()increases by exactly one after each successfulcreate_bountycallget_next_bounty_id()Testing
No local Rust/Soroban toolchain was available in the environment I made these changes in, so I was not able to run
cargo test/cargo build --target wasm32-unknown-unknownmyself. Please run the test suite locally before merging — in particular:I've reviewed the diff carefully for correctness, but automated verification is still needed.