Skip to content

#101 — / View Functions Panic on Missing IDs: Inconsistent Semantics #882

Description

@Topmatrixmor2014

Labels: Official Campaign | FWC26 GrantFox OSS Maybe Rewarded contract soroban api robustness bug

This is a smart-contract issue for the GrantFox FWC26 campaign. Return ContractError::NotFound from the stream/escrow getters so off-chain clients can distinguish "missing" from "contract error".

Requirements and Context

contracts/finchippay-contract/src/streams.rs:

  • get_stream returns Result<Stream, ContractError> with ContractError::NotFound — good.
  • get_claimable (≈ line 460) uses .expect("stream not found") — panics.
  • list_streams_by_payer uses .unwrap() on p_streams.get(i) and .unwrap() on the Stream lookup — panics on a stale index.

contracts/finchippay-contract/src/escrow.rs:

  • get_escrow returns Result<Escrow, ContractError> — good.
  • get_user_escrows silently returns an empty Vec for a missing key — acceptable but inconsistent.

The mix of Result, panic!, and silent-empty semantics across the read API forces SDK/indexer authors to special-case each call and makes a genuine NotFound indistinguishable from a contract bug. A stale StreamByPayer index entry (possible with the current silent-index-drop behavior, see batch-3 #62) would permanently panic list_streams_by_payer for that payer.

Objectives

  1. Convert get_claimable to return Result<i128, ContractError> (or 0 on missing — pick one and document).
  2. Make list_streams_by_payer skip (or return an error for) stale index entries instead of unwrap()-panicking.
  3. Add tests for missing IDs and stale indexes.

Suggested Execution

  1. Fork and branch: git checkout -b fix/view-semantics.
  2. Patch streams.rs getters; align escrow getters' semantics.
  3. Add tests; run cargo fmt --check && cargo clippy -- -D warnings && cargo test.

Acceptance Criteria

  • Every public getter returns a documented, non-panicking result for missing input.
  • Stale index entries are handled without panicking.
  • ≥4 tests; cargo test + wasm32v1-none build pass.

Guidelines

  • Keep SDK-facing names stable; document the chosen semantics in rustdoc.

Timeframe: 24 hours

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Third CampaignCampaign: Third CampaignapiapibugSomething isn't workingcontractcontractrobustnessRobustness improvementssorobansoroban

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions