Skip to content

Commit 264bdf8

Browse files
author
UDLD
authored
Merge pull request #134 from cryptape/develop
Rc/v0.24.1
2 parents 4243b93 + f946294 commit 264bdf8

File tree

15 files changed

+227
-48
lines changed

15 files changed

+227
-48
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dist: trusty
2+
13
language: java
24

35
jdk:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
All notable changes to this project will be documented in this file.
22

3+
# [v0.24.1](https://github.com/cryptape/cita-sdk-java/compare/v0.24.0...v0.24.1) (2019-08-16)
4+
5+
### Feature
6+
7+
* add a constructor parameter to contract deploy method
8+
* fix some issues
9+
310
# [v0.24.0](https://github.com/cryptape/cita-sdk-java/compare/v0.23.0...v0.24.0) (2019-05-30)
411

512
### Feature

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For detailed documentation, see [documentation](docs/index.md).
2020

2121
### Prerequisites
2222
Java 8
23-
Gradle 4.3
23+
Gradle 5.0
2424

2525
### Install
2626
Install from repositories:
@@ -29,12 +29,12 @@ maven
2929
<dependency>
3030
<groupId>com.cryptape.cita</groupId>
3131
<artifactId>core</artifactId>
32-
<version>0.24.0</version>
32+
<version>0.24.1</version>
3333
</dependency>
3434
```
3535
Gradle
3636
```
37-
compile 'com.cryptape.cita:core:0.24.0'
37+
compile 'com.cryptape.cita:core:0.24.1'
3838
```
3939

4040
Install manually
@@ -52,7 +52,7 @@ gradle shadowJar
5252
### CITA Test net
5353

5454
Use CITA test net (recommended):
55-
http://121.196.200.225:1337 is provided as a test net.
55+
https://node.cryptape.com is provided as a test net.
5656

5757
Or build your own CITA net:
5858
Please find more information in [CITA](https://github.com/cryptape/cita).
@@ -124,7 +124,7 @@ Example generate Java class from `Token.sol`, `Token.bin` and `Token.abi` under
124124
```shell
125125
java -jar console/build/libs/console-0.17-all.jar solidity generate tests/src/main/resources/Token.bin tests/src/main/resources/Token.abi -o tests/src/main/java/ -p com.cryptape.cita.tests
126126
```
127-
`Token.java` will be created from commands above and class `Token` can be used with CitaTransactionManager to deploy and call smart contract `Token`. Please be attention that [CitaTransactionManager](https://github.com/cryptape/cita-sdk-java/blob/master/core/src/main/java/com/cryptape/cita/tx/CitaTransactionManager.java) is supposed to be used as TransactionManager for transaction creation in CITA network.
127+
`Token.java` will be created from commands above and class `Token` can be used with TransactionManager to deploy and call smart contract `Token`. Please be attention that [TransactionManager](https://github.com/cryptape/cita-sdk-java/blob/master/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java) is supposed to be used as TransactionManager for transaction creation in CITA network.
128128
Please check [TokenCodegenExample.java](https://github.com/cryptape/cita-sdk-java/blob/master/tests/src/main/java/com/cryptape/cita/tests/TokenCodegenExample.java) for a complete example.
129129

130130
### Working with smart contract with cita-sdk-java Account (Test)
@@ -162,20 +162,20 @@ cita-sdk-java 是对以太坊 Web3j 进行改写,适配 CITA 的一个 Java
162162

163163
### 预装组件
164164
Java 8
165-
Gradle 4.3
165+
Gradle 5.0
166166

167167
### 安装
168168
通过远程仓库安装:
169169
```
170170
<dependency>
171171
<groupId>com.cryptape.cita</groupId>
172172
<artifactId>core</artifactId>
173-
<version>0.24.0</version>
173+
<version>0.24.1</version>
174174
</dependency>
175175
```
176176
Gradle
177177
```
178-
compile 'com.cryptape.cita:core:0.24.0'
178+
compile 'com.cryptape.cita:core:0.24.1'
179179
```
180180

181181
手动安装
@@ -192,7 +192,7 @@ gradle shadowJar
192192

193193
### CITA 测试网络
194194
使用 CITA 测试网络(推荐):
195-
http://121.196.200.225:1337
195+
https://node.cryptape.com
196196

197197
或者可以部署你自己的 CITA:
198198
如果需要了解怎么部署 CITA 网络,请查阅[CITA](https://github.com/cryptape/cita)
@@ -262,7 +262,7 @@ $ java -jar console-0.17-all.jar solidity generate [--javaTypes|--solidityTypes]
262262
```
263263
java -jar console/build/libs/console-0.17-all.jar solidity generate tests/src/main/resources/Token.bin tests/src/main/resources/Token.abi -o tests/src/main/java/ -p com.cryptape.cita.tests
264264
```
265-
`Token.java` 会通过以上命令生成, `Token` 可以与 `CitaTransactionManager` 一起使用来和 Token 合约交互。请注意在 CITA 中应该使用 [CitaTransactionManager](https://github.com/cryptape/cita-sdk-java/blob/master/core/src/main/java/com/cryptape/cita/tx/CitaTransactionManager.java) 而不是 TransactionManager。
265+
`Token.java` 会通过以上命令生成, `Token` 可以与 `TransactionManager` 一起使用来和 Token 合约交互。请注意在 CITA 中应该使用 [TransactionManager](https://github.com/cryptape/cita-sdk-java/blob/master/core/src/main/java/com/cryptape/cita/tx/TransactionManager.java) 而不是 TransactionManager。
266266
请在 [TokenCodegenExample.java](https://github.com/cryptape/cita-sdk-java/blob/master/tests/src/main/java/com/cryptape/cita/tests/TokenCodegenExample.java) 查看完整代码.
267267

268268
### 通过 CITAj 中的 Account 与智能合约交互(测试阶段)

build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ buildscript {
2222

2323
dependencies {
2424
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3'
25-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
25+
/*
26+
* the version need adapt to gradle version
27+
* refer to https://github.com/fzdy1914/Inventory-Manager/commit/6e0df8af1ddf9261082389c4e1bb2fb728c2ae66
28+
*/
29+
classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
2630
}
2731
}
2832

@@ -45,7 +49,7 @@ allprojects {
4549
targetCompatibility = 1.8
4650

4751
group 'com.cryptape.cita'
48-
version '0.24.0'
52+
version '0.24.1'
4953

5054
apply plugin: 'java'
5155
apply plugin: 'jacoco'
@@ -141,7 +145,7 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) {
141145
publications {
142146
mavenJava(MavenPublication) {
143147
groupId 'com.cryptape.cita'
144-
version '0.24.0'
148+
version '0.24.1'
145149
from components.java
146150

147151
artifact sourcesJar {

codegen/src/main/java/com/cryptape/cita/codegen/SolidityFunctionWrapper.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
public class SolidityFunctionWrapper extends Generator {
5858

5959
private static final String BINARY = "BINARY";
60+
private static final String ABI = "ABI";
6061
private static final String CITAJ = "citaj";
6162
private static final String CREDENTIALS = "credentials";
6263
private static final String TRANSACTION_MANAGER = "transactionManager";
@@ -105,7 +106,7 @@ void generateJavaFiles(
105106
throws IOException, ClassNotFoundException {
106107
String className = Strings.capitaliseFirstLetter(contractName);
107108

108-
TypeSpec.Builder classBuilder = createClassBuilder(className, bin);
109+
TypeSpec.Builder classBuilder = createClassBuilder(className, bin, convertToAbiString(abi));
109110

110111
classBuilder.addMethod(
111112
buildConstructorAdaptToCita(TransactionManager.class, TRANSACTION_MANAGER));
@@ -170,15 +171,16 @@ private void addAddressesSupport(TypeSpec.Builder classBuilder, Map<String, Stri
170171
}
171172

172173

173-
private TypeSpec.Builder createClassBuilder(String className, String binary) {
174+
private TypeSpec.Builder createClassBuilder(String className, String binary, String abi) {
174175

175176
String javadoc = CODEGEN_WARNING + getCITAjVersion();
176177

177178
return TypeSpec.classBuilder(className)
178179
.addModifiers(Modifier.PUBLIC)
179180
.addJavadoc(javadoc)
180181
.superclass(Contract.class)
181-
.addField(createBinaryDefinition(binary));
182+
.addField(createBinaryDefinition(binary))
183+
.addField(createAbiDefinition(abi));
182184
}
183185

184186
private String getCITAjVersion() {
@@ -201,6 +203,13 @@ private FieldSpec createBinaryDefinition(String binary) {
201203
.build();
202204
}
203205

206+
private FieldSpec createAbiDefinition(String abi) {
207+
return FieldSpec.builder(String.class, ABI)
208+
.addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC)
209+
.initializer("$S", abi)
210+
.build();
211+
}
212+
204213
private List<MethodSpec> buildFunctionDefinitions(
205214
String className,
206215
TypeSpec.Builder classBuilder,
@@ -1075,6 +1084,11 @@ private List<AbiDefinition> loadContractDefinition(String abi) throws IOExceptio
10751084
return Arrays.asList(abiDefinition);
10761085
}
10771086

1087+
private String convertToAbiString(List<AbiDefinition> abi) throws IOException {
1088+
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
1089+
return objectMapper.writeValueAsString(abi);
1090+
}
1091+
10781092
private static class NamedTypeName {
10791093
private final TypeName typeName;
10801094
private final String name;

console/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//apply plugin: 'com.github.johnrengelman.shadow'
1+
apply plugin: 'com.github.johnrengelman.shadow'
22
apply plugin: 'application'
33

44
description 'cita-sdk-java command line tools'
@@ -9,8 +9,13 @@ dependencies {
99
testCompile project(path: ':crypto', configuration: 'archives'),
1010
project(path: ':core', configuration: 'archives'),
1111
project(path: ':codegen', configuration: 'archives')
12-
testCompile files(project(':crypto').sourceSets.test.output.classesDir)
13-
testCompile files(project(':codegen').sourceSets.test.output.classesDir)
12+
/*
13+
* The classesDir property was deprecated in gradle 4.x, and removed in gradle 5.x
14+
* refer to https://stackoverflow.com/questions/54707148/gradle-could-not-get-unknown-property-classesdir-for-main-classes
15+
* refer to https://docs.gradle.org/5.0/release-notes.html
16+
*/
17+
testCompile files(project(':crypto').sourceSets.test.output.classesDirs)
18+
testCompile files(project(':codegen').sourceSets.test.output.classesDirs)
1419
}
1520

1621
// Build command line library release with target distShadowZip

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies {
1515
"com.google.code.gson:gson:$gsonVersion"
1616
testCompile project(path: ':crypto', configuration: 'archives'),
1717
"nl.jqno.equalsverifier:equalsverifier:$equalsverifierVersion"
18-
testCompile files(project(':crypto').sourceSets.test.output.classesDir)
18+
testCompile files(project(':crypto').sourceSets.test.output.classesDirs)
1919
}
2020

2121
task createProperties(dependsOn: processResources) doLast {

core/src/main/java/com/cryptape/cita/protocol/account/Account.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cryptape.cita.protocol.account;
22

3+
import com.cryptape.cita.utils.Numeric;
34
import java.io.File;
45
import java.io.IOException;
56
import java.math.BigInteger;
@@ -49,14 +50,40 @@ public RawTransactionManager getTransactionManager() {
4950

5051
/// TODO: get contract address from receipt after deploy, then return contract name
5152
public AppSendTransaction deploy(
52-
File contractFile, String nonce, long quota,
53-
int version, BigInteger chainId, String value)
54-
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
53+
File contractFile, String nonce, long quota,
54+
int version, BigInteger chainId, String value)
55+
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
5556
CompiledContract contract = new CompiledContract(contractFile);
5657
String contractBin = contract.getBin();
5758
return this.transactionManager
58-
.sendTransaction("", contractBin, quota, nonce, getValidUntilBlock(),
59-
version, chainId, value);
59+
.sendTransaction("", contractBin, quota, nonce, getValidUntilBlock(),
60+
version, chainId, value);
61+
}
62+
63+
/**
64+
*
65+
* @param contractFile
66+
* @param constructorCode add by timmyz, fulfill the construction contract situations
67+
* @param nonce
68+
* @param quota
69+
* @param version
70+
* @param chainId
71+
* @param value
72+
* @return
73+
* @throws IOException
74+
* @throws InterruptedException
75+
* @throws CompiledContract.ContractCompileError
76+
*/
77+
public AppSendTransaction deploy(
78+
File contractFile, String constructorCode, String nonce, long quota,
79+
int version, BigInteger chainId, String value)
80+
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
81+
CompiledContract contract = new CompiledContract(contractFile);
82+
String contractBin = contract.getBin();
83+
String data = constructorCode != null ? contractBin + Numeric.cleanHexPrefix(constructorCode) : contractBin;
84+
return this.transactionManager
85+
.sendTransaction("", data, quota, nonce, getValidUntilBlock(),
86+
version, chainId, value);
6087
}
6188

6289
public Flowable<AppSendTransaction> deployAsync(

core/src/main/java/com/cryptape/cita/protocol/core/methods/request/Transaction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cryptape.cita.utils.Numeric;
2525
import com.cryptape.cita.utils.Strings;
2626

27+
import static com.cryptape.cita.utils.Numeric.encodeQuantity;
2728
import static org.abstractj.kalium.encoders.Encoder.HEX;
2829
import static com.cryptape.cita.utils.Numeric.cleanHexPrefix;
2930
import static com.cryptape.cita.utils.Numeric.prependHexPrefix;
@@ -239,7 +240,7 @@ private static String processValue(String value) {
239240
} else {
240241
BigInteger valueBigInt = value.matches("0[xX][0-9a-fA-F]+") ? Numeric.toBigInt(value) : new BigInteger(value);
241242
if (Transaction.MAX_VALUE.compareTo(valueBigInt) > 0) {
242-
return valueBigInt.toString(16);
243+
return encodeQuantity(valueBigInt);
243244
} else {
244245
System.out.println("Value you input is out of bound");
245246
throw new IllegalArgumentException(

0 commit comments

Comments
 (0)