Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions contracts/nft-reward/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ pub enum NftErrorCode {
NftNotTransferable = 11,
NftLocked = 12,
InvalidMetadata = 13,
InvalidTitle = 14,
InvalidDescription = 15,
InvalidImageUri = 16,
InvalidHuntTitle = 17,
MetadataFrozen = 14,
}
46 changes: 45 additions & 1 deletion contracts/nft-reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
pub transferable: bool,
pub minted_at: u64,
pub locked: bool,
pub metadata_frozen: bool,
}

/// Event emitted when an NFT is minted.
Expand Down Expand Up @@ -143,6 +144,14 @@
pub updater: Address,
}

/// Event emitted when an NFT's metadata is permanently frozen.
#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NftMetadataFrozenEvent {
pub nft_id: u64,
pub owner: Address,
}

/// Event emitted when admin batch-updates image URIs across NFTs.
#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -180,7 +189,7 @@
/// Contract version constant.
pub const CONTRACT_VERSION: u32 = 2;

#[contractimpl]

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

duplicate definitions with name `spec_xdr_get_admin`

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `__SPEC_XDR_FN_SET_REWARD_MANAGER` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `__SPEC_XDR_FN_GET_ADMIN` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `__set_reward_manager` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `__get_admin` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

duplicate definitions with name `spec_xdr_set_reward_manager`

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

duplicate definitions with name `spec_xdr_get_admin`

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `__SPEC_XDR_FN_SET_REWARD_MANAGER` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `__SPEC_XDR_FN_GET_ADMIN` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `__set_reward_manager` is defined multiple times

Check failure on line 192 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `__get_admin` is defined multiple times
impl NftReward {
/// Initializes the NFT reward contract with an admin, minter, and optional max supply cap.
pub fn initialize(
Expand Down Expand Up @@ -600,6 +609,7 @@
transferable,
minted_at,
locked: false,
metadata_frozen: false,
};

Storage::save_nft(&env, &nft_data);
Expand Down Expand Up @@ -676,12 +686,12 @@
}

/// Returns the configured admin address, if set.
pub fn get_admin(env: Env) -> Option<Address> {

Check failure on line 689 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

duplicate definitions with name `get_admin`

Check failure on line 689 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

duplicate definitions with name `get_admin`
Storage::get_admin(&env)
}

/// Sets the RewardManager contract address. Only the admin can call this.
pub fn set_reward_manager(

Check failure on line 694 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

duplicate definitions with name `set_reward_manager`

Check failure on line 694 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

duplicate definitions with name `set_reward_manager`
env: Env,
admin: Address,
reward_manager: Address,
Expand Down Expand Up @@ -731,7 +741,11 @@
return Err(crate::errors::NftErrorCode::NotOwner);
}

let new_description = Self::validate_metadata_field(
if nft.metadata_frozen {
return Err(crate::errors::NftErrorCode::MetadataFrozen);
}

let new_description = Self::sanitize_metadata_field(
&env,
&new_description,
MAX_NFT_DESCRIPTION_BYTES,
Expand All @@ -752,6 +766,36 @@
Ok(())
}

/// Permanently freezes the NFT's metadata, preventing future updates. Owner only.
pub fn freeze_nft_metadata(
env: Env,
nft_id: u64,
owner: Address,
) -> Result<(), crate::errors::NftErrorCode> {
owner.require_auth();

let mut nft =
Storage::get_nft(&env, nft_id).ok_or(crate::errors::NftErrorCode::NftNotFound)?;

if nft.owner != owner {
return Err(crate::errors::NftErrorCode::NotOwner);
}

if nft.metadata_frozen {
return Err(crate::errors::NftErrorCode::MetadataFrozen);
}

nft.metadata_frozen = true;
Storage::save_nft(&env, &nft);

env.events().publish(
(Symbol::new(&env, "NftMetadataFrozen"), nft_id),
NftMetadataFrozenEvent { nft_id, owner },
);

Ok(())
}

/// Returns the total number of NFTs minted so far.
pub fn total_supply(env: Env) -> u64 {
Storage::get_nft_counter(&env)
Expand Down Expand Up @@ -784,7 +828,7 @@
}

// Apply bounded scan limit to prevent excessive gas consumption
let bounded_limit = limit.min(MAX_SCAN_LIMIT);

Check failure on line 831 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find value `MAX_SCAN_LIMIT` in this scope

Check failure on line 831 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

cannot find value `MAX_SCAN_LIMIT` in this scope
let end = offset.saturating_add(bounded_limit).min(total_count);

let mut result = Vec::new(&env);
Expand Down Expand Up @@ -866,7 +910,7 @@
}

/// Searches NFTs by title (case-insensitive partial match).
/// Returns a vector of NFT IDs whose titles contain the search query.

Check failure on line 913 in contracts/nft-reward/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

empty line after outer attribute

pub fn search_by_title(env: Env, _query: String) -> Vec<u64> {
Vec::new(&env)
Expand Down
Loading