@@ -297,41 +297,49 @@ async function executeProposal(
297
297
}
298
298
299
299
try {
300
- await execute ( project_name , proposal_id ) ;
301
- const executorAccount = await server . getAccount ( publicKey ) ;
302
- const outcomeTransactionEnvelope = executeXdr
303
- ? xdr . TransactionEnvelope . fromXDR ( executeXdr , "base64" )
304
- : undefined ;
300
+ // Execute the proposal in the smart contract first
301
+ const result = await execute ( project_name , proposal_id ) ;
305
302
306
- const outcomeTransaction = outcomeTransactionEnvelope ?. v1 ( ) . tx ( ) ;
303
+ // Only proceed with the outcome transaction if we have an XDR to execute
304
+ if ( executeXdr ) {
305
+ const executorAccount = await server . getAccount ( publicKey ) ;
306
+ const outcomeTransactionEnvelope = xdr . TransactionEnvelope . fromXDR (
307
+ executeXdr ,
308
+ "base64" ,
309
+ ) ;
310
+ const outcomeTransaction = outcomeTransactionEnvelope ?. v1 ( ) . tx ( ) ;
307
311
308
- const transactionBuilder = new TransactionBuilder ( executorAccount , {
309
- fee : import . meta. env . PUBLIC_DEFAULT_FEE ,
310
- networkPassphrase : import . meta. env . PUBLIC_SOROBAN_NETWORK_PASSPHRASE ,
311
- } ) ;
312
+ const transactionBuilder = new TransactionBuilder ( executorAccount , {
313
+ fee : import . meta. env . PUBLIC_DEFAULT_FEE ,
314
+ networkPassphrase : import . meta. env . PUBLIC_SOROBAN_NETWORK_PASSPHRASE ,
315
+ } ) ;
312
316
313
- outcomeTransaction ?. operations ( ) . forEach ( ( operation ) => {
314
- transactionBuilder . addOperation ( operation ) ;
315
- } ) ;
317
+ outcomeTransaction ?. operations ( ) . forEach ( ( operation ) => {
318
+ transactionBuilder . addOperation ( operation ) ;
319
+ } ) ;
320
+
321
+ const compositeTransaction = transactionBuilder . setTimeout ( 180 ) . build ( ) ;
316
322
317
- const compositeTransaction = transactionBuilder . setTimeout ( 180 ) . build ( ) ;
323
+ const { signedTxXdr } = await kit . signTransaction (
324
+ compositeTransaction . toXDR ( ) ,
325
+ ) ;
318
326
319
- const { signedTxXdr } = await kit . signTransaction (
320
- compositeTransaction . toXDR ( ) ,
321
- ) ;
327
+ const signedTransaction = new Transaction (
328
+ signedTxXdr ,
329
+ import . meta. env . PUBLIC_SOROBAN_NETWORK_PASSPHRASE ,
330
+ ) ;
322
331
323
- const signedTransaction = new Transaction (
324
- signedTxXdr ,
325
- import . meta. env . PUBLIC_SOROBAN_NETWORK_PASSPHRASE ,
326
- ) ;
332
+ const txResult = await server . sendTransaction ( signedTransaction ) ;
327
333
328
- const result = await server . sendTransaction ( signedTransaction ) ;
334
+ if ( txResult . status === "ERROR" ) {
335
+ throw new Error ( "Outcome transaction failed" ) ;
336
+ }
329
337
330
- if ( result . status === "ERROR" ) {
331
- throw new Error ( "Transaction failed" ) ;
332
- } else {
333
- return result . hash ;
338
+ return txResult . hash ;
334
339
}
340
+
341
+ // If no XDR to execute, just return the execution result
342
+ return result . result ;
335
343
} catch ( e : any ) {
336
344
throw new Error ( e . message ) ;
337
345
}
0 commit comments