From 492a080b28c1af94b1a76a735ff98ce13f932457 Mon Sep 17 00:00:00 2001 From: shawazi Date: Fri, 4 Oct 2024 08:11:17 -0400 Subject: [PATCH] remove extra callout end tag, remove messed up git additions, remove magic number in instructions/initialize.rs --- .../onchain-development/intro-to-anchor.md | 53 +++---------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/content/courses/onchain-development/intro-to-anchor.md b/content/courses/onchain-development/intro-to-anchor.md index fc0d087dd..5a669def2 100644 --- a/content/courses/onchain-development/intro-to-anchor.md +++ b/content/courses/onchain-development/intro-to-anchor.md @@ -578,8 +578,6 @@ avm 0.30.1 anchor-cli 0.30.1 ``` - - #### Creating a new Anchor project with the multiple files template ```shell @@ -658,7 +656,8 @@ anchor keys sync This will update your Anchor.toml and src/lib.rs files with the correct program ID. -Update the src/lib.rs file with the following: +Update the src/lib.rs file with the following (but keep your declare_id as it is +after running `anchor keys sync`): ```rust use anchor_lang::prelude::*; @@ -704,10 +703,6 @@ use anchor_lang::prelude::*; #[account] #[derive(InitSpace)] -<<<<<<< HEAD -#[derive(InitSpace)] -======= ->>>>>>> origin/superteamintro-to-anchor pub struct Counter { pub count: u64, } @@ -748,30 +743,17 @@ space allocation from the official [anchor documentation](https://www.anchor-lang.com/docs/space). -<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD Inside of `instructions/initialize.rs`, -adjust the code to match the following: - -======= - -> > > > > > > # 0a8ed53 (add callout info box for derive(initspace) macro (or is it an attribute?)) -> > > > > > > -> > > > > > > Inside of `instructions/initialize.rs`, adjust the code to match -> > > > > > > the following: - -> > > > > > > # c11ca55 (final edits, fix huge issues with tutorial workflow, should work properly on any system now if you follow the steps) -> > > > > > > -> > > > > > > Inside of `instructions/initialize.rs`, adjust the code to match -> > > > > > > the following: - -> > > > > > > origin/superteamintro-to-anchor +Inside of `instructions/initialize.rs`, adjust the code to match the following: ```rust use crate::state::Counter; use anchor_lang::prelude::*; +const DISCRIMINATOR: usize = 8; + #[derive(Accounts)] pub struct Initialize<'info> { - #[account(init, payer = user, space = 8 + Counter::INIT_SPACE)] + #[account(init, payer = user, space = DISCRIMINATOR + Counter::INIT_SPACE)] pub counter: Account<'info, Counter>, #[account(mut)] pub user: Signer<'info>, @@ -790,7 +772,7 @@ pub fn handler(ctx: Context) -> Result<()> { Within instructions/increment.rs, let’s implement an `increment` instruction handler to increment the `count` once a `counter` account is initialized by the first instruction handler. This instruction handler requires a `Context` of type -`Update` (implemented in the next step) and takes no additional instruction +`Update` (implemented in a previous step) and takes no additional instruction data. In the instruction handler's logic, we are simply tracking the current state, and then incrementing the existing `counter` account’s `count` field by `1`. @@ -800,15 +782,7 @@ use crate::state::Counter; use anchor_lang::prelude::*; #[derive(Accounts)] -<<<<<<< HEAD -<<<<<<< HEAD -pub struct DecrementUpdate<'info> { -======= -pub struct IncrementUpdate<'info> { ->>>>>>> 5789e73 (add another callout info box for the agave installation section, and re-incorporate some tutorial notes from the previous lab's instructions, since they offer useful information. fix erroneous initialize handler that was somehow passing tests) -======= pub struct IncrementUpdate<'info> { ->>>>>>> origin/superteamintro-to-anchor #[account(mut)] pub counter: Account<'info, Counter>, pub user: Signer<'info>, @@ -1041,18 +1015,7 @@ As always, get creative with these challenges and take them beyond the basic instructions if you want - and have fun! Try to do this independently if you can! But if you get stuck, feel free to -<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD reference -the [solution code](https://github.com/shawazi/anchor-counter). ======= -reference the [solution code](https://github.com/shawazi/anchor-counter). - -> > > > > > > # d1d522f (replace unboxed-software repo link for solution to my own solution) -> > > > > > > -> > > > > > > reference -> > > > > > > the [solution code](https://github.com/shawazi/anchor-counter). -> > > > > > > ac32de3 (add command for 'anchor keys sync' to lab, according to -> > > > > > > CONTRIBUTING.md) ======= reference -> > > > > > > the [solution code](https://github.com/shawazi/anchor-counter). -> > > > > > > origin/superteamintro-to-anchor +the [solution code](https://github.com/shawazi/anchor-counter). Push your code to GitHub and