@@ -89,20 +89,26 @@ pub async fn build_and_send_transaction<S: Signer>(
8989 . await
9090}
9191
92+ #[ derive( Debug , Default ) ]
93+ pub struct BuildTransactionConfig {
94+ pub rpc_config : RpcConfig ,
95+ pub fee_config : FeeConfig ,
96+ pub compute_config : ComputeConfig ,
97+ }
98+
9299/// Build a transaction with compute budget and priority fees from the supplied configuration
93100///
94101/// This function handles:
95102/// 1. Building a transaction message with all instructions
96103/// 2. Adding compute budget instructions
97104/// 3. Adding any Jito tip instructions
98105/// 4. Supporting address lookup tables for account compression
99- pub async fn build_transaction_with_config (
106+ pub async fn build_transaction_with_config_obj (
100107 mut instructions : Vec < Instruction > ,
101108 payer : & Pubkey ,
102109 address_lookup_tables : Option < Vec < AddressLookupTableAccount > > ,
103110 rpc_client : & RpcClient ,
104- rpc_config : & RpcConfig ,
105- fee_config : & FeeConfig ,
111+ config : & BuildTransactionConfig ,
106112) -> Result < VersionedTransaction , String > {
107113 let recent_blockhash = rpc_client
108114 . get_latest_blockhash ( )
@@ -113,13 +119,21 @@ pub async fn build_transaction_with_config(
113119
114120 let address_lookup_tables_clone = address_lookup_tables. clone ( ) ;
115121
116- let compute_units = compute_budget:: estimate_compute_units (
117- rpc_client,
118- & instructions,
119- payer,
120- address_lookup_tables_clone,
121- )
122- . await ?;
122+ let compute_units = match config. compute_config . unit_limit {
123+ ComputeUnitLimitStrategy :: Dynamic => {
124+ compute_budget:: estimate_compute_units (
125+ rpc_client,
126+ & instructions,
127+ payer,
128+ address_lookup_tables_clone,
129+ )
130+ . await ?
131+ }
132+ ComputeUnitLimitStrategy :: Exact ( units) => units,
133+ } ;
134+
135+ let rpc_config = & config. rpc_config ;
136+ let fee_config = & config. fee_config ;
123137 let budget_instructions = compute_budget:: get_compute_budget_instruction (
124138 rpc_client,
125139 compute_units,
@@ -153,12 +167,46 @@ pub async fn build_transaction_with_config(
153167 Message :: try_compile ( payer, & instructions, & [ ] , recent_blockhash)
154168 . map_err ( |e| format ! ( "Failed to compile message: {}" , e) ) ?
155169 } ;
170+
171+ // Provide the correct number of signatures for the transaction, otherwise (de)serialization can fail
156172 Ok ( VersionedTransaction {
157- signatures : vec ! [ ] ,
173+ signatures : vec ! [
174+ solana_sdk:: signature:: Signature :: default ( ) ;
175+ message. header. num_required_signatures. into( )
176+ ] ,
158177 message : VersionedMessage :: V0 ( message) ,
159178 } )
160179}
161180
181+ /// Build a transaction with compute budget and priority fees from the supplied configuration
182+ ///
183+ /// This function handles:
184+ /// 1. Building a transaction message with all instructions
185+ /// 2. Adding compute budget instructions
186+ /// 3. Adding any Jito tip instructions
187+ /// 4. Supporting address lookup tables for account compression
188+ pub async fn build_transaction_with_config (
189+ instructions : Vec < Instruction > ,
190+ payer : & Pubkey ,
191+ address_lookup_tables : Option < Vec < AddressLookupTableAccount > > ,
192+ rpc_client : & RpcClient ,
193+ rpc_config : & RpcConfig ,
194+ fee_config : & FeeConfig ,
195+ ) -> Result < VersionedTransaction , String > {
196+ build_transaction_with_config_obj (
197+ instructions,
198+ payer,
199+ address_lookup_tables,
200+ rpc_client,
201+ & BuildTransactionConfig {
202+ rpc_config : ( * rpc_config) . clone ( ) ,
203+ fee_config : ( * fee_config) . clone ( ) ,
204+ ..Default :: default ( )
205+ } ,
206+ )
207+ . await
208+ }
209+
162210/// Build a transaction with compute budget and priority fees from the global configuration
163211///
164212/// This function handles:
0 commit comments