From 28648e64886925fc200acfbcfdc700cadbd302f4 Mon Sep 17 00:00:00 2001 From: Kartik Soneji Date: Tue, 17 Sep 2024 00:40:23 +0530 Subject: [PATCH] feature: Add flag `--new-update-authority` to the Reveal Command (#484) Add flag `--new-update-authority` to `reveal` --- src/cli/mod.rs | 4 ++++ src/main.rs | 2 ++ src/reveal/process.rs | 30 +++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 3e404794..10bea527 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -214,6 +214,10 @@ pub enum Commands { /// RPC timeout to retrieve the mint list (in seconds). #[clap(short, long)] timeout: Option, + + /// Address to transfer the update authority to + #[clap(short, long)] + new_update_authority: Option, }, /// Show the on-chain config of an existing candy machine diff --git a/src/main.rs b/src/main.rs index 67fcf74d..017c05f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -469,6 +469,7 @@ async fn run() -> Result<()> { cache, config, timeout, + new_update_authority, } => { process_reveal(RevealArgs { keypair, @@ -476,6 +477,7 @@ async fn run() -> Result<()> { cache, config, timeout, + new_update_authority, }) .await? } diff --git a/src/reveal/process.rs b/src/reveal/process.rs index c7f25cb8..ae02993f 100644 --- a/src/reveal/process.rs +++ b/src/reveal/process.rs @@ -32,6 +32,7 @@ pub struct RevealArgs { pub cache: String, pub config: String, pub timeout: Option, + pub new_update_authority: Option, } #[derive(Clone, Debug)] @@ -41,6 +42,7 @@ pub struct MetadataUpdateValues { pub new_uri: String, pub new_name: String, pub index: String, + pub new_update_authority: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] @@ -94,6 +96,22 @@ pub async fn process_reveal(args: RevealArgs) -> Result<()> { } }; + let new_update_authority = if let Some(new_update_authority) = &args.new_update_authority { + match Pubkey::from_str(new_update_authority) { + Ok(new_update_authority) => Some(new_update_authority), + Err(_) => { + let error = anyhow!( + "Failed to parse new update authority: {}", + new_update_authority + ); + error!("{:?}", error); + return Err(error); + } + } + } else { + None + }; + spinner.finish_with_message("Done"); println!( @@ -257,6 +275,15 @@ pub async fn process_reveal(args: RevealArgs) -> Result<()> { .ok_or_else(|| anyhow!("No name found for number: {num}"))? .name .clone(); + // if new update authority is set, and it isn't equal to the current update authority + // then change it along with the rest of the metadata + let set_update_authority = new_update_authority.and_then(|new_update_authority| { + if new_update_authority != m.update_authority { + Some(new_update_authority) + } else { + None + } + }); update_values.push(MetadataUpdateValues { metadata_pubkey, @@ -264,6 +291,7 @@ pub async fn process_reveal(args: RevealArgs) -> Result<()> { new_uri, new_name, index: num, + new_update_authority: set_update_authority, }); } spinner.finish_and_clear(); @@ -372,7 +400,7 @@ async fn update_metadata_value( TOKEN_METADATA_PROGRAM_ID, value.metadata_pubkey, update_authority.pubkey(), - None, + value.new_update_authority, Some(data_v2), None, None,