From 22a44a9767c7b7328bcab34c8532be7ba94407d2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 19 Apr 2022 20:52:04 -0400 Subject: [PATCH] more declare_id info (#71) --- src/anchor_in_depth/high-level_overview.md | 2 +- src/anchor_in_depth/the_accounts_struct.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/anchor_in_depth/high-level_overview.md b/src/anchor_in_depth/high-level_overview.md index e2434c8..646c3ba 100644 --- a/src/anchor_in_depth/high-level_overview.md +++ b/src/anchor_in_depth/high-level_overview.md @@ -1,5 +1,5 @@ # High-level Overview -An Anchor program consists of three parts. The `program` module, the Accounts structs which are marked with `#[derive(Accounts)]`, and the `declareId` macro. The `program` module is where you write your business logic. The Accounts structs is where you validate accounts. The`declareId` macro creates an `ID` field that stores the address of your program. +An Anchor program consists of three parts. The `program` module, the Accounts structs which are marked with `#[derive(Accounts)]`, and the `declare_id` macro. The `program` module is where you write your business logic. The Accounts structs is where you validate accounts. The`declare_id` macro creates an `ID` field that stores the address of your program. Anchor uses this hardcoded `ID` for security checks and it also allows other crates to access your program's address. When you start up a new Anchor project, you'll see the following: ```rust,ignore diff --git a/src/anchor_in_depth/the_accounts_struct.md b/src/anchor_in_depth/the_accounts_struct.md index 98d8d2e..36be18d 100644 --- a/src/anchor_in_depth/the_accounts_struct.md +++ b/src/anchor_in_depth/the_accounts_struct.md @@ -43,7 +43,7 @@ pub struct SetData<'info> { `Account` is generic over `T`. This `T` is a type you can create yourself to store data. In this example, we have created a struct `MyAccount` with a single `data` field to store a `u64`. Account requires `T` to implement certain functions (e.g. functions that (de)serialize `T`). Most of the time, you can use the `#[account]` attribute to add these functions to your data, as is done in the example. -Most importantly, the `#[account]` attribute sets the owner of that data to the `ID` (the one we created earlier with `declareId`) of the crate `#[account]` is used in. The Account type can then check for you that the `AccountInfo` passed into your instruction has its `owner` field set to the correct program. In this example, `MyAccount` is declared in our own crate so `Account` will verify that the owner of `my_account` equals the address we declared with `declareId`. +Most importantly, the `#[account]` attribute sets the owner of that data to the `ID` (the one we created earlier with `declare_id`) of the crate `#[account]` is used in. The Account type can then check for you that the `AccountInfo` passed into your instruction has its `owner` field set to the correct program. In this example, `MyAccount` is declared in our own crate so `Account` will verify that the owner of `my_account` equals the address we declared with `declare_id`. #### Using `Account<'a, T>` with non-anchor program accounts