Skip to content

Commit

Permalink
<feat>(driver): add fabric block and tx timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Sep 7, 2023
1 parent 569d32e commit 8d2d5fc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand Down Expand Up @@ -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')
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/webank/wecross/stub/fabric/FabricBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/webank/wecross/stub/fabric/FabricDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public void asyncGetTransaction(
blockNumber,
blockManager,
hasOnChain -> {
if (!hasOnChain.booleanValue()) {
if (!hasOnChain) {
callback.onResponse(
new Exception(
"Transaction proof verify failed. Tx("
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,14 +18,20 @@ public class FabricTransaction {
private List<TransactionAction> 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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8d2d5fc

Please sign in to comment.