diff --git a/src/main/java/com/webank/wecross/restserver/fetcher/TransactionFetcher.java b/src/main/java/com/webank/wecross/restserver/fetcher/TransactionFetcher.java index 77c09268..2a2d47e1 100644 --- a/src/main/java/com/webank/wecross/restserver/fetcher/TransactionFetcher.java +++ b/src/main/java/com/webank/wecross/restserver/fetcher/TransactionFetcher.java @@ -13,7 +13,6 @@ import com.webank.wecross.zone.Chain; import com.webank.wecross.zone.ZoneManager; import java.util.Objects; - import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -247,7 +246,8 @@ private void recursiveFetchTransactionList( response); } - if (block.transactionsHashes.isEmpty() && block.transactionsWithDetail.isEmpty()) { + if (block.transactionsHashes.isEmpty() + && block.transactionsWithDetail.isEmpty()) { // blank block response.setNextBlockNumber(blockNumber - 1); response.setNextOffset(0); @@ -266,24 +266,35 @@ private void recursiveFetchTransactionList( response); mainCallback.onResponse( new WeCrossException( - WeCrossException.ErrorCode.GET_BLOCK_ERROR, "Wrong offset"), + WeCrossException.ErrorCode.GET_BLOCK_ERROR, + "Wrong offset"), null); return; } for (index = offset; - index < block.transactionsWithDetail.size() && count > 0; - index++) { + index < block.transactionsWithDetail.size() && count > 0; + index++) { Transaction transaction = block.transactionsWithDetail.get(index); - if (Objects.nonNull(transaction) && StringUtils.isNotBlank(transaction.getTransactionResponse().getHash())) { + if (Objects.nonNull(transaction) + && StringUtils.isNotBlank( + transaction.getTransactionResponse().getHash())) { TransactionListResponse.TransactionWithDetail transactionDetail = new TransactionListResponse.TransactionWithDetail(); transactionDetail.setBlockNumber(blockNumber); - transactionDetail.setTxHash(transaction.getTransactionResponse().getHash()); + transactionDetail.setTxHash( + transaction.getTransactionResponse().getHash()); if (transaction.isTransactionByProxy()) { transactionDetail.setPath(transaction.getResource()); - transactionDetail.setAccountIdentity(transaction.getAccountIdentity()); - transactionDetail.setMethod(transaction.getTransactionRequest().getMethod()); - transactionDetail.setXaTransactionID((String) transaction.getTransactionRequest().getOptions().get(StubConstant.XA_TRANSACTION_ID)); + transactionDetail.setAccountIdentity( + transaction.getAccountIdentity()); + transactionDetail.setMethod( + transaction.getTransactionRequest().getMethod()); + transactionDetail.setXaTransactionID( + (String) + transaction + .getTransactionRequest() + .getOptions() + .get(StubConstant.XA_TRANSACTION_ID)); } response.addTransactionWithDetail(transactionDetail); count--; @@ -308,13 +319,14 @@ private void recursiveFetchTransactionList( response); mainCallback.onResponse( new WeCrossException( - WeCrossException.ErrorCode.GET_BLOCK_ERROR, "Wrong offset"), + WeCrossException.ErrorCode.GET_BLOCK_ERROR, + "Wrong offset"), null); return; } for (index = offset; - index < block.transactionsHashes.size() && count > 0; - index++) { + index < block.transactionsHashes.size() && count > 0; + index++) { // hash is blank if (!"".equals(block.transactionsHashes.get(index).trim())) { TransactionListResponse.Transaction transaction = diff --git a/src/main/java/com/webank/wecross/restserver/response/TransactionListResponse.java b/src/main/java/com/webank/wecross/restserver/response/TransactionListResponse.java index a9c3fca5..ede0150a 100644 --- a/src/main/java/com/webank/wecross/restserver/response/TransactionListResponse.java +++ b/src/main/java/com/webank/wecross/restserver/response/TransactionListResponse.java @@ -10,7 +10,9 @@ public class TransactionListResponse { private int nextOffset; private List transactions = Collections.synchronizedList(new LinkedList<>()); - private List transactionWithDetails = Collections.synchronizedList(new LinkedList<>()); + private List transactionWithDetails = + Collections.synchronizedList(new LinkedList<>()); + public TransactionListResponse() {} public void addTransactionWithDetail(TransactionWithDetail transactionWithDetail) { @@ -21,7 +23,6 @@ public void addTransactionWithDetails(List transactionWit this.transactionWithDetails.addAll(transactionWithDetails); } - public void addTransaction(Transaction transaction) { this.transactions.add(transaction); } @@ -164,15 +165,25 @@ public void setXaTransactionID(String xaTransactionID) { @Override public String toString() { - return "TransactionWithDetail{" + - "txHash='" + txHash + '\'' + - ", blockNumber=" + blockNumber + - ", accountIdentity='" + accountIdentity + '\'' + - ", path='" + path + '\'' + - ", method='" + method + '\'' + - ", xaTransactionID='" + xaTransactionID + '\'' + - '}'; + return "TransactionWithDetail{" + + "txHash='" + + txHash + + '\'' + + ", blockNumber=" + + blockNumber + + ", accountIdentity='" + + accountIdentity + + '\'' + + ", path='" + + path + + '\'' + + ", method='" + + method + + '\'' + + ", xaTransactionID='" + + xaTransactionID + + '\'' + + '}'; } } - } diff --git a/src/main/java/com/webank/wecross/stub/Block.java b/src/main/java/com/webank/wecross/stub/Block.java index 71a01ec8..d1a9f35d 100644 --- a/src/main/java/com/webank/wecross/stub/Block.java +++ b/src/main/java/com/webank/wecross/stub/Block.java @@ -9,7 +9,7 @@ public class Block { @JsonIgnore public byte[] rawBytes; public BlockHeader blockHeader; public List transactionsHashes = new LinkedList<>(); - public List transactionsWithDetail= new LinkedList<>(); + public List transactionsWithDetail = new LinkedList<>(); public BlockHeader getBlockHeader() { return blockHeader;