feat: Sysvar address check example added (#15)
This commit is contained in:
parent
7dc2f407f1
commit
302b6ac59d
File diff suppressed because it is too large
Load Diff
|
@ -10,4 +10,5 @@ members = [
|
|||
"programs/7-bump-seed-canonicalization/*",
|
||||
"programs/8-pda-sharing/*",
|
||||
"programs/9-closing-accounts/*",
|
||||
"programs/10-sysvar-address-checking/*"
|
||||
]
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
[package]
|
||||
name = "insecure"
|
||||
version = "0.1.0"
|
||||
description = "Created with Anchor"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "insecure"
|
||||
|
||||
[features]
|
||||
no-entrypoint = []
|
||||
no-idl = []
|
||||
no-log-ix-name = []
|
||||
cpi = ["no-entrypoint"]
|
||||
default = []
|
||||
|
||||
[profile.release]
|
||||
overflow-checks = true
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "0.25.0"
|
|
@ -0,0 +1,2 @@
|
|||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
|
@ -0,0 +1,18 @@
|
|||
use anchor_lang::prelude::*;
|
||||
|
||||
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||
|
||||
#[program]
|
||||
pub mod insecure {
|
||||
use super::*;
|
||||
|
||||
pub fn check_sysvar_address(ctx: Context<CheckSysvarAddress>) -> Result<()> {
|
||||
msg!("Rent Key -> {}", ctx.accounts.rent.key().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct CheckSysvarAddress<'info> {
|
||||
rent: AccountInfo<'info>,
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
[package]
|
||||
name = "recommended"
|
||||
version = "0.1.0"
|
||||
description = "Created with Anchor"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "secure"
|
||||
|
||||
[features]
|
||||
no-entrypoint = []
|
||||
no-idl = []
|
||||
no-log-ix-name = []
|
||||
cpi = ["no-entrypoint"]
|
||||
default = []
|
||||
|
||||
[profile.release]
|
||||
overflow-checks = true
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "0.25.0"
|
|
@ -0,0 +1,2 @@
|
|||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
|
@ -0,0 +1,18 @@
|
|||
use anchor_lang::prelude::*;
|
||||
|
||||
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||
|
||||
#[program]
|
||||
pub mod recommended {
|
||||
use super::*;
|
||||
|
||||
pub fn check_sysvar_address(ctx: Context<CheckSysvarAddress>) -> Result<()> {
|
||||
msg!("Rent Key -> {}", ctx.accounts.rent.key().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct CheckSysvarAddress<'info> {
|
||||
rent: Sysvar<'info, Rent>,
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
[package]
|
||||
name = "secure"
|
||||
version = "0.1.0"
|
||||
description = "Created with Anchor"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "secure"
|
||||
|
||||
[features]
|
||||
no-entrypoint = []
|
||||
no-idl = []
|
||||
no-log-ix-name = []
|
||||
cpi = ["no-entrypoint"]
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "0.25.0"
|
|
@ -0,0 +1,2 @@
|
|||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
|
@ -0,0 +1,19 @@
|
|||
use anchor_lang::prelude::*;
|
||||
use anchor_lang::solana_program::sysvar;
|
||||
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||
|
||||
#[program]
|
||||
pub mod secure {
|
||||
use super::*;
|
||||
|
||||
pub fn check_sysvar_address(ctx: Context<CheckSysvarAddress>) -> Result<()> {
|
||||
require_eq!(ctx.accounts.rent.key(), sysvar::rent::ID);
|
||||
msg!("Rent Key -> {}", ctx.accounts.rent.key().to_string());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct CheckSysvarAddress<'info> {
|
||||
rent: AccountInfo<'info>,
|
||||
}
|
Loading…
Reference in New Issue