Function safe_initialize_token_account

Source
pub fn safe_initialize_token_account(
    input: InitializeTokenAccount<'_, '_, '_>,
    allow_existing: bool,
) -> Result<()>
Expand description

Initializes a token account without checking for the mint extensions.

This function is useful when the mint is known to have any extensions, which might not be supported by the current version of the spl-token-2022 create. Trying to deserialize the extension types will result in an error. For this reason, this function uses an “internal” IExtensionType to safely calculate the length of the account.

When allow_existing is true, the function will not try to create the account; otherwise, it will fail if the account already exists. This provides the same functionality as init_if_needed.