@@ -95,12 +95,19 @@ func (s *Solana) BroadcastTx(ctx context.Context, tx *solana.Transaction) (solan
9595 )
9696}
9797
98- func (s * Solana ) WaitForTxConfirmation (txSig solana.Signature ) error {
99- return s .WaitForTxStatus (txSig , rpc .ConfirmationStatusConfirmed )
100- }
101-
102- func (s * Solana ) WaitForTxFinalization (txSig solana.Signature ) error {
103- return s .WaitForTxStatus (txSig , rpc .ConfirmationStatusFinalized )
98+ // confirmationStatusLevel returns a numeric level for comparison.
99+ // Higher numbers indicate higher confirmation levels.
100+ func confirmationStatusLevel (status rpc.ConfirmationStatusType ) int {
101+ switch status {
102+ case rpc .ConfirmationStatusProcessed :
103+ return 1
104+ case rpc .ConfirmationStatusConfirmed :
105+ return 2
106+ case rpc .ConfirmationStatusFinalized :
107+ return 3
108+ default :
109+ return 0
110+ }
104111}
105112
106113func (s * Solana ) WaitForTxStatus (txSig solana.Signature , status rpc.ConfirmationStatusType ) error {
@@ -114,7 +121,7 @@ func (s *Solana) WaitForTxStatus(txSig solana.Signature, status rpc.Confirmation
114121 return false , fmt .Errorf ("transaction %s failed with error: %s" , txSig , out .Value [0 ].Err )
115122 }
116123
117- if out .Value [0 ].ConfirmationStatus == status {
124+ if confirmationStatusLevel ( out .Value [0 ].ConfirmationStatus ) >= confirmationStatusLevel ( status ) {
118125 return true , nil
119126 }
120127 return false , nil
@@ -142,7 +149,7 @@ func (s *Solana) FundUser(pubkey solana.PublicKey, amount uint64) (solana.Signat
142149 return solana.Signature {}, err
143150 }
144151
145- return s .SignAndBroadcastTx (context .TODO (), tx , s .Faucet )
152+ return s .SignAndBroadcastTxWithConfirmedStatus (context .TODO (), tx , s .Faucet )
146153}
147154
148155func (s * Solana ) CreateAndFundWallet () (* solana.Wallet , error ) {
@@ -170,12 +177,10 @@ func (s *Solana) WaitForProgramAvailabilityWithTimeout(ctx context.Context, prog
170177 return false
171178}
172179
173- // SignAndBroadcastTxWithRetry retries transaction broadcasting with default timeout
174180func (s * Solana ) SignAndBroadcastTxWithRetry (ctx context.Context , tx * solana.Transaction , wallet * solana.Wallet ) (solana.Signature , error ) {
175181 return s .SignAndBroadcastTxWithRetryTimeout (ctx , tx , wallet , 30 )
176182}
177183
178- // SignAndBroadcastTxWithRetryTimeout retries transaction broadcasting with specified timeout
179184func (s * Solana ) SignAndBroadcastTxWithRetryTimeout (ctx context.Context , tx * solana.Transaction , wallet * solana.Wallet , timeoutSeconds int ) (solana.Signature , error ) {
180185 var lastErr error
181186 for range timeoutSeconds {
@@ -189,6 +194,35 @@ func (s *Solana) SignAndBroadcastTxWithRetryTimeout(ctx context.Context, tx *sol
189194 return solana.Signature {}, fmt .Errorf ("transaction broadcast timed out after %d seconds: %w" , timeoutSeconds , lastErr )
190195}
191196
197+ func (s * Solana ) SignAndBroadcastTxWithConfirmedStatus (ctx context.Context , tx * solana.Transaction , wallet * solana.Wallet ) (solana.Signature , error ) {
198+ return s .SignAndBroadcastTxWithOpts (ctx , tx , wallet , rpc .ConfirmationStatusConfirmed )
199+ }
200+
201+ func (s * Solana ) SignAndBroadcastTxWithOpts (ctx context.Context , tx * solana.Transaction , wallet * solana.Wallet , status rpc.ConfirmationStatusType ) (solana.Signature , error ) {
202+ _ , err := s .SignTx (ctx , tx , wallet )
203+ if err != nil {
204+ return solana.Signature {}, err
205+ }
206+
207+ sig , err := s .RPCClient .SendTransactionWithOpts (
208+ ctx ,
209+ tx ,
210+ rpc.TransactionOpts {
211+ SkipPreflight : true ,
212+ },
213+ )
214+ if err != nil {
215+ return solana.Signature {}, err
216+ }
217+
218+ err = s .WaitForTxStatus (sig , status )
219+ if err != nil {
220+ return solana.Signature {}, err
221+ }
222+
223+ return sig , err
224+ }
225+
192226// WaitForBalanceChange waits for an account balance to change from the initial value
193227func (s * Solana ) WaitForBalanceChange (ctx context.Context , account solana.PublicKey , initialBalance uint64 ) (uint64 , bool ) {
194228 return s .WaitForBalanceChangeWithTimeout (ctx , account , initialBalance , 30 )
@@ -197,7 +231,7 @@ func (s *Solana) WaitForBalanceChange(ctx context.Context, account solana.Public
197231// WaitForBalanceChangeWithTimeout waits for an account balance to change with specified timeout
198232func (s * Solana ) WaitForBalanceChangeWithTimeout (ctx context.Context , account solana.PublicKey , initialBalance uint64 , timeoutSeconds int ) (uint64 , bool ) {
199233 for range timeoutSeconds {
200- balanceResp , err := s .RPCClient .GetBalance (ctx , account , "confirmed" )
234+ balanceResp , err := s .RPCClient .GetBalance (ctx , account , rpc . CommitmentConfirmed )
201235 if err == nil {
202236 currentBalance := balanceResp .Value
203237 if currentBalance != initialBalance {
0 commit comments