Skip to content

Commit

Permalink
import processor code from token-group example program
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 24, 2023
1 parent 6f7fef4 commit 17c963d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 53 deletions.
1 change: 1 addition & 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 token-collection/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ solana-program = "1.17.2"
spl-pod = { version = "0.1.0", path = "../../libraries/pod" }
spl-program-error = { version = "0.3.0" , path = "../../libraries/program-error" }
spl-token-2022 = { version = "0.9.0", path = "../../token/program-2022", features = ["no-entrypoint"] }
spl-token-group-example = { version = "0.1.0", path = "../../token-group/example", features = ["no-entrypoint"] }
spl-token-group-interface = { version = "0.1.0", path = "../../token-group/interface" }
spl-token-metadata-interface = { version = "0.2", path = "../../token-metadata/interface" }
spl-type-length-value = { version = "0.3.0", path = "../../libraries/type-length-value" }
Expand Down
62 changes: 9 additions & 53 deletions token-collection/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use {
},
spl_token_group_interface::{
error::TokenGroupError,
instruction::{
InitializeGroup, TokenGroupInstruction, UpdateGroupAuthority, UpdateGroupMaxSize,
},
instruction::{InitializeGroup, TokenGroupInstruction},
state::{TokenGroup, TokenGroupMember},
},
spl_token_metadata_interface::state::TokenMetadata,
Expand Down Expand Up @@ -93,54 +91,6 @@ pub fn process_initialize_collection(
Ok(())
}

/// Processes an
/// [UpdateGroupMaxSize](enum.GroupInterfaceInstruction.html)
/// instruction to update the max size of a collection.
pub fn process_update_collection_max_size(
_program_id: &Pubkey,
accounts: &[AccountInfo],
data: UpdateGroupMaxSize,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();

let collection_info = next_account_info(account_info_iter)?;
let update_authority_info = next_account_info(account_info_iter)?;

let mut buffer = collection_info.try_borrow_mut_data()?;
let mut state = TlvStateMut::unpack(&mut buffer)?;
let collection = state.get_first_value_mut::<TokenGroup>()?;

check_update_authority(update_authority_info, &collection.update_authority)?;

collection.update_max_size(data.max_size.into())?;

Ok(())
}

/// Processes an
/// [UpdateGroupAuthority](enum.GroupInterfaceInstruction.html)
/// instruction to update the authority of a collection.
pub fn process_update_collection_authority(
_program_id: &Pubkey,
accounts: &[AccountInfo],
data: UpdateGroupAuthority,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();

let collection_info = next_account_info(account_info_iter)?;
let update_authority_info = next_account_info(account_info_iter)?;

let mut buffer = collection_info.try_borrow_mut_data()?;
let mut state = TlvStateMut::unpack(&mut buffer)?;
let collection = state.get_first_value_mut::<TokenGroup>()?;

check_update_authority(update_authority_info, &collection.update_authority)?;

collection.update_authority = data.new_authority;

Ok(())
}

/// Processes an [InitializeMember](enum.GroupInterfaceInstruction.html)
/// instruction
pub fn process_initialize_collection_member(
Expand Down Expand Up @@ -192,11 +142,17 @@ pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> P
}
TokenGroupInstruction::UpdateGroupMaxSize(data) => {
msg!("Instruction: UpdateCollectionMaxSize");
process_update_collection_max_size(program_id, accounts, data)
// Same functionality as the example program
spl_token_group_example::processor::process_update_group_max_size(
program_id, accounts, data,
)
}
TokenGroupInstruction::UpdateGroupAuthority(data) => {
msg!("Instruction: UpdateCollectionAuthority");
process_update_collection_authority(program_id, accounts, data)
// Same functionality as the example program
spl_token_group_example::processor::process_update_group_authority(
program_id, accounts, data,
)
}
TokenGroupInstruction::InitializeMember(_) => {
msg!("Instruction: InitializeCollectionMember");
Expand Down

0 comments on commit 17c963d

Please sign in to comment.