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

Feature sign mints #91

Merged
merged 3 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add sign to mint fuctions
  • Loading branch information
jclmnop committed Feb 19, 2022
commit 9105073aa4257c6feb59786c5c862d5d733f578e
19 changes: 16 additions & 3 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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;

const MINT_LAYOUT: u64 = 82;

Expand All @@ -38,6 +39,7 @@ pub fn mint_list(
external_metadata_uris: Option<String>,
immutable: bool,
primary_sale_happened: bool,
sign: bool,
) -> Result<()> {
if !is_only_one_option(&list_dir, &external_metadata_uris) {
return Err(anyhow!(
Expand All @@ -53,6 +55,7 @@ pub fn mint_list(
list_dir,
immutable,
primary_sale_happened,
sign,
)?;
} else if let Some(external_metadata_uris) = external_metadata_uris {
mint_from_uris(
Expand All @@ -62,6 +65,7 @@ pub fn mint_list(
external_metadata_uris,
immutable,
primary_sale_happened,
sign,
)?;
} else {
return Err(anyhow!(
Expand All @@ -79,6 +83,7 @@ pub fn mint_from_files(
list_dir: String,
immutable: bool,
primary_sale_happened: bool,
sign: bool,
) -> Result<()> {
let use_rate_limit = *USE_RATE_LIMIT.read().unwrap();
let handle = create_rate_limiter();
Expand All @@ -105,6 +110,7 @@ pub fn mint_from_files(
None,
immutable,
primary_sale_happened,
sign,
) {
Ok(_) => (),
Err(e) => error!("Failed to mint {:?}: {}", &path, e),
Expand All @@ -129,6 +135,7 @@ pub fn mint_from_uris(
external_metadata_uris_path: String,
immutable: bool,
primary_sale_happened: bool,
sign: bool,
) -> Result<()> {
let f = File::open(external_metadata_uris_path)?;
let external_metadata_uris: Vec<String> = serde_json::from_reader(f)?;
Expand All @@ -145,6 +152,7 @@ pub fn mint_from_uris(
Some(uri),
immutable,
primary_sale_happened,
sign,
) {
Ok(_) => (),
Err(e) => error!("Failed to mint {:?}: {}", &uri, e),
Expand All @@ -161,19 +169,20 @@ pub fn mint_one<P: AsRef<Path>>(
external_metadata_uri: Option<&String>,
immutable: bool,
primary_sale_happened: bool,
sign: bool,
) -> Result<()> {
if !is_only_one_option(&nft_data_file, &external_metadata_uri) {
return Err(anyhow!(
"You must supply either --nft_data_file or --external-metadata-uris but not both"
));
}

let keypair = parse_keypair(&keypair)?;
let parsed_keypair = parse_keypair(&keypair)?;

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

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

let (tx_id, mint_account) = mint(
client,
keypair,
parsed_keypair,
receiver,
nft_data,
immutable,
Expand All @@ -214,6 +223,10 @@ pub fn mint_one<P: AsRef<Path>>(
info!("Tx id: {:?}\nMint account: {:?}", &tx_id, &mint_account);
let message = format!("Tx id: {:?}\nMint account: {:?}", &tx_id, &mint_account,);
println!("{}", message);
if sign {
//TODO: Error handling
sign_one(client, keypair.clone(), mint_account.to_string())?;
}

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub enum MintSubcommands {
primary_sale_happened: bool,

/// Sign NFT after minting it
#[structopt(short, long)]
#[structopt(long)]
sign: bool,
},
#[structopt(name = "list")]
Expand Down Expand Up @@ -194,7 +194,7 @@ pub enum MintSubcommands {
primary_sale_happened: bool,

/// Sign NFTs after minting them
#[structopt(short, long)]
#[structopt(long)]
sign: bool,
},
}
Expand Down
4 changes: 4 additions & 0 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
external_metadata_uri,
immutable,
primary_sale_happened,
sign,
} => mint_one(
&client,
&keypair,
Expand All @@ -55,6 +56,7 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
external_metadata_uri.as_ref(),
immutable,
primary_sale_happened,
sign,
),
MintSubcommands::List {
keypair,
Expand All @@ -63,6 +65,7 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
external_metadata_uris,
immutable,
primary_sale_happened,
sign,
} => mint_list(
&client,
keypair,
Expand All @@ -71,6 +74,7 @@ pub fn process_mint(client: &RpcClient, commands: MintSubcommands) -> Result<()>
external_metadata_uris,
immutable,
primary_sale_happened,
sign,
),
}
}
Expand Down