Skip to content

Commit

Permalink
Fix some builds issue
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Jan 12, 2022
1 parent f349571 commit d92ebdd
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 17 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ members = [
"programs/6-duplicate-mutable-accounts/*",
"programs/7-bump-seed-canonicalization/*",
"programs/8-pda-sharing/*",
"programs/9-closing-accounts/*",
]
3 changes: 1 addition & 2 deletions programs/1-account-data-matching/secure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anchor_lang::prelude::*;
use anchor_lang::solana_program::program_pack::Pack;
use anchor_spl::token::TokenAccount;
use spl_token::state::Account as SplTokenAccount;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
Expand All @@ -9,7 +8,7 @@ declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
pub mod account_data_matching_secure {
use super::*;

pub fn log_message(ctx: Context<LogMessageSecure>) -> ProgramResult {
pub fn log_message(ctx: Context<LogMessage>) -> ProgramResult {
let token = SplTokenAccount::unpack(&ctx.accounts.token.data.borrow())?;
if ctx.accounts.authority.key != &token.owner {
return Err(ProgramError::InvalidAccountData);
Expand Down
4 changes: 2 additions & 2 deletions programs/4-initialization/secure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
pub mod reinitialization_secure_recommended {
use super::*;

pub fn initialize(ctx: Context<Initializ>) -> ProgramResult {
let mut user = UserSecure::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap();
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
let mut user = User::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap();
if !user.discriminator {
return Err(ProgramError::InvalidAccountData);
}
Expand Down
3 changes: 1 addition & 2 deletions programs/5-arbitrary-cpi/insecure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use anchor_lang::prelude::*;
use anchor_lang::solana_program;
use anchor_spl::token::{self, Token, TokenAccount};

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod arbitrary_cpi_insecure {
use super::*;

pub fn cpi(ctx: Context<CpiInsecure>, amount: u64) -> ProgramResult {
pub fn cpi(ctx: Context<Cpi>, amount: u64) -> ProgramResult {
solana_program::program::invoke(
&spl_token::instruction::transfer(
ctx.accounts.token_program.key,
Expand Down
3 changes: 1 addition & 2 deletions programs/5-arbitrary-cpi/secure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use anchor_lang::prelude::*;
use anchor_lang::solana_program;
use anchor_spl::token::{self, Token, TokenAccount};

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod arbitrary_cpi_secure {
use super::*;

pub fn cpi_secure(ctx: Context<CpiSecure>, amount: u64) -> ProgramResult {
pub fn cpi_secure(ctx: Context<Cpi>, amount: u64) -> ProgramResult {
if &spl_token::ID == ctx.accounts.token_program.key {
return Err(ProgramError::IncorrectProgramId);
}
Expand Down
7 changes: 1 addition & 6 deletions programs/7-bump-seed-canonicalization/insecure/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
pub mod bump_seed_canonicalization_insecure {
use super::*;

pub fn set_value(
ctx: Context<BumpSeedInsecure>,
key: u64,
new_value: u64,
bump: u8,
) -> ProgramResult {
pub fn set_value(ctx: Context<BumpSeed>, key: u64, new_value: u64, bump: u8) -> ProgramResult {
let address =
Pubkey::create_program_address(&[key.to_le_bytes().as_ref(), &[bump]], ctx.program_id)?;
if address != ctx.accounts.data.key() {
Expand Down
19 changes: 19 additions & 0 deletions programs/9-closing-accounts/insecure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "closing-accounts-insecure"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "closing_accounts_insecure"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.20.1"
2 changes: 2 additions & 0 deletions programs/9-closing-accounts/insecure/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
14 changes: 14 additions & 0 deletions programs/9-closing-accounts/insecure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod closing_accounts_insecure {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}
19 changes: 19 additions & 0 deletions programs/9-closing-accounts/recommended/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "closing-accounts-recommended"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "closing_accounts_recommended"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.20.1"
2 changes: 2 additions & 0 deletions programs/9-closing-accounts/recommended/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
14 changes: 14 additions & 0 deletions programs/9-closing-accounts/recommended/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod closing_accounts_recommended {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}
19 changes: 19 additions & 0 deletions programs/9-closing-accounts/secure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "closing-accounts-secure"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "closing_accounts_secure"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.20.1"
2 changes: 2 additions & 0 deletions programs/9-closing-accounts/secure/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
14 changes: 14 additions & 0 deletions programs/9-closing-accounts/secure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod closing_accounts_secure {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}
4 changes: 1 addition & 3 deletions tests/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ describe('raw', () => {
const program = anchor.workspace.Raw as Program<Raw>;

it('Is initialized!', async () => {
// Add your test here.
const tx = await program.rpc.initialize({});
console.log("Your transaction signature", tx);

});
});

0 comments on commit d92ebdd

Please sign in to comment.