#119 Audit and consolidate .unwrap_or patterns FIXED - #127
Open
Kappa16 wants to merge 1 commit into
Open
Conversation
Audit and consolidate `.unwrap_or` patterns FIXED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Audit and consolidate
.unwrap_orpatterns FIXEDCLOSE #119
Description
This PR fixes the issue of silent defaults in storage reads across the codebase. Previously,
unwrap_or(0),unwrap_or(false), andunwrap_or_elsewere used extensively without a shared helper, making it impossible to distinguish between "key missing" and "key exists with zero/false value" — a critical safety concern for persistent storage reads like balances and tip counts.Changes made:
Added 5 explicit storage helper functions that return
Option<T>:get_instance()- reads instance storageget_persistent()- reads persistent storageget_balance_opt()- reads balance (persistent)get_tip_count_opt()- reads tip count (persistent)get_paused_opt()- reads paused flag (instance)Updated 8 view functions to return
Option<T>instead of primitives:get_balance()→Option<i128>get_tip_count()→Option<u64>is_paused()→Option<bool>get_fee_percentage()→Option<u32>get_max_creators()→Option<u32>get_max_tips_per_creator()→Option<u32>get_min_tip_amount()→Option<i128>get_creator_count()→Option<u32>Updated all tests to assert
Some(value)instead of bare values.Type of change
Option<T>; external callers must handleNonecaseHow Has This Been Tested?
cargo testpasses (library compiles; test compilation blocked by upstream soroban-sdk 22.x / ed25519-dalek 3.0 conflict unrelated to this PR)cargo clippyshows no warnings (on library build)cargo fmt -- --checkpassescargo build --release --target wasm32-unknown-unknownsucceedsChecklist:
cargo fmt)cargo clippy)Some(value)vsNonedistinction)