Skip to content

Commit 5d877d2

Browse files
authored
Merge pull request #183 from MaggieNgWu/dev
solve build.gradle conflict, merge dev to master
2 parents 07beb27 + 8a0dfa3 commit 5d877d2

File tree

44 files changed

+543
-216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+543
-216
lines changed

.ci/ci_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LOG_INFO() {
88
check_basic()
99
{
1010
# check code format
11-
bash gradlew verifyGoogleJavaFormat
11+
# bash gradlew verifyGoogleJavaFormat
1212
# build
1313
bash gradlew build --info
1414
}

build.gradle

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ ext {
1919
commonsLang3Version = "3.1"
2020
javapoetVersion = "1.7.0"
2121
picocliVersion = "3.6.0"
22-
nettyVersion = "4.1.50.Final"
23-
nettySMSSLContextVersion = "1.1.0"
22+
nettyVersion = "4.1.53.Final"
23+
nettySMSSLContextVersion = "1.2.0"
2424
toml4jVersion = "0.7.2"
2525
bcprovJDK15onVersion = "1.60"
26-
keyMiniToolkit = "1.0.0"
26+
keyMiniToolkit = "1.0.2"
2727

2828
solcJVersion = "0.4.25.1"
2929
//solcJVersion = "0.5.2.0"
@@ -38,7 +38,7 @@ ext {
3838
// integrationTest.mustRunAfter test
3939
allprojects {
4040
group = 'org.fisco-bcos.java-sdk'
41-
version = '2.6.1-rc1'
41+
version = '2.6.1-SNAPSHOT'
4242
apply plugin: 'maven'
4343
apply plugin: 'maven-publish'
4444
apply plugin: 'idea'
@@ -61,7 +61,7 @@ allprojects {
6161

6262
// In this section you declare where to find the dependencies of your project
6363
repositories {
64-
jcenter()
64+
mavenCentral()
6565
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
6666
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
6767
}
@@ -147,6 +147,10 @@ sourceSets {
147147
}
148148
}
149149
integrationTest {
150+
copy {
151+
from file('src/test/resources/amop/')
152+
into 'conf/amop'
153+
}
150154
java {
151155
compileClasspath += main.output + test.output
152156
runtimeClasspath += main.output + test.output
@@ -156,6 +160,13 @@ sourceSets {
156160
resources.srcDir file('src/integration-test/resources')
157161
}
158162
}
163+
164+
googleJavaFormat {
165+
options style: 'AOSP'
166+
source = sourceSets*.allJava
167+
include '**/*.java'
168+
}
169+
159170
configurations {
160171
integrationTestCompile.extendsFrom testCompile
161172
integrationTestRuntime.extendsFrom testRuntime
@@ -182,16 +193,6 @@ dependencies {
182193
testCompile ("org.fisco-bcos:solcJ:${solcJVersion}")
183194
testCompile ("com.google.guava:guava:${guavaVersion}")
184195
}
185-
googleJavaFormat {
186-
options style: 'AOSP'
187-
source = sourceSets*.allJava
188-
include '**/*.java'
189-
}
190-
191-
verifyGoogleJavaFormat {
192-
source = sourceSets*.allJava
193-
include '**/*.java'
194-
}
195196

196197
javadoc {
197198
options.addStringOption('Xdoclint:none', '-quiet')
@@ -310,10 +311,6 @@ jar {
310311
from file('src/test/resources/log4j.properties')
311312
into 'dist/conf'
312313
}
313-
copy {
314-
from file('src/test/resources/amop/')
315-
into 'conf/amop'
316-
}
317314
}
318315
}
319316
check.dependsOn jacocoTestReport

sdk-abi/src/main/java/org/fisco/bcos/sdk/abi/ABICodec.java

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,50 @@ public String encodeMethodById(String ABI, String methodId, List<Object> params)
131131
throw new ABICodecException(errorMsg);
132132
}
133133

134-
public String encodeMethodByInterface(String ABI, String methodInterface, List<Object> params)
134+
private ABIDefinition getABIDefinition(String methodInterface) throws ABICodecException {
135+
int start = methodInterface.indexOf("(");
136+
int end = methodInterface.lastIndexOf(")");
137+
if (start == -1 || end == -1 || start >= end) {
138+
String errorMsg = " error format";
139+
logger.error(errorMsg);
140+
throw new ABICodecException(errorMsg);
141+
}
142+
String name = methodInterface.substring(0, start);
143+
String type = methodInterface.substring(start + 1, end);
144+
if (type.indexOf("tuple") != -1) {
145+
String errorMsg = " cannot support tuple type";
146+
logger.error(errorMsg);
147+
throw new ABICodecException(errorMsg);
148+
}
149+
String[] types = type.split(",");
150+
List<ABIDefinition.NamedType> inputs = new ArrayList<ABIDefinition.NamedType>();
151+
for (String s : types) {
152+
ABIDefinition.NamedType input = new ABIDefinition.NamedType("name", s);
153+
inputs.add(input);
154+
}
155+
156+
return new ABIDefinition(false, inputs, name, null, "function", false, "nonpayable");
157+
}
158+
159+
public String encodeMethodByInterface(String methodInterface, List<Object> params)
135160
throws ABICodecException {
136-
FunctionEncoder functionEncoder = new FunctionEncoder(cryptoSuite);
137-
String methodId = functionEncoder.buildMethodId(methodInterface);
138-
return encodeMethodById(ABI, methodId, params);
161+
ABIDefinition abiDefinition = getABIDefinition(methodInterface);
162+
if (abiDefinition.getInputs().size() == params.size()) {
163+
@SuppressWarnings("static-access")
164+
ABIObject inputABIObject = abiObjectFactory.createInputObject(abiDefinition);
165+
ABICodecObject abiCodecObject = new ABICodecObject();
166+
try {
167+
String methodId = abiDefinition.getMethodId(cryptoSuite);
168+
return methodId + abiCodecObject.encodeValue(inputABIObject, params).encode();
169+
} catch (Exception e) {
170+
logger.error(
171+
" exception in encodeMethodByInterfaceFromObject : {}", e.getMessage());
172+
}
173+
}
174+
175+
String errorMsg = " cannot encode in encodeMethodByInterfaceFromObject";
176+
logger.error(errorMsg);
177+
throw new ABICodecException(errorMsg);
139178
}
140179

141180
public String encodeMethodFromString(String ABI, String methodName, List<String> params)
@@ -194,11 +233,25 @@ public String encodeMethodByIdFromString(String ABI, String methodId, List<Strin
194233
throw new ABICodecException(errorMsg);
195234
}
196235

197-
public String encodeMethodByInterfaceFromString(
198-
String ABI, String methodInterface, List<String> params) throws ABICodecException {
199-
FunctionEncoder functionEncoder = new FunctionEncoder(cryptoSuite);
200-
String methodId = functionEncoder.buildMethodId(methodInterface);
201-
return encodeMethodByIdFromString(ABI, methodId, params);
236+
public String encodeMethodByInterfaceFromString(String methodInterface, List<String> params)
237+
throws ABICodecException {
238+
ABIDefinition abiDefinition = getABIDefinition(methodInterface);
239+
if (abiDefinition.getInputs().size() == params.size()) {
240+
@SuppressWarnings("static-access")
241+
ABIObject inputABIObject = abiObjectFactory.createInputObject(abiDefinition);
242+
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
243+
try {
244+
String methodId = abiDefinition.getMethodId(cryptoSuite);
245+
return methodId + abiCodecJsonWrapper.encode(inputABIObject, params).encode();
246+
} catch (IOException e) {
247+
logger.error(
248+
" exception in encodeMethodByInterfaceFromString : {}", e.getMessage());
249+
}
250+
}
251+
252+
String errorMsg = " cannot encode in encodeMethodByInterfaceFromString";
253+
logger.error(errorMsg);
254+
throw new ABICodecException(errorMsg);
202255
}
203256

204257
public List<Object> decodeMethod(ABIDefinition abiDefinition, String output)
@@ -334,7 +387,10 @@ public List<Object> decodeEvent(String ABI, String eventName, EventLog log)
334387
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
335388
ABICodecObject abiCodecObject = new ABICodecObject();
336389
try {
337-
List<Object> params = abiCodecObject.decodeJavaObject(inputObject, log.getData());
390+
List<Object> params = new ArrayList<>();
391+
if (!log.getData().equals("0x")) {
392+
params = abiCodecObject.decodeJavaObject(inputObject, log.getData());
393+
}
338394
List<String> topics = log.getTopics();
339395
return mergeEventParamsAndTopics(abiDefinition, params, topics);
340396
} catch (Exception e) {
@@ -355,7 +411,10 @@ public List<Object> decodeEventByTopic(String ABI, String eventTopic, EventLog l
355411
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
356412
ABICodecObject abiCodecObject = new ABICodecObject();
357413
try {
358-
List<Object> params = abiCodecObject.decodeJavaObject(inputObject, log.getData());
414+
List<Object> params = new ArrayList<>();
415+
if (!log.getData().equals("0x")) {
416+
params = abiCodecObject.decodeJavaObject(inputObject, log.getData());
417+
}
359418
List<String> topics = log.getTopics();
360419
return mergeEventParamsAndTopics(abiDefinition, params, topics);
361420
} catch (Exception e) {
@@ -390,7 +449,10 @@ public List<String> decodeEventToString(String ABI, String eventName, EventLog l
390449
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
391450
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
392451
try {
393-
List<String> params = abiCodecJsonWrapper.decode(inputObject, log.getData());
452+
List<String> params = new ArrayList<>();
453+
if (!log.getData().equals("0x")) {
454+
params = abiCodecJsonWrapper.decode(inputObject, log.getData());
455+
}
394456
List<String> topics = log.getTopics();
395457
return mergeEventParamsAndTopicsToString(abiDefinition, params, topics);
396458
} catch (Exception e) {
@@ -411,7 +473,10 @@ public List<String> decodeEventByTopicToString(String ABI, String eventTopic, Ev
411473
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
412474
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
413475
try {
414-
List<String> params = abiCodecJsonWrapper.decode(inputObject, log.getData());
476+
List<String> params = new ArrayList<>();
477+
if (!log.getData().equals("0x")) {
478+
params = abiCodecJsonWrapper.decode(inputObject, log.getData());
479+
}
415480
List<String> topics = log.getTopics();
416481
return mergeEventParamsAndTopicsToString(abiDefinition, params, topics);
417482
} catch (Exception e) {

sdk-abi/src/test/java/org/fisco/bcos/sdk/test/abi/ABICodecTest.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,33 @@ public void testEncodeFromString() {
341341
encodedWithMethodId,
342342
abiCodec.encodeMethodById(
343343
abiDesc, test.getMethodId(Utils.getCryptoSuite()), abiObjects));
344-
// MethodByInterface String & JavaObject
345-
Assert.assertEquals(
346-
encodedWithMethodId,
347-
abiCodec.encodeMethodByInterfaceFromString(
348-
abiDesc, test.getMethodSignatureAsString(), args));
349-
Assert.assertEquals(
350-
encodedWithMethodId,
351-
abiCodec.encodeMethodByInterface(
352-
abiDesc, test.getMethodSignatureAsString(), abiObjects));
344+
} catch (ABICodecException e) {
345+
Assert.fail(e.getMessage());
346+
}
347+
}
348+
349+
@Test
350+
public void testEncodeByInterface() {
351+
ABICodec abiCodec = new ABICodec(Utils.getCryptoSuite());
352+
List<Object> argsObjects = new ArrayList<Object>();
353+
List<BigInteger> b1 = new ArrayList<BigInteger>();
354+
b1.add(new BigInteger("100"));
355+
b1.add(new BigInteger("200"));
356+
argsObjects.add(b1);
357+
List<BigInteger> b2 = new ArrayList<BigInteger>();
358+
b2.add(new BigInteger("100"));
359+
b2.add(new BigInteger("200"));
360+
b2.add(new BigInteger("300"));
361+
argsObjects.add(b2);
362+
byte[] b = "1234".getBytes();
363+
argsObjects.add(b);
364+
String a = "0x5678";
365+
argsObjects.add(a);
366+
try {
367+
String s1 = abiCodec.encodeMethodByInterface("call(uint256[2],uint256[],bytes,address)", argsObjects);
368+
String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"u1\",\"type\":\"uint256[2]\"},{\"name\":\"u2\",\"type\":\"uint256[]\"},{\"name\":\"b\",\"type\":\"bytes\"},{\"name\":\"a\",\"type\":\"address\"}],\"name\":\"call\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"u\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a\",\"type\":\"uint256\"},{\"name\":\"s\",\"type\":\"string\"}],\"name\":\"add\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"LogAdd1\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"LogAdd2\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"u\",\"type\":\"uint256\"},{\"indexed\":true,\"name\":\"a\",\"type\":\"uint256\"},{\"indexed\":true,\"name\":\"s\",\"type\":\"string\"}],\"name\":\"LogAdd3\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"LogAdd4\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"LogAdd5\",\"type\":\"event\"}]";
369+
String s2 = abiCodec.encodeMethod(abi, "call", argsObjects);
370+
Assert.assertEquals(s1, s2);
353371
} catch (ABICodecException e) {
354372
Assert.fail(e.getMessage());
355373
}

sdk-amop/src/main/java/org/fisco/bcos/sdk/amop/Amop.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.UUID;
2121
import org.fisco.bcos.sdk.amop.topic.TopicManager;
2222
import org.fisco.bcos.sdk.channel.Channel;
23-
import org.fisco.bcos.sdk.channel.ResponseCallback;
2423
import org.fisco.bcos.sdk.config.ConfigOption;
2524
import org.fisco.bcos.sdk.crypto.keystore.KeyTool;
2625

@@ -81,7 +80,7 @@ static Amop build(Channel channel, ConfigOption config) {
8180
* @param content the sent message
8281
* @param callback the callback that will be called when receive the AMOP response
8382
*/
84-
void sendAmopMsg(AmopMsgOut content, ResponseCallback callback);
83+
void sendAmopMsg(AmopMsgOut content, AmopResponseCallback callback);
8584

8685
/**
8786
* Send amop msg
@@ -97,14 +96,6 @@ static Amop build(Channel channel, ConfigOption config) {
9796
*/
9897
Set<String> getSubTopics();
9998

100-
/**
101-
* Get list of subscribers to a topic
102-
*
103-
* @param topicName the topic you want to query
104-
* @return List of subscribers
105-
*/
106-
List<String> getTopicSubscribers(String topicName);
107-
10899
/**
109100
* set amop default callback
110101
*
@@ -118,9 +109,6 @@ static Amop build(Channel channel, ConfigOption config) {
118109
/** Stop. */
119110
void stop();
120111

121-
/** If configured private topic, wait until finish verify */
122-
void waitFinishPrivateTopicVerify();
123-
124112
/**
125113
* generate message sequence string
126114
*

sdk-amop/src/main/java/org/fisco/bcos/sdk/amop/AmopImp.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.fisco.bcos.sdk.model.AmopMsg;
3535
import org.fisco.bcos.sdk.model.Message;
3636
import org.fisco.bcos.sdk.model.MsgType;
37+
import org.fisco.bcos.sdk.model.Response;
3738
import org.fisco.bcos.sdk.utils.ObjectMapperFactory;
3839
import org.slf4j.Logger;
3940
import org.slf4j.LoggerFactory;
@@ -96,7 +97,7 @@ public void unsubscribeTopic(String topicName) {
9697
}
9798

9899
@Override
99-
public void sendAmopMsg(AmopMsgOut content, ResponseCallback callback) {
100+
public void sendAmopMsg(AmopMsgOut content, AmopResponseCallback callback) {
100101
if (!topicManager.canSendTopicMsg(content)) {
101102
logger.error(
102103
"can not send this amop private msg out, you have not configured the public keys. topic:{}",
@@ -110,7 +111,15 @@ public void sendAmopMsg(AmopMsgOut content, ResponseCallback callback) {
110111
msg.setData(content.getContent());
111112
Options ops = new Options();
112113
ops.setTimeout(content.getTimeout());
113-
this.channel.asyncSendToRandom(msg, callback, ops);
114+
ResponseCallback cb =
115+
new ResponseCallback() {
116+
@Override
117+
public void onResponse(Response response) {
118+
AmopResponse amopResponse = new AmopResponse(response);
119+
callback.onResponse(amopResponse);
120+
}
121+
};
122+
this.channel.asyncSendToRandom(msg, cb, ops);
114123
logger.info(
115124
"send amop msg to a random peer, seq{} topic{}", msg.getSeq(), content.getTopic());
116125
}
@@ -141,11 +150,6 @@ public Set<String> getSubTopics() {
141150
return topicManager.getTopicNames();
142151
}
143152

144-
@Override
145-
public List<String> getTopicSubscribers(String topicName) {
146-
return null;
147-
}
148-
149153
@Override
150154
public void setCallback(AmopCallback cb) {
151155
topicManager.setCallback(cb);
@@ -165,11 +169,6 @@ public void stop() {
165169
unSubscribeAll();
166170
}
167171

168-
@Override
169-
public void waitFinishPrivateTopicVerify() {
170-
// todo add wait function
171-
}
172-
173172
private void unSubscribeAll() {
174173
List<String> peers = this.channel.getAvailablePeer();
175174
logger.info("unsubscribe all topics, inform {} peers", peers.size());

0 commit comments

Comments
 (0)