Skip to main content
8 events
when toggle format what by license comment
Oct 11, 2023 at 16:09 answer added Joe C timeline score: 2
Aug 22, 2022 at 7:55 comment added vicyyn Although I really advise you that you use Anchor since it saves you a lot of time, you can either check init_if_needed in the anchor lang repo and try to do the same, or you can check the data if allocated then only initialize if it's empty (just throwing ideas)
Aug 22, 2022 at 0:13 history edited ixmorrow CC BY-SA 4.0
added 22 characters in body; edited title
Aug 22, 2022 at 0:11 comment added ixmorrow Thank you for the answer, I should have clarified though I was looking for a way to do this in Native Rust (i.e. without Anchor)
Aug 20, 2022 at 16:30 history edited vicyyn CC BY-SA 4.0
typos and titles
Aug 20, 2022 at 16:29 comment converted from answer vicyyn in anchor add init_if_needed constraint Exact same functionality as the init constraint but only runs if the account does not exist yet. If the account does exist, it still checks whether the given init constraints are correct, e.g. that the account has the expected amount of space and, if it's a PDA, the correct seeds etc. ``` #[account(init_if_needed, payer = payer)] pub data_account: Account<'info, MyData>, ``` --- note This feature should be used with care and is therefore behind a feature flag. You can enable it by importing anchor-lang with the init-if-needed cargo feature.
S Aug 20, 2022 at 15:15 review First questions
Aug 22, 2022 at 0:16
S Aug 20, 2022 at 15:15 history asked ixmorrow CC BY-SA 4.0