Skip to content

Commit

Permalink
add supports_interfaces to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-fleming committed Nov 18, 2023
1 parent e812a87 commit 7ce2616
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/api/introspection.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ SRC5 component extending xref:ISRC5[`ISRC5`].
.InternalImpl

* xref:#SRC5Component-register_interface[`++register_interface(self, interface_id)++`]
* xref:#SRC5Component-register_interfaces[`++register_interfaces(self, interface_ids)++`]
* xref:#SRC5Component-deregister_interface[`++deregister_interface(self, interface_id)++`]
--

Expand All @@ -87,6 +88,12 @@ See xref:ISRC5-supports_interface[`ISRC5::supports_interface`].

Registers support for the given `interface_id`.

[.contract-item]
[[SRC5Component-register_interfaces]]
==== `[.contract-item-name]#++register_interfaces++#++(ref self: ComponentState, interface_ids: Span<felt252>)++` [.item-kind]#internal#

Registers support for the given `interface_ids`.

[.contract-item]
[[SRC5Component-deregister_interface]]
==== `[.contract-item-name]#++deregister_interface++#++(ref self: ComponentState, interface_id: felt252)++` [.item-kind]#internal#
Expand Down
25 changes: 4 additions & 21 deletions docs/modules/ROOT/pages/guides/src5-migration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod MigratingContract {
}
----

The contract will also need to register the interface ID values in order to continue declaring support for those interfaces.
The contract will also need to register the new SRC5 interface IDs in order to continue declaring support for those interfaces.
We can create a migration initializer to handle this which needs to be called after the contract upgrade.

TIP: OpenZeppelin's Contracts for Cairo already provides the interface IDs of common interfaces in the API section (like {isrc6}).
Expand All @@ -85,30 +85,13 @@ mod MigratingContract {
(...)
#[external(v0)]
fn initialize_src5_migration(ref self: ContractState, interface_ids: Span<felt252>) {
fn migration_initializer(ref self: ContractState, interface_ids: Span<felt252>) {
// Add permissions mechanism
self.register_interfaces(interface_ids);
}
#[generate_trait]
impl InternalImpl of InternalTrait {
fn register_interfaces(ref self: ContractState, mut interface_ids: Span<felt252>) {
loop {
if interface_ids.len() == 0 {
break;
}
let id = *interface_ids.pop_front().unwrap();
self.src5.register_interface(id);
}
}
self.src5.register_interfaces(interface_ids);
}
}
----

Note that SRC5 interface IDs are calculated differently than those in ERC165.
Because of this, contracts that leverage introspection (like ERC721) will also need to be upgraded in order to query the correct interface IDs.

Deployed contracts with upgradeability should also be carefully tested before migrating.
Note that deployed contracts with upgradeability should also be carefully tested before migrating.
Upgradeable contracts will likely include some form of a permissions mechanism for upgrading contracts.
Take extreme care with ensuring admins are not inadvertantly stripped of their permissions.

0 comments on commit 7ce2616

Please sign in to comment.