1010import com .platon .protocol .core .DefaultBlockParameter ;
1111import com .platon .protocol .core .DefaultBlockParameterName ;
1212import com .platon .protocol .core .RemoteCall ;
13+ import com .platon .protocol .core .Response ;
1314import com .platon .protocol .core .methods .request .Transaction ;
1415import com .platon .protocol .core .methods .response .Log ;
1516import com .platon .protocol .core .methods .response .PlatonCall ;
1617import com .platon .protocol .core .methods .response .PlatonGetCode ;
1718import com .platon .protocol .core .methods .response .TransactionReceipt ;
1819import com .platon .protocol .exceptions .TransactionException ;
1920import com .platon .tx .exceptions .ContractCallException ;
21+ import com .platon .tx .exceptions .PlatonCallException ;
22+ import com .platon .tx .exceptions .PlatonCallTimeoutException ;
2023import com .platon .tx .gas .DefaultGasProvider ;
2124import com .platon .tx .gas .GasProvider ;
2225import com .platon .utils .Numeric ;
26+ import com .platon .utils .Strings ;
2327
2428import java .io .IOException ;
2529import java .lang .reflect .Constructor ;
@@ -149,6 +153,20 @@ private List<Type> executeCall(
149153 defaultBlockParameter )
150154 .send ();
151155
156+ //判断底层返回的错误信息是否包含超时信息
157+ if (ethCall .hasError ()){
158+ Response .Error error = ethCall .getError ();
159+ String message = error .getMessage ();
160+ String lowMessage = !Strings .isBlank (message )? message .toLowerCase () : null ;
161+ //包含timeout则抛超时异常,其他错误则直接抛出runtime异常
162+ if (!Strings .isBlank (lowMessage )
163+ && lowMessage .contains ("timeout" )){
164+ throw new PlatonCallTimeoutException (error .getCode (),error .getMessage (),ethCall );
165+ } else {
166+ throw new PlatonCallException (error .getCode (),error .getMessage (),ethCall );
167+ }
168+ }
169+
152170 String value = ethCall .getValue ();
153171 return FunctionReturnDecoder .decode (value , function .getOutputParameters ());
154172 }
@@ -268,7 +286,7 @@ private static <T extends Contract> T create(
268286 return contract ;
269287 }
270288
271- protected static <T extends Contract > T deploy (Class <T > type , Web3j web3j , Credentials credentials , GasProvider contractGasProvider , String binary , String encodedConstructor , BigInteger value ) throws RuntimeException , TransactionException {
289+ protected static <T extends Contract > T deploy (Class <T > type , Web3j web3j , Credentials credentials , GasProvider contractGasProvider , String binary , String encodedConstructor , BigInteger value ) throws RuntimeException , TransactionException , IOException {
272290
273291 try {
274292 Constructor <T > constructor = type .getDeclaredConstructor (String .class , Web3j .class , Credentials .class , GasProvider .class );
@@ -280,12 +298,14 @@ protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Crede
280298 return create (contract , binary , encodedConstructor , value );
281299 } catch (TransactionException e ) {
282300 throw e ;
301+ } catch (IOException e ) {
302+ throw e ;
283303 } catch (Exception e ) {
284304 throw new RuntimeException (e );
285305 }
286306 }
287307
288- protected static <T extends Contract > T deploy (Class <T > type , Web3j web3j , TransactionManager transactionManager , GasProvider contractGasProvider , String binary , String encodedConstructor , BigInteger value ) throws RuntimeException , TransactionException {
308+ protected static <T extends Contract > T deploy (Class <T > type , Web3j web3j , TransactionManager transactionManager , GasProvider contractGasProvider , String binary , String encodedConstructor , BigInteger value ) throws RuntimeException , TransactionException , IOException {
289309
290310 try {
291311 Constructor <T > constructor = type .getDeclaredConstructor (String .class , Web3j .class , TransactionManager .class , GasProvider .class );
@@ -296,6 +316,8 @@ protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Trans
296316 return create (contract , binary , encodedConstructor , value );
297317 } catch (TransactionException e ) {
298318 throw e ;
319+ } catch (IOException e ) {
320+ throw e ;
299321 } catch (Exception e ) {
300322 throw new RuntimeException (e );
301323 }
0 commit comments