|
@@ -61,10 +61,10 @@ pub struct NewAccount {
|
|
|
## declare_id! macro
|
|
|
|
|
|
The
|
|
|
-[`declare_id`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L439)
|
|
|
+[`declare_id`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L537)
|
|
|
macro specifies the on-chain address of the program, known as the program ID.
|
|
|
You can find the implementation of the code generated by the `declare_id!` macro
|
|
|
-[here](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/id.rs#L40-L73).
|
|
|
+[here](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/id.rs#L37-L70).
|
|
|
|
|
|
```rust title="lib.rs"
|
|
|
use anchor_lang::prelude::*;
|
|
@@ -91,14 +91,14 @@ the one generated when you run `anchor build` locally.
|
|
|
## #[program] attribute
|
|
|
|
|
|
The
|
|
|
-[`#[program]`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/program/src/lib.rs#L12)
|
|
|
+[`#[program]`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/program/src/lib.rs#L12)
|
|
|
attribute annotates the module containing all the instruction handlers for your
|
|
|
program. Each public function within this module corresponds to an instruction
|
|
|
that can be invoked.
|
|
|
|
|
|
You can find the implementation of the code generated by the `#[program]`
|
|
|
attribute
|
|
|
-[here](https://github.com/coral-xyz/anchor/tree/v0.30.1/lang/syn/src/codegen/program).
|
|
|
+[here](https://github.com/coral-xyz/anchor/tree/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/syn/src/codegen/program).
|
|
|
|
|
|
```rust title="lib.rs"
|
|
|
use anchor_lang::prelude::*;
|
|
@@ -137,11 +137,11 @@ pub struct NewAccount {
|
|
|
Instruction handlers are functions that define the logic executed when an
|
|
|
instruction is invoked. The first parameter of each handler is a `Context<T>`
|
|
|
type, where `T` is a struct implementing the
|
|
|
-[`Accounts`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/src/lib.rs#L105)
|
|
|
+[`Accounts`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/src/lib.rs#L108)
|
|
|
trait and specifies the accounts the instruction requires.
|
|
|
|
|
|
The
|
|
|
-[`Context`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/src/context.rs#L24)
|
|
|
+[`Context`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/src/context.rs#L24)
|
|
|
type provides the instruction with access to the following non-argument inputs:
|
|
|
|
|
|
```rust
|
|
@@ -213,16 +213,16 @@ pub struct Initialize<'info> {
|
|
|
## #[derive(Accounts)] macro
|
|
|
|
|
|
The
|
|
|
-[`#[derive(Accounts)]`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/derive/accounts/src/lib.rs#L630)
|
|
|
+[`#[derive(Accounts)]`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/derive/accounts/src/lib.rs#L631)
|
|
|
macro is applied to a struct to specify the accounts that must be provided when
|
|
|
an instruction is invoked. This macro implements the
|
|
|
-[`Accounts`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/src/lib.rs#L105)
|
|
|
+[`Accounts`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/src/lib.rs#L108)
|
|
|
trait, which simplifies account validation and serialization and deserialization
|
|
|
of account data.
|
|
|
|
|
|
You can find the implementation of the code generated by the
|
|
|
`#[derive(Accounts)]` macro
|
|
|
-[here](https://github.com/coral-xyz/anchor/tree/v0.30.1/lang/syn/src/codegen/accounts).
|
|
|
+[here](https://github.com/coral-xyz/anchor/tree/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/syn/src/codegen/accounts).
|
|
|
|
|
|
```rust
|
|
|
// [!code word:Accounts]
|
|
@@ -268,9 +268,9 @@ Anchor programs in two ways that are generally used together:
|
|
|
`Accounts` trait.
|
|
|
|
|
|
You can find a full list of the constraints
|
|
|
- [here](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/syn/src/parser/accounts/constraints.rs)
|
|
|
+ [here](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/syn/src/parser/accounts/constraints.rs)
|
|
|
and implementation
|
|
|
- [here](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/syn/src/codegen/accounts/constraints.rs).
|
|
|
+ [here](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/syn/src/codegen/accounts/constraints.rs).
|
|
|
|
|
|
```rust
|
|
|
#[derive(Accounts)]
|
|
@@ -290,7 +290,7 @@ Anchor programs in two ways that are generally used together:
|
|
|
what the program expects.
|
|
|
|
|
|
You can find the implementation of the account types
|
|
|
- [here](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/src/accounts).
|
|
|
+ [here](https://github.com/coral-xyz/anchor/tree/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/src/accounts).
|
|
|
|
|
|
```rust
|
|
|
#[derive(Accounts)]
|
|
@@ -346,7 +346,7 @@ pub struct NewAccount {
|
|
|
## #[account] attribute
|
|
|
|
|
|
The
|
|
|
-[`#[account]`](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L66)
|
|
|
+[`#[account]`](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L97)
|
|
|
attribute is applied to structs that define the structure of the data stored in
|
|
|
custom accounts created by your program.
|
|
|
|
|
@@ -362,14 +362,14 @@ This macro implements various traits
|
|
|
[detailed here](https://docs.rs/anchor-lang/latest/anchor_lang/attr.account.html).
|
|
|
The key functionalities of the `#[account]` macro include:
|
|
|
|
|
|
-- [Assign Program Owner](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L119-L132):
|
|
|
+- [Assign Program Owner](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L130-L143):
|
|
|
When creating an account, the program owner of the account is automatically
|
|
|
set to the program specified in `declare_id`.
|
|
|
-- [Set Discriminator](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L101-L117):
|
|
|
+- [Set Discriminator](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L111-L128):
|
|
|
A unique 8 byte discriminator, specific to the account type, is added as the
|
|
|
first 8 bytes of account data during its initialization. This helps in
|
|
|
differentiating account types and is used for account validation.
|
|
|
-- [Data Serialization and Deserialization](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L202-L246):
|
|
|
+- [Data Serialization and Deserialization](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L224-L270):
|
|
|
Account data is automatically serialized and deserialized as the account type.
|
|
|
|
|
|
```rust title="lib.rs"
|
|
@@ -411,7 +411,7 @@ pub struct NewAccount {
|
|
|
An account discriminator in an Anchor program refers to an 8 byte identifier
|
|
|
unique to each account type. You can find the implementation of the account
|
|
|
discriminator
|
|
|
-[here](https://github.com/coral-xyz/anchor/blob/v0.30.1/lang/attribute/account/src/lib.rs#L101-L117).
|
|
|
+[here](https://github.com/coral-xyz/anchor/blob/0e5285aecdf410fa0779b7cd09a47f235882c156/lang/attribute/account/src/lib.rs#L111-L128).
|
|
|
|
|
|
The discriminator is the first 8 bytes of the SHA256 hash of the string
|
|
|
`account:<AccountName>`. This discriminator is stored as the first 8 bytes of
|