Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decoding and deriving token record; bump metaboss_lib version #262

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ indexmap = { version = "1.9.1", features = ["serde"] }
indicatif = { version = "0.16.2", features = ["rayon"] }
lazy_static = "1.4.0"
log = "0.4.17"
metaboss_lib = "0.5.1"
metaboss_lib = "0.6.0"
mpl-token-metadata = { version = "1.9.0", features = [ "no-entrypoint", "serde-feature"] }
num_cpus = "1.13.1"
phf = { version = "0.10", features = ["macros"] }
Expand Down
8 changes: 8 additions & 0 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ pub fn decode_token_account(client: &RpcClient, token_account: &str) -> AnyResul
Ok(())
}

pub fn decode_token_record_from_mint(client: &RpcClient, mint: &str) -> AnyResult<()> {
let pubkey = Pubkey::from_str(mint)?;
let token_record = metaboss_lib::decode::decode_token_record_from_mint(client, pubkey)?;
println!("{token_record:?}");

Ok(())
}

pub fn decode_raw(client: &RpcClient, mint_account: &str) -> Result<Vec<u8>, DecodeError> {
let pubkey = match Pubkey::from_str(mint_account) {
Ok(pubkey) => pubkey,
Expand Down
10 changes: 10 additions & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::constants::{MASTER_EDITION_PREFIX, METADATA_PREFIX, USER_PREFIX};
use metaboss_lib::derive::derive_token_record_pda;
use mpl_token_metadata::id as metadata_program_id;
use solana_sdk::pubkey::Pubkey;
use std::{convert::AsRef, str::FromStr};
Expand Down Expand Up @@ -57,6 +58,15 @@ pub fn get_cmv3_pda(candy_machine_id: String) {
println!("{}", derive_cmv3_pda(&pubkey));
}

pub fn get_token_record_pda(mint_account: String, token_account: String) {
let mint_pubkey =
Pubkey::from_str(&mint_account).expect("Failed to parse pubkey from mint account!");
let token_pubkey =
Pubkey::from_str(&token_account).expect("Failed to parse pubkey from token account!");

println!("{}", derive_token_record_pda(&mint_pubkey, &token_pubkey));
}

fn derive_generic_pda(seeds: Vec<&[u8]>, program_id: Pubkey) -> Pubkey {
let (pda, _) = Pubkey::find_program_address(&seeds, &program_id);
pda
Expand Down
13 changes: 12 additions & 1 deletion src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,15 @@ pub enum DecodeSubcommands {
#[structopt(short = "a", long)]
metadata_delegate_record: String,
},
/// Decode a TokenRecord from a TokenRecord account or a mint account
TokenRecord {
/// TokenRecord address
#[structopt(short = "a", long)]
token_record: String,
token_record: Option<String>,

/// Mint address
#[structopt(short = "m", long)]
mint: Option<String>,
},
CollectionDelegate {
/// CollectionAuthorityRecord address
Expand Down Expand Up @@ -696,6 +701,12 @@ pub enum DeriveSubcommands {
/// Derive CMV2 PDA
#[structopt(name = "cmv2-creator")]
CMV2Creator { candy_machine_id: String },

#[structopt(name = "token-record")]
TokenRecord {
mint_account: String,
token_account: String,
},
}

#[derive(Debug, StructOpt)]
Expand Down
27 changes: 21 additions & 6 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fs::File;

use anyhow::Result;
use anyhow::{bail, Result};
use metaboss_lib::decode::{
decode_collection_authority_record, decode_metadata_delegate, decode_token_record,
decode_use_authority_record,
decode_token_record_from_mint, decode_use_authority_record,
};
use solana_client::{nonblocking::rpc_client::RpcClient as AsyncRpcClient, rpc_client::RpcClient};

Expand All @@ -25,11 +25,12 @@ use crate::decode::{
};
use crate::derive::{
get_cmv2_pda, get_edition_marker_pda, get_edition_pda, get_generic_pda, get_metadata_pda,
get_token_record_pda,
};
use crate::find::find_missing_editions_process;
use crate::mint::{mint_editions, mint_list, mint_missing_editions, mint_one, process_mint_asset};
use crate::opt::*;
use crate::parse::{parse_errors_code, parse_errors_file};
use crate::parse::{is_only_one_option, parse_errors_code, parse_errors_file};
use crate::sign::{sign_all, sign_one};
use crate::snapshot::{
snapshot_cm_accounts, snapshot_holders, snapshot_indexed_holders, snapshot_indexed_mints,
Expand Down Expand Up @@ -361,10 +362,20 @@ pub fn process_decode(client: &RpcClient, commands: DecodeSubcommands) -> Result

println!("{record:?}");
}
DecodeSubcommands::TokenRecord { token_record } => {
let record = decode_token_record(client, token_record)?;
DecodeSubcommands::TokenRecord { token_record, mint } => {
if !is_only_one_option(&token_record, &mint) {
bail!("Please specify either a token record or a mint, but not both.");
}

println!("{record:?}");
if let Some(token_record) = token_record {
let record = decode_token_record(client, token_record)?;

println!("{record:?}");
} else if let Some(mint) = mint {
let records = decode_token_record_from_mint(client, mint)?;

println!("{records:?}");
}
}
DecodeSubcommands::Mint {
account,
Expand Down Expand Up @@ -401,6 +412,10 @@ pub fn process_derive(commands: DeriveSubcommands) {
edition_num,
} => get_edition_marker_pda(mint_account, edition_num),
DeriveSubcommands::CMV2Creator { candy_machine_id } => get_cmv2_pda(candy_machine_id),
DeriveSubcommands::TokenRecord {
mint_account,
token_account,
} => get_token_record_pda(mint_account, token_account),
}
}

Expand Down