-
Notifications
You must be signed in to change notification settings - Fork 182
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: use of WorldContractReader
from abigen!
#1010
Conversation
abigen!
WorldContractReader
from abigen!
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.
Looks good! Can we remove the from_str
methods if we pass a FieldElement instead?
let model = world.model(&name, BlockId::Tag(BlockTag::Latest)).await?; | ||
let schema = model.schema(BlockId::Tag(BlockTag::Latest)).await?; | ||
let layout = model.layout(BlockId::Tag(BlockTag::Latest)).await?; | ||
world.set_call_block_id(BlockId::Tag(BlockTag::Latest)); |
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.
Hm this is an interesting pattern. Why did you decide to go this path vs passing for each call?
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.
Adding an extra-parameter to function in a sense makes it less natural to call a function of our contract as we have to know that the abigen
will add this extra param.
But at the same time, having the set_call_block_id
pattern is a "limitation"/"constraint" when the instance is shared, as we need a mut
reference to adjust the block id, and this may cause some races without adding mutex for instance.
So... I would say that it was an experiment, and after making more test I am not sure what can be the best approach. Or maybe abigen
may give this option to the user?
If there is no problem at externalizing the inputs verification, we can definitely remove the Taking this example: pub async fn grant_writer_from_str(
&self,
model: &str,
contract: &ContractAddress,
) -> Result<
InvokeTransactionResult,
WorldContractError<A::SignError, <A::Provider as Provider>::Error>,
> {
let model = cairo_short_string_to_felt(model)
.map_err(WorldContractError::CairoShortStringToFeltError)?;
self.grant_writer(&model, contract).await.map_err(WorldContractError::AccountError)
} The model verification should then be done out of this function by the caller of the generated |
0f4d258
to
19d76ce
Compare
I think this is fine, until cairo gets a string type which can handle validation internally |
dd36cf5
to
4979471
Compare
6a784ce
to
a08f2cb
Compare
45c5558
to
71a1830
Compare
@tarrencev if you have time I would appreciate a new review on this one. 🙏 (Contains the commit from #1297 as I used it for debug, I can rebase depending on which is merged first) |
I'm thinking of generating the two This will also help us ensuring that the rust programs correctly use the cairo methods. What is the best for that, adding a step in the CI and use |
This is currently done here: https://github.com/dojoengine/dojo/blob/main/crates/dojo-test-utils/build.rs |
cdc91b8
to
6e7ceac
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1010 +/- ##
==========================================
+ Coverage 59.24% 60.43% +1.18%
==========================================
Files 225 226 +1
Lines 18900 18777 -123
==========================================
+ Hits 11198 11347 +149
+ Misses 7702 7430 -272 ☔ View full report in Codecov by Sentry. |
Due to the dependencies between Inside the @kariy @tarrencev let me know if you have a chance to review and if some stuff here must be re-considered. 🙏 |
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.
really nice improvement
This PR aims at exploring how
abigen!
macro in PR onstarknet-rs
can be used to reduce amount of code related to contract calls / invokes.Few points here:
abigen!
is still experimental, but thanks to this PR I was able to fix several important things. Thank you dojo! :)abigen
, so some functions were not modified. However, if we can add options to the macro, an option likeexternal_generate_call=true
can trigger an additional code generation for externals likemy_external_call
which returns theCall
instead of actually executing the transaction. This will allow the combinations of severalCalls
in only oneexecute
, leveragingabigen
rust string typing. Example where it can be useful in torii: register_models.from_str
as there are some additional parameter checking based on input string. Does this sound good to you too?Contract
andContractReader
, I've ported the same implementation in theabigen
which in my opinion is a very good approach. This allows the current code to directly add someimpl
for the structs generated byabigen
which have the same name as the one before.JSON
files, I have some problem with the paths, wereclippy
is expecting a relative path to theCargo.toml
oftorii-client
, butcargo build -p torii-client
is expecting a relative path toCargo.toml
of the workspace. Keep investigating, but any help on this would be very welcomed!Scarb.toml
:Is it ok to push this change, or we do not want this into the scarb manifest?
I'll keep this PR in draft for now to gather some feedback on this work. Any comment would be greatly appreciated to keep exploring this path and enhancing robustness and capabilities of
abigen
.