Conversation
|
Contract comparison - from 473a955 to 55ee5d2
|
There was a problem hiding this comment.
Pull request overview
This pull request refactors the crowdfunding contract to improve code organization and make it more suitable for tutorial purposes. The main changes involve reordering the init function parameters and adding additional validation.
- Reordered
initparameters to puttoken_identifierfirst, followed bytargetanddeadline - Reorganized validation logic in
initto validate token identifier before other parameters - Added
is_fungible()check in thefundfunction to prevent NFTs/SFTs from being accepted
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/examples/crowdfunding/src/crowdfunding.rs | Updated init parameter order, reordered validation logic, and added fungible token check in fund |
| contracts/examples/crowdfunding/src/crowdfunding_proxy.rs | Updated proxy init method to match new parameter order |
| contracts/examples/crowdfunding/tests/crowdfunding_esdt_blackbox_test.rs | Updated test to use new parameter order in init call |
| contracts/examples/crowdfunding/scenarios/crowdfunding-init.scen.json | Updated scenario file arguments to match new parameter order |
| contracts/examples/crowdfunding/scenarios/egld-crowdfunding-init.scen.json | Updated scenario file arguments to match new parameter order |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| require!( | ||
| self.status() == Status::FundingPeriod, | ||
| "cannot fund after deadline" | ||
| payment.token_identifier == self.cf_token_id().get(), | ||
| "wrong token" | ||
| ); | ||
| require!(payment.is_fungible(), "only fungible tokens accepted"); | ||
| require!( | ||
| payment.token_identifier == self.cf_token_identifier().get(), | ||
| "wrong token" | ||
| self.status() == Status::FundingPeriod, | ||
| "cannot fund after deadline" | ||
| ); |
There was a problem hiding this comment.
The validation order is suboptimal. The self.status() check (line 42) calls get_current_time_millis() and get_current_funds(), which involve blockchain queries and storage reads. The payment.is_fungible() check (line 40) is a simple local check. Moving the fungibility check before the status check would avoid unnecessary expensive operations when the payment is not fungible (e.g., NFTs).
There was a problem hiding this comment.
It doesn't matter, failure consumes all the gas either way.
Changes to make the code flow better and suit it better for the tutorial.