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

refactor(editions): add support for inifinite editions & update docs #129

Merged
merged 2 commits into from
May 25, 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
Next Next commit
refactor(editions): add support for inifinite editions & update docs
  • Loading branch information
samuelvanderwaal committed May 25, 2022
commit bd9f5a2079d78bfb437d6db2c1437bf8f9a1bdf9
13 changes: 13 additions & 0 deletions docs-src/src/mint.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ If `receiver` is set, the NFT will be minted directly to the receiver's address,

Use the `--sign` option to sign the metadata with the keypair immediately after minting.

#### Editions

To mint a NFT with the ability to print editions from it use the `--max-editions <max-editions>` option. This defaults to `0` meaning no editions are allowed. Setting it to a positive integer means you can print up to that many editions. Setting to a value of `-1` means unlimited editions. Because of how the CLI interprets the `-` symbol to set max editions to infinite you should use the `=` sign for the `--max-editions` option: `metaboss mint one -a <master_account> --max-editions='-1'`.

To mint editions from a master NFT use the`metaboss mint editions` command to either mint the next `n` editions sequentially using `--next-editions <int>` or mint specific edition numbers using `--specific-editions <int> <int> <int>` with a list of integer edition numbers to mint.

To find any edition numbers in the sequence that have not been minted use `metaboss find missing-editions`.

To find and mint any missing editions and mint them to the authority keypair use `metaboss mint missing-editions`.

To find the full list of options for each command use `-h` or `--help` as normal.


### Mint List

Mint multiple NFTs from a list of JSON files.
Expand Down
13 changes: 7 additions & 6 deletions src/find.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use metaboss_lib::{derive::derive_edition_pda, snapshot::get_edition_accounts_by_master};
use mpl_token_metadata::state::Edition;
use mpl_token_metadata::state::{Edition};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{borsh::try_from_slice_unchecked, pubkey::Pubkey};
use std::str::FromStr;
Expand Down Expand Up @@ -29,13 +29,14 @@ pub fn find_missing_editions(client: &RpcClient, mint: &str) -> Result<Vec<u64>>
}
edition_nums.sort_unstable();

for (index, num) in edition_nums.iter().enumerate().skip(1) {
let prev_num = edition_nums[index - 1];
if prev_num != num - 1 {
let s: Vec<u64> = (prev_num + 1..*num).collect();
missing_nums.extend_from_slice(&s);
// Find any missing editions between 1 and the largest edition number currently printed.
let largest_edition_number = edition_nums.last().unwrap_or(&0);
for i in 1..=*largest_edition_number {
if !edition_nums.contains(&i) {
missing_nums.push(i);
}
}

spinner.finish();

println!("Edition numbers: {:?}", edition_nums);
Expand Down
18 changes: 13 additions & 5 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn mint_from_files(
list_dir: String,
immutable: bool,
primary_sale_happened: bool,
max_editions: u64,
max_editions: i64,
sign: bool,
) -> Result<()> {
let use_rate_limit = *USE_RATE_LIMIT.read().unwrap();
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn mint_from_uris(
external_metadata_uris_path: String,
immutable: bool,
primary_sale_happened: bool,
max_editions: u64,
max_editions: i64,
sign: bool,
track: bool,
) -> Result<()> {
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn mint_one<P: AsRef<Path>>(
external_metadata_uri: Option<&String>,
immutable: bool,
primary_sale_happened: bool,
max_editions: u64,
max_editions: i64,
sign: bool,
) -> Result<String> {
if !is_only_one_option(&nft_data_file, &external_metadata_uri) {
Expand Down Expand Up @@ -498,11 +498,19 @@ pub fn mint(
nft_data: NFTData,
immutable: bool,
primary_sale_happened: bool,
max_editions: u64,
max_editions: i64,
) -> Result<(Signature, Pubkey)> {
let metaplex_program_id = Pubkey::from_str(METAPLEX_PROGRAM_ID)?;
let mint = Keypair::new();

// Max editions of -1 means infinite supply (max_supply = None)
// Otherwise max_supply is the number of editions
let max_supply = if max_editions == -1 {
None
} else {
Some(max_editions as u64)
};

// Convert local NFTData type to Metaplex Data type
let data = convert_local_to_remote_data(nft_data)?;

Expand Down Expand Up @@ -589,7 +597,7 @@ pub fn mint(
funder.pubkey(),
metadata_account,
funder.pubkey(),
Some(max_editions),
max_supply,
);

let mut instructions = vec![
Expand Down
2 changes: 1 addition & 1 deletion src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ pub enum MintSubcommands {

/// Maximum number of editions. Defaults to zero, meaning no editions allowed.
#[structopt(short = "e", long, default_value = "0")]
max_editions: u64,
max_editions: i64,

/// Sign NFT after minting it
#[structopt(long)]
Expand Down