Skip to content

Commit

Permalink
Switching to plain deserialize for TM resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Sep 10, 2024
1 parent 64fb1f6 commit 3b1a5f7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
32 changes: 24 additions & 8 deletions Cargo.lock

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

20 changes: 12 additions & 8 deletions src/config/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,18 @@ impl FromStr for Cluster {
}
}

impl ToString for Cluster {
fn to_string(&self) -> String {
match self {
Cluster::Devnet => "devnet".to_string(),
Cluster::Mainnet => "mainnet".to_string(),
Cluster::Localnet => "localnet".to_string(),
Cluster::Unknown => "unknown".to_string(),
}
impl Display for Cluster {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
Cluster::Devnet => "devnet",
Cluster::Mainnet => "mainnet",
Cluster::Localnet => "localnet",
Cluster::Unknown => "unknown",
}
)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/deploy/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use anchor_client::solana_sdk::{
signature::{Keypair, Signer},
};
use anyhow::Result;
use borsh::BorshDeserialize;
use console::style;
use mpl_token_metadata::state::{Metadata, TokenMetadataAccount};
use mpl_token_metadata::state::Metadata;

use crate::{
cache::*,
Expand Down Expand Up @@ -175,7 +176,7 @@ pub async fn process_deploy(args: DeployArgs) -> Result<()> {

let collection_metadata = find_metadata_pda(&collection_mint);
let data = program.rpc().get_account_data(&collection_metadata)?;
let metadata = Metadata::safe_deserialize(data.as_slice())?;
let metadata = Metadata::deserialize(&mut data.as_slice())?;

let sig = initialize_candy_machine(
&config_data,
Expand Down
7 changes: 5 additions & 2 deletions src/freeze/thaw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{fmt::Display, time::Duration};

use anchor_client::solana_sdk::compute_budget::ComputeBudgetInstruction;
use borsh::BorshDeserialize;
use mpl_candy_guard::{
accounts::Route as RouteAccount, guards::FreezeInstruction, instruction::Route,
instructions::RouteArgs, state::GuardType,
Expand Down Expand Up @@ -251,7 +252,8 @@ pub async fn process_thaw(args: ThawArgs) -> Result<()> {
.unwrap()
.value
.unwrap();
let metadata = Metadata::safe_deserialize(&metadata_account.data).unwrap();
let metadata =
Metadata::deserialize(&mut metadata_account.data.as_slice()).unwrap();

let rule_set = if let Some(ProgrammableConfig::V1 { rule_set }) =
metadata.programmable_config
Expand Down Expand Up @@ -460,7 +462,8 @@ pub async fn process_thaw(args: ThawArgs) -> Result<()> {
.unwrap()
.value
.unwrap();
let metadata = Metadata::safe_deserialize(&metadata_account.data).unwrap();
let metadata =
Metadata::deserialize(&mut metadata_account.data.as_slice()).unwrap();

let rule_set = if let Some(ProgrammableConfig::V1 { rule_set }) =
metadata.programmable_config
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn setup_logging(level: Option<EnvFilter>) -> Result<()> {
let file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(log_path)
.unwrap();

Expand Down
5 changes: 3 additions & 2 deletions src/mint/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anchor_client::solana_sdk::{
system_program, sysvar,
};
use anyhow::Result;
use borsh::BorshDeserialize;
use console::style;
use mpl_candy_machine_core::{
accounts as nft_accounts, instruction as nft_instruction, AccountVersion, CandyMachine,
Expand All @@ -17,7 +18,7 @@ use mpl_token_metadata::{
find_collection_authority_account, find_metadata_delegate_record_account,
find_token_record_account,
},
state::{Metadata, TokenMetadataAccount},
state::Metadata,
};
use solana_client::rpc_response::Response;
use spl_associated_token_account::get_associated_token_address;
Expand Down Expand Up @@ -250,7 +251,7 @@ pub async fn mint(
let collection_metadata = find_metadata_pda(&collection_mint);

let data = program.rpc().get_account_data(&collection_metadata)?;
let metadata = Metadata::safe_deserialize(data.as_slice())?;
let metadata = Metadata::deserialize(&mut data.as_slice())?;

let metadata_pda = find_metadata_pda(&nft_mint.pubkey());
let master_edition_pda = find_master_edition_pda(&nft_mint.pubkey());
Expand Down
5 changes: 3 additions & 2 deletions src/pdas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use anchor_client::{
Program,
};
use anyhow::{anyhow, Result};
use borsh::BorshDeserialize;
use mpl_token_metadata::{
pda::{find_master_edition_account, find_metadata_account},
state::{Key, MasterEditionV2, Metadata, TokenMetadataAccount, MAX_MASTER_EDITION_LEN},
state::{Key, MasterEditionV2, Metadata, MAX_MASTER_EDITION_LEN},
utils::try_from_slice_checked,
};

Expand Down Expand Up @@ -37,7 +38,7 @@ pub fn get_metadata_pda<C: Deref<Target = impl Signer> + Clone>(
&metadata_pubkey.to_string()
)
})?;
let metadata = Metadata::safe_deserialize(metadata_account.data.as_slice());
let metadata = Metadata::deserialize(&mut metadata_account.data.as_slice());
metadata.map(|m| (metadata_pubkey, m)).map_err(|_| {
anyhow!(
"Failed to deserialize metadata account: {}",
Expand Down
2 changes: 1 addition & 1 deletion src/upload/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn process_upload(args: UploadArgs) -> Result<()> {

// creates/loads the cache
let mut cache = load_cache(&args.cache, true)?;
if asset_pairs.get(&-1).is_none() {
if !asset_pairs.contains_key(&-1) {
cache.items.remove("-1");
}

Expand Down

0 comments on commit 3b1a5f7

Please sign in to comment.