@@ -9,11 +9,13 @@ use sncast::helpers::rpc::RpcArgs;
9
9
use sncast:: response:: declare:: {
10
10
AlreadyDeclaredResponse , DeclareResponse , DeclareTransactionResponse ,
11
11
} ;
12
- use sncast:: response:: errors:: StarknetCommandError ;
12
+ use sncast:: response:: errors:: { SNCastProviderError , SNCastStarknetError , StarknetCommandError } ;
13
13
use sncast:: { ErrorData , WaitForTx , apply_optional_fields, handle_wait_for_tx} ;
14
14
use starknet:: accounts:: AccountError :: Provider ;
15
15
use starknet:: accounts:: { ConnectedAccount , DeclarationV3 } ;
16
- use starknet:: core:: types:: { DeclareTransactionResult , StarknetError } ;
16
+ use starknet:: core:: types:: {
17
+ ContractExecutionError , DeclareTransactionResult , StarknetError , TransactionExecutionErrorData ,
18
+ } ;
17
19
use starknet:: providers:: ProviderError ;
18
20
use starknet:: {
19
21
accounts:: { Account , SingleOwnerAccount } ,
@@ -157,6 +159,22 @@ pub async fn declare_with_artifacts(
157
159
class_hash : class_hash. into_ ( ) ,
158
160
} ) )
159
161
}
162
+ Err ( Provider ( ProviderError :: StarknetError ( StarknetError :: TransactionExecutionError (
163
+ TransactionExecutionErrorData {
164
+ execution_error : ContractExecutionError :: Message ( message) ,
165
+ ..
166
+ } ,
167
+ ) ) ) ) if message. contains ( "is already declared" ) => {
168
+ if skip_on_already_declared {
169
+ Ok ( DeclareResponse :: AlreadyDeclared ( AlreadyDeclaredResponse {
170
+ class_hash : class_hash. into_ ( ) ,
171
+ } ) )
172
+ } else {
173
+ Err ( StarknetCommandError :: ProviderError (
174
+ SNCastProviderError :: StarknetError ( SNCastStarknetError :: ClassAlreadyDeclared ) ,
175
+ ) )
176
+ }
177
+ }
160
178
Err ( Provider ( error) ) => Err ( StarknetCommandError :: ProviderError ( error. into ( ) ) ) ,
161
179
Err ( error) => Err ( anyhow ! ( format!( "Unexpected error occurred: {error}" ) ) . into ( ) ) ,
162
180
}
0 commit comments