Skip to content
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

Fix: Clone who parameter before inserting into balances map #139

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

0xScratch
Copy link

Within the lesson 3 of section 1, there's an error while we create the set_balance function for Pallet Struct. That's how the current code looks like (with an error):

image

and here's the fix, by replacing who with who.clone() within the insert method:

image

Two grammatical fixes are included...Thanks!

The `who` parameter needs to be cloned to avoid borrowing issues when inserted into the `balances` map
This change corrects the balance retrieval method by removing the unnecessary reference to the `who` parameter, ensuring proper lookup in the BTreeMap.
@0xScratch
Copy link
Author

Just noticed another error while retrieving the balance using balance function of the Pallet struct:

Screenshot (9)

This is likely the fix, replacement of &who with who:

pub fn balance(&self, who: &String) -> u128 {
    *self.balances.get(who).unwrap_or(&0)
}

@0xScratch
Copy link
Author

Hey @nomadbitcoin, can you take a look at these PRs? They might be useful for developers to interact with these lessons within the program alongside me.

Copy link

@nomadbitcoin nomadbitcoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I just tested it now and although the solutioj for the problem is correct the exercise is wrong, your update seems correct, thank you!

@nomadbitcoin
Copy link

you're right, I just tested it now and your update seems correct, thank you!

@nomadbitcoin nomadbitcoin merged commit fe1bc9e into w3b3d3v:web3dev-version Oct 22, 2024
1 check failed
@0xScratch 0xScratch deleted the patch-2 branch October 22, 2024 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants