You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-16Lines changed: 0 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,22 +143,6 @@ state assocated with each user in individual `#[account]` structs.
143
143
For more, see the [examples](https://github.com/project-serum/anchor/tree/master/examples)
144
144
directory.
145
145
146
-
## Accounts attribute syntax.
147
-
148
-
There are several inert attributes that can be specified on a struct deriving `Accounts`.
149
-
150
-
| Attribute | Location | Description |
151
-
|:--|:--|:--|
152
-
|`#[account(signer)]`| On raw `AccountInfo` structs. | Checks the given account signed the transaction. |
153
-
|`#[account(mut)]`| On `AccountInfo`, `ProgramAccount` or `CpiAccount` structs. | Marks the account as mutable and persists the state transition. |
154
-
|`#[account(init)]`| On `ProgramAccount` structs. | Marks the account as being initialized, skipping the account discriminator check. |
155
-
|`#[account(belongs_to = <target>)]`| On `ProgramAccount` or `CpiAccount` structs | Checks the `target` field on the account matches the `target` field in the struct deriving `Accounts`. |
156
-
|`#[account(has_one = <target>)]`| On `ProgramAccount` or `CpiAccount` structs | Semantically different, but otherwise the same as `belongs_to`. |
157
-
|`#[account(seeds = [<seeds>])]`| On `AccountInfo` structs | Seeds for the program derived address an `AccountInfo` struct represents. |
158
-
|`#[account(owner = program \| skip)]`| On `AccountInfo` structs | Checks the owner of the account is the current program or skips the check. |
159
-
|`#[account("<literal>")]`| On any type deriving `Accounts`| Executes the given code literal as a constraint. The literal should evaluate to a boolean. |
160
-
|`#[account(rent_exempt = <skip>)]`| On `AccountInfo` or `ProgramAccount` structs | Optional attribute to skip the rent exemption check. By default, all accounts marked with `#[account(init)]` will be rent exempt, and so this should rarely (if ever) be used. Similarly, omitting `= skip` will mark the account rent exempt. |
Copy file name to clipboardExpand all lines: lang/derive/accounts/src/lib.rs
+41-2Lines changed: 41 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,47 @@ use anchor_syn::parser::accounts as accounts_parser;
5
5
use proc_macro::TokenStream;
6
6
use syn::parse_macro_input;
7
7
8
-
/// Implements an `Accounts` deserializer on the given struct, applying any
9
-
/// constraints specified via `#[account]` attributes.
8
+
/// Implements an [`Accounts`](./trait.Accounts.html) deserializer on the given
9
+
/// struct, applying any constraints specified via inert `#[account(..)]`
10
+
/// attributes upon deserialization.
11
+
///
12
+
/// # Example
13
+
///
14
+
/// ```
15
+
/// #[derive(Accounts)]
16
+
/// pub struct Auth<'info> {
17
+
/// #[account(mut, has_one = authority)]
18
+
/// pub data: ProgramAccount<'info, MyData>,
19
+
/// #[account(signer)]
20
+
/// pub authority: AccountInfo<'info>,
21
+
/// }
22
+
///
23
+
/// #[account]
24
+
/// pub struct MyData {
25
+
/// authority: Pubkey,
26
+
/// protected_data: u64,
27
+
/// }
28
+
/// ```
29
+
///
30
+
/// Here, any instance of the `Auth` struct created via
31
+
/// [`try_accounts`](trait.Accounts.html#tymethod.try_accounts) is guaranteed
32
+
/// to have been both
33
+
///
34
+
/// * Signed by `authority`.
35
+
/// * Checked that `&data.authority == authority.key`.
36
+
///
37
+
/// The full list of available attributes is as follows.
38
+
///
39
+
/// | Attribute | Location | Description |
40
+
/// |:--|:--|:--|
41
+
/// | `#[account(signer)]` | On raw `AccountInfo` structs. | Checks the given account signed the transaction. |
42
+
/// | `#[account(mut)]` | On `AccountInfo`, `ProgramAccount` or `CpiAccount` structs. | Marks the account as mutable and persists the state transition. |
43
+
/// | `#[account(init)]` | On `ProgramAccount` structs. | Marks the account as being initialized, skipping the account discriminator check. |
44
+
/// | `#[account(belongs_to = <target>)]` | On `ProgramAccount` or `CpiAccount` structs | Checks the `target` field on the account matches the `target` field in the struct deriving `Accounts`. |
45
+
/// | `#[account(has_one = <target>)]` | On `ProgramAccount` or `CpiAccount` structs | Semantically different, but otherwise the same as `belongs_to`. |
46
+
/// | `#[account(seeds = [<seeds>])]` | On `AccountInfo` structs | Seeds for the program derived address an `AccountInfo` struct represents. |
47
+
/// | `#[account("<literal>")]` | On any type deriving `Accounts` | Executes the given code literal as a constraint. The literal should evaluate to a boolean. |
48
+
/// | `#[account(rent_exempt = <skip>)]` | On `AccountInfo` or `ProgramAccount` structs | Optional attribute to skip the rent exemption check. By default, all accounts marked with `#[account(init)]` will be rent exempt, and so this should rarely (if ever) be used. Similarly, omitting `= skip` will mark the account rent exempt. |
0 commit comments