@@ -55,20 +55,16 @@ public AccountSequence getAccountSequence(String address) {
5555
5656 @ Override
5757 public Infos getNodeInfo () {
58- try {
59- JsonRpcResponse <NodeInfos > rpcResponse = binanceDexNodeApi .getNodeStatus ().execute ().body ();
60- checkRpcResult (rpcResponse );
61- NodeInfos nodeInfos = rpcResponse .getResult ();
62- return convert (nodeInfos );
63- } catch (IOException e ) {
64- throw new RuntimeException (e );
65- }
58+ JsonRpcResponse <NodeInfos > rpcResponse = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi .getNodeStatus ());
59+ checkRpcResult (rpcResponse );
60+ NodeInfos nodeInfos = rpcResponse .getResult ();
61+ return convert (nodeInfos );
6662 }
6763
6864 @ Override
6965 public List <Fees > getFees () {
7066 try {
71- JsonRpcResponse <ABCIQueryResult > rpcResponse = binanceDexNodeApi .getFees (). execute (). body ( );
67+ JsonRpcResponse <ABCIQueryResult > rpcResponse = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getFees ());
7268 checkRpcResult (rpcResponse );
7369 byte [] value = rpcResponse .getResult ().getResponse ().getValue ();
7470 int startIndex = 2 ;
@@ -87,7 +83,7 @@ public List<Fees> getFees() {
8783 public Account getAccount (String address ) {
8884 String encodedAddress = "0x" + ARG_ACCOUNT_PREFIX + Hex .toHexString (Crypto .decodeAddress (address ));
8985 try {
90- JsonRpcResponse <AccountResult > response = binanceDexNodeApi .getAccount (encodedAddress ). execute (). body ( );
86+ JsonRpcResponse <AccountResult > response = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getAccount (encodedAddress ));
9187 checkRpcResult (response );
9288 if (response .getResult ().getResponse ().getValue () != null ){
9389 byte [] value = response .getResult ().getResponse ().getValue ();
@@ -104,23 +100,19 @@ public Account getAccount(String address) {
104100
105101 @ Override
106102 public List <Transaction > getBlockTransactions (Long height ) {
107- try {
108- JsonRpcResponse <BlockInfoResult > response = binanceDexNodeApi
109- .getBlockTransactions ("\" tx.height=" + height .toString () + "\" " ).execute ().body ();
110- checkRpcResult (response );
111- return response .getResult ().getTxs ().stream ()
112- .map (transactionConverter ::convert )
113- .flatMap (List ::stream )
114- .collect (Collectors .toList ());
115- } catch (IOException e ) {
116- throw new RuntimeException (e );
117- }
103+ JsonRpcResponse <BlockInfoResult > response = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi
104+ .getBlockTransactions ("\" tx.height=" + height .toString () + "\" " ));
105+ checkRpcResult (response );
106+ return response .getResult ().getTxs ().stream ()
107+ .map (transactionConverter ::convert )
108+ .flatMap (List ::stream )
109+ .collect (Collectors .toList ());
118110 }
119111
120112 @ Override
121113 public Transaction getTransaction (String hash ) {
122114 try {
123- JsonRpcResponse <TransactionResult > rpcResponse = binanceDexNodeApi .getTransaction ("0x" + hash ). execute (). body ( );
115+ JsonRpcResponse <TransactionResult > rpcResponse = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getTransaction ("0x" + hash ));
124116 checkRpcResult (rpcResponse );
125117 TransactionResult transactionResult = rpcResponse .getResult ();
126118 byte [] txBytes = transactionResult .getTx ();
@@ -152,25 +144,17 @@ public Transaction getTransaction(String hash) {
152144
153145 @ Override
154146 public BlockMeta getBlockMetaByHeight (Long height ) {
155- try {
156- JsonRpcResponse <BlockMeta .BlockMetaResult > rpcResponse = binanceDexNodeApi .getBlock (height ).execute ().body ();
157- checkRpcResult (rpcResponse );
158- BlockMeta .BlockMetaResult result = rpcResponse .getResult ();
159- return result .getBlockMeta ();
160- } catch (Exception e ) {
161- throw new RuntimeException (e );
162- }
147+ JsonRpcResponse <BlockMeta .BlockMetaResult > rpcResponse = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi .getBlock (height ));
148+ checkRpcResult (rpcResponse );
149+ BlockMeta .BlockMetaResult result = rpcResponse .getResult ();
150+ return result .getBlockMeta ();
163151 }
164152
165153 @ Override
166154 public BlockMeta getBlockMetaByHash (String hash ) {
167155 try {
168- JsonRpcResponse <BlockMeta .BlockMetaResult > rpcResponse = binanceDexNodeApi .getBlock ("0x" + hash ). execute (). body ( );
156+ JsonRpcResponse <BlockMeta .BlockMetaResult > rpcResponse = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getBlock ("0x" + hash ));
169157 checkRpcResult (rpcResponse );
170- if (null != rpcResponse .getError () && null != rpcResponse .getError ().getCode () && rpcResponse .getError ().getCode ().intValue () != 0 ) {
171- throw new RuntimeException (rpcResponse .getError ().toString ());
172- }
173-
174158 BlockMeta .BlockMetaResult result = rpcResponse .getResult ();
175159 return result .getBlockMeta ();
176160 } catch (Exception e ) {
@@ -182,7 +166,7 @@ public BlockMeta getBlockMetaByHash(String hash) {
182166 public com .binance .dex .api .client .domain .Token getTokenInfoBySymbol (String symbol ) {
183167 try {
184168 String pathWithSymbol = "\" tokens/info/" + symbol + "\" " ;
185- JsonRpcResponse <ABCIQueryResult > rpcResponse = binanceDexNodeApi .getTokenInfo (pathWithSymbol ). execute (). body ( );
169+ JsonRpcResponse <ABCIQueryResult > rpcResponse = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getTokenInfo (pathWithSymbol ));
186170 checkRpcResult (rpcResponse );
187171 byte [] value = rpcResponse .getResult ().getResponse ().getValue ();
188172 int startIndex = getStartIndex (value );
@@ -197,22 +181,18 @@ public com.binance.dex.api.client.domain.Token getTokenInfoBySymbol(String symbo
197181
198182 @ Override
199183 public List <StakeValidator > getStakeValidator () {
200- try {
201- JsonRpcResponse <ABCIQueryResult > rpcResponse = binanceDexNodeApi .getStakeValidators ().execute ().body ();
202- checkRpcResult (rpcResponse );
203- byte [] value = rpcResponse .getResult ().getResponse ().getValue ();
204- return StakeValidator .fromJsonToArray (new String (value ), hrp );
205- } catch (IOException e ) {
206- throw new RuntimeException (e );
207- }
184+ JsonRpcResponse <ABCIQueryResult > rpcResponse = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi .getStakeValidators ());
185+ checkRpcResult (rpcResponse );
186+ byte [] value = rpcResponse .getResult ().getResponse ().getValue ();
187+ return StakeValidator .fromJsonToArray (new String (value ), hrp );
208188 }
209189
210190 @ Override
211191 public Proposal getProposalById (String proposalId ) {
212192 try {
213193 Map .Entry proposalIdEntry = Maps .immutableEntry ("ProposalID" , proposalId );
214194 String requestData = "0x" + Hex .toHexString (EncodeUtils .toJsonStringSortKeys (proposalIdEntry ).getBytes ());
215- JsonRpcResponse <ABCIQueryResult > rpcResponse = binanceDexNodeApi .getProposalById (requestData ). execute (). body ( );
195+ JsonRpcResponse <ABCIQueryResult > rpcResponse = BinanceDexApiClientGenerator . executeSync ( binanceDexNodeApi .getProposalById (requestData ));
216196 checkRpcResult (rpcResponse );
217197 ABCIQueryResult .Response response = rpcResponse .getResult ().getResponse ();
218198 if (response .getCode () != null ) {
@@ -313,13 +293,11 @@ protected com.binance.dex.api.client.domain.Token convert(TokenInfo tokenInfo) {
313293
314294 protected List <TransactionMetadata > syncBroadcast (String requestBody , Wallet wallet ) {
315295 try {
316- CommitBroadcastResult commitBroadcastResult = binanceDexNodeApi .commitBroadcast (requestBody ).execute ().body ().getResult ();
296+ JsonRpcResponse <CommitBroadcastResult > rpcResponse = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi .commitBroadcast (requestBody ));
297+ CommitBroadcastResult commitBroadcastResult = rpcResponse .getResult ();
317298 TransactionMetadata transactionMetadata = new TransactionMetadata ();
318299 transactionMetadata .setCode (commitBroadcastResult .getCheckTx ().getCode ());
319- if (commitBroadcastResult != null
320- && commitBroadcastResult .getHeight () != null
321- && StringUtils .isNoneBlank (commitBroadcastResult .getHash ())
322- && transactionMetadata .getCode () == 0 ) {
300+ if (commitBroadcastResult .getHeight () != null && StringUtils .isNoneBlank (commitBroadcastResult .getHash ()) && transactionMetadata .getCode () == 0 ) {
323301 wallet .increaseAccountSequence ();
324302 transactionMetadata .setHash (commitBroadcastResult .getHash ());
325303 transactionMetadata .setHeight (commitBroadcastResult .getHeight ());
@@ -331,21 +309,22 @@ protected List<TransactionMetadata> syncBroadcast(String requestBody, Wallet wal
331309 }
332310
333311 return Lists .newArrayList (transactionMetadata );
334- } catch (BinanceDexApiException | IOException e ) {
312+ } catch (BinanceDexApiException e ) {
335313 wallet .invalidAccountSequence ();
336314 throw new RuntimeException (e );
337315 }
338316 }
339317
340318 protected List <TransactionMetadata > asyncBroadcast (String requestBody , Wallet wallet ) {
341319 try {
342- AsyncBroadcastResult asyncBroadcastResult = binanceDexNodeApi .asyncBroadcast (requestBody ).execute ().body ().getResult ();
320+ JsonRpcResponse <AsyncBroadcastResult > rpcResponse = BinanceDexApiClientGenerator .executeSync (binanceDexNodeApi .asyncBroadcast (requestBody ));
321+ AsyncBroadcastResult asyncBroadcastResult = rpcResponse .getResult ();
343322 TransactionMetadata transactionMetadata = new TransactionMetadata ();
344323
345324 transactionMetadata .setCode (asyncBroadcastResult .getCode ());
346325 transactionMetadata .setLog (asyncBroadcastResult .getLog ());
347326
348- if (asyncBroadcastResult != null && asyncBroadcastResult .getCode (). intValue () == 0 ) {
327+ if (asyncBroadcastResult .getCode () == 0 ) {
349328 wallet .increaseAccountSequence ();
350329 transactionMetadata .setHash (asyncBroadcastResult .getHash ());
351330 transactionMetadata .setData (asyncBroadcastResult .getData ());
@@ -356,7 +335,7 @@ protected List<TransactionMetadata> asyncBroadcast(String requestBody, Wallet wa
356335 }
357336
358337 return Lists .newArrayList (transactionMetadata );
359- } catch (BinanceDexApiException | IOException e ) {
338+ } catch (BinanceDexApiException e ) {
360339 wallet .invalidAccountSequence ();
361340 throw new RuntimeException (e );
362341 }
0 commit comments