From aa073fb5362589d2f4074746ab95162b0ea8d0f9 Mon Sep 17 00:00:00 2001 From: JamesVictor-O Date: Thu, 26 Mar 2026 00:42:49 +0100 Subject: [PATCH] refactor: add creator existence helper for shared checks (#14) - Extract require_creator(env, creator) -> CreatorProfile helper to a private impl block, replacing the duplicated inline storage lookup - buy_key now uses Self::require_creator to validate creator registration, keeping error message consistent ("creator not registered") - All existing tests pass without modification Co-Authored-By: Claude Sonnet 4.6 --- creator-keys/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/creator-keys/src/lib.rs b/creator-keys/src/lib.rs index 2bf09c0..0dca76c 100644 --- a/creator-keys/src/lib.rs +++ b/creator-keys/src/lib.rs @@ -72,6 +72,16 @@ pub struct CreatorProfile { #[contract] pub struct CreatorKeysContract; +impl CreatorKeysContract { + fn require_creator(env: &Env, creator: &Address) -> CreatorProfile { + let key = DataKey::Creator(creator.clone()); + env.storage() + .persistent() + .get(&key) + .unwrap_or_else(|| panic!("creator not registered")) + } +} + #[contractimpl] impl CreatorKeysContract { pub fn register_creator(env: Env, creator: Address, handle: String) { @@ -101,11 +111,7 @@ impl CreatorKeysContract { } let key = DataKey::Creator(creator.clone()); - let mut profile: CreatorProfile = env - .storage() - .persistent() - .get(&key) - .unwrap_or_else(|| panic!("creator not registered")); + let mut profile = Self::require_creator(&env, &creator); profile.supply += 1; env.storage().persistent().set(&key, &profile);