Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<feat>(ClientWrapper): add block transactions details #151

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {

// WeCross

implementation ('com.webank:wecross-java-stub:1.3.2-SNAPSHOT') {
implementation ('com.webank:wecross-java-stub:1.4.0-SNAPSHOT') {
exclude group: 'org.fisco-bcos', module: 'tcnative'
}
configurations.compile.exclude(group: 'ch.qos.logback')
Expand Down
63 changes: 58 additions & 5 deletions src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
import static com.webank.wecross.utils.FabricUtils.longToBytes;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.webank.wecross.account.FabricAccount;
import com.webank.wecross.account.FabricAccountFactory;
import com.webank.wecross.common.FabricType;
import com.webank.wecross.stub.*;
import com.webank.wecross.stub.Account;
import com.webank.wecross.stub.Block;
import com.webank.wecross.stub.BlockManager;
import com.webank.wecross.stub.Connection;
import com.webank.wecross.stub.Driver;
import com.webank.wecross.stub.Path;
import com.webank.wecross.stub.Request;
import com.webank.wecross.stub.ResourceInfo;
import com.webank.wecross.stub.Response;
import com.webank.wecross.stub.StubConstant;
import com.webank.wecross.stub.Transaction;
import com.webank.wecross.stub.TransactionContext;
import com.webank.wecross.stub.TransactionException;
import com.webank.wecross.stub.TransactionRequest;
import com.webank.wecross.stub.TransactionResponse;
import com.webank.wecross.stub.fabric.FabricCustomCommand.InstallChaincodeRequest;
import com.webank.wecross.stub.fabric.FabricCustomCommand.InstallCommand;
import com.webank.wecross.stub.fabric.FabricCustomCommand.InstantiateChaincodeRequest;
Expand All @@ -21,7 +36,9 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.hyperledger.fabric.protos.common.Common;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -396,7 +413,6 @@ public void asyncGetBlock(
block.setRawBytes(response.getData());

FabricBlock fabricBlock = null;
List<String> transactionsHashes = new ArrayList<>();
try {
fabricBlock = FabricBlock.encode(response.getData());
if (blockVerifierString != null) {
Expand Down Expand Up @@ -425,11 +441,48 @@ public void asyncGetBlock(
}

if (!onlyHeader) {
transactionsHashes = new ArrayList<>(fabricBlock.getValidTxs());
Common.Block b = Common.Block.parseFrom(response.getData());
List<ByteString> dataList = b.getData().getDataList();
for (ByteString data : dataList) {
try {
Common.Envelope envelope = Common.Envelope.parseFrom(data);
String payload = envelope.toString();
int from = payload.indexOf("-----BEGIN CERTIFICATE-----");
int end = payload.indexOf("-----END CERTIFICATE-----");
String identity =
payload.substring(from, end)
+ "-----END CERTIFICATE-----\n";
FabricTransaction fabricTransaction =
FabricTransaction.buildFromEnvelopeBytes(
envelope.toByteArray());
if (StringUtils.isBlank(fabricTransaction.getTxID())) {
continue;
}
Transaction transaction =
parseFabricTransaction(fabricTransaction);
transaction
.getTransactionResponse()
.setErrorCode(
FabricType.TransactionResponseStatus
.SUCCESS);
transaction.setAccountIdentity(identity);
transaction
.getTransactionResponse()
.setHash(fabricTransaction.getTxID());
transaction.setTxBytes(data.toByteArray());
transaction
.getTransactionResponse()
.setBlockNumber(blockNumber);
block.getTransactionsWithDetail().add(transaction);
} catch (InvalidProtocolBufferException e) {
logger.warn(
"Invalid fabric block transactions,blockNumber: {},e: {}",
blockNumber,
e.getMessage());
}
}
}
block.setBlockHeader(fabricBlock.dumpWeCrossHeader());
block.setTransactionsHashes(transactionsHashes);

callback.onResponse(null, block);
} catch (Exception e) {
String errorMsg =
Expand Down
Loading