Skip to content

feat: add on-chain score change history to reputation-contract #47

Description

@EmeditWeb

Problem

The reputation contract only stores the current score (storage.rs lines 27-46). Historical score changes are only emitted as events (off-chain), not stored on-chain. There is no function to query score history or past score changes.

Contract impact: Users cannot query their score history from the contract. The off-chain indexer must track all events to build a history, which may have gaps if the indexer was down.

Before Starting

Read: context/architecture-context.md

Root Cause

Score history storage was deferred during initial implementation.

What To Build

  1. Add ScoreChange struct with score, timestamp, reason
  2. Store score changes in persistent storage with Vec or similar
  3. Add get_score_history(env, address, page, limit) -> Vec<ScoreChange> function
  4. Ensure TTL extension on each append
  5. Cap history at 100 entries per user (FIFO eviction)

Files To Touch

  • contracts/reputation-contract/src/storage.rs — add history storage
  • contracts/reputation-contract/src/types.rs — add ScoreChange struct
  • contracts/reputation-contract/src/lib.rs — add get_score_history
  • contracts/reputation-contract/src/events.rs — ensure events include reason

Acceptance Criteria

  • Score history stored on-chain
  • get_score_history returns paginated results
  • Capped at 100 entries per user
  • TTL extended on every write
  • All existing tests pass

Mandatory Checks

  • context/ files read
  • cargo build passes
  • cargo test passes
  • PR references this issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions