@@ -3,7 +3,7 @@ import { signTransaction } from "@stellar/freighter-api";
33
44// Use require for the default export
55const StellarSdk = require ( "@stellar/stellar-sdk" ) ;
6- const { Server, TransactionBuilder, Operation, SorobanRpc } = StellarSdk ;
6+ const { Server, TransactionBuilder, Operation, SorobanRpc, FeeBumpTransaction } = StellarSdk ;
77
88// Import Networks separately to avoid conflict
99import { Networks } from "@stellar/stellar-sdk" ;
@@ -14,6 +14,7 @@ import {
1414 initializeRPCManager ,
1515 DEFAULT_RPC_CONFIG ,
1616} from "./rpc-failover" ;
17+ import { classifyError , SorobanError } from "./errors" ;
1718
1819// Configuration helpers – prefer environment variables so they can be swapped
1920// for different networks (testnet / preview / mainnet) without changing code.
@@ -151,25 +152,29 @@ export async function createEvent(
151152 args,
152153 } ) ;
153154
154- const tx = new TransactionBuilder ( sourceAccount , {
155- fee : fee . toString ( ) ,
156- networkPassphrase : NETWORK_PASSPHRASE ,
157- } )
158- . addOperation ( operation )
159- . setTimeout ( 30 )
160- . build ( ) ;
161-
162- const txXdr = tx . toXDR ( ) ;
163-
164- // ask configured wallet provider to sign
165- const signedTxXdr = await signTransactionFn ( txXdr , {
166- networkPassphrase : NETWORK_PASSPHRASE ,
167- address : params . organizer ,
168- } ) ;
169-
170- // submit to horizon and return the result
171- const signedTx = TransactionBuilder . fromXDR ( signedTxXdr , NETWORK_PASSPHRASE ) ;
172- return await server . submitTransaction ( signedTx as any ) ;
155+ try {
156+ const tx = new TransactionBuilder ( sourceAccount , {
157+ fee : fee . toString ( ) ,
158+ networkPassphrase : NETWORK_PASSPHRASE ,
159+ } )
160+ . addOperation ( operation )
161+ . setTimeout ( 30 )
162+ . build ( ) ;
163+
164+ const txXdr = tx . toXDR ( ) ;
165+
166+ // ask configured wallet provider to sign
167+ const signedTxXdr = await signTransactionFn ( txXdr , {
168+ networkPassphrase : NETWORK_PASSPHRASE ,
169+ address : params . organizer ,
170+ } ) ;
171+
172+ // submit to horizon and return the result
173+ const signedTx = TransactionBuilder . fromXDR ( signedTxXdr , NETWORK_PASSPHRASE ) ;
174+ return await server . submitTransaction ( signedTx as any ) ;
175+ } catch ( error ) {
176+ throw classifyError ( error ) ;
177+ }
173178}
174179
175180export async function buyTickets (
@@ -596,3 +601,40 @@ export async function getActiveListings(): Promise<any[]> {
596601 created_at : Number ( l . created_at ) ,
597602 } ) ) ;
598603}
604+
605+ /**
606+ * Builds a fee bump transaction for a given inner transaction.
607+ * @param innerTx The original transaction to be wrapped.
608+ * @param feeSource The account address that will pay the fees.
609+ * @param baseFee The fee to be paid for the fee bump transaction.
610+ */
611+ export async function buildFeeBumpTransaction (
612+ innerTxXdr : string ,
613+ feeSource : string ,
614+ baseFee : string ,
615+ ) {
616+ const server = await getRPCManager ( ) . getHorizonServer ( ) ;
617+ const feeSourceAccount = await server . loadAccount ( feeSource ) ;
618+
619+ const innerTx = TransactionBuilder . fromXDR ( innerTxXdr , NETWORK_PASSPHRASE ) ;
620+
621+ return TransactionBuilder . buildFeeBumpTransaction (
622+ feeSourceAccount ,
623+ baseFee ,
624+ innerTx ,
625+ NETWORK_PASSPHRASE ,
626+ ) ;
627+ }
628+
629+ /**
630+ * Submits a fee bump transaction to the network.
631+ * @param feeBumpTx The fee bump transaction to submit.
632+ */
633+ export async function submitFeeBumpTransaction ( feeBumpTx : any ) {
634+ const server = await getRPCManager ( ) . getHorizonServer ( ) ;
635+ try {
636+ return await server . submitTransaction ( feeBumpTx ) ;
637+ } catch ( error ) {
638+ throw classifyError ( error ) ;
639+ }
640+ }
0 commit comments