Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/.ghaignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ tokens/escrow/anchor

# not live
tokens/token-2022/group/anchor

# error in tests
tokens/external-delegate-token-master/anchor

# build failed - program outdated
tokens/token-2022/metadata/anchor

# dependency issues
tokens/token-2022/nft-meta-data-pointer/anchor-example/anchor
9 changes: 4 additions & 5 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,15 @@ jobs:
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
steps:
- uses: actions/checkout@v4
- uses: heyAyushh/setup-anchor@v4.4
- uses: heyAyushh/setup-anchor@v0.31
with:
anchor-version: 0.30.1
anchor-version: 0.31.1
solana-cli-version: stable
node-version: 20.x
use-avm: false
- name: Display Versions and Install pnpm
run: |
solana -V
solana-keygen new --no-bip39-passphrase
# it's okay to use --force in github action since all programs are tested in isolation
solana-keygen new --no-bip39-passphrase --force
rustc -V
anchor -V
npm i -g pnpm
Expand Down
48 changes: 23 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.1"
anchor-lang = "0.31.1"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
2 changes: 1 addition & 1 deletion basics/counter/anchor/programs/counter_anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
2 changes: 1 addition & 1 deletion basics/favorites/anchor/programs/favorites/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ default = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = {version = "0.30.1", features = ["init-if-needed"]}
anchor-lang = {version = "0.31.1", features = ["init-if-needed"]}
solana-program = "=2.0.3"
29 changes: 15 additions & 14 deletions basics/favorites/native/program/src/instructions/create_pda.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
use crate::state::Favorites;
use borsh::BorshSerialize;
use solana_program::{
account_info::{next_account_info, AccountInfo},
pubkey::Pubkey,
program_error::ProgramError,
entrypoint::ProgramResult,
system_instruction,
msg,
program::invoke_signed,
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
sysvar::Sysvar
system_instruction,
sysvar::Sysvar,
};
use crate::state::Favorites;

pub fn create_pda(
program_id: &Pubkey,
accounts: &[AccountInfo],
data: Favorites
) -> ProgramResult {
pub fn create_pda(program_id: &Pubkey, accounts: &[AccountInfo], data: Favorites) -> ProgramResult {
let account_iter = &mut accounts.iter();
let user = next_account_info(account_iter)?; // the user who's signing the transaction
let favorite_account = next_account_info(account_iter)?; // The target account that will be created in the process
let system_program = next_account_info(account_iter)?;

// deriving the favorite pda
let (favorite_pda, favorite_bump) = Pubkey::find_program_address(&[b"favorite", user.key.as_ref()], program_id);
// deriving the favorite pda
let (favorite_pda, favorite_bump) =
Pubkey::find_program_address(&[b"favorite", user.key.as_ref()], program_id);

// Checking if the favorite account is same as the derived favorite pda
if favorite_account.key != &favorite_pda {
Expand All @@ -46,13 +43,17 @@ pub fn create_pda(

invoke_signed(
&ix,
&[user.clone(), favorite_account.clone(), system_program.clone()],
&[
user.clone(),
favorite_account.clone(),
system_program.clone(),
],
&[&[b"favorite", user.key.as_ref(), &[favorite_bump]]],
)?;

// Serialize and store the data
data.serialize(&mut &mut favorite_account.data.borrow_mut()[..])?;
msg!("{:#?}",data);
msg!("{:#?}", data);
} else {
return Err(ProgramError::AccountAlreadyInitialized.into());
}
Expand Down
33 changes: 18 additions & 15 deletions basics/favorites/native/program/src/instructions/get_pda.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
use crate::state::Favorites;
use borsh::BorshDeserialize;
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
account_info::{ AccountInfo, next_account_info},
msg,
program_error::ProgramError,
pubkey::Pubkey,
program_error::ProgramError
};
use borsh::BorshDeserialize;
use crate::state::Favorites;


pub fn get_pda(
program_id: &Pubkey,
accounts: &[AccountInfo],
) -> ProgramResult {
pub fn get_pda(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
let account_iter = &mut accounts.iter();
let user = next_account_info(account_iter)?;
let favorite_account = next_account_info(account_iter)?;

// deriving the favorite pda
let (favorite_pda, _) = Pubkey::find_program_address(&[b"favorite", user.key.as_ref()], program_id);
// deriving the favorite pda
let (favorite_pda, _) =
Pubkey::find_program_address(&[b"favorite", user.key.as_ref()], program_id);

// Checking if the favorite account is same as the derived favorite pda
if favorite_account.key != &favorite_pda {
return Err(ProgramError::IncorrectProgramId);
return Err(ProgramError::IncorrectProgramId);
};

let favorites = Favorites::try_from_slice(&favorite_account.data.borrow())?;

msg!("User {}'s favorite number is {}, favorite color is: {}, and their hobbies are {:#?}", user.key, favorites.number, favorites.color, favorites.hobbies);
msg!(
"User {}'s favorite number is {}, favorite color is: {}, and their hobbies are {:#?}",
user.key,
favorites.number,
favorites.color,
favorites.hobbies
);
Ok(())
}
}
2 changes: 1 addition & 1 deletion basics/favorites/native/program/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod create_pda;
pub mod get_pda;

use create_pda::*;
use get_pda::*;
use get_pda::*;
5 changes: 1 addition & 4 deletions basics/favorites/native/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use solana_program::entrypoint;

pub mod state;
pub mod instructions;
pub mod processor;
pub mod state;

use processor::process_instruction;

entrypoint!(process_instruction);



8 changes: 2 additions & 6 deletions basics/favorites/native/program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
pubkey::Pubkey,
};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

use crate::instructions::{create_pda::*, get_pda::*};
use crate::state::Favorites;
Expand All @@ -23,7 +19,7 @@ pub fn process_instruction(

match instruction {
FavoritesInstruction::CreatePda(data) => create_pda(program_id, accounts, data),
FavoritesInstruction::GetPda => get_pda(program_id,accounts),
FavoritesInstruction::GetPda => get_pda(program_id, accounts),
}?;

Ok(())
Expand Down
6 changes: 2 additions & 4 deletions basics/favorites/native/program/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use borsh::{BorshDeserialize, BorshSerialize};
pub struct Favorites {
pub number: u64,
pub color: String,
pub hobbies: Vec<String>
pub hobbies: Vec<String>,
}

#[derive(BorshDeserialize, BorshSerialize)]
pub struct GetFavorites {
}

pub struct GetFavorites {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-lang = "0.31.1"
Loading
Loading