Skip to content

Commit

Permalink
Move asset and collection primitive types to state
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Feb 17, 2024
1 parent 4040e7e commit 966b76a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
10 changes: 1 addition & 9 deletions programs/mpl-asset/src/plugins/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@ use solana_program::pubkey::Pubkey;
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)]
pub struct Collection {
collection_address: Pubkey,
}

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct CollectionData {
pub key: Key, //2
pub update_authority: Pubkey, //32
pub owner: Pubkey, //32
pub name: String, //4
pub uri: String, //4
required: bool,
}
7 changes: 0 additions & 7 deletions programs/mpl-asset/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
mod asset;
mod royalties;

pub use asset::*;
pub use royalties::*;

use borsh::{BorshDeserialize, BorshSerialize};
Expand Down Expand Up @@ -52,10 +49,6 @@ pub trait DataStorage {
fn load_mut(&self, data: &mut [u8]);
}

pub trait Compressible {
fn hash(&self) -> Result<[u8; 32], ProgramError>;
}

// pub trait PluginTrait
// where
// Self: BorshSerialize + BorshDeserialize + Clone + std::fmt::Debug + Sized,
Expand Down
3 changes: 1 addition & 2 deletions programs/mpl-asset/src/processor/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use solana_program::{
use crate::{
error::MplAssetError,
instruction::{accounts::CreateAccounts, CreateArgs},
plugins::{Asset, Compressible, HashedAsset, Key},
state::DataState,
state::{Asset, Compressible, DataState, HashedAsset, Key},
};

pub(crate) fn create<'a>(accounts: &'a [AccountInfo<'a>], args: CreateArgs) -> ProgramResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@ use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankAccount;
use solana_program::{keccak, program_error::ProgramError, pubkey::Pubkey};

use super::Compressible;

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
}
use super::{Compressible, Key};

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct Asset {
pub key: Key, //2
pub key: Key, //1
pub update_authority: Pubkey, //32
pub owner: Pubkey, //32
pub name: String, //4
Expand All @@ -32,7 +23,7 @@ impl Compressible for Asset {

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct HashedAsset {
pub key: Key, //2
pub key: Key, //1
pub hash: [u8; 32], //32
pub watermark_slot: Option<u64>, //1 | 9
}
11 changes: 11 additions & 0 deletions programs/mpl-asset/src/state/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct CollectionData {
pub key: Key, //1
pub update_authority: Pubkey, //32
pub owner: Pubkey, //32
pub name: String, //4
pub uri: String, //4
}
16 changes: 16 additions & 0 deletions programs/mpl-asset/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod asset;
pub use asset::*;

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::account_info::AccountInfo;
use solana_program::entrypoint::ProgramResult;
Expand Down Expand Up @@ -46,3 +49,16 @@ pub enum Authority {
Permanent { address: Pubkey },
SameAs { plugin: Plugin },
}

pub trait Compressible {
fn hash(&self) -> Result<[u8; 32], ProgramError>;
}

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
}

0 comments on commit 966b76a

Please sign in to comment.