Skip to content

Commit

Permalink
check_program util
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannis Chatziveroglou committed Nov 10, 2022
1 parent 794d0d4 commit 9532901
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cardinal-creator-standard",
"version": "1.0.7",
"version": "1.0.8",
"description": "SDK for cardinal-creator-standard",
"main": "index.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion programs/cardinal-creator-standard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cardinal-creator-standard"
version = "1.0.7"
version = "1.0.8"
description = "The Cardinal Creator Standard"
edition = "2021"
homepage = "https://cardinal.so"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn handler(ctx: TransferCtx) -> ProgramResult {
.expect("Failed to get instruction");

if !allowed_programs.is_empty()
&& !is_default_program(ix.program_id)
&& !is_default_program(&ix.program_id)
&& !allowed_programs.contains(&ix.program_id)
{
return Err(ProgramError::from(ErrorCode::ProgramNotAllowed));
Expand Down
30 changes: 29 additions & 1 deletion programs/cardinal-creator-standard/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use solana_program::pubkey::Pubkey;

use crate::utils::assert_with_msg;

use std::collections::HashSet;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
Expand All @@ -25,7 +26,7 @@ pub const COLLECTOR: &str = "gmdS6fDgVbeCCYwwvTPJRKM9bFbAgSZh6MTDUT2DcgV";
pub const RULESET_AUTHORITY: &str = "gmdS6fDgVbeCCYwwvTPJRKM9bFbAgSZh6MTDUT2DcgV";
pub const DEFAULT_PROGRAMS: [&str; 1] = ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"];

pub fn is_default_program(program_id: Pubkey) -> bool {
pub fn is_default_program(program_id: &Pubkey) -> bool {
DEFAULT_PROGRAMS.contains(&&program_id.to_string()[..])
}
///////////// CONSTANTS /////////////
Expand Down Expand Up @@ -245,3 +246,30 @@ impl CreatorStandardAccount for Ruleset {
}

///////////// RULESET /////////////

///////////// UTILS /////////////
pub fn check_program(program_id: Pubkey, ruleset: &Ruleset) -> bool {
let mut allowed_programs = HashSet::new();
for program_id in &ruleset.allowed_programs {
allowed_programs.insert(program_id);
}

let mut disallowed_addresses = HashSet::new();
for program_id in &ruleset.disallowed_addresses {
disallowed_addresses.insert(program_id);
}

if !allowed_programs.is_empty()
&& !is_default_program(&program_id)
&& !allowed_programs.contains(&program_id)
{
return false;
}

if !disallowed_addresses.is_empty() && disallowed_addresses.contains(&program_id) {
return false;
}

return true;
}
///////////// UTILS /////////////

0 comments on commit 9532901

Please sign in to comment.