Skip to content

Commit

Permalink
<feat>(block): add block transaction details list
Browse files Browse the repository at this point in the history
<feat>(transactionFetcher): support transaction details list and transaction hash list
  • Loading branch information
lbhan2 committed Dec 11, 2023
1 parent a66e6cc commit b48726e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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--;
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class TransactionListResponse {
private int nextOffset;
private List<Transaction> transactions = Collections.synchronizedList(new LinkedList<>());

private List<TransactionWithDetail> transactionWithDetails = Collections.synchronizedList(new LinkedList<>());
private List<TransactionWithDetail> transactionWithDetails =
Collections.synchronizedList(new LinkedList<>());

public TransactionListResponse() {}

public void addTransactionWithDetail(TransactionWithDetail transactionWithDetail) {
Expand All @@ -21,7 +23,6 @@ public void addTransactionWithDetails(List<TransactionWithDetail> transactionWit
this.transactionWithDetails.addAll(transactionWithDetails);
}


public void addTransaction(Transaction transaction) {
this.transactions.add(transaction);
}
Expand Down Expand Up @@ -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
+ '\''
+ '}';
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/webank/wecross/stub/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Block {
@JsonIgnore public byte[] rawBytes;
public BlockHeader blockHeader;
public List<String> transactionsHashes = new LinkedList<>();
public List <Transaction> transactionsWithDetail= new LinkedList<>();
public List<Transaction> transactionsWithDetail = new LinkedList<>();

public BlockHeader getBlockHeader() {
return blockHeader;
Expand Down

0 comments on commit b48726e

Please sign in to comment.