Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use name for contract interface to be consistent #2482

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions crates/dojo-core/src/contract/contract.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#[starknet::interface]
pub trait IContract<T> {
fn contract_name(self: @T) -> ByteArray;
fn name(self: @T) -> ByteArray;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Ohayo, sensei!
It looks like there are still a couple of places where contract_name is being used. You'll need to update these to ensure consistency across the codebase:

  • crates/dojo-core/src/world/world_contract.cairo
  • crates/dojo-core/src/tests/world/resources.cairo
🔗 Analysis chain

Ohayo, sensei! The name change looks good!

The renaming of contract_name to name aligns well with our consistency goals. It's a cleaner and more idiomatic approach. Nice work!

Let's make sure this change doesn't cause any unexpected issues elsewhere in the dojo, sensei. Here's a quick check we can run:


Ohayo, sensei!
The initial scripts faced some hiccups, but don't worry—we've got this! Let's run the updated checks to ensure contract_name has been fully replaced and name is being used correctly throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining uses of 'contract_name' and verify 'name' usage

echo "Checking for any remaining 'contract_name' occurrences:"
rg --type cairo 'contract_name'

echo "\nVerifying 'name' method usage in IContract implementations:"
ast-grep --lang cairo --pattern 'impl $_ of IContract<$_> {
  $$$
  fn name($$$) -> ByteArray {
    $$$
  }
  $$$
}'

Length of output: 557


Script:

#!/bin/bash
# Description: Check for any remaining uses of 'contract_name' in .cairo files

echo "Searching for 'contract_name' in .cairo files:"
fd --extension cairo --type f | xargs rg 'contract_name'

echo "\nVerifying 'name' method usage in IContract implementations:"
fd --extension cairo --type f | xargs rg 'fn name\(.*\) -> ByteArray'

Length of output: 1601

fn namespace(self: @T) -> ByteArray;
fn tag(self: @T) -> ByteArray;

fn name_hash(self: @T) -> felt252;
fn namespace_hash(self: @T) -> felt252;
fn selector(self: @T) -> felt252;
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-lang/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl DojoContract {

#[abi(embed_v0)]
pub impl ContractImpl of IContract<ContractState> {
fn contract_name(self: @ContractState) -> ByteArray {
fn name(self: @ContractState) -> ByteArray {
\"$name$\"
}

Expand Down
Loading