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
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:Replace all
panic!()calls withResult<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.rscontracts/streaming/src/test.rscontracts/streaming/src/test_security.rs