From f6196e78221dafa1fc956a6d6db6aa1a5cc5b07f Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Fri, 26 Jul 2024 01:48:08 -0400 Subject: [PATCH 1/2] Update get_compute_units --- src/optimized_transaction.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/optimized_transaction.rs b/src/optimized_transaction.rs index 53f3fd1..290eccc 100644 --- a/src/optimized_transaction.rs +++ b/src/optimized_transaction.rs @@ -40,7 +40,7 @@ impl Helius { instructions: Vec, payer: Pubkey, lookup_tables: Vec, - signers: &[&dyn Signer], + signers: Option<&[&dyn Signer]>, ) -> Result> { // Set the compute budget limit let test_instructions: Vec = vec![ComputeBudgetInstruction::set_compute_unit_limit(1_400_000)] @@ -56,9 +56,16 @@ impl Helius { v0::Message::try_compile(&payer, &test_instructions, &lookup_tables, recent_blockhash)?; let versioned_message: VersionedMessage = VersionedMessage::V0(v0_message); - // Create a signed VersionedTransaction - let transaction: VersionedTransaction = VersionedTransaction::try_new(versioned_message, signers) - .map_err(|e| HeliusError::InvalidInput(format!("Signing error: {:?}", e)))?; + // Create a VersionedTransaction (signed or unsigned) + let transaction: VersionedTransaction = if let Some(signers) = signers { + VersionedTransaction::try_new(versioned_message, signers) + .map_err(|e| HeliusError::InvalidInput(format!("Signing error: {:?}", e)))? + } else { + VersionedTransaction { + signatures: vec![], + message: versioned_message, + } + }; // Simulate the transaction let config: RpcSimulateTransactionConfig = RpcSimulateTransactionConfig { @@ -160,7 +167,7 @@ impl Helius { v0::Message::try_compile(&payer_pubkey, &config.instructions, lookup_tables, recent_blockhash)?; let versioned_message: VersionedMessage = VersionedMessage::V0(v0_message); - let all_signers = if let Some(fee_payer) = config.fee_payer { + let all_signers: Vec<&dyn Signer> = if let Some(fee_payer) = config.fee_payer { let mut all_signers: Vec<&dyn Signer> = config.signers.clone(); if !all_signers.iter().any(|signer| signer.pubkey() == fee_payer.pubkey()) { all_signers.push(fee_payer); @@ -238,7 +245,7 @@ impl Helius { updated_instructions, payer_pubkey, config.lookup_tables.clone().unwrap_or_default(), - &config.signers, + Some(&config.signers), ) .await?; From 32437dc21f2a9b6d496e395abf64f762b0bdae76 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Fri, 26 Jul 2024 01:51:21 -0400 Subject: [PATCH 2/2] Make sig_verify Optional --- src/optimized_transaction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/optimized_transaction.rs b/src/optimized_transaction.rs index 290eccc..1757a26 100644 --- a/src/optimized_transaction.rs +++ b/src/optimized_transaction.rs @@ -69,7 +69,7 @@ impl Helius { // Simulate the transaction let config: RpcSimulateTransactionConfig = RpcSimulateTransactionConfig { - sig_verify: true, + sig_verify: signers.is_some(), ..Default::default() }; let result: Response = self