Skip to content

Commit 996a351

Browse files
authored
Fix balance_of() and this_balance() inline docs (#5586)
## Description [This](https://forum.fuel.network/t/confusion-about-assets-on-sway/4210/1) forum post brought up the `balance_of()` inline documentation had an error. This has been resolved in the PR. ## Checklist - [x] 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.
1 parent 7bcac37 commit 996a351

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sway-lib-std/src/context.sw

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ use ::registers::balance;
1919
/// # Examples
2020
///
2121
/// ```sway
22-
/// use std::{context::this_balance, constants::ZERO_B256, hash::sha256, asset::mint, call_frames::contract_id};
22+
/// use std::{context::this_balance, constants::DEFAULT_SUB_ID, asset::mint};
2323
///
2424
/// fn foo() {
25-
/// mint(ZERO_B256, 50);
26-
/// assert(this_balance(sha256((ZERO_B256, contract_id()))) == 50);
25+
/// mint(DEFAULT_SUB_ID, 50);
26+
/// let asset_id = AssetId::default();
27+
/// assert(this_balance(asset_id)) == 50);
2728
/// }
2829
/// ```
2930
pub fn this_balance(asset_id: AssetId) -> u64 {
@@ -44,11 +45,12 @@ pub fn this_balance(asset_id: AssetId) -> u64 {
4445
/// # Examples
4546
///
4647
/// ```sway
47-
/// use std::{context::balance_of, constants::ZERO_B256, hash::sha256, asset::mint, call_frames::contract_id};
48+
/// use std::{asset::mint, call_frames::contract_id, constants::DEFAULT_SUB_ID, context::balance_of};
4849
///
4950
/// fn foo() {
50-
/// mint(ZERO_B256, 50);
51-
/// assert(balance_of(contract_id(), sha256((ZERO_B256, contract_id()))) == 50);
51+
/// mint(DEFAULT_SUB_ID, 50);
52+
/// let asset_id = AssetId::default();
53+
/// assert(balance_of(contract_id(), asset_id) == 50);
5254
/// }
5355
/// ```
5456
pub fn balance_of(target: ContractId, asset_id: AssetId) -> u64 {

0 commit comments

Comments
 (0)