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
15 changes: 15 additions & 0 deletions metadata/program/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// A constant seed used for metadata-related operations.
/// This is a byte slice with the value `"metadata"`.
pub const METADATA_SEED: &[u8] = b"metadata";

/// The maximum allowed length for a name in the metadata.
/// This value is set to 32 characters.
pub const MAX_NAME_LEN: usize = 32;

/// The maximum allowed length for a symbol in the metadata.
/// This value is set to 10 characters.
pub const MAX_SYMBOL_LEN: usize = 10;

/// The maximum allowed length for a URI in the metadata.
/// This value is set to 200 characters.
pub const MAX_URI_LEN: usize = 200;
2 changes: 2 additions & 0 deletions metadata/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod constants;
pub mod entrypoint;
pub mod error;
pub mod instruction;
pub mod processor;
pub mod state;
pub mod utils;

// Defineing the program ID
solana_program::declare_id!("metaAig5QsCBSfstkwqPQxzdjXdUB8JxjfvtvEPNe3F");
20 changes: 10 additions & 10 deletions metadata/program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use crate::{error::MetadataError, instruction::TokenInstruction, state::TokenMetadata};
use crate::{
constants::{MAX_NAME_LEN, MAX_SYMBOL_LEN, MAX_URI_LEN, METADATA_SEED},
error::MetadataError,
instruction::TokenInstruction,
state::TokenMetadata,
utils::derive_metadata_pda,
};

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
Expand All @@ -13,10 +19,6 @@ use solana_program::{
sysvar::Sysvar,
};

const MAX_NAME_LEN: usize = 32;
const MAX_SYMBOL_LEN: usize = 10;
const MAX_URI_LEN: usize = 200;

pub struct Processor;
impl Processor {
pub fn process(
Expand Down Expand Up @@ -84,8 +86,7 @@ impl Processor {
}

// Create PDA account
let (pda, bump_seed) =
Pubkey::find_program_address(&[b"metadata", mint_account.key.as_ref()], program_id);
let (pda, bump_seed) = derive_metadata_pda(mint_account.key, program_id);
if pda != *metadata_account.key {
return Err(MetadataError::InvalidPda.into());
}
Expand All @@ -108,7 +109,7 @@ impl Processor {
metadata_account.clone(),
system_program.clone(),
],
&[&[b"metadata", mint_account.key.as_ref(), &[bump_seed]]],
&[&[METADATA_SEED, mint_account.key.as_ref(), &[bump_seed]]],
)?;

// Write metadata to the account
Expand Down Expand Up @@ -142,8 +143,7 @@ impl Processor {
let authority = next_account_info(account_info_iter)?;

// Check mint account
let (pda, _bump_seed) =
Pubkey::find_program_address(&[b"metadata", mint_account.key.as_ref()], program_id);
let (pda, _bump_seed) = derive_metadata_pda(mint_account.key, program_id);
if pda != *metadata_account.key {
return Err(MetadataError::InvalidPda.into());
}
Expand Down
6 changes: 4 additions & 2 deletions metadata/program/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use solana_program::{program_error::ProgramError, pubkey::Pubkey};
use solana_program::pubkey::Pubkey;

use crate::constants::METADATA_SEED;

pub fn derive_metadata_pda(mint: &Pubkey, program_id: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[b"metadata", mint.as_ref()], program_id)
Pubkey::find_program_address(&[METADATA_SEED, mint.as_ref()], program_id)
}
Loading