diff --git a/.github/workflows/ci_check.yml b/.github/workflows/ci_check.yml index 6bfae39..91d0a2a 100644 --- a/.github/workflows/ci_check.yml +++ b/.github/workflows/ci_check.yml @@ -7,7 +7,7 @@ on: pull_request jobs: ubuntu1804jdk8: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up JDK 1.8 @@ -20,7 +20,7 @@ jobs: run: bash <(curl -s https://codecov.io/bash) ubuntu1804jdk11: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up JDK 11 diff --git a/build.gradle b/build.gradle index 1798e16..98005ac 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'com.github.sherter.google-java-format' version '0.8' - id 'com.github.johnrengelman.shadow' version '5.2.0' + id 'com.github.johnrengelman.shadow' version '6.1.0' id 'org.ajoberstar.grgit' version '4.0.1' id 'maven-publish' } @@ -72,7 +72,7 @@ dependencies { // WeCross - implementation ('com.webank:wecross-java-stub:1.3.0') { + implementation ('com.webank:wecross-java-stub:1.3.2-SNAPSHOT') { exclude group: 'org.fisco-bcos', module: 'tcnative' } configurations.compile.exclude(group: 'ch.qos.logback') diff --git a/src/main/java/com/webank/wecross/stub/fabric/FabricBlock.java b/src/main/java/com/webank/wecross/stub/fabric/FabricBlock.java index 9b5117a..762d320 100644 --- a/src/main/java/com/webank/wecross/stub/fabric/FabricBlock.java +++ b/src/main/java/com/webank/wecross/stub/fabric/FabricBlock.java @@ -72,6 +72,15 @@ public BlockHeader dumpWeCrossHeader() { blockHeader.setHash(this.getHash()); blockHeader.setPrevHash(header.getPrevHash()); blockHeader.setTransactionRoot(header.getDataHash()); + try { + Common.Envelope envelope = Common.Envelope.parseFrom(blockData.blockData.getData(0)); + Common.Payload payload = Common.Payload.parseFrom(envelope.getPayload()); + Common.ChannelHeader channelHeader = + Common.ChannelHeader.parseFrom(payload.getHeader().getChannelHeader()); + blockHeader.setTimestamp(channelHeader.getTimestamp().getSeconds()); + } catch (Exception ignored) { + blockHeader.setTimestamp(0); + } return blockHeader; } diff --git a/src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java b/src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java index c269e36..1971efd 100644 --- a/src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java +++ b/src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java @@ -498,7 +498,7 @@ public void asyncGetTransaction( blockNumber, blockManager, hasOnChain -> { - if (!hasOnChain.booleanValue()) { + if (!hasOnChain) { callback.onResponse( new Exception( "Transaction proof verify failed. Tx(" @@ -597,15 +597,17 @@ private void asyncSendTransactionHandleOrdererResponse( + txBlockNumber + ")"); } else { + FabricTransaction fabricTransaction = + FabricTransaction.buildFromPayloadBytes( + ordererPayloadToSign); response = decodeTransactionResponse( - FabricTransaction.buildFromPayloadBytes( - ordererPayloadToSign) - .getOutputBytes()); + fabricTransaction.getOutputBytes()); response.setHash(txID); response.setBlockNumber(txBlockNumber); response.setErrorCode( FabricType.TransactionResponseStatus.SUCCESS); + response.setTimestamp(fabricTransaction.getTimestamp()); response.setMessage("Success"); transactionException = TransactionException.Builder.newSuccessException(); @@ -1195,6 +1197,7 @@ private Transaction parseFabricTransaction(FabricTransaction fabricTransaction) ByteString payload = ByteString.copyFrom(outputBytes); String[] output = new String[] {payload.toStringUtf8()}; transaction.getTransactionResponse().setResult(output); + transaction.getTransactionResponse().setTimestamp(fabricTransaction.getTimestamp()); /** xa */ transaction.setTransactionByProxy(byProxy); diff --git a/src/main/java/com/webank/wecross/stub/fabric/FabricTransaction.java b/src/main/java/com/webank/wecross/stub/fabric/FabricTransaction.java index b150af5..cd6b8f0 100644 --- a/src/main/java/com/webank/wecross/stub/fabric/FabricTransaction.java +++ b/src/main/java/com/webank/wecross/stub/fabric/FabricTransaction.java @@ -1,6 +1,7 @@ package com.webank.wecross.stub.fabric; import com.google.protobuf.ByteString; +import com.google.protobuf.Timestamp; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.LinkedList; @@ -17,14 +18,20 @@ public class FabricTransaction { private List transactionActionList = new ArrayList<>(); private String txID; + private long timestamp = 0; + FabricTransaction(byte[] payloadBytes) throws Exception { Common.Payload transactionPayload = Common.Payload.parseFrom(payloadBytes); this.header = transactionPayload.getHeader(); - this.txID = Common.ChannelHeader.parseFrom(header.getChannelHeader()).getTxId(); + Common.ChannelHeader channelHeader = + Common.ChannelHeader.parseFrom(header.getChannelHeader()); + this.txID = channelHeader.getTxId(); this.transaction = org.hyperledger.fabric.protos.peer.FabricTransaction.Transaction.parseFrom( transactionPayload.getData()); + Timestamp ts = channelHeader.getTimestamp(); + this.timestamp = ts.getSeconds(); for (org.hyperledger.fabric.protos.peer.FabricTransaction.TransactionAction action : transaction.getActionsList()) { transactionActionList.add(new TransactionAction(action)); @@ -74,6 +81,10 @@ public byte[] getOutputBytes() { .getOutputBytes(); } + public long getTimestamp() { + return timestamp; + } + public static class TransactionAction { private org.hyperledger.fabric.protos.peer.FabricTransaction.TransactionAction transactionAction;