diff --git a/creator-keys/src/lib.rs b/creator-keys/src/lib.rs index c9e1d90..c9be411 100644 --- a/creator-keys/src/lib.rs +++ b/creator-keys/src/lib.rs @@ -257,6 +257,24 @@ pub fn read_key_balance(env: &Env, creator: &Address) -> u32 { .unwrap_or(0) } +/// Reads an empty string for use as a default in read-only view methods. +/// +/// Use this helper wherever an empty string is needed to maintain consistency +/// and reduce duplication of string allocation logic. +pub fn read_none_string(env: &Env) -> String { + String::from_str(env, "") +} + +/// Reads the handle for a creator, returning an empty string for unregistered creators. +/// +/// Use this helper wherever repeated handle read logic is needed to maintain +/// missing-handle behavior consistency across the contract. +pub fn read_creator_handle(env: &Env, creator: &Address) -> String { + read_creator_profile(env, creator) + .map(|p| p.handle) + .unwrap_or_else(|| read_none_string(env)) +} + fn read_protocol_fee_config(env: &Env) -> Option { env.storage() .persistent() @@ -491,7 +509,7 @@ impl CreatorKeysContract { }, None => CreatorDetailsView { creator, - handle: String::from_str(&env, ""), + handle: read_none_string(&env), supply: 0, is_registered: false, },