Skip to content

Commit

Permalink
feature: Add flag --new-update-authority to the Reveal Command (#484)
Browse files Browse the repository at this point in the history
Add flag `--new-update-authority` to `reveal`
  • Loading branch information
KartikSoneji authored Sep 16, 2024
1 parent 31867a6 commit 28648e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ pub enum Commands {
/// RPC timeout to retrieve the mint list (in seconds).
#[clap(short, long)]
timeout: Option<u64>,

/// Address to transfer the update authority to
#[clap(short, long)]
new_update_authority: Option<String>,
},

/// Show the on-chain config of an existing candy machine
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,15 @@ async fn run() -> Result<()> {
cache,
config,
timeout,
new_update_authority,
} => {
process_reveal(RevealArgs {
keypair,
rpc_url,
cache,
config,
timeout,
new_update_authority,
})
.await?
}
Expand Down
30 changes: 29 additions & 1 deletion src/reveal/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct RevealArgs {
pub cache: String,
pub config: String,
pub timeout: Option<u64>,
pub new_update_authority: Option<String>,
}

#[derive(Clone, Debug)]
Expand All @@ -41,6 +42,7 @@ pub struct MetadataUpdateValues {
pub new_uri: String,
pub new_name: String,
pub index: String,
pub new_update_authority: Option<Pubkey>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -257,13 +275,23 @@ 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,
metadata: m,
new_uri,
new_name,
index: num,
new_update_authority: set_update_authority,
});
}
spinner.finish_and_clear();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 28648e6

Please sign in to comment.