Skip to content

Commit

Permalink
switch update/initialize ix based on whether or not pda exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ngundotra committed Dec 18, 2024
1 parent 37373da commit c74d6dd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,12 +1488,26 @@ async fn export_pda_tx(
let (pda, _) =
find_build_params_pda(&Pubkey::try_from(program_id)?, &Pubkey::try_from(uploader)?);

// check if account already exists
let instruction = match connection.get_account(&pda) {
Ok(account_info) => {
if account_info.data.len() > 0 {
println!("PDA already exists, creating update transaction");
OtterVerifyInstructions::Update
} else {
println!("PDA does not exist, creating initialize transaction");
OtterVerifyInstructions::Initialize
}
}
Err(_) => OtterVerifyInstructions::Initialize,
};

let tx = compose_transaction(
&input_params,
Pubkey::try_from(uploader)?,
pda,
Pubkey::try_from(program_id)?,
OtterVerifyInstructions::Initialize,
instruction,
compute_unit_price,
);

Expand Down

0 comments on commit c74d6dd

Please sign in to comment.