Skip to content

[Giveaway] Add read-only view functions for giveaway state #433

Description

@3m1n3nc3

Description

contracts/geev-core/src/giveaway.rs exposes no read-only view functions. Every other module offers at least one getter — mutual_aid.rs has get_request (line 53), profile.rs has get_profile / resolve_username / get_reputation, governance.rs has get_flag_count / has_flagged — but a client that wants to read a giveaway must decode raw DataKey::Giveaway(id) / DataKey::ParticipantIndex(id, index) storage entries itself. The only lookup helper that exists, find_winner_index (line 317), is private.

This forces the off-chain indexer and the frontend to duplicate the contract's storage layout, which then silently breaks whenever DataKey or the Giveaway struct changes.

User Story

As an Indexer / Frontend Developer,
I want to read giveaway state through contract view functions,
so that I do not have to reimplement the contract's storage layout off-chain.

Requirements and Context

  • Files / refs: contracts/geev-core/src/giveaway.rs, contracts/geev-core/src/test.rs, contracts/README.md
  • Add get_giveaway(giveaway_id) -> Option<Giveaway>, mirroring MutualAidContract::get_request
  • Add get_winners(giveaway_id) -> Vec<Address> and get_participants(giveaway_id) -> Vec<Address>
  • Add has_claimed(giveaway_id, winner) -> bool reading DataKey::Claimed(id, winner)
  • All getters must be read-only: no require_auth, no storage writes, and return Option / empty Vec instead of panicking on a missing id

Suggested Implementation

1. Add get_giveaway returning Option<Giveaway> from DataKey::Giveaway
2. Add get_winners reading giveaway.winners, empty Vec when absent
3. Add get_participants walking DataKey::ParticipantIndex 0..participant_count
4. Add has_claimed reading DataKey::Claimed(id, winner)
5. Add tests covering populated, empty, and non-existent giveaway ids

Acceptance Criteria

  • Giveaway state is readable without decoding raw storage keys
  • Getters never panic for unknown ids and never mutate state
  • Tests cover populated, empty, and missing-id cases

Submission Guidelines

  • Branch: feat/giveaway-view-functions
  • Depends on: None
  • PR: feat(giveaway): add read-only view functions

Gap verified against origin/main at 87de441 on 2026-08-27; line references above are from that commit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions