Skip to content

Commit

Permalink
Merge pull request #154 from kyonRay/master
Browse files Browse the repository at this point in the history
Release v1.4.0
  • Loading branch information
kyonRay authored Mar 2, 2024
2 parents 569d32e + d214bef commit 9b85665
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name: actions check
on: pull_request

jobs:
ubuntu1804jdk8:
runs-on: ubuntu-18.04
ubuntujdk8:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
Expand All @@ -19,8 +19,8 @@ jobs:
- name: upload coverage
run: bash <(curl -s https://codecov.io/bash)

ubuntu1804jdk11:
runs-on: ubuntu-18.04
ubuntujdk11:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
Expand Down
13 changes: 9 additions & 4 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 All @@ -14,7 +14,7 @@ apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'com.github.johnrengelman.shadow'
group 'com.webank.wecross'
version '1.3.0'
version '1.4.0'

sourceCompatibility = 1.8

Expand Down Expand Up @@ -60,19 +60,24 @@ dependencies {
}
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'com.google.guava:guava:30.1-jre'
implementation 'com.google.guava:guava:32.0.1-jre'
implementation 'org.yaml:snakeyaml:2.0'

// Fabric
implementation 'javassist:javassist:3.12.1.GA'
implementation ("org.hyperledger.fabric-sdk-java:fabric-sdk-java:1.4.4") {
exclude group: 'io.netty'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.apache.logging.log4j'
exclude group: 'log4j'
}
implementation "com.google.protobuf:protobuf-java:3.25.3"
implementation 'org.apache.commons:commons-compress:1.26.0'
// implementation 'io.netty:netty-tcnative-boringssl-static:2.0.27.Final'

// WeCross

implementation ('com.webank:wecross-java-stub:1.3.0') {
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
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.3.0
v1.4.0
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
74 changes: 65 additions & 9 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 Expand Up @@ -498,7 +551,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 +650,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 +1250,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
2 changes: 1 addition & 1 deletion src/main/java/com/webank/wecross/utils/TarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static byte[] generateTarGzInputStreamBytes(File src, String pathPrefix)

archiveEntry = new TarArchiveEntry(childFile, relativePath);
try (FileInputStream fileInputStream = new FileInputStream(childFile)) {
archiveOutputStream.putArchiveEntry(archiveEntry);
archiveOutputStream.putArchiveEntry((TarArchiveEntry) archiveEntry);

try {
IOUtils.copy(fileInputStream, archiveOutputStream);
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/chaincode/WeCrossHub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
NilFlag = "null"
CallTypeQuery = "0"
CallTypeInvoke = "1"
CallTypeGetBlock = "2"

ChannelKey = "channel"
CurrentIndexKey = "current_index"
Expand Down Expand Up @@ -77,6 +78,8 @@ func (h *Hub) Invoke(stub shim.ChaincodeStubInterface) (res peer.Response) {
res = h.interchainInvoke(stub, args)
case "interchainQuery":
res = h.interchainQuery(stub, args)
case "interchainGetBlock":
res = h.interchainGetBlock(stub, args)
case "registerCallbackResult":
res = h.registerCallbackResult(stub, args)
case "selectCallbackResult":
Expand Down Expand Up @@ -124,6 +127,16 @@ func (h *Hub) interchainQuery(stub shim.ChaincodeStubInterface, args []string) p
return shim.Success(uint64ToBytes(uid))
}

func (h *Hub) interchainGetBlock(stub shim.ChaincodeStubInterface, args []string) peer.Response {
if len(args) != 5 {
return shim.Error("incorrect number of arguments, expecting 5")
}

uid := handleRequest(stub, CallTypeGetBlock, args[0], args[1], args[2], args[3], args[4])

return shim.Success(uint64ToBytes(uid))
}

func handleRequest(stub shim.ChaincodeStubInterface, callType, path, method, args, callbackPath, callbackMethod string) uint64 {
increment, err := stub.GetState(IncrementKey)
checkError(err)
Expand Down

0 comments on commit 9b85665

Please sign in to comment.