-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: cainome cli update and new config parsing #22
Conversation
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct ContractParserConfig { | ||
/// The file extension that should be considered as a Sierra file. | ||
pub sierra_extension: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could add
pub struct ContractParserConfig {
#[serde(default = ".contract_class.json")]
pub sierra_extension: String,
#[serde(default)]
pub type_aliases: HashMap<String, String>,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i think about it I have some doubts :)). So imo we can add this or leave it as it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could add
pub struct ContractParserConfig { #[serde(default = ".contract_class.json")] pub sierra_extension: String, #[serde(default)] pub type_aliases: HashMap<String, String>, }
Isn't the default implementation already defined below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I've missed that. We could then have
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct ContractParserConfig {
pub sierra_extension: String,
pub type_aliases: HashMap<String, String>,
}
This would allow the fields to be left unspecified when the user wants to have the default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I've missed that. We could then have
#[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct ContractParserConfig { pub sierra_extension: String, pub type_aliases: HashMap<String, String>, }This would allow the fields to be left unspecified when the user wants to have the default
Yep I did that at first, but I wanted to enforce the sierra extension. But as you mention, we may prefer having a 100% default value, and having the .contract_class.json
only in the example file? This is what you suggest?
Because we want an extension by default, and not an empty string. That's why I preferred to have a value in the default. :)
Hey @glihm, thank you for this. I have 3 points: It seems ok when i run a rust fmt on the file, maybe we could format it so that this step is not needed? |
You should use
That's a very good point. We should check if this can be done from rust code to avoid linter to generate a diff after code generation.
You mean like we have type aliases, adding a contract name aliasing in the parser configuration? |
Hey @glihm pub mod account {
use cainome::rs::abigen;
abigen!(
CartridgeAccount, //HERE
include_str!("../../../target/dev/cartridge_account_Account.contract_class.json"),
type_aliases {
webauthn_session::session_component::Event as SessionComponentEvent;
webauthn_auth::component::webauthn_component::Event as WebauthnComponentEvent;
}
);
}
pub mod erc20 {
use cainome::rs::abigen;
abigen!(
Erc20Contract, //HERE
include_str!("../../../target/dev/cartridge_account_ERC20.contract_class.json"),
type_aliases {
openzeppelin::token::erc20::erc20::ERC20Component::Event as ERC20ComponentEvent;
openzeppelin::access::ownable::ownable::OwnableComponent::Event as OwnableComponentEvent;
}
);
} |
Yes exactly, we can do that by adding a key in the parser configuration: {
"contracts": {
"cartridge_account_Account", "CartridgeAccount",
"file_name_of_contract", "MyContractName",
}
} This is a details but I think you get an important point. Because the name of the contract into the |
Thanks! Let's try with this then. 👍 |
No description provided.