Skip to content

Commit

Permalink
Add leaf schema accessors to program and Rust client
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Oct 5, 2023
1 parent 77debad commit e804b70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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 e804b70

Please sign in to comment.