Skip to content

Commit

Permalink
cli: make keypair path mandatory and use it as ix authority if multis…
Browse files Browse the repository at this point in the history
…ig is not specified
  • Loading branch information
losman0s committed Apr 17, 2024
1 parent 17c4828 commit 1fc3305
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub enum ProfileCommand {
#[clap(long)]
cluster: Cluster,
#[clap(long)]
keypair_path: Option<String>,
keypair_path: String,
#[clap(long)]
multisig: Option<Pubkey>,
#[clap(long)]
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/marginfi-cli/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ pub fn bank_configure(
pub fn create_profile(
name: String,
cluster: Cluster,
keypair_path: Option<String>,
keypair_path: String,
multisig: Option<Pubkey>,
rpc_url: String,
program_id: Option<Pubkey>,
Expand Down
30 changes: 6 additions & 24 deletions clients/rust/marginfi-cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use {
pub struct Profile {
pub name: String,
pub cluster: Cluster,
pub keypair_path: Option<String>,
pub keypair_path: String,
pub multisig: Option<Pubkey>,
pub rpc_url: String,
pub program_id: Option<Pubkey>,
Expand All @@ -38,22 +38,14 @@ impl Profile {
pub fn new(
name: String,
cluster: Cluster,
keypair_path: Option<String>,
keypair_path: String,
multisig: Option<Pubkey>,
rpc_url: String,
program_id: Option<Pubkey>,
commitment: Option<CommitmentLevel>,
marginfi_group: Option<Pubkey>,
marginfi_account: Option<Pubkey>,
) -> Self {
if keypair_path.is_none() && multisig.is_none() {
panic!("Either keypair_path or multisig must be set");
}

if keypair_path.is_some() && multisig.is_some() {
panic!("Only one of keypair_path or multisig can be set");
}

Profile {
name,
cluster,
Expand All @@ -68,12 +60,8 @@ impl Profile {
}

pub fn get_config(&self, global_options: Option<&GlobalOptions>) -> Result<Config> {
let fee_payer = if let Some(keypair_path) = self.keypair_path.clone() {
read_keypair_file(&*shellexpand::tilde(&keypair_path))
.expect("Example requires a keypair file")
} else {
Keypair::new()
};
let fee_payer = read_keypair_file(&*shellexpand::tilde(&self.keypair_path))
.expect("Example requires a keypair file");

let multisig = self.multisig;

Expand Down Expand Up @@ -138,22 +126,17 @@ impl Profile {
group: Option<Pubkey>,
account: Option<Pubkey>,
) -> Result<()> {
if keypair_path.is_some() && multisig.is_some() {
panic!("Only one of keypair_path or multisig can be set");
}

if let Some(cluster) = cluster {
self.cluster = cluster;
}

if let Some(keypair_path) = keypair_path {
self.keypair_path = Some(keypair_path);
self.multisig = None;
self.keypair_path = keypair_path;
}

if let Some(multisig) = multisig {
self.multisig = Some(multisig);
self.keypair_path = None;
}

if let Some(rpc_url) = rpc_url {
Expand Down Expand Up @@ -285,8 +268,7 @@ Profile:
config.explicit_fee_payer(),
config.authority(),
self.keypair_path
.clone()
.unwrap_or_else(|| "None".to_owned()),
.clone(),
self.multisig
.map(|x| x.to_string())
.unwrap_or_else(|| "None".to_owned()),
Expand Down

0 comments on commit 1fc3305

Please sign in to comment.