Skip to content

Commit

Permalink
Bummping Kinobi version and adding from-primitive derives.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Apr 10, 2024
1 parent 7b54ae2 commit 7fe3d22
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 55 deletions.
5 changes: 4 additions & 1 deletion clients/rust/src/generated/types/data_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use num_derive::FromPrimitive;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[derive(
BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DataState {
AccountState,
Expand Down
5 changes: 4 additions & 1 deletion clients/rust/src/generated/types/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use num_derive::FromPrimitive;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[derive(
BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Key {
Uninitialized,
Expand Down
5 changes: 4 additions & 1 deletion clients/rust/src/generated/types/plugin_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use num_derive::FromPrimitive;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[derive(
BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PluginType {
Royalties,
Expand Down
33 changes: 1 addition & 32 deletions clients/rust/src/hooked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod collection;
pub use collection::*;

use borsh::{BorshDeserialize, BorshSerialize};
use num_traits::FromPrimitive;
use std::{cmp::Ordering, mem::size_of};

use crate::{
Expand All @@ -20,24 +21,6 @@ use crate::{
};
use solana_program::account_info::AccountInfo;

impl PluginType {
// Needed to determine if a plugin is a known or unknown type.
pub fn from_u8(n: u8) -> Option<PluginType> {
match n {
0 => Some(PluginType::Royalties),
1 => Some(PluginType::FreezeDelegate),
2 => Some(PluginType::BurnDelegate),
3 => Some(PluginType::TransferDelegate),
4 => Some(PluginType::UpdateDelegate),
5 => Some(PluginType::PermanentFreezeDelegate),
6 => Some(PluginType::Attributes),
7 => Some(PluginType::PermanentTransferDelegate),
8 => Some(PluginType::PermanentBurnDelegate),
_ => None,
}
}
}

impl From<&Plugin> for PluginType {
fn from(plugin: &Plugin) -> Self {
match plugin {
Expand Down Expand Up @@ -113,20 +96,6 @@ impl SolanaAccount for PluginHeaderV1 {
}
}

impl Key {
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Key::Uninitialized),
1 => Some(Key::AssetV1),
2 => Some(Key::HashedAssetV1),
3 => Some(Key::PluginHeaderV1),
4 => Some(Key::PluginRegistryV1),
5 => Some(Key::CollectionV1),
_ => None,
}
}
}

/// Load the one byte key from the account data at the given offset.
pub fn load_key(account: &AccountInfo, offset: usize) -> Result<Key, std::io::Error> {
let key = Key::from_u8((*account.data).borrow()[offset]).ok_or(std::io::Error::new(
Expand Down
1 change: 1 addition & 0 deletions clients/rust/src/hooked/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use borsh::BorshDeserialize;
use num_traits::FromPrimitive;
use solana_program::account_info::AccountInfo;

use crate::{
Expand Down
1 change: 1 addition & 0 deletions clients/rust/src/indexable_asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use base64::prelude::*;
use borsh::BorshDeserialize;
use num_traits::FromPrimitive;
use solana_program::pubkey::Pubkey;
use std::{collections::HashMap, io::ErrorKind};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
},
"devDependencies": {
"@metaplex-foundation/amman": "^0.12.1",
"@metaplex-foundation/kinobi": "^0.17.7",
"@metaplex-foundation/kinobi": "^0.18.3",
"@metaplex-foundation/shank-js": "^0.1.7",
"typescript": "^4.9.4"
},
"packageManager": "[email protected]"
}
}
73 changes: 55 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7fe3d22

Please sign in to comment.