Skip to content

Commit

Permalink
ERC721HooksTrait::token_uri()
Browse files Browse the repository at this point in the history
  • Loading branch information
rsodre committed Oct 16, 2024
1 parent 92aa42d commit cc0505e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/token/src/erc721/erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ pub mod ERC721Component {
token_id: u256,
auth: ContractAddress
);

fn token_uri(
self: @ComponentState<TContractState>,
token_id: u256,
) -> ByteArray;
}

//
Expand Down Expand Up @@ -241,7 +246,7 @@ pub mod ERC721Component {
TContractState,
+HasComponent<TContractState>,
+SRC5Component::HasComponent<TContractState>,
+ERC721HooksTrait<TContractState>,
impl Hooks: ERC721HooksTrait<TContractState>,
+Drop<TContractState>
> of interface::IERC721Metadata<ComponentState<TContractState>> {
/// Returns the NFT name.
Expand All @@ -263,6 +268,10 @@ pub mod ERC721Component {
fn token_uri(self: @ComponentState<TContractState>, token_id: u256) -> ByteArray {
self._require_owned(token_id);
let base_uri = self._base_uri();
let custom_uri = Hooks::token_uri(self, token_id);
if (custom_uri.len() > 0) {
return custom_uri;
}
if base_uri.len() == 0 {
return "";
} else {
Expand Down Expand Up @@ -839,4 +848,9 @@ pub impl ERC721HooksEmptyImpl<TContractState> of ERC721Component::ERC721HooksTra
token_id: u256,
auth: ContractAddress
) {}

fn token_uri(
self: @ERC721Component::ComponentState<TContractState>,
token_id: u256,
) -> ByteArray {""}
}

0 comments on commit cc0505e

Please sign in to comment.