Skip to content

Commit

Permalink
Merge pull request #53 from metaplex-foundation/danenbm/accessors
Browse files Browse the repository at this point in the history
Add leaf schema accessors to program and Rust client
  • Loading branch information
danenbm authored Oct 5, 2023
2 parents 77debad + c03745b commit 1923f83
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clients/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum InstructionName {
SetAndVerifyCollection,
MintToCollectionV1,
SetDecompressibleState,
UpdateMetadata,
}

pub fn get_instruction_type(full_bytes: &[u8]) -> InstructionName {
Expand Down Expand Up @@ -54,7 +55,7 @@ pub fn get_instruction_type(full_bytes: &[u8]) -> InstructionName {
[82, 104, 152, 6, 149, 111, 100, 13] => InstructionName::SetDecompressibleState,
// `SetDecompressableState` instruction mapped to `SetDecompressibleState` instruction
[18, 135, 238, 168, 246, 195, 61, 115] => InstructionName::SetDecompressibleState,

[170, 182, 43, 239, 97, 78, 225, 186] => InstructionName::UpdateMetadata,
_ => InstructionName::Unknown,
}
}
Expand Down
38 changes: 37 additions & 1 deletion clients/rust/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::derivable_impls)]
use solana_program::keccak;
use solana_program::{keccak, pubkey::Pubkey};

use crate::types::{LeafSchema, UpdateArgs, Version};

Expand Down Expand Up @@ -33,6 +33,42 @@ impl LeafSchema {
LeafSchema::V1 { .. } => Version::V1,
}
}

pub fn id(&self) -> Pubkey {
match self {
LeafSchema::V1 { id, .. } => *id,
}
}

pub fn owner(&self) -> Pubkey {
match self {
LeafSchema::V1 { owner, .. } => *owner,
}
}

pub fn delegate(&self) -> Pubkey {
match self {
LeafSchema::V1 { delegate, .. } => *delegate,
}
}

pub fn nonce(&self) -> u64 {
match self {
LeafSchema::V1 { nonce, .. } => *nonce,
}
}

pub fn data_hash(&self) -> [u8; 32] {
match self {
LeafSchema::V1 { data_hash, .. } => *data_hash,
}
}

pub fn creator_hash(&self) -> [u8; 32] {
match self {
LeafSchema::V1 { creator_hash, .. } => *creator_hash,
}
}
}

impl Default for LeafSchema {
Expand Down
12 changes: 12 additions & 0 deletions programs/bubblegum/program/src/state/leaf_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ impl LeafSchema {
}
}

pub fn owner(&self) -> Pubkey {
match self {
LeafSchema::V1 { owner, .. } => *owner,
}
}

pub fn delegate(&self) -> Pubkey {
match self {
LeafSchema::V1 { delegate, .. } => *delegate,
}
}

pub fn nonce(&self) -> u64 {
match self {
LeafSchema::V1 { nonce, .. } => *nonce,
Expand Down

0 comments on commit 1923f83

Please sign in to comment.