Browse Source

Merge commit 'd3a7ebbf92742c26130447388c873256bc0dc438' into release/1.4.0

* commit 'd3a7ebbf92742c26130447388c873256bc0dc438': (35 commits)
  fix sdk compile error
  fix merge develop code , compile error!
  update headers
  add auto node shell
  update header
  cancel sender thread config
  update headers
  update headers
  update headers
  update peer-startup.sh and headers
  modify consensus config file ,write state transfer log to disk
  update headers
  update headers
  update headers
  update headers
  update headers
  update headers
  update headers
  update headers
  modify shell of startup and shutdown
  ...

# Conflicts:
#	core
#	deploy/deploy-peer/src/main/resources/config/init/bftsmart.config
#	explorer
#	framework
#	test
tags/1.4.0^2
huanghaiquan 4 years ago
parent
commit
3fb785eb61
12 changed files with 403 additions and 162 deletions
  1. +0
    -36
      deploy/deploy-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java
  2. +3
    -11
      deploy/deploy-gateway/src/main/resources/config/gateway.conf
  3. +62
    -29
      deploy/deploy-gateway/src/main/resources/scripts/shutdown.sh
  4. +98
    -14
      deploy/deploy-gateway/src/main/resources/scripts/startup.sh
  5. +0
    -24
      deploy/deploy-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java
  6. +3
    -1
      deploy/deploy-peer/src/main/resources/config/init/bftsmart.config
  7. +62
    -29
      deploy/deploy-peer/src/main/resources/scripts/peer-shutdown.sh
  8. +112
    -14
      deploy/deploy-peer/src/main/resources/scripts/peer-startup.sh
  9. +12
    -0
      samples/sdk-samples/pom.xml
  10. +4
    -4
      samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Constant.java
  11. +5
    -0
      samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_Base_Demo.java
  12. +42
    -0
      samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_Update_ConsensusSettings_Demo.java

+ 0
- 36
deploy/deploy-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java View File

@@ -15,45 +15,9 @@ public class GatewayBooter {

public static void main(String[] args) {
try {
writePID();
GatewayServerBooter.main(args);
} catch (Exception e) {
System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage());
}
}

private static final void writePID() throws Exception {
URL url = GatewayBooter.class.getProtectionDomain().getCodeSource().getLocation();
String currPath = java.net.URLDecoder.decode(url.getPath(), "UTF-8");
if (currPath.contains("!/")) {
currPath = currPath.substring(5, currPath.indexOf("!/"));
}
if (currPath.endsWith(".jar")) {
currPath = currPath.substring(0, currPath.lastIndexOf("/") + 1);
}
System.out.printf("currentPath = %s \r\n", currPath);
File file = new File(currPath);
String homeDir = file.getParent();
String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log";
File pidFile = new File(pidFilePath);
if (!pidFile.exists()) {
File dir = pidFile.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
pidFile.createNewFile();
}
String name = ManagementFactory.getRuntimeMXBean().getName();
String pid = name.split("@")[0];
List<String> bootInfos = new ArrayList<>();
bootInfos.add("JDChain gateway starts to boot ......\r\n");
bootInfos.add(String.format("GW_BOOT_TIME = [%s] \r\n", new Date().toString()));
bootInfos.add(String.format("GW_BOOT_PID = [%s] \r\n", pid));
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) {
for (String bootInfo : bootInfos) {
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8));
}
outputStream.flush();
}
}
}

+ 3
- 11
deploy/deploy-gateway/src/main/resources/config/gateway.conf View File

@@ -5,20 +5,12 @@ http.port=8080
#网关的HTTP服务上下文路径,可选;
#http.context-path=

#对端Peer节点的数量
peer.size=2
#共识节点的服务地址(与该网关节点连接的Peer节点的IP地址);
peer.0.host=127.0.0.1
peer.host=127.0.0.1
#共识节点的服务端口(与该网关节点连接的Peer节点的端口,即在Peer节点的peer-startup.sh中定义的端口);
peer.0.port=7080
peer.port=7080
#共识节点的服务是否启用安全证书;
peer.0.secure=false
#共识节点的服务地址(与该网关节点连接的Peer节点的IP地址);
peer.1.host=127.0.0.1
#共识节点的服务端口(与该网关节点连接的Peer节点的端口,即在Peer节点的peer-startup.sh中定义的端口);
peer.1.port=7081
#共识节点的服务是否启用安全证书;
peer.1.secure=false
peer.secure=false

#共识节点的服务提供解析器
#BftSmart共识Provider:com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider


+ 62
- 29
deploy/deploy-gateway/src/main/resources/scripts/shutdown.sh View File

@@ -1,32 +1,65 @@
#!/bin/bash

#启动Home路径
BOOT_HOME=$(cd `dirname $0`;cd ../; pwd)

#进程启动后PID.log所在路径
PID_LOG=$BOOT_HOME/bin/PID.log

#从启动文件中读取PID
if [ -f "$PID_LOG" ]; then
# File exist
echo "Read PID From File:[$PID_LOG] ..."
PID_LINE=`sed -n '$p' $PID_LOG`
echo "Last Gateway Boot Info = $PID_LINE ..."
if [[ $PID_LINE == *GW_BOOT_PID* ]]; then
LOG_PID=$(echo $PID_LINE | cut -d "=" -f 2 | cut -d "[" -f 2 | cut -d "]" -f 1)
echo "Last Gateway Boot PID = $LOG_PID ..."
PID=`ps -ef | grep deploy-gateway- | grep $LOG_PID | grep -v grep | awk '{print $2}'`
#定义程序启动的Jar包前缀
APP_JAR_PREFIX=deploy-gateway-

#获取当前的根目录
APP_HOME=$(cd `dirname $0`;cd ../; pwd)

#System路径
APP_LIB_PATH=$APP_HOME/lib

#获取Peer节点的启动Jar包
APP_JAR=$(ls $APP_LIB_PATH | grep $APP_JAR_PREFIX)

#APP_JAR的具体路径
APP_JAR_PATH=$APP_LIB_PATH/$APP_JAR

###################################
#(函数)判断程序是否已启动
#
#说明:
#使用awk,分割出pid ($1部分),及Java程序名称($2部分)
###################################
#初始化psid变量(全局)
psid=0

checkpid() {
psid=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'`
}

###################################
#(函数)停止程序
#
#说明:
#1. 首先调用checkpid函数,刷新$psid全局变量
#2. 如果程序已经启动($psid不等于0),则开始执行停止,否则,提示程序未运行
#3. 使用kill -9 pid命令进行强制杀死进程
#4. 执行kill命令行紧接其后,马上查看上一句命令的返回值: $?
#5. 如果步骤4的结果$?等于0,则打印[OK],否则打印[Failed]
#注意:echo -n 表示打印字符后,不换行
#注意: 在shell编程中,"$?" 表示上一句命令或者一个函数的返回值
###################################
stop() {
checkpid

if [[ $psid -ne 0 ]]; then
echo "Stopping Gateway ......(pid=$psid) "
JAVA_CMD="kill -9 $psid"
sleep 1
$JAVA_CMD
if [[ $? -eq 0 ]]; then
echo "[OK]"
else
echo "[Failed]"
fi
#启动文件不存在则直接通过PS进行过滤
else
PID=`ps -ef | grep $BOOT_HOME/lib/deploy-gateway- | grep -v grep | awk '{print $2}'`
fi

#通过Kill命令将进程杀死
if [ -z "$PID" ]; then
echo "Unable to find gateway PID. stop aborted."
else
echo "Start to kill PID = $PID ..."
kill -9 $PID
echo "Gateway has been stopped ..."
fi
else
echo "================================"
echo "WARN: Gateway is not running"
echo "================================"
fi
}


#真正停止的处理流程
stop

+ 98
- 14
deploy/deploy-gateway/src/main/resources/scripts/startup.sh View File

@@ -1,19 +1,103 @@
#!/bin/bash

HOME=$(cd `dirname $0`;cd ../; pwd)
GATEWAY=$(ls $HOME/lib | grep deploy-gateway-)
PROC_INFO=$HOME/lib/$GATEWAY" -c "$HOME/config/gateway.conf
#echo $PROC_INFO
#get PID
PID=`ps -ef | grep "$PROC_INFO" | grep -v grep | awk '{print $2}'`
#echo $PID
if [[ ! -z $PID ]]
then
echo "process already exists,please check... If necessary, you should kill the process first."
exit
#设置Java命令
JAVA_BIN=java
#定义程序启动的Jar包前缀
APP_JAR_PREFIX=deploy-gateway-
#检查Java环境变量
if [ ! -n "$JAVA_HOME" ]; then
echo "UnFound environment variable[JAVA_HOME], will use command[java]..."
else
JAVA_BIN=$JAVA_HOME/bin/java
fi
if [ ! -n "$GATEWAY" ]; then
echo "GateWay Is Null !!!"

#获取当前的根目录
APP_HOME=$(cd `dirname $0`;cd ../; pwd)

#Lib目录
APP_LIB_PATH=$APP_HOME/lib

#节点输出日志路径
LOG_OUT=$APP_HOME/bin/gw.out

#获取Peer节点的启动Jar包
APP_JAR=$(ls $APP_LIB_PATH | grep $APP_JAR_PREFIX)

#Config配置路径
CONFIG_PATH=$APP_HOME/config

#gateway.conf完整路径
GATEWAY_CONFIG=$CONFIG_PATH/gateway.conf

#定义程序启动的参数
JAVA_OPTS="-jar -server -Xms1024m -Xmx1024m"

#APP具体相关命令
APP_CMD=$APP_LIB_PATH/$APP_JAR" -c "$GATEWAY_CONFIG

#APP_JAR的具体路径
APP_JAR_PATH=$APP_LIB_PATH/$APP_JAR

#JAVA_CMD具体命令
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD"

###################################
#(函数)判断程序是否已启动
#
#说明:
#使用awk,分割出pid ($1部分),及Java程序名称($2部分)
###################################
#初始化psid变量(全局)
psid=0

checkpid() {
javaps=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'`

if [[ -n "$javaps" ]]; then
psid=$javaps
else
psid=0
fi
}

###################################
#(函数)打印系统环境参数
###################################
info() {
echo "System Information:"
echo "****************************"
echo `uname -a`
echo
echo `$JAVA_BIN -version`
echo
echo "APP_HOME=$APP_HOME"
echo "APP_JAR=$APP_JAR"
echo "CONFIG_PATH=$CONFIG_PATH"
echo "APP_JAR_PATH=$APP_JAR_PATH"
echo
echo "JAVA_CMD=$JAVA_CMD"
echo "****************************"
}

#真正启动的处理流程
checkpid

if [[ $psid -ne 0 ]]; then
echo "================================"
echo "warn: Gateway already started! (pid=$psid)"
echo "================================"
else
nohup java -jar -server -Djdchain.log=$HOME $PROC_INFO $* >$HOME/bin/gw.out 2>&1 &
echo "Starting Gateway ......"
nohup $JAVA_BIN $JAVA_OPTS $APP_CMD $* >$LOG_OUT 2>&1 &
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD $*"
sleep 1
checkpid
if [[ $psid -ne 0 ]]; then
echo "(pid=$psid) [OK]"
info
else
echo "[Failed]"
fi
fi

+ 0
- 24
deploy/deploy-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java View File

@@ -33,12 +33,8 @@ public class PeerBooter {

public static void main(String[] args) {
try {

HomeContext homeContext = HomeBooter.createHomeContext(args);

startPeer(homeContext);

writePID(homeContext.getHomeDir());
} catch (Exception e) {
System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage());
}
@@ -56,24 +52,4 @@ public class PeerBooter {
SYSTEM_MAIN_CLASS, home.getSystemClassLoader(), home.getStartingArgs() };
modularFactoryMethod.invoke(null, systemStartingArgs);
}

private static final void writePID(String homeDir) throws IOException {
String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log";
File pidFile = new File(pidFilePath);
if (!pidFile.exists()) {
pidFile.createNewFile();
}
String name = ManagementFactory.getRuntimeMXBean().getName();
String pid = name.split("@")[0];
List<String> bootInfos = new ArrayList<>();
bootInfos.add("JDChain peer node starts to boot ......\r\n");
bootInfos.add(String.format("PEER_BOOT_TIME = [%s] \r\n", new Date().toString()));
bootInfos.add(String.format("PEER_BOOT_PID = [%s] \r\n", pid));
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) {
for (String bootInfo : bootInfos) {
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8));
}
outputStream.flush();
}
}
}

+ 3
- 1
deploy/deploy-peer/src/main/resources/config/init/bftsmart.config View File

@@ -74,6 +74,8 @@ system.servers.f = 1
#Timeout to asking for a client request
system.totalordermulticast.timeout = 60000

#Allowable time tolerance range(millisecond)
system.totalordermulticast.timeTolerance = 3000000

#Maximum batch size (in number of messages)
system.totalordermulticast.maxbatchsize = 2000
@@ -132,7 +134,7 @@ system.totalordermulticast.timeout_highMark = 200

system.totalordermulticast.log = true
system.totalordermulticast.log_parallel = false
system.totalordermulticast.log_to_disk = false
system.totalordermulticast.log_to_disk = true
system.totalordermulticast.sync_log = false

#Period at which BFT-SMaRt requests the state to the application (for the state transfer state protocol)


+ 62
- 29
deploy/deploy-peer/src/main/resources/scripts/peer-shutdown.sh View File

@@ -1,32 +1,65 @@
#!/bin/bash

#启动Home路径
BOOT_HOME=$(cd `dirname $0`;cd ../; pwd)

#进程启动后PID.log所在路径
PID_LOG=$BOOT_HOME/bin/PID.log

#从启动文件中读取PID
if [ -f "$PID_LOG" ]; then
# File exist
echo "Read PID From File:[$PID_LOG] ..."
PID_LINE=`sed -n '$p' $PID_LOG`
echo "Last Peer Boot Info = $PID_LINE ..."
if [[ $PID_LINE == *PEER_BOOT_PID* ]]; then
LOG_PID=$(echo $PID_LINE | cut -d "=" -f 2 | cut -d "[" -f 2 | cut -d "]" -f 1)
echo "Last Peer Boot PID = $LOG_PID ..."
PID=`ps -ef | grep deploy-peer- | grep $LOG_PID | grep -v grep | awk '{print $2}'`
#定义程序启动的Jar包前缀
APP_JAR_PREFIX=deploy-peer-

#获取当前的根目录
APP_HOME=$(cd `dirname $0`;cd ../; pwd)

#System路径
APP_SYSTEM_PATH=$APP_HOME/system

#获取Peer节点的启动Jar包
APP_JAR=$(ls $APP_SYSTEM_PATH | grep $APP_JAR_PREFIX)

#APP_JAR的具体路径
APP_JAR_PATH=$APP_SYSTEM_PATH/$APP_JAR

###################################
#(函数)判断程序是否已启动
#
#说明:
#使用awk,分割出pid ($1部分),及Java程序名称($2部分)
###################################
#初始化psid变量(全局)
psid=0

checkpid() {
psid=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'`
}

###################################
#(函数)停止程序
#
#说明:
#1. 首先调用checkpid函数,刷新$psid全局变量
#2. 如果程序已经启动($psid不等于0),则开始执行停止,否则,提示程序未运行
#3. 使用kill -9 pid命令进行强制杀死进程
#4. 执行kill命令行紧接其后,马上查看上一句命令的返回值: $?
#5. 如果步骤4的结果$?等于0,则打印[OK],否则打印[Failed]
#注意:echo -n 表示打印字符后,不换行
#注意: 在shell编程中,"$?" 表示上一句命令或者一个函数的返回值
###################################
stop() {
checkpid

if [[ $psid -ne 0 ]]; then
echo "Stopping Peer ......(pid=$psid) "
JAVA_CMD="kill -9 $psid"
sleep 1
$JAVA_CMD
if [[ $? -eq 0 ]]; then
echo "[OK]"
else
echo "[Failed]"
fi
#启动文件不存在则直接通过PS进行过滤
else
PID=`ps -ef | grep $BOOT_HOME/system/deploy-peer- | grep -v grep | awk '{print $2}'`
fi

#通过Kill命令将进程杀死
if [ -z "$PID" ]; then
echo "Unable to find peer PID. stop aborted."
else
echo "Start to kill PID = $PID ..."
kill -9 $PID
echo "Peer has been stopped ..."
fi
else
echo "================================"
echo "WARN: Peer is not running"
echo "================================"
fi
}


#真正停止的处理流程
stop

+ 112
- 14
deploy/deploy-peer/src/main/resources/scripts/peer-startup.sh View File

@@ -1,19 +1,117 @@
#!/bin/bash

HOME=$(cd `dirname $0`;cd ../; pwd)
PEER=$(ls $HOME/system | grep deploy-peer-)
PROC_INFO=$HOME/system/$PEER" -home="$HOME" -c "$HOME/config/ledger-binding.conf" -p 7080"
#echo $PROC_INFO
#get PID
PID=`ps -ef | grep "$PROC_INFO" | grep -v grep | awk '{print $2}'`
#echo $PID
if [[ ! -z $PID ]]
then
echo "process already exists,please check... If necessary, you should kill the process first."
exit
#设置Java命令
JAVA_BIN=java

#定义程序启动的Jar包前缀
APP_JAR_PREFIX=deploy-peer-

#Peer节点Web端口
#请运维根据实际环境进行调整或通过-p参数传入
WEB_PORT=7080
#端口配置参数
IS_CONFIG=false
for i in "$@"; do
if [ $i = "-p" ];then
IS_CONFIG=true
fi
done

#检查Java环境变量
if [ ! -n "$JAVA_HOME" ]; then
echo "UnFound environment variable[JAVA_HOME], will use command[java]..."
else
JAVA_BIN=$JAVA_HOME/bin/java
fi
if [ ! -n "$PEER" ]; then
echo "Peer Is Null !!!"

#获取当前的根目录
APP_HOME=$(cd `dirname $0`;cd ../; pwd)

#System目录
APP_SYSTEM_PATH=$APP_HOME/system

#节点输出日志路径
LOG_OUT=$APP_HOME/bin/peer.out

#获取Peer节点的启动Jar包
APP_JAR=$(ls $APP_SYSTEM_PATH | grep $APP_JAR_PREFIX)

#Config配置路径
CONFIG_PATH=$APP_HOME/config

#ledger-binding.conf完整路径
LEDGER_BINDING_CONFIG=$CONFIG_PATH/ledger-binding.conf

#定义程序启动的参数
JAVA_OPTS="-jar -server -Xms2048m -Xmx2048m"

#APP具体相关命令
APP_CMD=$APP_SYSTEM_PATH/$APP_JAR" -home="$APP_HOME" -c "$LEDGER_BINDING_CONFIG" -p "$WEB_PORT
if [ $IS_CONFIG = true ];then
APP_CMD=$APP_SYSTEM_PATH/$APP_JAR" -home="$APP_HOME" -c "$LEDGER_BINDING_CONFIG
fi

#APP_JAR的具体路径
APP_JAR_PATH=$APP_SYSTEM_PATH/$APP_JAR

#JAVA_CMD具体命令
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD"

###################################
#(函数)判断程序是否已启动
#
#说明:
#使用awk,分割出pid ($1部分),及Java程序名称($2部分)
###################################
#初始化psid变量(全局)
psid=0

checkpid() {
javaps=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'`

if [[ -n "$javaps" ]]; then
psid=$javaps
else
psid=0
fi
}

###################################
#(函数)打印系统环境参数
###################################
info() {
echo "System Information:"
echo "****************************"
echo `uname -a`
echo
echo `$JAVA_BIN -version`
echo
echo "APP_HOME=$APP_HOME"
echo "APP_JAR=$APP_JAR"
echo "CONFIG_PATH=$CONFIG_PATH"
echo "APP_JAR_PATH=$APP_JAR_PATH"
echo
echo "JAVA_CMD=$JAVA_CMD"
echo "****************************"
}

#真正启动的处理流程
checkpid

if [[ $psid -ne 0 ]]; then
echo "================================"
echo "warn: Peer already started! (pid=$psid)"
echo "================================"
else
nohup java -jar -server -Xmx1g -Xms1g -Djdchain.log=$HOME $PROC_INFO $* >$HOME/bin/peer.out 2>&1 &
echo "Starting Peer ......"
nohup $JAVA_BIN $JAVA_OPTS $APP_CMD $* >$LOG_OUT 2>&1 &
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD $*"
sleep 1
checkpid
if [[ $psid -ne 0 ]]; then
echo "(pid=$psid) [OK]"
info
else
echo "[Failed]"
fi
fi

+ 12
- 0
samples/sdk-samples/pom.xml View File

@@ -18,6 +18,18 @@
<groupId>com.jd.blockchain</groupId>
<artifactId>ledger-model</artifactId>
</dependency>
<dependency>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto-classic</artifactId>
</dependency>
<dependency>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto-framework</artifactId>
</dependency>
<dependency>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto-sm</artifactId>
</dependency>
<dependency>
<groupId>com.jd.blockchain</groupId>
<artifactId>contract-samples</artifactId>


+ 4
- 4
samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Constant.java View File

@@ -7,20 +7,20 @@ import java.io.File;

public class SDKDemo_Constant {

public static final String GW_IPADDR = "127.0.0.1";
public static final String GW_IPADDR = "jdchain-cloud0-8080.jdfmgt.com";
// public static final String GW_IPADDR = "192.168.151.41";

public static final int GW_PORT = 11000;
public static final int GW_PORT = 80;
// public static final int GW_PORT = 18081;

public static final String[] PUB_KEYS = {
"3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
"3snPdw7i7Pf2u9KTNUhxrYxgEymH24zP3NNNauRVwX5yDD6rzu2uBY",
"3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
"3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
"3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"};

public static final String[] PRIV_KEYS = {
"177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
"177gjy71kcL5pU2YayqeZ44AfE87o8b5PfLeBER1rjsjViGux3TzdLcQs7QEznRMCw2sAHD",
"177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
"177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
"177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns"};


+ 5
- 0
samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_Base_Demo.java View File

@@ -48,4 +48,9 @@ public abstract class SDK_Base_Demo {
ptx.sign(adminKey);
return ptx.commit();
}

protected void printTxResponse(TransactionResponse response) {
System.out.printf("TxResponse's state = [%s][%s], blockHeight = [%s] ! \r\n",
response.isSuccess(), response.getExecutionState(), response.getBlockHeight());
}
}

+ 42
- 0
samples/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_Update_ConsensusSettings_Demo.java View File

@@ -0,0 +1,42 @@
package com.jd.blockchain.sdk.samples;

import com.jd.blockchain.ledger.PreparedTransaction;
import com.jd.blockchain.ledger.TransactionResponse;
import com.jd.blockchain.ledger.TransactionTemplate;
import com.jd.blockchain.utils.Property;

import java.util.ArrayList;
import java.util.List;

public class SDK_Update_ConsensusSettings_Demo extends SDK_Base_Demo {

public static void main(String[] args) {
new SDK_Update_ConsensusSettings_Demo().updateSettings();
}

public void updateSettings() {

List<Property> properties = new ArrayList<Property>();

// 修改bftsmart.conf配置文件中的选项;
properties.add(new Property("system.communication.useSenderThread", "false"));

Property[] propertiesArray = properties.toArray(new Property[properties.size()]);

TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);

txTpl.settings().update(propertiesArray);

// TX 准备就绪;
PreparedTransaction prepTx = txTpl.prepare();

// 使用私钥进行签名;
prepTx.sign(adminKey);

// 提交交易;
TransactionResponse transactionResponse = prepTx.commit();

System.out.println(transactionResponse.isSuccess());

}
}

Loading…
Cancel
Save