tensor_eigen/commands/whitelist/
update.rs

1use super::*;
2
3use solana_sdk::signature::read_keypair_file;
4use tensor_whitelist::{
5    instructions::{UpdateWhitelistV2, UpdateWhitelistV2InstructionArgs},
6    types::{Condition, Operation},
7};
8
9pub struct UpdateWhitelistV2Params {
10    pub keypair_path: Option<PathBuf>,
11    pub rpc_url: Option<String>,
12    pub whitelist_address: Pubkey,
13    pub new_conditions_path: Option<PathBuf>,
14    pub new_update_authority_path: Option<PathBuf>,
15    pub new_freeze_authority: Option<Pubkey>,
16}
17
18pub fn update_whitelist_v2(args: UpdateWhitelistV2Params) -> Result<()> {
19    let config = CliConfig::new(args.keypair_path, args.rpc_url)?;
20
21    let payer = config.keypair.pubkey();
22    let owner = config.keypair.pubkey();
23
24    let new_conditions: Option<Vec<Condition>> = args.new_conditions_path.map(|path| {
25        serde_json::from_reader(
26            std::fs::File::open(path).expect("Failed to open new conditions file"),
27        )
28        .expect("Failed to parse new conditions")
29    });
30
31    let freeze_authority = match args.new_freeze_authority {
32        Some(pubkey) => Operation::Set(pubkey),
33        None => Operation::Noop,
34    };
35
36    let update_args = UpdateWhitelistV2InstructionArgs {
37        freeze_authority,
38        conditions: new_conditions,
39    };
40
41    let new_update_authority = args
42        .new_update_authority_path
43        .map(|path| read_keypair_file(path).expect("Failed to read new update authority keypair"));
44
45    let ix = UpdateWhitelistV2 {
46        payer,
47        update_authority: owner,
48        whitelist: args.whitelist_address,
49        new_update_authority: new_update_authority.as_ref().map(|k| k.pubkey()),
50        system_program: solana_sdk::system_program::id(),
51    }
52    .instruction(update_args);
53
54    let signers = if let Some(ref new_auth) = new_update_authority {
55        vec![&config.keypair, new_auth]
56    } else {
57        vec![&config.keypair]
58    };
59    let tx = transaction!(&signers, &[ix], &config.client);
60
61    config.client.send_and_confirm_transaction(&tx)?;
62
63    println!("Whitelist updated: {}", args.whitelist_address);
64
65    Ok(())
66}