more declare_id info (#71)
This commit is contained in:
parent
f8dfcbb1af
commit
22a44a9767
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue