Skip to content

Commit

Permalink
Merge pull request #114 from metaplex-foundation/fix/missing-anchor
Browse files Browse the repository at this point in the history
Fixing out of sync Anchor types and extending to hooked.
  • Loading branch information
blockiosaurus authored May 8, 2024
2 parents 008d7ab + 031b797 commit 1dbacb8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
10 changes: 7 additions & 3 deletions clients/rust/src/generated/types/add_blocker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AddBlocker {}
10 changes: 7 additions & 3 deletions clients/rust/src/generated/types/immutable_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImmutableMetadata {}
3 changes: 3 additions & 0 deletions clients/rust/src/hooked/advanced_types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "anchor")]
use anchor_lang::prelude::AnchorDeserialize;
#[cfg(not(feature = "anchor"))]
use borsh::BorshDeserialize;
use solana_program::pubkey::Pubkey;
use std::{cmp::Ordering, io::ErrorKind};
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/hooked/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "anchor")]
use anchor_lang::prelude::AnchorSerialize;
#[cfg(not(feature = "anchor"))]
use borsh::BorshSerialize;

use crate::{
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/hooked/collection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "anchor")]
use anchor_lang::prelude::AnchorSerialize;
#[cfg(not(feature = "anchor"))]
use borsh::BorshSerialize;

use crate::{
Expand Down
11 changes: 8 additions & 3 deletions clients/rust/src/hooked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ pub use asset::*;
pub mod collection;
pub use collection::*;

use borsh::{BorshDeserialize, BorshSerialize};
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{
AnchorDeserialize as CrateDeserialize, AnchorSerialize as CrateSerialize,
};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize as CrateDeserialize, BorshSerialize as CrateSerialize};
use num_traits::FromPrimitive;
use std::{cmp::Ordering, mem::size_of};

Expand Down Expand Up @@ -110,15 +115,15 @@ pub fn load_key(account: &AccountInfo, offset: usize) -> Result<Key, std::io::Er
}

/// A trait for generic blobs of data that have size.
pub trait DataBlob: BorshSerialize + BorshDeserialize {
pub trait DataBlob: CrateSerialize + CrateDeserialize {
/// Get the size of an empty instance of the data blob.
fn get_initial_size() -> usize;
/// Get the current size of the data blob.
fn get_size(&self) -> usize;
}

/// A trait for Solana accounts.
pub trait SolanaAccount: BorshSerialize + BorshDeserialize {
pub trait SolanaAccount: CrateSerialize + CrateDeserialize {
/// Get the discriminator key for the account.
fn key() -> Key;

Expand Down
7 changes: 5 additions & 2 deletions clients/rust/src/hooked/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use borsh::BorshDeserialize;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::AnchorDeserialize as CrateDeserialize;
#[cfg(not(feature = "anchor"))]
use borsh::BorshDeserialize as CrateDeserialize;
use num_traits::FromPrimitive;
use solana_program::account_info::AccountInfo;

Expand All @@ -14,7 +17,7 @@ use crate::{
};

/// Fetch the plugin from the registry.
pub fn fetch_plugin<T: DataBlob + SolanaAccount, U: BorshDeserialize>(
pub fn fetch_plugin<T: DataBlob + SolanaAccount, U: CrateDeserialize>(
account: &AccountInfo,
plugin_type: PluginType,
) -> Result<(PluginAuthority, U, usize), std::io::Error> {
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/indexable_asset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(feature = "anchor")]
use anchor_lang::prelude::AnchorDeserialize;
use base64::prelude::*;
#[cfg(not(feature = "anchor"))]
use borsh::BorshDeserialize;
use num_traits::FromPrimitive;
use solana_program::pubkey::Pubkey;
Expand Down

0 comments on commit 1dbacb8

Please sign in to comment.