Skip to content

Commit

Permalink
feat: migrate out of custom_uri component in favor of standard erc721
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Apr 17, 2024
1 parent b6dafe1 commit 5a9531e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 70 deletions.
1 change: 0 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repository = "https://github.com/starknet-id/identity"
starknet = "2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "a83f36b23f1af6e160288962be4a2701c3ecbcda" }
storage_read = { git = "https://github.com/starknet-id/storage_read_component.git", rev = "c7a640371d0336cc09b907154cbfeec743739ff9" }
custom_uri = { git = "https://github.com/starknet-id/custom_uri_component.git", rev = "7e8a3507d32548e0bb145cf9ee8b3eecac3c3386" }

[[target.starknet-contract]]
sierra = true
Expand Down
1 change: 0 additions & 1 deletion src/identity.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mod main;
mod internal;
mod erc721;
42 changes: 0 additions & 42 deletions src/identity/erc721.cairo

This file was deleted.

28 changes: 4 additions & 24 deletions src/identity/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ mod Identity {
use integer::{u256_safe_divmod, u256_as_non_zero};
use core::pedersen;
use storage_read::{main::storage_read_component, interface::IStorageRead};
use custom_uri::{interface::IInternalCustomURI, main::custom_uri_component};
use openzeppelin::{
account, access::ownable::OwnableComponent,
upgrades::{UpgradeableComponent, interface::IUpgradeable},
token::erc721::{
ERC721Component, erc721::ERC721Component::InternalTrait as ERC721InternalTrait
},
introspection::{src5::SRC5Component, dual_src5::{DualCaseSRC5, DualCaseSRC5Trait}}
introspection::{src5::SRC5Component}
};
use identity::identity::{internal::InternalTrait};

Expand All @@ -28,7 +27,6 @@ mod Identity {
const VERIFIER_DATA_ADDR: felt252 =
304878986635684253299743444353489138340069571156984851619649640349195152192;

component!(path: custom_uri_component, storage: custom_uri, event: CustomUriEvent);
component!(path: storage_read_component, storage: storage_read, event: StorageReadEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: ERC721Component, storage: erc721, event: ERC721Event);
Expand All @@ -39,8 +37,6 @@ mod Identity {
// allow to check what interface is supported
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;
#[abi(embed_v0)]
impl SRC5CamelImpl = SRC5Component::SRC5CamelImpl<ContractState>;
impl SRC5InternalImpl = SRC5Component::InternalImpl<ContractState>;
// make it a NFT
#[abi(embed_v0)]
Expand All @@ -49,8 +45,7 @@ mod Identity {
impl ERC721CamelOnlyImpl = ERC721Component::ERC721CamelOnlyImpl<ContractState>;
// allow to query name of nft collection
#[abi(embed_v0)]
impl IERC721MetadataImpl =
identity::identity::erc721::IERC721MetadataImpl<ContractState>;
impl IERC721MetadataImpl = ERC721Component::ERC721MetadataImpl<ContractState>;
// allow to query nft metadata json
#[abi(embed_v0)]
impl StorageReadImpl = storage_read_component::StorageRead<ContractState>;
Expand All @@ -69,8 +64,6 @@ mod Identity {
// legacy owner
Proxy_admin: felt252,
#[substorage(v0)]
custom_uri: custom_uri_component::Storage,
#[substorage(v0)]
storage_read: storage_read_component::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage,
Expand All @@ -96,8 +89,6 @@ mod Identity {
MainIdUpdate: MainIdUpdate,
// components
#[flat]
CustomUriEvent: custom_uri_component::Event,
#[flat]
StorageReadEvent: storage_read_component::Event,
#[flat]
SRC5Event: SRC5Component::Event,
Expand Down Expand Up @@ -151,12 +142,9 @@ mod Identity {
}

#[constructor]
fn constructor(
ref self: ContractState, owner: ContractAddress, token_uri_base: Span<felt252>,
) {
fn constructor(ref self: ContractState, owner: ContractAddress, token_uri_base: ByteArray,) {
self.ownable.initializer(owner);
self.erc721.initializer('Starknet.id', 'ID');
self.custom_uri.set_base_uri(token_uri_base);
self.erc721.initializer("Starknet.id", "ID", token_uri_base);
}

#[abi(embed_v0)]
Expand Down Expand Up @@ -324,13 +312,5 @@ mod Identity {
)
);
}

// this function should be called after upgrading from Cairo 0 contract
fn finalize_migration(ref self: ContractState, token_uri_base: Span<felt252>) {
let caller = get_caller_address();
assert(caller.into() == self.Proxy_admin.read(), 'only proxy admin can migrate');
self.ownable.initializer(caller);
self.custom_uri.set_base_uri(token_uri_base);
}
}
}
2 changes: 0 additions & 2 deletions src/interface/identity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ trait IIdentity<TContractState> {
fn set_extended_verifier_data(
ref self: TContractState, id: u128, field: felt252, data: Span<felt252>, domain: u32
);

fn finalize_migration(ref self: TContractState, token_uri_base: Span<felt252>);
}

0 comments on commit 5a9531e

Please sign in to comment.