@@ -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,26 @@ 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" ) && skip_on_already_declared => {
168
+ Ok ( DeclareResponse :: AlreadyDeclared ( AlreadyDeclaredResponse {
169
+ class_hash : class_hash. into_ ( ) ,
170
+ } ) )
171
+ }
172
+ Err ( Provider ( ProviderError :: StarknetError ( StarknetError :: TransactionExecutionError (
173
+ TransactionExecutionErrorData {
174
+ execution_error : ContractExecutionError :: Message ( message) ,
175
+ ..
176
+ } ,
177
+ ) ) ) ) if message. contains ( "is already declared" ) => {
178
+ Err ( StarknetCommandError :: ProviderError (
179
+ SNCastProviderError :: StarknetError ( SNCastStarknetError :: ClassAlreadyDeclared ) ,
180
+ ) )
181
+ }
160
182
Err ( Provider ( error) ) => Err ( StarknetCommandError :: ProviderError ( error. into ( ) ) ) ,
161
183
Err ( error) => Err ( anyhow ! ( format!( "Unexpected error occurred: {error}" ) ) . into ( ) ) ,
162
184
}
0 commit comments