-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the
DEFAULT_SUB_ID
constant (#5246)
## Description The following pull request does two things: 1. Introduces the `DEFAULT_SUB_ID` constant. This is equivalent to the `ZERO_B256` constant. This constant makes the Sway code easier to read and comprehend improving the developer's UX. The actual value of the default is something the developer no longer needs to think about. Before: ```sway let my_asset = AssetId::new(my_contract, ZERO_B256); ``` Now: ```sway let my_asset = AssetId::new(my_contract, DEFAULT_SUB_ID); ``` 2. Removes the `ContractId` argument from the `AssetId::default()` function. In 90% of cases `default()` is used within the contract that issued the token, making this an unnecessary argument. This function now fetches the contract id of the contract it's called in, thus eliminating the need to import another function and add additional arguments. In the case a developer needs the default of another contract, the `DEFAULT_SUB_ID` can be used instead making the distinction more legible and apparent. Before: ```sway use std::call_frames::contract_id; fn foo(other_contract: ContractId) { let other_asset = AssetId::default(other_contract); let my_asset = AssetId::default(contract_id()); } ``` After: ```sway fn foo(other_contract: ContractId) { let other_asset = AssetId::new(other_contract, DEFAULT_SUB_ID); let my_asset = AssetId::default(); } ``` ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: SwayStar123 <46050679+SwayStar123@users.noreply.github.com>
- Loading branch information
1 parent
fe5085a
commit 37b0a70
Showing
6 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters