Skip to content

Commit

Permalink
Merge pull request #134 from cryptape/develop
Browse files Browse the repository at this point in the history
Rc/v0.24.1
  • Loading branch information
UDLD authored Aug 16, 2019
2 parents 4243b93 + f946294 commit 264bdf8
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist: trusty

language: java

jdk:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
All notable changes to this project will be documented in this file.

# [v0.24.1](https://github.com/cryptape/cita-sdk-java/compare/v0.24.0...v0.24.1) (2019-08-16)

### Feature

* add a constructor parameter to contract deploy method
* fix some issues

# [v0.24.0](https://github.com/cryptape/cita-sdk-java/compare/v0.23.0...v0.24.0) (2019-05-30)

### Feature
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For detailed documentation, see [documentation](docs/index.md).

### Prerequisites
Java 8
Gradle 4.3
Gradle 5.0

### Install
Install from repositories:
Expand All @@ -29,12 +29,12 @@ maven
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.24.0</version>
<version>0.24.1</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.24.0'
compile 'com.cryptape.cita:core:0.24.1'
```

Install manually
Expand All @@ -52,7 +52,7 @@ gradle shadowJar
### CITA Test net

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

Or build your own CITA net:
Please find more information in [CITA](https://github.com/cryptape/cita).
Expand Down Expand Up @@ -124,7 +124,7 @@ Example generate Java class from `Token.sol`, `Token.bin` and `Token.abi` under
```shell
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
```
`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.
`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.
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.

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

### 预装组件
Java 8
Gradle 4.3
Gradle 5.0

### 安装
通过远程仓库安装:
```
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.24.0</version>
<version>0.24.1</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.24.0'
compile 'com.cryptape.cita:core:0.24.1'
```

手动安装
Expand All @@ -192,7 +192,7 @@ gradle shadowJar

### CITA 测试网络
使用 CITA 测试网络(推荐):
http://121.196.200.225:1337
https://node.cryptape.com

或者可以部署你自己的 CITA:
如果需要了解怎么部署 CITA 网络,请查阅[CITA](https://github.com/cryptape/cita)
Expand Down Expand Up @@ -262,7 +262,7 @@ $ java -jar console-0.17-all.jar solidity generate [--javaTypes|--solidityTypes]
```
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
```
`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。
`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。
请在 [TokenCodegenExample.java](https://github.com/cryptape/cita-sdk-java/blob/master/tests/src/main/java/com/cryptape/cita/tests/TokenCodegenExample.java) 查看完整代码.

### 通过 CITAj 中的 Account 与智能合约交互(测试阶段)
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ buildscript {

dependencies {
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3'
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
/*
* the version need adapt to gradle version
* refer to https://github.com/fzdy1914/Inventory-Manager/commit/6e0df8af1ddf9261082389c4e1bb2fb728c2ae66
*/
classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
}
}

Expand All @@ -45,7 +49,7 @@ allprojects {
targetCompatibility = 1.8

group 'com.cryptape.cita'
version '0.24.0'
version '0.24.1'

apply plugin: 'java'
apply plugin: 'jacoco'
Expand Down Expand Up @@ -141,7 +145,7 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) {
publications {
mavenJava(MavenPublication) {
groupId 'com.cryptape.cita'
version '0.24.0'
version '0.24.1'
from components.java

artifact sourcesJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class SolidityFunctionWrapper extends Generator {

private static final String BINARY = "BINARY";
private static final String ABI = "ABI";
private static final String CITAJ = "citaj";
private static final String CREDENTIALS = "credentials";
private static final String TRANSACTION_MANAGER = "transactionManager";
Expand Down Expand Up @@ -105,7 +106,7 @@ void generateJavaFiles(
throws IOException, ClassNotFoundException {
String className = Strings.capitaliseFirstLetter(contractName);

TypeSpec.Builder classBuilder = createClassBuilder(className, bin);
TypeSpec.Builder classBuilder = createClassBuilder(className, bin, convertToAbiString(abi));

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


private TypeSpec.Builder createClassBuilder(String className, String binary) {
private TypeSpec.Builder createClassBuilder(String className, String binary, String abi) {

String javadoc = CODEGEN_WARNING + getCITAjVersion();

return TypeSpec.classBuilder(className)
.addModifiers(Modifier.PUBLIC)
.addJavadoc(javadoc)
.superclass(Contract.class)
.addField(createBinaryDefinition(binary));
.addField(createBinaryDefinition(binary))
.addField(createAbiDefinition(abi));
}

private String getCITAjVersion() {
Expand All @@ -201,6 +203,13 @@ private FieldSpec createBinaryDefinition(String binary) {
.build();
}

private FieldSpec createAbiDefinition(String abi) {
return FieldSpec.builder(String.class, ABI)
.addModifiers(Modifier.PRIVATE, Modifier.FINAL, Modifier.STATIC)
.initializer("$S", abi)
.build();
}

private List<MethodSpec> buildFunctionDefinitions(
String className,
TypeSpec.Builder classBuilder,
Expand Down Expand Up @@ -1075,6 +1084,11 @@ private List<AbiDefinition> loadContractDefinition(String abi) throws IOExceptio
return Arrays.asList(abiDefinition);
}

private String convertToAbiString(List<AbiDefinition> abi) throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
return objectMapper.writeValueAsString(abi);
}

private static class NamedTypeName {
private final TypeName typeName;
private final String name;
Expand Down
11 changes: 8 additions & 3 deletions console/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'

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

// Build command line library release with target distShadowZip
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
"com.google.code.gson:gson:$gsonVersion"
testCompile project(path: ':crypto', configuration: 'archives'),
"nl.jqno.equalsverifier:equalsverifier:$equalsverifierVersion"
testCompile files(project(':crypto').sourceSets.test.output.classesDir)
testCompile files(project(':crypto').sourceSets.test.output.classesDirs)
}

task createProperties(dependsOn: processResources) doLast {
Expand Down
37 changes: 32 additions & 5 deletions core/src/main/java/com/cryptape/cita/protocol/account/Account.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cryptape.cita.protocol.account;

import com.cryptape.cita.utils.Numeric;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
Expand Down Expand Up @@ -49,14 +50,40 @@ public RawTransactionManager getTransactionManager() {

/// TODO: get contract address from receipt after deploy, then return contract name
public AppSendTransaction deploy(
File contractFile, String nonce, long quota,
int version, BigInteger chainId, String value)
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
File contractFile, String nonce, long quota,
int version, BigInteger chainId, String value)
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
CompiledContract contract = new CompiledContract(contractFile);
String contractBin = contract.getBin();
return this.transactionManager
.sendTransaction("", contractBin, quota, nonce, getValidUntilBlock(),
version, chainId, value);
.sendTransaction("", contractBin, quota, nonce, getValidUntilBlock(),
version, chainId, value);
}

/**
*
* @param contractFile
* @param constructorCode add by timmyz, fulfill the construction contract situations
* @param nonce
* @param quota
* @param version
* @param chainId
* @param value
* @return
* @throws IOException
* @throws InterruptedException
* @throws CompiledContract.ContractCompileError
*/
public AppSendTransaction deploy(
File contractFile, String constructorCode, String nonce, long quota,
int version, BigInteger chainId, String value)
throws IOException, InterruptedException, CompiledContract.ContractCompileError {
CompiledContract contract = new CompiledContract(contractFile);
String contractBin = contract.getBin();
String data = constructorCode != null ? contractBin + Numeric.cleanHexPrefix(constructorCode) : contractBin;
return this.transactionManager
.sendTransaction("", data, quota, nonce, getValidUntilBlock(),
version, chainId, value);
}

public Flowable<AppSendTransaction> deployAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.cryptape.cita.utils.Numeric;
import com.cryptape.cita.utils.Strings;

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

0 comments on commit 264bdf8

Please sign in to comment.