From 046f595602b2a4ed17bf073345a28391b3d266b5 Mon Sep 17 00:00:00 2001 From: Agbasimere Date: Sun, 29 Mar 2026 22:19:01 +0100 Subject: [PATCH 1/2] feat: add shared string read helpers and refactor view methods --- creator-keys/src/lib.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/creator-keys/src/lib.rs b/creator-keys/src/lib.rs index af2315e..20d0b86 100644 --- a/creator-keys/src/lib.rs +++ b/creator-keys/src/lib.rs @@ -235,6 +235,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() @@ -437,12 +455,7 @@ impl CreatorKeysContract { /// When the creator is not registered, `is_registered` is `false` and /// default values are provided for other fields. pub fn get_creator_details(env: Env, creator: Address) -> CreatorDetailsView { - let key = DataKey::Creator(creator.clone()); - match env - .storage() - .persistent() - .get::(&key) - { + match read_creator_profile(&env, &creator) { Some(profile) => CreatorDetailsView { creator: profile.creator, handle: profile.handle, @@ -451,7 +464,7 @@ impl CreatorKeysContract { }, None => CreatorDetailsView { creator, - handle: String::from_str(&env, ""), + handle: read_none_string(&env), supply: 0, is_registered: false, }, From 95596193a71223f285c61c36c720a886ee865c8b Mon Sep 17 00:00:00 2001 From: Agbasimere Date: Sun, 29 Mar 2026 22:23:01 +0100 Subject: [PATCH 2/2] style: fix formatting in shared string read helpers --- creator-keys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/creator-keys/src/lib.rs b/creator-keys/src/lib.rs index 20d0b86..a1e4a2e 100644 --- a/creator-keys/src/lib.rs +++ b/creator-keys/src/lib.rs @@ -245,7 +245,7 @@ pub fn read_none_string(env: &Env) -> String { /// 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 +/// 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)