Skip to content

Commit

Permalink
add update sfbp-all (samuelvanderwaal#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal authored Jul 13, 2022
1 parent 1de093f commit 8d608d1
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 635 deletions.
25 changes: 24 additions & 1 deletion src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ pub enum SnapshotSubcommands {
#[derive(Debug, StructOpt)]
pub enum UpdateSubcommands {
/// Update the seller fee basis points field inside the data struct on an NFT
#[structopt(name = "seller-fee-basis-points")]
#[structopt(name = "sfbp")]
SellerFeeBasisPoints {
/// Path to the creator's keypair file
#[structopt(short, long)]
Expand All @@ -802,6 +802,29 @@ pub enum UpdateSubcommands {
#[structopt(short, long)]
new_seller_fee_basis_points: u16,
},
/// Update the seller fee basis points field inside the data struct on an NFT
#[structopt(name = "sfbp-all")]
SellerFeeBasisPointsAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: Option<String>,

/// Path to the mint list file
#[structopt(short = "L", long)]
mint_list: Option<String>,

/// Cache file
#[structopt(short, long)]
cache_file: Option<String>,

/// New seller fee basis points for the metadata
#[structopt(short, long)]
new_sfbp: u16,

/// Maximum retries: retry failed items up to this many times.
#[structopt(long, default_value = "1")]
retries: u8,
},
/// Update the name field inside the data struct on an NFT
#[structopt(name = "name")]
Name {
Expand Down
17 changes: 17 additions & 0 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@ pub async fn process_update(client: RpcClient, commands: UpdateSubcommands) -> R
&account,
&new_seller_fee_basis_points,
),
UpdateSubcommands::SellerFeeBasisPointsAll {
keypair,
mint_list,
cache_file,
new_sfbp,
retries,
} => {
update_seller_fee_basis_points_all(UpdateSellerFeeBasisPointsAllArgs {
client,
keypair,
mint_list,
cache_file,
new_sfbp,
retries,
})
.await
}
UpdateSubcommands::Name {
keypair,
account,
Expand Down
2 changes: 1 addition & 1 deletion src/update/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use solana_client::rpc_client::RpcClient;
pub use solana_sdk::{
pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction,
};
pub use std::{cmp, str::FromStr, sync::Arc};
pub use std::{cmp, fmt::Display, str::FromStr, sync::Arc};

pub use crate::cache::{Action, BatchActionArgs, RunActionArgs};
pub use crate::decode::{decode, get_metadata_pda};
Expand Down
2 changes: 1 addition & 1 deletion src/update/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn update_creator_by_position(
Ok(())
}

pub async fn update_creator(
async fn update_creator(
client: Arc<RpcClient>,
keypair: Arc<Keypair>,
mint_account: String,
Expand Down
90 changes: 90 additions & 0 deletions src/update/seller_fee_basis_points.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
use super::{common::*, update_data};

pub struct UpdateSellerFeeBasisPointsArgs {
pub client: Arc<RpcClient>,
pub keypair: Arc<Keypair>,
pub payer: Arc<Keypair>,
pub mint_account: String,
pub new_sfbp: u16,
}
pub struct UpdateSellerFeeBasisPointsAllArgs {
pub client: RpcClient,
pub keypair: Option<String>,
pub mint_list: Option<String>,
pub cache_file: Option<String>,
pub new_sfbp: u16,
pub retries: u8,
}

pub fn update_seller_fee_basis_points_one(
client: &RpcClient,
keypair: Option<String>,
Expand All @@ -25,3 +41,77 @@ pub fn update_seller_fee_basis_points_one(
update_data(client, &parsed_keypair, mint_account, new_data)?;
Ok(())
}

async fn update_sfbp(args: UpdateSellerFeeBasisPointsArgs) -> Result<(), ActionError> {
let old_md = decode(&args.client, &args.mint_account)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;
let old_data = old_md.data;

let new_data = DataV2 {
creators: old_data.creators,
seller_fee_basis_points: args.new_sfbp,
name: old_data.name,
symbol: old_data.symbol,
uri: old_data.uri,
collection: old_md.collection,
uses: old_md.uses,
};

update_data(&args.client, &args.keypair, &args.mint_account, new_data)
.map_err(|e| ActionError::ActionFailed(args.mint_account.to_string(), e.to_string()))?;

Ok(())
}

pub struct UpdateSellerFeeBasisPointsAll {}

#[async_trait]
impl Action for UpdateSellerFeeBasisPointsAll {
fn name() -> &'static str {
"update-sfbp-all"
}

async fn action(args: RunActionArgs) -> Result<(), ActionError> {
// Converting back and forth between String and u16 is dumb but I couldn't figure out a
// nice way to do this with generics.
let sfbp = args.new_value.parse::<u16>().map_err(|e| {
ActionError::ActionFailed(
args.mint_account.to_string(),
format!("Invalid new_sfbp: {}", e),
)
})?;

// Set Update Authority can have an optional payer.
update_sfbp(UpdateSellerFeeBasisPointsArgs {
client: args.client.clone(),
keypair: args.keypair.clone(),
payer: args.payer.clone(),
mint_account: args.mint_account,
new_sfbp: sfbp,
})
.await
}
}

pub async fn update_seller_fee_basis_points_all(
args: UpdateSellerFeeBasisPointsAllArgs,
) -> AnyResult<()> {
let solana_opts = parse_solana_config();
let keypair = parse_keypair(args.keypair, solana_opts);

// We don't support an optional payer for this action currently.
let payer = None;

let args = BatchActionArgs {
client: args.client,
keypair,
payer,
mint_list: args.mint_list,
cache_file: args.cache_file,
new_value: args.new_sfbp.to_string(),
retries: args.retries,
};
UpdateSellerFeeBasisPointsAll::run(args).await?;

Ok(())
}
Loading

0 comments on commit 8d608d1

Please sign in to comment.