Skip to content

Replace panic! with Soroban contracterror enum #1

Description

@Austinaminu2

Problem

The smart contract uses panic!() with string messages for all error conditions (e.g., panic!("total_amount must be > 0")). Panic strings are expensive in Soroban — they inflate WASM size and don't give callers structured error codes.

Proposed solution

Define a #[contracterror] enum with named variants:

#[contracterror]
#[derive(Copy, Clone, Debug)]
pub enum StreamError {
    InvalidAmount = 1,
    InvalidSchedule = 2,
    InvalidCliff = 3,
    StreamNotFound = 4,
    StreamCancelled = 5,
    Unauthorized = 6,
    InvalidWithdrawAmount = 7,
}

Replace all panic!() calls with Result<T, StreamError> return types. This reduces WASM size, enables programmatic error handling on the frontend, and follows Soroban best practices.

Files to change

  • contracts/streaming/src/lib.rs
  • contracts/streaming/src/test.rs
  • contracts/streaming/src/test_security.rs

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestsmart-contractSoroban smart contract

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