Skip to content

Commit

Permalink
Merge pull request #48 from fqliao/release-1.0.1
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
fqliao authored Apr 8, 2019
2 parents 0e616da + 0858a99 commit ef3504c
Show file tree
Hide file tree
Showing 17 changed files with 966 additions and 283 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# safelist
branches:
only:
- master
only:
- /.*/

language: java
jdk:
Expand Down
23 changes: 19 additions & 4 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
### v1.0.1

(2019-04-02)

* Add

1. 提供`getDeployLog`(查询部署的合约地址),`exit`(退出控制台)命令。
2. 提供下载控制台脚本`download_console.sh`
3. `start.sh`脚本中增加对Java版本检测。

* Update
1. 支持合约引入Solidity library库。
2. 支持合约地址可以省略0x以及前缀0。例如,0x000ac78可以简写成0xac78或ac78。
3. 优化命令的帮助信息。

### v1.0.0

(2019-03-18)

* Add

1. 提供区块链状态查询命令
2. 提供管理区块链节点的命令
3. 提供简单易用的部署和调用合约命令
4. 提供合约编译工具将solidity合约文件编译为java合约文件
1. 提供区块链状态查询命令
2. 提供管理区块链节点的命令
3. 提供简单易用的部署和调用合约命令
4. 提供合约编译工具将Solidity合约文件编译为Java合约文件。
3 changes: 0 additions & 3 deletions lib/web3sdk.jar

This file was deleted.

42 changes: 42 additions & 0 deletions solidity/contracts/Ok.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pragma solidity ^0.4.24;
contract Ok{

struct Account{
address account;
uint balance;
}

struct Translog {
string time;
address from;
address to;
uint amount;
}

Account from;
Account to;
event TransEvent(uint num);
Translog[] log;

function Ok(){
from.account=0x1;
from.balance=10000000000;
to.account=0x2;
to.balance=0;

}

function get()constant returns(uint){
return to.balance;
}

function trans(uint num){
if (from.balance < num || to.balance + num < to.balance)
return; // Deny overflow

from.balance=from.balance-num;
to.balance+=num;
TransEvent(num);
log.push(Translog("20170413",from.account,to.account,num));
}
}
56 changes: 50 additions & 6 deletions src/main/java/console/ConsoleClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package console;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.fisco.bcos.web3j.protocol.ObjectMapperFactory;
import org.fisco.bcos.web3j.protocol.channel.ResponseExcepiton;
import org.fisco.bcos.web3j.protocol.core.Response;
import org.fisco.bcos.web3j.protocol.exceptions.MessageDecodingException;
import org.jline.builtins.Completers.FilesCompleter;
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
Expand Down Expand Up @@ -69,6 +73,7 @@ public static void main(String[] args) {
new ArgumentCompleter(new StringsCompleter("callByCNS"), new FilesCompleter(path)));
completers.add(
new ArgumentCompleter(new StringsCompleter("queryCNS"), new FilesCompleter(path)));
completers.add(new ArgumentCompleter(new StringsCompleter("getDeployLog")));
completers.add(new ArgumentCompleter(new StringsCompleter("addSealer")));
completers.add(new ArgumentCompleter(new StringsCompleter("addObserver")));
completers.add(new ArgumentCompleter(new StringsCompleter("removeNode")));
Expand All @@ -91,10 +96,11 @@ public static void main(String[] args) {
completers.add(new ArgumentCompleter(new StringsCompleter("revokeSysConfigManager")));
completers.add(new ArgumentCompleter(new StringsCompleter("listSysConfigManager")));
completers.add(new ArgumentCompleter(new StringsCompleter("setSystemConfigByKey"), new StringsCompleter(Common.TxCountLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("setSystemConfigByKey"), new StringsCompleter(Common.txGasLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("setSystemConfigByKey"), new StringsCompleter(Common.TxGasLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("getSystemConfigByKey"), new StringsCompleter(Common.TxCountLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("getSystemConfigByKey"), new StringsCompleter(Common.txGasLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("getSystemConfigByKey"), new StringsCompleter(Common.TxGasLimit)));
completers.add(new ArgumentCompleter(new StringsCompleter("quit")));
completers.add(new ArgumentCompleter(new StringsCompleter("exit")));

Terminal terminal = TerminalBuilder.terminal();
lineReader =
Expand All @@ -121,7 +127,7 @@ public static void main(String[] args) {
System.out.print("");
continue;
}
if ("quit".equals(params[0]) || "q".equals(params[0])) {
if ("quit".equals(params[0]) || "q".equals(params[0]) || "exit".equals(params[0])) {
if (HelpInfo.promptNoParams(params, "q")) {
continue;
} else if (params.length > 2) {
Expand Down Expand Up @@ -209,6 +215,9 @@ public static void main(String[] args) {
case "deploy":
console.deploy(params);
break;
case "getDeployLog":
console.getDeployLog(params);
break;
case "call":
console.call(params);
break;
Expand Down Expand Up @@ -302,7 +311,9 @@ public static void main(String[] args) {
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage() + " does not exist.");
System.out.println();
} catch (IOException e) {
} catch (MessageDecodingException e) {
pringMessageDecodeingException(e);
}catch (IOException e) {
if (e.getMessage().startsWith("activeConnections")) {
System.out.println("Lost the connection to the node. "
+ "Please check the connection between the console and the node.");
Expand All @@ -314,10 +325,43 @@ public static void main(String[] args) {
}
System.out.println();
}
catch (InvocationTargetException e) {
System.out.println("Contract call failed.");
System.out.println();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.out.println();
if(e.getMessage().contains("MessageDecodingException"))
{
pringMessageDecodeingException(new MessageDecodingException(e.getMessage().split("MessageDecodingException: ")[1]));
}
else {
System.out.println(e.getMessage());
System.out.println();
}
}
}
}

private static void pringMessageDecodeingException(MessageDecodingException e) {
String message = e.getMessage();
Response t = null;
try {
t = ObjectMapperFactory.getObjectMapper(true).readValue(
message.substring(message.indexOf("{"), message.lastIndexOf("}") + 1),
Response.class);
if (t != null) {
ConsoleUtils.printJson(
"{\"code\":"
+ t.getError().getCode()
+ ", \"msg\":"
+ "\""
+ t.getError().getMessage()
+ "\"}");
System.out.println();
}
}catch (Exception e1) {
System.out.println(e1.getMessage());
System.out.println();
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/console/ConsoleFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ public interface ConsoleFace {

void getSystemConfigByKey(String[] params) throws Exception;

void getDeployLog(String[] params) throws Exception;

void init(String[] args);
}
Loading

0 comments on commit ef3504c

Please sign in to comment.