Skip to content

Commit

Permalink
Merge pull request #201 from cyjseagull/release-2.7.0
Browse files Browse the repository at this point in the history
sync code from release-2.7.0 into master
  • Loading branch information
cyjseagull authored Nov 23, 2020
2 parents 5a5afc4 + 023360f commit 229bee0
Show file tree
Hide file tree
Showing 92 changed files with 1,344 additions and 5,390 deletions.
2 changes: 0 additions & 2 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ check_sm_node()
}
LOG_INFO "------ download_tassl---------"
download_tassl
LOG_INFO "------ check_basic---------"
./gradlew build -x test
LOG_INFO "------ download_build_chain---------"
download_build_chain
LOG_INFO "------ check_standard_node---------"
Expand Down
2 changes: 1 addition & 1 deletion .ci/ci_check_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

scan_code_script="cobra/cobra.py -f json -o /tmp/report.json -t "
ignore_files=(sh crt key json toml SignatureTest.java Ok.java bin abi ChannelTest.java ParallelOkDemo.java PerformanceAmop.java DagPrecompiledDemo.java KeyToolTest.java CryptoSuite.java AmopMsgHandlerTest.java TopicManager.java PrivateTopicVerifyTest.java AmopMsgBuilder.java TopicManagerTest.java AmopSubscribe.java AmopPublisher.java AmopPublisherPrivate.java AmopSubscribePrivate.java AmopPublisherFile.java AmopPublisherPrivateFile.java DemoAmopCallback.java FileToByteArrayHelper.java OkD.java TableTest.java PerformanceTable.java HelloWorld.java PerformanceRPC.java CodecTest.java ResponseTest.java ConfigTest.java)
commit_limit=6
commit_limit=100

LOG_ERROR() {
content=${1}
Expand Down
51 changes: 49 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
## v2.7.0
(2020-11-20)
Please read documentation of Java SDK.

* [English User Handbook](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/java_sdk/index.html)
* [Chinese User Handbook](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk/index.html#)
* [Chinese WIKI](https://github.com/FISCO-BCOS/java-sdk/wiki)

Added:
* Added `getBatchReceiptsByBlockNumberAndRange` and `getBatchReceiptsByBlockHashAndRange` interfaces to support batch pull block transaction receipts
* Added the `getNodeInfo` interface to obtain subscribed topics information
* Added `revokeManager` interface to revoke contract life cycle management authority
* `ChainGovernanceService` adds `queryVotesOfMember` and `queryVotesOfThreshold` interfaces to support query voting status

Changed:
* Separate `sdk-demo` as a `java-sdk-demo` project

Fixed:
* Fix the exception of contract receipt parsing null pointer exception when deploying constructor with event

Compatibility

* FISCO BCOS v2.0+
* AMOP Not compatible with Web3SDK

----
请参考文档:
* [英文版用户手册](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/java_sdk/index.html)
* [中文版用户手册](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk/index.html#)
* [中文版WIKI](https://github.com/FISCO-BCOS/java-sdk/wiki)

添加:
* 添加`getBatchReceiptsByBlockNumberAndRange``getBatchReceiptsByBlockHashAndRange`接口,支持批量拉取区块交易回执
* 添加`getNodeInfo`接口,获取订阅的topics信息
* 添加`revokeManager`接口,撤销合约生命周期管理权限
* `ChainGovernanceService`添加`queryVotesOfMember``queryVotesOfThreshold`接口,支持查询投票情况

修改:
*`sdk-demo`独立为`java-sdk-demo`项目

修复:
* 修复部署构造函数带有event的合约异常时,合约回执解析空指针异常

适配性:
* 适配FISCO BCOS v2.0+
* AMOP功能不兼容Web3SDK

## v2.6.1
(2020-10-29)
Please read documentation of Java SDK.
Expand All @@ -21,8 +68,8 @@ Fixed:

Compatibility

* FISCO BCOS v2.0+.
* Not compatible with Web3SDK. When two users want to use AMOP functions to talk with each other, they should either both use Java SDK, or both use Web3SDK.
* FISCO BCOS v2.0+
* AMOP Not compatible with Web3SDK

----
请参考文档:
Expand Down
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ ext {
bcprovJDK15onVersion = "1.60"
keyMiniToolkit = "1.0.2"

solcJVersion = "0.4.25.1"
//solcJVersion = "0.5.2.0"
//solcJVersion = "0.6.10.0"
slf4jVersion = "1.7.30"
junitVersion = "4.12"
commonsCollections4Version = "4.4"
Expand All @@ -39,7 +36,7 @@ ext {
// integrationTest.mustRunAfter test
allprojects {
group = 'org.fisco-bcos.java-sdk'
version = '2.6.1'
version = '2.7.0-SNAPSHOT'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'idea'
Expand All @@ -58,12 +55,14 @@ allprojects {
html.enabled false
}
}
sourceCompatibility = '1.8'
sourceCompatibility = 1.8
targetCompatibility = 1.8

// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2"}
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

Expand Down Expand Up @@ -156,7 +155,6 @@ sourceSets {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
srcDir file('sdk-demo/src/main')
}
resources.srcDir file('src/integration-test/resources')
}
Expand Down Expand Up @@ -191,7 +189,6 @@ dependencies {
compile ("com.moandjiezana.toml:toml4j:${toml4jVersion}")

testCompile ("org.apache.commons:commons-collections4:${commonsCollections4Version}")
testCompile ("org.fisco-bcos:solcJ:${solcJVersion}")
testCompile ("com.google.guava:guava:${guavaVersion}")
}

Expand Down
7 changes: 6 additions & 1 deletion sdk-amop/src/main/java/org/fisco/bcos/sdk/amop/AmopImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ public void sendAmopMsg(AmopMsgOut content, AmopResponseCallback callback) {
new ResponseCallback() {
@Override
public void onResponse(Response response) {
logger.trace(
"receive response from subscriber, seq:{}",
response.getMessageID());
AmopResponse amopResponse = new AmopResponse(response);
callback.onResponse(amopResponse);
}
};
this.channel.asyncSendToRandom(msg, cb, ops);
logger.info(
"send amop msg to a random peer, seq{} topic{}", msg.getSeq(), content.getTopic());
"send amop msg to a random peer, seq: {} topic: {}",
msg.getSeq(),
content.getTopic());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public void onConnect(ChannelHandlerContext ctx) {

@Override
public void onMessage(ChannelHandlerContext ctx, Message msg) {
logger.trace(
"receive msg, msg type:{}, content:{}", msg.getType(), new String(msg.getData()));
logger.trace("receive msg, msg type:{}, seq:{}", msg.getType(), msg.getSeq());
if (!isRunning) {
logger.warn("Amop on msg, amop is not running, exit.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ public void run(Timeout timeout) {
@Override
public void asyncSendToRandom(Message out, ResponseCallback callback, Options options) {
List<String> peerList = getAvailablePeer();
if (peerList.size() == 0) {
logger.warn(
"no available peer to send to, seq: {}, type: {}", out.getSeq(), out.getType());
return;
}
int random = (int) (Math.random() * (peerList.size()));
String peerIpPort = peerList.get(random);
logger.trace("send message to random peer {} ", peerIpPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onConnect(ChannelHandlerContext ctx) {

@Override
public void onMessage(ChannelHandlerContext ctx, Message msg) {
logger.trace(
logger.debug(
"onMessage in ChannelMsgHandler called, host : {}, seq : {}, msgType : {}",
ChannelVersionNegotiation.getPeerHost(ctx),
msg.getSeq(),
Expand All @@ -129,10 +129,10 @@ public void onMessage(ChannelHandlerContext ctx, Message msg) {
if (callback != null) {
callback.cancelTimeout();
logger.trace(
" receive response, seq: {}, result: {}, content: {}",
" call registered callback, seq: {}, type: {} ,result: {}",
msg.getSeq(),
msg.getResult(),
new String(msg.getData()));
msg.getType(),
msg.getResult());

Response response = new Response();
if (msg.getResult() != 0) {
Expand All @@ -144,15 +144,16 @@ public void onMessage(ChannelHandlerContext ctx, Message msg) {
response.setCtx(ctx);
callback.onResponse(response);
} else {
logger.trace(
" receive response with invalid seq, type: {}, result: {}, content: {}",
(int) msg.getType(),
msg.getResult(),
new String(msg.getData()));
MsgHandler msgHandler = msgHandlers.get(msg.getType().intValue());
if (msgHandler != null) {
logger.trace(
" receive message, no callback, call handler, seq:{} , type: {}, result: {}",
msg.getSeq(),
(int) msg.getType(),
msg.getResult());
msgHandler.onMessage(ctx, msg);
}
logger.debug(" call ");
}
}

Expand Down
54 changes: 54 additions & 0 deletions sdk-core/src/main/java/org/fisco/bcos/sdk/model/DataCompress.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2014-2020 [fisco-dev]
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
*/

package org.fisco.bcos.sdk.model;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class DataCompress {
public static byte[] compress(String data) {

Deflater compress = new Deflater();

compress.setInput(data.getBytes());

byte[] compressedData = new byte[data.length()];
compress.finish();

int compressLength = compress.deflate(compressedData, 0, compressedData.length);
return Arrays.copyOfRange(compressedData, 0, compressLength);
}

public static byte[] uncompress(byte[] compressedData) throws IOException, DataFormatException {

Inflater decompressor = new Inflater();
decompressor.setInput(compressedData);

try (ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length)) {
byte[] buf = new byte[1024];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}

return bos.toByteArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class PrecompiledRetCode {
new RetCode(-52000, "The committee member already exist");

// ContractLifeCyclePrecompiled -51999 ~ -51900
public static final RetCode CODE_INVALID_REVOKE_LAST_AUTHORIZATION =
new RetCode(
-51907, "The permission of the last contract status manager can't be revoked");
public static final RetCode CODE_INVALID_NON_EXIST_AUTHORIZATION =
new RetCode(-51906, "The contract status manager doesn't exist");
public static final RetCode CODE_INVALID_NO_AUTHORIZED =
new RetCode(-51905, "Have no permission to access the contract table");
public static final RetCode CODE_INVALID_TABLE_NOT_EXIST =
Expand All @@ -72,6 +77,8 @@ public class PrecompiledRetCode {
new RetCode(-51600, "Execute PaillierAdd failed");

// CRUDPrecompiled -51599 ~ -51500
public static final RetCode CODE_INVALID_UPDATE_TABLE_KEY =
new RetCode(-51503, "Don't update the table key");
public static final RetCode CODE_CONDITION_OPERATION_UNDEFINED =
new RetCode(-51502, "Undefined function of Condition Precompiled");
public static final RetCode CODE_PARSE_CONDITION_ERROR =
Expand Down Expand Up @@ -100,7 +107,7 @@ public class PrecompiledRetCode {
-51004,
"The committee permission control by ChainGovernancePrecompiled are recommended");
public static final RetCode CODE_CONTRACT_NOT_EXIST =
new RetCode(-51003, "The contract is not exist");
new RetCode(-51003, "The contract doesn't exist");
public static final RetCode CODE_TABLE_NAME_OVERFLOW =
new RetCode(-51002, "The table name string length exceeds the maximum limit");
public static final RetCode CODE_TABLE_AND_ADDRESS_NOT_EXIST =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class TransactionReceipt {
private List<Logs> logs;
private String logsBloom;
private String status;
// the node returned status message corresponding to the status
private String statusMsg;
private String input;
private String output;
private List<MerkleProofUnit> txProof;
Expand Down Expand Up @@ -268,6 +270,14 @@ public boolean equals(Object o) {
&& Objects.equals(receiptProof, that.receiptProof);
}

public String getStatusMsg() {
return statusMsg;
}

public void setStatusMsg(String statusMsg) {
this.statusMsg = statusMsg;
}

@Override
public int hashCode() {
return Objects.hash(
Expand Down Expand Up @@ -327,6 +337,9 @@ public String toString() {
+ ", status='"
+ status
+ '\''
+ ", statusMsg='"
+ statusMsg
+ '\''
+ ", input='"
+ input
+ '\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
public interface Hash {
String hash(final String inputData);

String hashBytes(byte[] inputBytes);

byte[] hash(final byte[] inputBytes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public byte[] hash(final byte[] inputBytes) {
return Hex.decode(calculateHash(inputBytes));
}

@Override
public String hashBytes(byte[] inputBytes) {
return calculateHash(inputBytes);
}

private String calculateHash(final byte[] inputBytes) {
// Note: the exceptions should be handled by the caller
CryptoResult hashResult = NativeInterface.keccak256(Hex.toHexString(inputBytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
public class SM3Hash implements Hash {
@Override
public String hash(final String inputData) {
return calcualteHash(inputData.getBytes());
return calculateHash(inputData.getBytes());
}

@Override
public String hashBytes(byte[] inputBytes) {
return calculateHash(inputBytes);
}

@Override
public byte[] hash(final byte[] inputBytes) {
// Considering inefficient string conversion, this interface is not recommended
return Hex.decode(calcualteHash(inputBytes));
return Hex.decode(calculateHash(inputBytes));
}

private String calcualteHash(final byte[] inputBytes) {
private String calculateHash(final byte[] inputBytes) {
CryptoResult hashResult = NativeInterface.sm3(Hex.toHexString(inputBytes));
// call sm3 failed
if (hashResult.wedprErrorMessage != null && !hashResult.wedprErrorMessage.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SignatureResult sign(final String message, final CryptoKeyPair keyPair) {

@Override
public SignatureResult sign(final byte[] message, final CryptoKeyPair keyPair) {
return sign(new String(message), keyPair);
return sign(Hex.toHexString(message), keyPair);
}

@Override
Expand Down
Loading

0 comments on commit 229bee0

Please sign in to comment.