@@ -81,7 +81,7 @@ await Profiler.Run("RequestAirdrop", async () => {
8181 } ) ;
8282 }
8383
84- public async Task < string > SendAndConfirmInstruction ( IRpcClient client , TransactionInstruction instruction , List < Account > ? signers = null , PublicKey ? payer = null )
84+ public async Task < string > SendAndConfirmInstruction ( IRpcClient client , TransactionInstruction instruction , List < Account > ? signers = null , PublicKey ? payer = null , bool mayFail = false )
8585 {
8686 if ( signers == null ) {
8787 signers = new List < Account > { Wallet . Account } ;
@@ -96,23 +96,31 @@ public async Task<string> SendAndConfirmInstruction(IRpcClient client, Transacti
9696 . AddInstruction ( instruction )
9797 . Build ( signers ) ;
9898
99- var signature = await client . SendTransactionAsync ( transaction , true , Commitment . Processed ) ;
99+ var signature = await client . SendTransactionAsync ( transaction , false , Commitment . Processed ) ;
100100 var confirmed = await client . ConfirmTransaction ( signature . Result , Commitment . Processed ) ;
101101 if ( signature . WasSuccessful && confirmed )
102102 {
103103 return signature . Result ;
104104 }
105- string errorMessage = signature . Reason . ToString ( ) ;
106- errorMessage += "\n " + signature . RawRpcResponse ;
107- if ( signature . ErrorData != null ) {
108- errorMessage += "\n " + string . Join ( "\n " , signature . ErrorData . Logs ) ;
105+
106+ if ( mayFail ) {
107+ return null ;
108+ } else {
109+ string errorMessage = signature . Reason . ToString ( ) ;
110+ errorMessage += "\n " + signature . RawRpcResponse ;
111+ if ( signature . ErrorData != null ) {
112+ errorMessage += "\n " + string . Join ( "\n " , signature . ErrorData . Logs ) ;
113+ }
114+
115+ Console . WriteLine ( errorMessage ) ;
116+ Environment . Exit ( 1 ) ;
117+ return null ;
109118 }
110- throw new Exception ( errorMessage ) ;
111119 }
112120
113- public async Task < string > SendAndConfirmInstruction ( TransactionInstruction instruction , List < Account > ? signers = null , PublicKey ? payer = null )
121+ public async Task < string > SendAndConfirmInstruction ( TransactionInstruction instruction , List < Account > ? signers = null , PublicKey ? payer = null , bool mayFail = false )
114122 {
115- return await SendAndConfirmInstruction ( Client , instruction , signers , payer ) ;
123+ return await SendAndConfirmInstruction ( Client , instruction , signers , payer , mayFail ) ;
116124 }
117125
118126 public async Task < AccountInfo > GetAccountInfo ( IRpcClient client , PublicKey publicKey )
0 commit comments