From 0d878865c8359dc06c12f8edaa6434f5e61ec1d9 Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Wed, 14 Apr 2021 10:18:10 -0700 Subject: [PATCH] docs: Explain attribute. --- docs/src/tutorials/tutorial-6.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/src/tutorials/tutorial-6.md b/docs/src/tutorials/tutorial-6.md index 0c4232d7..bfcf3a23 100644 --- a/docs/src/tutorials/tutorial-6.md +++ b/docs/src/tutorials/tutorial-6.md @@ -12,11 +12,11 @@ Why should you care? UX. Consider a wallet. Would you rather have a wallet with a single SOL address, which you can use to receive *all* SPL tokens, or would you rather have a wallet with a different -address for every SPL token. Now generalize this. For every program you use, do you +address for every SPL token? Now generalize this. For every program you use, do you want a single account, i.e. your SOL wallet, to define your application state? Or do you want to keep track of all your account addresses, separately, for every program in existance? -Associated accounts allow your users to reason about single address, their main SOL wallet, +Associated accounts allow your users to reason about a single address, their main SOL wallet, a huge improvement on the account model introduced thus far. Luckily, Anchor provides the ability to easily created associated program accounts for your program. @@ -55,6 +55,8 @@ does nothing other than create a mint and *associated* token account. <<< @/../examples/tutorial/basic-5/programs/basic-5/src/lib.rs#code +### Deriving Accounts + Two new keywords are introduced to the `CreateToken` account context: * `associated = ` @@ -80,6 +82,16 @@ can create your associated account. By convention, the names must be as given he For more details on how to use `#[account(associated)]`, see [docs.rs](https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html). +### Defining an Associated Account + +The new `#[acount(associated)]` attribute will allow you to create a new associated account similar to `#[account(init)]`, but +to actually define an account as associated, one must use the `#[associated]` attribute *instead* of the `#[account]` attribute. + +This new `#[associated]` attribute extends `#[account]` to include two things + +* A `Default` implementation, which is required for automatic size detection (performed when `#[account(space = "")]` is omitted from the accounts context). +* The implementation of the [Bump](https://docs.rs/anchor-lang/latest/anchor_lang/trait.Bump.html) trait, which is a bit of an implementation but is required for program derived addresses on Solana. + ## Using the Client The client can be used similarly to all other examples. Additionally, we introduce