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

impl Mapping::contains, Mapping::remove #2436

Merged
merged 3 commits into from
Jun 30, 2023
Merged

Conversation

collinc97
Copy link
Collaborator

New Syntax

  • Mapping::contains(balances, account) Returns true if account is present in mapping balances
  • Mapping::remove(balances, account) Removes account from mapping balances

Example

program test.aleo {

    mapping balances: address => u32;

    transition foo() -> () {
        return then finalize(self.caller);
    }

    finalize foo(account: address) -> () {
        Mapping::set(balances, account, 1u32);

        let expect_true: bool = Mapping::contains(balances, account); // true
        assert(expect_true);

        Mapping::remove(balances, account); // Remove the mapping entry for account

        let expect_false: bool = Mapping::contains(balances, account); // false
        assert(!expect_false);
    }
}

@collinc97 collinc97 requested a review from a team June 29, 2023 22:02
@collinc97 collinc97 marked this pull request as ready for review June 29, 2023 22:02
Copy link
Collaborator

@bendyarm bendyarm left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

LGTM!

@collinc97 collinc97 merged commit b690a62 into testnet3 Jun 30, 2023
6 checks passed
@collinc97 collinc97 deleted the feat/contains-remove branch June 30, 2023 00:04
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.

4 participants