@@ -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 } ,
@@ -133,6 +135,7 @@ pub async fn declare_with_artifacts(
133
135
) ;
134
136
135
137
let declared = declaration. send ( ) . await ;
138
+ dbg ! ( & declared) ;
136
139
137
140
match declared {
138
141
Ok ( DeclareTransactionResult {
@@ -157,6 +160,26 @@ pub async fn declare_with_artifacts(
157
160
class_hash : class_hash. into_ ( ) ,
158
161
} ) )
159
162
}
163
+ Err ( Provider ( ProviderError :: StarknetError ( StarknetError :: TransactionExecutionError (
164
+ TransactionExecutionErrorData {
165
+ execution_error : ContractExecutionError :: Message ( message) ,
166
+ ..
167
+ } ,
168
+ ) ) ) ) if message. contains ( "is already declared" ) && skip_on_already_declared => {
169
+ Ok ( DeclareResponse :: AlreadyDeclared ( AlreadyDeclaredResponse {
170
+ class_hash : class_hash. into_ ( ) ,
171
+ } ) )
172
+ }
173
+ Err ( Provider ( ProviderError :: StarknetError ( StarknetError :: TransactionExecutionError (
174
+ TransactionExecutionErrorData {
175
+ execution_error : ContractExecutionError :: Message ( message) ,
176
+ ..
177
+ } ,
178
+ ) ) ) ) if message. contains ( "is already declared" ) => {
179
+ Err ( StarknetCommandError :: ProviderError (
180
+ SNCastProviderError :: StarknetError ( SNCastStarknetError :: ClassAlreadyDeclared ) ,
181
+ ) )
182
+ }
160
183
Err ( Provider ( error) ) => Err ( StarknetCommandError :: ProviderError ( error. into ( ) ) ) ,
161
184
Err ( error) => Err ( anyhow ! ( format!( "Unexpected error occurred: {error}" ) ) . into ( ) ) ,
162
185
}
0 commit comments