Skip to content

Commit

Permalink
feat: default to keypair set in solana config (samuelvanderwaal#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal authored Mar 9, 2022
1 parent ce29ae0 commit 74262e4
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 142 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spl-associated-token-account = "1.0.3"
spl-token = "3.2.0"
structopt = "0.3.23"
thiserror = "1.0.30"
shellexpand = "2.1.0"

[features]

Expand Down
11 changes: 8 additions & 3 deletions src/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ use spl_associated_token_account::get_associated_token_address;
use spl_token;
use std::str::FromStr;

use crate::decode::decode;
use crate::derive::derive_metadata_pda;
use crate::parse::parse_keypair;
use crate::{decode::decode, parse::parse_solana_config};

pub fn burn_one(client: &RpcClient, keypair: String, mint_address: String) -> Result<()> {
pub fn burn_one(
client: &RpcClient,
keypair_path: Option<String>,
mint_address: String,
) -> Result<()> {
let mint_pubkey = Pubkey::from_str(&mint_address)?;
let keypair = parse_keypair(&keypair)?;
let solana_opts = parse_solana_config();
let keypair = parse_keypair(keypair_path, solana_opts);
let owner_pubkey = keypair.pubkey();

let sig = burn(client, &keypair, &owner_pubkey, &mint_pubkey, 1)?;
Expand Down
17 changes: 12 additions & 5 deletions src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ use solana_client::rpc_client::RpcClient;
use solana_sdk::{pubkey::Pubkey, signer::Signer, transaction::Transaction};
use std::str::FromStr;

use crate::derive::{derive_collection_authority_record, derive_metadata_pda};
use crate::parse::parse_keypair;
use crate::{
derive::{derive_collection_authority_record, derive_metadata_pda},
parse::parse_solana_config,
};

pub fn approve_delegate(
client: &RpcClient,
keypair: String,
keypair_path: Option<String>,
collection_mint: String,
delegate_authority: String,
) -> Result<()> {
let collection_pubkey = Pubkey::from_str(&collection_mint)?;
let keypair = parse_keypair(&keypair)?;
let solana_opts = parse_solana_config();
let keypair = parse_keypair(keypair_path, solana_opts);

let delegate_pubkey = Pubkey::from_str(&delegate_authority)?;

let (collection_authority_record, _bump) =
Expand Down Expand Up @@ -58,11 +63,13 @@ pub fn approve_delegate(

pub fn revoke_delegate(
client: &RpcClient,
keypair: String,
keypair_path: Option<String>,
collection_mint: String,
delegate_authority: String,
) -> Result<()> {
let keypair = parse_keypair(&keypair)?;
let solana_opts = parse_solana_config();
let keypair = parse_keypair(keypair_path, solana_opts);

let collection_pubkey = Pubkey::from_str(&collection_mint)?;
let delegate_pubkey = Pubkey::from_str(&delegate_authority)?;

Expand Down
27 changes: 14 additions & 13 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use std::{fs::File, path::Path, str::FromStr};
use crate::data::NFTData;
use crate::limiter::create_rate_limiter;
use crate::parse::*;
use crate::{constants::*, parse::convert_local_to_remote_data};
use crate::sign::sign_one;
use crate::{constants::*, parse::convert_local_to_remote_data};

const MINT_LAYOUT: u64 = 82;

pub fn mint_list(
client: &RpcClient,
keypair: String,
keypair_path: Option<String>,
receiver: Option<String>,
list_dir: Option<String>,
external_metadata_uris: Option<String>,
Expand All @@ -50,7 +50,7 @@ pub fn mint_list(
if let Some(list_dir) = list_dir {
mint_from_files(
client,
keypair,
keypair_path,
receiver,
list_dir,
immutable,
Expand All @@ -60,7 +60,7 @@ pub fn mint_list(
} else if let Some(external_metadata_uris) = external_metadata_uris {
mint_from_uris(
client,
keypair,
keypair_path,
receiver,
external_metadata_uris,
immutable,
Expand All @@ -78,7 +78,7 @@ pub fn mint_list(

pub fn mint_from_files(
client: &RpcClient,
keypair: String,
keypair_path: Option<String>,
receiver: Option<String>,
list_dir: String,
immutable: bool,
Expand All @@ -104,7 +104,7 @@ pub fn mint_from_files(

match mint_one(
client,
&keypair,
keypair_path.clone(),
&receiver,
Some(path),
None,
Expand All @@ -130,7 +130,7 @@ pub fn mint_from_files(

pub fn mint_from_uris(
client: &RpcClient,
keypair: String,
keypair_path: Option<String>,
receiver: Option<String>,
external_metadata_uris_path: String,
immutable: bool,
Expand All @@ -146,7 +146,7 @@ pub fn mint_from_uris(
.for_each(|uri| {
match mint_one(
client,
&keypair,
keypair_path.clone(),
&receiver,
None::<String>,
Some(uri),
Expand All @@ -163,7 +163,7 @@ pub fn mint_from_uris(
}
pub fn mint_one<P: AsRef<Path>>(
client: &RpcClient,
keypair: &String,
keypair_path: Option<String>,
receiver: &Option<String>,
nft_data_file: Option<P>,
external_metadata_uri: Option<&String>,
Expand All @@ -177,12 +177,13 @@ pub fn mint_one<P: AsRef<Path>>(
));
}

let parsed_keypair = parse_keypair(&keypair)?;
let solana_opts = parse_solana_config();
let keypair = parse_keypair(keypair_path.clone(), solana_opts);

let receiver = if let Some(address) = receiver {
Pubkey::from_str(&address)?
} else {
parsed_keypair.pubkey()
keypair.pubkey()
};

let nft_data: NFTData = if let Some(nft_data_file) = nft_data_file {
Expand Down Expand Up @@ -214,7 +215,7 @@ pub fn mint_one<P: AsRef<Path>>(

let (tx_id, mint_account) = mint(
client,
parsed_keypair,
keypair,
receiver,
nft_data,
immutable,
Expand All @@ -225,7 +226,7 @@ pub fn mint_one<P: AsRef<Path>>(
println!("{}", message);
if sign {
//TODO: Error handling
sign_one(client, keypair.clone(), mint_account.to_string())?;
sign_one(client, keypair_path.clone(), mint_account.to_string())?;
}

Ok(())
Expand Down
40 changes: 20 additions & 20 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub enum BurnSubcommands {
One {
/// Path to the authority & funder keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Token mint account
#[structopt(short, long)]
Expand All @@ -101,7 +101,7 @@ pub enum CollectionsSubcommands {
ApproveAuthority {
/// Path to the update authority keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Collection mint address
#[structopt(short, long)]
Expand All @@ -115,7 +115,7 @@ pub enum CollectionsSubcommands {
RevokeAuthority {
/// Path to the update authority keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Collection mint address
#[structopt(short, long)]
Expand Down Expand Up @@ -182,7 +182,7 @@ pub enum MintSubcommands {
One {
/// Path to the update_authority keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Receiving address, if different from update authority.
#[structopt(short = "R", long)]
Expand Down Expand Up @@ -213,7 +213,7 @@ pub enum MintSubcommands {
List {
/// Path to the update_authority keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Receiving address, if different from update authority
#[structopt(short = "R", long)]
Expand Down Expand Up @@ -248,7 +248,7 @@ pub enum SetSubcommands {
PrimarySaleHappened {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -259,7 +259,7 @@ pub enum SetSubcommands {
UpdateAuthority {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -274,7 +274,7 @@ pub enum SetSubcommands {
UpdateAuthorityAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Path to JSON mint accounts file
#[structopt(short = "a", long)]
Expand All @@ -289,7 +289,7 @@ pub enum SetSubcommands {
Immutable {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -298,7 +298,7 @@ pub enum SetSubcommands {
ImmutableAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Path to JSON mint accounts file
#[structopt(short, long)]
Expand All @@ -313,7 +313,7 @@ pub enum SignSubcommands {
One {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account to sign
#[structopt(short, long)]
Expand All @@ -324,7 +324,7 @@ pub enum SignSubcommands {
All {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Creator to filter accounts by (for CM v2 use --v2 if candy_machine account is passed)
#[structopt(short, long)]
Expand Down Expand Up @@ -416,7 +416,7 @@ pub enum UpdateSubcommands {
Name {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -431,7 +431,7 @@ pub enum UpdateSubcommands {
Symbol {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -446,7 +446,7 @@ pub enum UpdateSubcommands {
Creators {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -465,7 +465,7 @@ pub enum UpdateSubcommands {
Data {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -480,7 +480,7 @@ pub enum UpdateSubcommands {
DataAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Path to directory containing JSON files with new data
#[structopt(short, long)]
Expand All @@ -491,7 +491,7 @@ pub enum UpdateSubcommands {
Uri {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
Expand All @@ -506,7 +506,7 @@ pub enum UpdateSubcommands {
UriAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,

/// JSON file with list of mint accounts and new URIs
#[structopt(short = "u", long)]
Expand All @@ -524,6 +524,6 @@ pub enum WithdrawSubcommands {

/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,
keypair: Option<String>,
},
}
Loading

0 comments on commit 74262e4

Please sign in to comment.