Commit a6ae394b authored by liuyuhang's avatar liuyuhang

add chain33_GetAccounts to common

parents bd2c2e0d 586d3ebf
......@@ -106,7 +106,7 @@ chain33_ImportPrivkey() {
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"'"$label"'"}]'
resp=$(curl -ksd "{$req}" "$MAIN_HTTP")
ok=$(jq '(.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
ok=$(jq '(((.error|not) and (.result.label=="'"$label"'") and (.result.acc.addr == "'"$acc"'")) or (.error=="ErrPrivkeyExist"))' <<<"$resp")
[ "$ok" == true ]
}
......@@ -126,8 +126,32 @@ chain33_SignRawTx() {
fi
}
chain33_QueryBalance() {
local addr=$1
local MAIN_HTTP=$2
req='"method":"Chain33.GetAllExecBalance","params":[{"addr":"'"${addr}"'"}]'
#echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result != "")' <<<"$resp")
[ "$ok" == true ]
echo "$resp" | jq -r ".result"
}
chain33_QueryExecBalance() {
local addr=$1
local exec=$2
local MAIN_HTTP=$3
req='{"method":"Chain33.GetBalance", "params":[{"addresses" : ["'"${addr}"'"], "execer" : "'"${exec}"'"}]}'
resp=$(curl -ksd "$req" "${MAIN_HTTP}")
echo "#response: $resp"
ok=$(jq '(.error|not) and (.result[0] | [has("balance", "frozen"), true] | unique | length == 1)' <<<"$resp")
[ "$ok" == true ]
}
chain33_GetAccounts() {
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.GetAccounts","params":[{}]}' -H 'content-type:text/plain;' ${MAIN_HTTP})
echo "$resp"
}
}
\ No newline at end of file
......@@ -398,7 +398,8 @@ function main() {
dapp_run config
### test cases ###
ip=$(${CLI} net info | jq -r ".externalAddr[0:10]")
ip=$(${CLI} net info | jq -r ".externalAddr")
ip=$(echo "$ip" | cut -d':' -f 1)
dapp_run test "${ip}"
### rpc test ###
......
......@@ -18,8 +18,8 @@ import (
)
var (
consensusInterval = 16 //about 1 new block interval
minerInterval = 5
consensusInterval = 10 //about 1 new block interval
minerInterval = 10 //5s的主块间隔后分叉概率增加,10s可以消除一些分叉回退
)
type commitMsgClient struct {
......
......@@ -4,31 +4,20 @@ set -e
set -o pipefail
MAIN_HTTP=""
CASE_ERR=""
GAME_ID=""
PASSWD="ABCD"
HASH_VALUE=$(echo -n "ABCD1" | sha256sum | awk '{print $1}')
signedTx=""
txHash=""
ACCOUNT_A="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
# PRIVA_A="cc38546e9e659d15e6b4893f0ab32a06d103931a8230b0bde71459d2b27d6944"
ACCOUNT_B="19MJmA7GcE1NfMwdGqgLJioBjVbzQnVYvR"
PRIVA_B="5072a3b6ed612845a7c00b88b38e4564093f57ce652212d6e26da9fded83e951"
ACCOUNT_A="1PUiGcbsccfxW3zuvHXZBJfznziph5miAo"
PRIVA_A="56942AD84CCF4788ED6DACBC005A1D0C4F91B63BCF0C99A02BE03C8DEAE71138"
ACCOUNT_B="1EDnnePAZN48aC2hiTDzhkczfF39g1pZZX"
PRIVA_B="2116459C0EC8ED01AA0EEAE35CAC5C96F94473F7816F114873291217303F6989"
EXECTOR=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
function echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="FAIL"
fi
}
# shellcheck source=/dev/null
source ../dapp-test-common.sh
function chain33_GetExecAddr() {
#获取GAME合约地址
......@@ -44,41 +33,36 @@ function chain33_GetExecAddr() {
function CreateGameTx() {
local amount=$1
local hash_value=$2
local addr=$3
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"createGame", "payload":{"amount": '"${amount}"',"hashType":"sha256","hashValue":"'"${hash_value}"'"}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CreateGame createRawTx" 1
fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CreateGame signRawTx" "$?"
sendSignedTx
echo_rst "CreateGame sendSignedTx" "$?"
GAME_ID="${txHash}"
# create_txHash="${txHash}"
query_tx "${txHash}"
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
GAME_ID=$RAW_TX_HASH
echo_rst "CreateGame query_tx" "$?"
}
function MatchGameTx() {
local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"matchGame", "payload":{"gameId": "'"${gameId}"'","guess":2}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "MatchGame createRawTx" 1
fi
signRawTx "${rawTx}" "${ACCOUNT_B}"
echo_rst "MatchGame signRawTx" "$?"
sendSignedTx
echo_rst "MatchGame sendSignedTx" "$?"
# match_txHash="${txHash}"
query_tx "${txHash}"
chain33_SignRawTx "${rawTx}" "${PRIVA_B}" "${MAIN_HTTP}"
echo_rst "MatchGame query_tx" "$?"
}
......@@ -86,37 +70,34 @@ function CloseGameTx() {
local gameId=$1
local secret=$2
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"closeGame", "payload":{"gameId": "'"${gameId}"'","secret":"'"${secret}"'","result":1}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CloseGame createRawTx" 1
fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CloseGame signRawTx" "$?"
sendSignedTx
echo_rst "CloseGame sendSignedTx" "$?"
query_tx "${txHash}"
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CloseGame query_tx" "$?"
}
function CancleGameTx() {
local gameId=$1
local req='"method":"Chain33.CreateTransaction","params":[{"execer":"'"${EXECTOR}"'", "actionName":"cancelGame", "payload":{"gameId": "'"${gameId}"'"}}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "${MAIN_HTTP}")
echo "#response: $resp"
rawTx=$(echo "${resp}" | jq -r ".result")
if [ "$rawTx" == "null" ]; then
echo_rst "CancleGame createRawTx" 1
fi
signRawTx "${rawTx}" "${ACCOUNT_A}"
echo_rst "CancleGame signRawTx" "$?"
sendSignedTx
echo_rst "CancleGame sendSignedTx" "$?"
# close_txHash="${txHash}"
query_tx "${txHash}"
chain33_SignRawTx "${rawTx}" "${PRIVA_A}" "${MAIN_HTTP}"
echo_rst "CancleGame query_tx" "$?"
}
......@@ -147,118 +128,12 @@ function QueryGameByGameId() {
echo_rst "QueryGameByGameId" 0
}
function chain33_ImportPrivkey() {
local pri=$2
#local acc=$3
local req='"method":"Chain33.ImportPrivkey", "params":[{"privkey":"'"$pri"'", "label":"gameB"}]'
echo "#request: $req"
resp=$(curl -ksd "{$req}" "$1")
echo "#response: $resp"
# ok=$(jq '(.error|not) and (.result.label=="gameB") and (.result.acc.addr == "'"$acc"'")' <<<"$resp")
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
}
function Chain33_SendToAddress() {
from=$1
to=$2
amount=$3
http=$4
note="test"
resp=$(curl -ksd '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendToAddress","params":[{"from":"'"$from"'","to":"'"$to"'","amount":'"$amount"',"note":"'"$note"'"}]}' -H 'content-type:text/plain;' "${http}")
ok=$(jq '(.error|not)' <<<"$resp")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function chain33_unlock() {
ok=$(curl -k -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.UnLock","params":[{"passwd":"1314fuzamei","timeout":0}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result.isOK")
[ "$ok" == true ]
rst=$?
echo_rst "$FUNCNAME" "$rst"
}
function block_wait() {
local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
function signRawTx() {
unsignedTx=$1
addr=$2
signedTx=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.SignRawTx","params":[{"addr":"'"${addr}"'","txHex":"'"${unsignedTx}"'","expire":"120s","fee":1000000}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "$signedTx" == "null" ]; then
return 1
else
return 0
fi
}
function sendSignedTx() {
txHash=$(curl -s --data-binary '{"jsonrpc":"2.0","id":2,"method":"Chain33.SendTransaction","params":[{"token":"","data":"'"${signedTx}"'"}]}' -H 'content-type:text/plain;' ${MAIN_HTTP} | jq -r ".result")
if [ "$txHash" == "null" ]; then
return 1
else
return 0
fi
}
function query_tx() {
block_wait 1
txhash="$1"
# echo "req=$req"
local times=10
while true; do
req='{"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]}'
ret=$(curl -ksd "$req" ${MAIN_HTTP})
tx=$(jq -r ".result.tx.hash" <<<"$ret")
echo "====query tx= ${1}, return=$ret "
if [ "${tx}" != "${1}" ]; then
block_wait 1
times=$((times - 1))
if [ $times -le 0 ]; then
echo "====query tx=$1 failed"
echo "req=$req"
curl -ksd "$req" ${MAIN_HTTP}
exit 1
fi
else
exec_err=$(jq '(.result.receipt.logs[0].tyName == "LogErr")' <<<"$ret")
[ "$exec_err" != true ]
echo "====query tx=$1 success"
break
fi
done
}
function init() {
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ipara=$ispara"
from="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33_ImportPrivkey "${MAIN_HTTP}" "${PRIVA_B}" "${ACCOUNT_B}"
local game_addr=""
if [ "$ispara" == "true" ]; then
#主链中相应账户需要转帐
M_HTTP=${MAIN_HTTP//8901/8801}
Chain33_SendToAddress "${ACCOUNT_A}" "${ACCOUNT_B}" 20000000000 "${M_HTTP}"
block_wait 1
EXECTOR="user.p.para.game"
game_addr=$(curl -ksd '{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.game"}]}' ${MAIN_HTTP} | jq -r ".result")
else
......@@ -267,11 +142,11 @@ function init() {
fi
echo "gameAddr=${game_addr}"
Chain33_SendToAddress "${ACCOUNT_B}" "$game_addr" 5000000000 "${MAIN_HTTP}"
chain33_SendToAddress "${ACCOUNT_B}" "$game_addr" 5000000000 "${MAIN_HTTP}"
Chain33_SendToAddress "${ACCOUNT_A}" "$game_addr" 5000000000 "${MAIN_HTTP}"
chain33_SendToAddress "${ACCOUNT_A}" "$game_addr" 5000000000 "${MAIN_HTTP}"
block_wait 1
chain33_BlockWait 1 "$MAIN_HTTP"
}
function run_test() {
......@@ -311,12 +186,7 @@ function main() {
echo "=========== # game rpc test ============="
echo "main_ip=$MAIN_HTTP"
Chain33_SendToAddress "${ACCOUNT_A}" "${ACCOUNT_B}" 20000000000 "${MAIN_HTTP}"
block_wait 1
init
run_test "$MAIN_HTTP"
if [ -n "$CASE_ERR" ]; then
......
all:
chmod +x ./build.sh
./build.sh $(OUT) $(FLAG)
\ No newline at end of file
#!/usr/bin/env bash
strpwd=$(pwd)
strcmd=${strpwd##*dapp/}
strapp=${strcmd%/cmd*}
OUT_DIR="${1}/$strapp"
#FLAG=$2
mkdir -p "${OUT_DIR}"
cp ./build/* "${OUT_DIR}"
OUT_TESTDIR="${1}/dapptest/$strapp"
mkdir -p "${OUT_TESTDIR}"
chmod +x ./build/test-rpc.sh
cp ./build/test-rpc.sh "${OUT_TESTDIR}"
This diff is collapsed.
......@@ -47,6 +47,11 @@ func GetName() string {
return newGuessGame().GetName()
}
//ExecutorOrder Exec 的时候 同时执行 ExecLocal
func (g *Guess) ExecutorOrder() int64 {
return drivers.ExecLocalSameTime
}
//GetDriverName 获取Guess执行器的名称
func (g *Guess) GetDriverName() string {
return gty.GuessX
......
......@@ -2,36 +2,23 @@
# shellcheck disable=SC2128
MAIN_HTTP=""
CASE_ERR=""
oracle_addPublisher_unsignedTx="0a066d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630e6b685d696ee9394163a223151344e687572654a784b4e4266373164323642394a336642516f5163666d657a32"
oracle_addPublisher_unsignedTx_para="0a12757365722e702e706172612e6d616e61676512410a3f0a146f7261636c652d7075626c6973682d6576656e741222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a0361646420a08d0630a186de8894c9aa864d3a22314469484633317577783977356a6a733571514269474a6b4e686e71656564763157"
oracle_publisher_addr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
oracle_publisher_key="4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01"
eventId=""
txhash=""
#color
RED='\033[1;31m'
GRE='\033[1;32m'
NOC='\033[0m'
# $2=0 means true, other false
echo_rst() {
if [ "$2" -eq 0 ]; then
echo -e "${GRE}$1 ok${NOC}"
else
echo -e "${RED}$1 fail${NOC}"
CASE_ERR="err"
fi
}
# shellcheck source=/dev/null
source ../dapp-test-common.sh
oracle_AddPublisher() {
echo "=============== # Add publisher ==============="
ispara=$(echo '"'"${MAIN_HTTP}"'"' | jq '.|contains("8901")')
echo "ispara=$ispara"
if [ "$ispara" == true ]; then
signAndSendRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_addr}"
chain33_SignRawTx "${oracle_addPublisher_unsignedTx_para}" "${oracle_publisher_key}" "${MAIN_HTTP}"
else
signAndSendRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_addr}"
chain33_SignRawTx "${oracle_addPublisher_unsignedTx}" "${oracle_publisher_key}" "${MAIN_HTTP}"
fi
}
......@@ -44,7 +31,7 @@ oracle_publish_transaction() {
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}"
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
eventId="${txhash}"
echo "eventId $eventId"
}
......@@ -59,7 +46,7 @@ oracle_prePublishResult_transaction() {
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}"
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_eventAbort_transaction() {
......@@ -72,7 +59,7 @@ oracle_eventAbort_transaction() {
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}"
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_resultAbort_transaction() {
......@@ -85,7 +72,7 @@ oracle_resultAbort_transaction() {
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}"
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_publishResult_transaction() {
......@@ -98,32 +85,7 @@ oracle_publishResult_transaction() {
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
rawtx=$(jq -r ".result" <<<"$resp")
signAndSendRawTx "$rawtx" "${oracle_publisher_addr}"
}
# 签名并发送
signAndSendRawTx() {
unsignedTx=$1
addr=$2
req='"method":"Chain33.SignRawTx","params":[{"addr":"'${addr}'","txHex":"'${unsignedTx}'","expire":"120s"}]'
signedTx=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
if [ "$signedTx" == "null" ]; then
echo "An error occurred while signing"
else
sendSignedTx "$signedTx"
fi
}
sendSignedTx() {
signedTx=$1
local req='"method":"Chain33.SendTransaction","params":[{"token":"","data":"'"$signedTx"'"}]'
resp=$(curl -ksd "{$req}" ${MAIN_HTTP})
ok=$(echo "${resp}" | jq -r ".error")
[ "$ok" == null ]
rst=$?
#echo_rst "$FUNCNAME" "$rst"
txhash=$(echo "${resp}" | jq -r ".result")
echo "tx hash is $txhash"
chain33_SignRawTx "$rawtx" "${oracle_publisher_key}" "${MAIN_HTTP}"
}
oracle_QueryOraclesByID() {
......@@ -138,47 +100,6 @@ oracle_QueryOraclesByID() {
echo_rst "$FUNCNAME" "$rst"
}
function block_wait() {
local req='"method":"Chain33.GetLastHeader","params":[]'
cur_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
expect=$((cur_height + ${1}))
local count=0
while true; do
new_height=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq ".result.height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
function queryTransaction() {
block_wait 1
local txhash="$1"
local req='"method":"Chain33.QueryTransaction","params":[{"hash":"'"$txhash"'"}]'
local times=10
while true; do
ret=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result.tx.hash")
if [ "${ret}" != "${1}" ]; then
block_wait 1
times=$((times - 1))
if [ $times -le 0 ]; then
echo "====query tx=$1 failed"
echo "req=$req"
curl -ksd "{$req}" ${MAIN_HTTP}
return 1
exit 1
fi
else
echo "====query tx=$1 success"
return 0
break
fi
done
}
function run_test() {
# 增加发布人
oracle_AddPublisher
......@@ -189,7 +110,7 @@ function run_test() {
# 事件正式发布
oracle_publishResult_transaction "$eventId"
# 根据ID查询事件
block_wait 2
chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId"
# 生成发布事件的交易
......@@ -197,7 +118,7 @@ function run_test() {
# 取消事件发布
oracle_eventAbort_transaction "$eventId"
# 根据ID查询事件
block_wait 2
chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId"
# 生成发布事件的交易
......@@ -207,7 +128,7 @@ function run_test() {
# 取消事件预发布
oracle_resultAbort_transaction "$eventId"
# 根据ID查询事件
block_wait 2
chain33_BlockWait 2 "${MAIN_HTTP}"
oracle_QueryOraclesByID "$eventId"
}
......
This diff is collapsed.
......@@ -251,36 +251,25 @@ func CreateRawNodeManageCmd() *cobra.Command {
}
func addNodeManageFlags(cmd *cobra.Command) {
cmd.Flags().StringP("operation", "o", "", "operation:join,quit,vote")
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:join,2:vote,3:quit")
cmd.MarkFlagRequired("operation")
cmd.Flags().StringP("addr", "a", "", "operating target addr")
cmd.MarkFlagRequired("addrs")
cmd.Flags().StringP("value", "v", "", "vote value: yes,no")
cmd.Flags().Float64P("coins_frozen", "c", 0, "join to frozen coins amount, not less config")
cmd.Flags().StringP("id", "i", "", "operating target id")
cmd.Flags().Uint32P("value", "v", 1, "vote value: 1:yes,2:no")
cmd.Flags().Float64P("coins_frozen", "c", 0, "frozen coins amount, should not less nodegroup's")
}
func createNodeTx(cmd *cobra.Command, args []string) {
op, _ := cmd.Flags().GetString("operation")
op, _ := cmd.Flags().GetUint32("operation")
opAddr, _ := cmd.Flags().GetString("addr")
val, _ := cmd.Flags().GetString("value")
id, _ := cmd.Flags().GetString("id")
val, _ := cmd.Flags().GetUint32("value")
coins, _ := cmd.Flags().GetFloat64("coins_frozen")
if op != "vote" && op != "quit" && op != "join" {
fmt.Println("operation should be one of join,quit,vote")
return
}
if opAddr == "" {
fmt.Println("addr parameter should not be null")
return
}
if op == "vote" && (val != "yes" && val != "no") {
fmt.Println("vote operation value parameter require yes or no value")
return
}
payload := &pt.ParaNodeAddrConfig{Op: op, Value: val, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeAddrConfig{Op: op, Id: id, Value: val, Addr: opAddr, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX),
ActionName: "NodeConfig",
......@@ -305,11 +294,12 @@ func CreateNodeGroupApplyCmd() *cobra.Command {
}
func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:apply,2:approve,3:quit")
cmd.Flags().Uint32P("operation", "o", 0, "operation:1:apply,2:approve,3:quit,4:modify")
cmd.MarkFlagRequired("operation")
cmd.Flags().StringP("id", "i", "", "apply id for nodegroup ")
cmd.Flags().StringP("addrs", "a", "", "addrs apply for super node,split by ',' ")
cmd.MarkFlagRequired("addrs")
cmd.Flags().Float64P("coins_frozen", "c", 0, "coins amount to frozen, not less config")
......@@ -318,18 +308,10 @@ func addNodeGroupApplyCmdFlags(cmd *cobra.Command) {
func nodeGroupApply(cmd *cobra.Command, args []string) {
op, _ := cmd.Flags().GetUint32("operation")
addrs, _ := cmd.Flags().GetString("addrs")
id, _ := cmd.Flags().GetString("id")
coins, _ := cmd.Flags().GetFloat64("coins_frozen")
if op == 0 || op > 3 {
fmt.Println("operation should be one of 1:apply,2:approve,3:quit")
return
}
if addrs == "" {
fmt.Println("addrs should not be nil")
return
}
payload := &pt.ParaNodeGroupConfig{Op: op, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
payload := &pt.ParaNodeGroupConfig{Op: op, Id: id, Addrs: addrs, CoinsFrozen: int64(math.Trunc((coins+0.0000001)*1e4)) * 1e4}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pt.ParaX),
ActionName: "NodeGroupConfig",
......@@ -486,7 +468,7 @@ func addNodeBodyCmdFlags(cmd *cobra.Command) {
cmd.MarkFlagRequired("title")
cmd.Flags().StringP("addr", "a", "", "addr apply for super user")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("id", "i", "", "id apply for super user")
}
......@@ -494,12 +476,14 @@ func nodeInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
title, _ := cmd.Flags().GetString("title")
addr, _ := cmd.Flags().GetString("addr")
id, _ := cmd.Flags().GetString("id")
params := pt.ReqParacrossNodeInfo{
Title: title,
Addr: addr,
Id: id,
}
var res pt.ParaNodeAddrStatus
var res pt.ParaNodeIdStatus
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetNodeStatus", params, &res)
ctx.Run()
}
......
......@@ -77,7 +77,7 @@ func getConfigManageNodes(db dbm.KV, title string) (map[string]struct{}, []strin
}
func getParacrossNodes(db dbm.KV, title string) (map[string]struct{}, []string, error) {
key := calcParaNodeGroupKey(title)
key := calcParaNodeGroupAddrsKey(title)
return getNodes(db, key)
}
......@@ -418,7 +418,12 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
return receipt, nil
}
if enableParacrossTransfer && commit.Status.Height > 0 && len(commit.Status.CrossTxHashs) > 0 {
haveCrossTxs := len(commit.Status.CrossTxHashs) > 0
if commit.Status.Height > 0 && types.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx) && commit.Status.CrossTxHashs[0] == nil {
haveCrossTxs = false
}
if enableParacrossTransfer && commit.Status.Height > 0 && haveCrossTxs {
clog.Debug("paracross.Commit commitDone", "do cross", "")
crossTxReceipt, err := a.execCrossTxs(commit)
if err != nil {
......@@ -459,10 +464,10 @@ func (a *action) execCrossTx(tx *types.TransactionDetail, commit *pt.ParacrossCo
}
func getCrossTxHashs(api client.QueueProtocolAPI, commit *pt.ParacrossCommitAction) ([][]byte, []byte, error) {
crossTxHashs := commit.Status.CrossTxHashs
crossTxResult := commit.Status.CrossTxResult
if types.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx) {
if len(commit.Status.CrossTxHashs) == 0 {
clog.Error("getCrossTxHashs len=0", "paraHeight", commit.Status.Height,
"mainHeight", commit.Status.MainBlockHeight, "mainHash", hex.EncodeToString(commit.Status.MainBlockHash))
return nil, nil, types.ErrCheckTxHash
}
blockDetail, err := GetBlock(api, commit.Status.MainBlockHash)
......@@ -479,23 +484,32 @@ func getCrossTxHashs(api client.QueueProtocolAPI, commit *pt.ParacrossCommitActi
baseCheckTxHash := CalcTxHashsHash(baseHashs)
crossCheckHash := CalcTxHashsHash(paraCrossHashs)
if !bytes.Equal(commit.Status.CrossTxHashs[0], crossCheckHash) {
clog.Error("getCrossTxHashs para hash not equal", "main.crossHash", hex.EncodeToString(crossCheckHash),
clog.Error("getCrossTxHashs para hash not equal", "paraHeight", commit.Status.Height,
"mainHeight", commit.Status.MainBlockHeight, "mainHash", hex.EncodeToString(commit.Status.MainBlockHash),
"main.crossHash", hex.EncodeToString(crossCheckHash),
"commit.crossHash", hex.EncodeToString(commit.Status.CrossTxHashs[0]),
"main.baseHash", hex.EncodeToString(baseCheckTxHash), "commit.baseHash", hex.EncodeToString(commit.Status.TxHashs[0]))
for _, hash := range baseHashs {
clog.Error("getCrossTxHashs base tx hash", "txhash", hex.EncodeToString(hash))
}
for _, hash := range paraCrossHashs {
clog.Error("getCrossTxHashs paracross tx hash", "txhash", hex.EncodeToString(hash))
}
return nil, nil, types.ErrCheckTxHash
}
//只获取跨链tx
crossTxHashs = paraCrossHashs
rst, err := hex.DecodeString(string(commit.Status.CrossTxResult))
if err != nil {
clog.Error("getCrossTxHashs decode string", "CrossTxResult", string(commit.Status.CrossTxResult),
"commit.height", commit.Status.Height)
return nil, nil, types.ErrInvalidParam
}
crossTxResult = rst
return paraCrossHashs, rst, nil
}
return crossTxHashs, crossTxResult, nil
return commit.Status.CrossTxHashs, commit.Status.CrossTxResult, nil
}
func (a *action) execCrossTxs(commit *pt.ParacrossCommitAction) (*types.Receipt, error) {
......
......@@ -64,11 +64,11 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Prev.Status), Value: types.Encode(g.Prev)})
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Prev.Status, g.Prev.Id), Value: types.Encode(g.Prev)})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Current.Status), Value: nil})
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id), Value: nil})
} else if log.Ty == pt.TyLogParaNodeVoteDone {
var g pt.ReceiptParaNodeVoteDone
err := types.Decode(log.Log, &g)
......@@ -86,8 +86,7 @@ func (e *Paracross) ExecDelLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *
func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
var set types.LocalDBSet
for _, log := range receiptData.Logs {
if log.Ty == pt.TyLogParaNodeGroupApply || log.Ty == pt.TyLogParaNodeGroupApprove ||
log.Ty == pt.TyLogParaNodeGroupQuit {
if log.Ty == pt.TyLogParaNodeGroupConfig {
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
......@@ -95,11 +94,11 @@ func (e *Paracross) ExecDelLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title), Value: types.Encode(g.Prev)})
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title, g.Current.Id), Value: types.Encode(g.Prev)})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title), Value: nil})
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: nil})
}
}
return &set, nil
......
......@@ -67,11 +67,11 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Prev.Status), Value: nil})
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Prev.Status, g.Current.Id), Value: nil})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.ApplyAddr, g.Current.Status),
Key: calcLocalNodeTitleStatus(g.Current.Title, g.Current.Status, g.Current.Id),
Value: types.Encode(g.Current)})
} else if log.Ty == pt.TyLogParaNodeVoteDone {
var g pt.ReceiptParaNodeVoteDone
......@@ -90,8 +90,7 @@ func (e *Paracross) ExecLocal_NodeConfig(payload *pt.ParaNodeAddrConfig, tx *typ
func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
var set types.LocalDBSet
for _, log := range receiptData.Logs {
if log.Ty == pt.TyLogParaNodeGroupApply || log.Ty == pt.TyLogParaNodeGroupApprove ||
log.Ty == pt.TyLogParaNodeGroupQuit {
if log.Ty == pt.TyLogParaNodeGroupConfig {
var g pt.ReceiptParaNodeGroupConfig
err := types.Decode(log.Log, &g)
if err != nil {
......@@ -99,11 +98,11 @@ func (e *Paracross) ExecLocal_NodeGroupConfig(payload *pt.ParaNodeGroupConfig, t
}
if g.Prev != nil {
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title), Value: nil})
Key: calcLocalNodeGroupStatusTitle(g.Prev.Status, g.Current.Title, g.Current.Id), Value: nil})
}
set.KV = append(set.KV, &types.KeyValue{
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title), Value: types.Encode(g.Current)})
Key: calcLocalNodeGroupStatusTitle(g.Current.Status, g.Current.Title, g.Current.Id), Value: types.Encode(g.Current)})
}
}
return &set, nil
......
......@@ -16,7 +16,9 @@ var (
managerConfigNodes string //manager 合约配置的nodes
paraConfigNodes string //平行链自组织配置的nodes,最初是从manager同步过来
paraConfigNodeAddr string //平行链配置节点账户
paraNodeGroupApplyAddrs string
paraNodeGroupStatusAddrs string //正在申请的addrs
paraNodeID string
paraNodeGroupID string
localTx string
localTitle string
localTitleHeight string
......@@ -32,7 +34,9 @@ func setPrefix() {
managerConfigNodes = "paracross-nodes-"
paraConfigNodes = "mavl-paracross-nodes-title-"
paraConfigNodeAddr = "mavl-paracross-nodes-titleAddr-"
paraNodeGroupApplyAddrs = "mavl-paracross-nodegroup-apply-title-"
paraNodeGroupStatusAddrs = "mavl-paracross-nodegroup-apply-title-"
paraNodeID = "mavl-paracross-title-nodeid-"
paraNodeGroupID = "mavl-paracross-title-nodegroupid-"
localTx = "LODB-paracross-titleHeightAddr-"
localTitle = "LODB-paracross-title-"
localTitleHeight = "LODB-paracross-titleHeight-"
......@@ -62,7 +66,7 @@ func calcManageConfigNodesKey(title string) []byte {
return []byte(types.ManageKey(key))
}
func calcParaNodeGroupKey(title string) []byte {
func calcParaNodeGroupAddrsKey(title string) []byte {
return []byte(fmt.Sprintf(paraConfigNodes+"%s", title))
}
......@@ -70,8 +74,16 @@ func calcParaNodeAddrKey(title string, addr string) []byte {
return []byte(fmt.Sprintf(paraConfigNodeAddr+"%s-%s", title, addr))
}
func calcParaNodeGroupApplyKey(title string) []byte {
return []byte(fmt.Sprintf(paraNodeGroupApplyAddrs+"%s", title))
func calcParaNodeGroupStatusKey(title string) []byte {
return []byte(fmt.Sprintf(paraNodeGroupStatusAddrs+"%s", title))
}
func calcParaNodeIDKey(title, hash string) string {
return fmt.Sprintf(paraNodeID+"%s-%s", title, hash)
}
func calcParaNodeGroupIDKey(title, hash string) string {
return fmt.Sprintf(paraNodeGroupID+"%s-%s", title, hash)
}
func calcLocalTxKey(title string, height int64, addr string) []byte {
......@@ -90,22 +102,30 @@ func calcLocalAssetKey(hash []byte) []byte {
return []byte(fmt.Sprintf(localAssetKey+"%s", hash))
}
func calcLocalNodeTitleStatus(title, addr string, status int32) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-%s", title, status, addr))
func calcLocalNodeTitleStatus(title string, status int32, id string) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-%s", title, status, id))
}
func calcLocalNodeStatusPrefix(title string, status int32) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d", title, status))
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-%02d-", title, status))
}
func calcLocalNodeTitlePrefix(title string) []byte {
return []byte(fmt.Sprintf(localNodeTitleStatus+"%s-", title))
}
func calcLocalNodeTitleDone(title, addr string) []byte {
return []byte(fmt.Sprintf(localNodeTitleDone+"%s-%s", title, addr))
}
func calcLocalNodeGroupStatusTitle(status int32, title string) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-%s", status, title))
func calcLocalNodeGroupStatusTitle(status int32, title, id string) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-%s-%s", status, title, id))
}
func calcLocalNodeGroupStatusPrefix(status int32) []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d", status))
return []byte(fmt.Sprintf(localNodeGroupStatusTitle+"%02d-", status))
}
func calcLocalNodeGroupAllPrefix() []byte {
return []byte(fmt.Sprintf(localNodeGroupStatusTitle))
}
......@@ -75,7 +75,7 @@ func (p *Paracross) Query_GetNodeGroupAddrs(in *pt.ReqParacrossNodeInfo) (types.
nodes = append(nodes, k)
}
var reply types.ReplyConfig
reply.Key = string(calcParaNodeGroupKey(in.GetTitle()))
reply.Key = string(calcParaNodeGroupAddrsKey(in.GetTitle()))
reply.Value = fmt.Sprint(nodes)
return &reply, nil
}
......@@ -85,7 +85,24 @@ func (p *Paracross) Query_GetNodeAddrInfo(in *pt.ReqParacrossNodeInfo) (types.Me
if in == nil || in.Title == "" || in.Addr == "" {
return nil, types.ErrInvalidParam
}
stat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
addrStat, err := getNodeAddr(p.GetStateDB(), in.Title, in.Addr)
if err != nil {
return nil, err
}
stat, err := getNodeID(p.GetStateDB(), addrStat.ProposalId)
if err != nil {
return nil, err
}
return stat, nil
}
//Query_GetNodeIdInfo get specific node addr info
func (p *Paracross) Query_GetNodeIdInfo(in *pt.ReqParacrossNodeInfo) (types.Message, error) {
if in == nil || in.Title == "" || in.Id == "" {
return nil, types.ErrInvalidParam
}
stat, err := getNodeID(p.GetStateDB(), in.Id)
if err != nil {
return nil, err
}
......@@ -114,7 +131,7 @@ func (p *Paracross) Query_GetNodeGroupStatus(in *pt.ReqParacrossNodeInfo) (types
//Query_ListNodeGroupStatus list node info by status
func (p *Paracross) Query_ListNodeGroupStatus(in *pt.ReqParacrossNodeInfo) (types.Message, error) {
if in == nil || in.Status == 0 {
if in == nil {
return nil, types.ErrInvalidParam
}
return listLocalNodeGroupStatus(p.GetLocalDB(), in.Status)
......@@ -212,7 +229,7 @@ func listLocalTitles(db dbm.KVDB) (types.Message, error) {
MostSameCommit: st.MostSameCommit,
Title: st.Title,
Height: st.Height,
StateHash: hex.EncodeToString(st.StateHash),
StateHash: common.ToHex(st.StateHash),
TxCounts: st.TxCounts,
TxResult: hex.EncodeToString(st.TxResult),
}
......@@ -230,12 +247,12 @@ func listNodeStatus(db dbm.KVDB, prefix []byte) (types.Message, error) {
var resp pt.RespParacrossNodeAddrs
for _, r := range res {
var st pt.ParaNodeAddrStatus
var st pt.ParaNodeIdStatus
err = types.Decode(r, &st)
if err != nil {
panic(err)
}
resp.Addrs = append(resp.Addrs, &st)
resp.Ids = append(resp.Ids, &st)
}
return &resp, nil
}
......@@ -253,19 +270,31 @@ func listNodeGroupStatus(db dbm.KVDB, prefix []byte) (types.Message, error) {
if err != nil {
panic(err)
}
resp.Addrs = append(resp.Addrs, &st)
resp.Ids = append(resp.Ids, &st)
}
return &resp, nil
}
//按状态遍历
func listLocalNodeStatus(db dbm.KVDB, title string, status int32) (types.Message, error) {
prefix := calcLocalNodeStatusPrefix(title, status)
var prefix []byte
if status == 0 {
prefix = calcLocalNodeTitlePrefix(title)
} else {
prefix = calcLocalNodeStatusPrefix(title, status)
}
return listNodeStatus(db, prefix)
}
func listLocalNodeGroupStatus(db dbm.KVDB, status int32) (types.Message, error) {
prefix := calcLocalNodeGroupStatusPrefix(status)
var prefix []byte
if status == 0 {
prefix = calcLocalNodeGroupAllPrefix()
} else {
prefix = calcLocalNodeGroupStatusPrefix(status)
}
return listNodeGroupStatus(db, prefix)
}
......@@ -287,7 +316,7 @@ func loadLocalTitle(db dbm.KV, title string, height int64) (types.Message, error
MostSameCommit: st.MostSameCommit,
Title: st.Title,
Height: st.Height,
StateHash: hex.EncodeToString(st.StateHash),
StateHash: common.ToHex(st.StateHash),
TxCounts: st.TxCounts,
TxResult: hex.EncodeToString(st.TxResult),
}, nil
......
......@@ -62,8 +62,10 @@ func getMiners(detail *pt.ParacrossStatusDetails, blockHash []byte) []string {
//
func mergeReceipt(receipt1, receipt2 *types.Receipt) *types.Receipt {
if receipt2 != nil {
receipt1.KV = append(receipt1.KV, receipt2.KV...)
receipt1.Logs = append(receipt1.Logs, receipt2.Logs...)
}
receipt1.KV = append(receipt1.KV, receipt2.KV...)
receipt1.Logs = append(receipt1.Logs, receipt2.Logs...)
return receipt1
}
......@@ -74,7 +74,7 @@ func (suite *NodeManageTestSuite) SetupSuite() {
}
func (suite *NodeManageTestSuite) TestSetup() {
nodeConfigKey := calcParaNodeGroupKey(Title)
nodeConfigKey := calcParaNodeGroupAddrsKey(Title)
suite.T().Log(string(nodeConfigKey))
_, err := suite.stateDB.Get(nodeConfigKey)
if err != nil {
......@@ -96,6 +96,11 @@ func nodeCommitImpl(suite suite.Suite, exec *Paracross, privkeyStr string, tx *t
assert.NotNil(suite.T(), receipt)
assert.Nil(suite.T(), err)
for _, v := range receipt.KV {
if err := exec.GetStateDB().Set(v.Key, v.Value); err != nil {
panic(err)
}
}
return
}
......@@ -104,52 +109,52 @@ func checkGroupApplyReceipt(suite *NodeManageTestSuite, receipt *types.Receipt)
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeAddrStatus
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupApply), receipt.Logs[0].Ty)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupConfig), receipt.Logs[0].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeGroupApply), stat.Status)
}
func checkGroupApproveReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 6)
assert.Len(suite.T(), receipt.Logs, 6)
assert.Len(suite.T(), receipt.KV, 11)
assert.Len(suite.T(), receipt.Logs, 7)
len := len(receipt.KV)
var stat pt.ParaNodeAddrStatus
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[len-1].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupApprove), receipt.Logs[len-1].Ty)
//suite.T().Log("ty len-1", receipt.Logs[lenLogs-1].Ty,"len",lenLogs)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeGroupStatusUpdate), receipt.Logs[7-1].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeGroupApprove), stat.Status)
}
func checkJoinReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.KV, 2)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeAddrStatus
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
assert.Equal(suite.T(), int32(pt.TyLogParaNodeConfig), receipt.Logs[0].Ty)
assert.Equal(suite.T(), int32(pt.ParacrossNodeAdding), stat.Status)
assert.Equal(suite.T(), int32(pt.ParacrossNodeJoining), stat.Status)
assert.NotNil(suite.T(), stat.Votes)
}
func checkQuitReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.KV, 2)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeAddrStatus
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
//suite.T().Log("titleHeight", titleHeight)
......@@ -161,10 +166,8 @@ func checkQuitReceipt(suite *NodeManageTestSuite, receipt *types.Receipt) {
func checkVoteReceipt(suite *NodeManageTestSuite, receipt *types.Receipt, count int) {
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 1)
assert.Len(suite.T(), receipt.Logs, 1)
var stat pt.ParaNodeAddrStatus
var stat pt.ParaNodeIdStatus
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
assert.Len(suite.T(), stat.Votes.Votes, count)
......@@ -172,43 +175,47 @@ func checkVoteReceipt(suite *NodeManageTestSuite, receipt *types.Receipt, count
}
func checkVoteDoneReceipt(suite *NodeManageTestSuite, receipt *types.Receipt, count int, join bool) {
suite.NotNil(receipt)
assert.Equal(suite.T(), receipt.Ty, int32(types.ExecOk))
assert.Len(suite.T(), receipt.KV, 2)
assert.Len(suite.T(), receipt.Logs, 3)
var stat pt.ParaNodeAddrStatus
err := types.Decode(receipt.KV[0].Value, &stat)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
assert.Len(suite.T(), stat.Votes.Votes, count)
suite.T().Log("checkVoteDoneReceipt", "kvlen", len(receipt.KV))
var item types.ConfigItem
err = types.Decode(receipt.KV[1].Value, &item)
assert.Nil(suite.T(), err, "decode ParaNodeAddrStatus failed")
_, arry, err := getParacrossNodes(suite.stateDB, Title)
suite.Suite.Nil(err)
if join {
suite.Contains(item.GetArr().Value, Account14K)
suite.Contains(arry, Account14K)
} else {
suite.NotContains(item.GetArr().Value, Account14K)
suite.NotContains(arry, Account14K)
}
}
func voteTest(suite *NodeManageTestSuite, addr string, join bool) {
func voteTest(suite *NodeManageTestSuite, id string, join bool) {
var count int
config := &pt.ParaNodeAddrConfig{
Op: pt.ParaNodeVote,
Addr: addr,
Id: id,
Value: pt.ParaNodeVoteYes,
}
tx, err := pt.CreateRawNodeConfigTx(config)
suite.Nil(err)
count++
receipt := nodeCommit(suite, PrivKeyA, tx)
checkVoteReceipt(suite, receipt, 1)
checkVoteReceipt(suite, receipt, count)
count++
receipt = nodeCommit(suite, PrivKeyB, tx)
checkVoteReceipt(suite, receipt, 2)
checkVoteReceipt(suite, receipt, count)
count++
if !join {
receipt = nodeCommit(suite, PrivKey14K, tx)
checkVoteReceipt(suite, receipt, count)
count++
}
receipt = nodeCommit(suite, PrivKeyC, tx)
checkVoteDoneReceipt(suite, receipt, 3, join)
checkVoteDoneReceipt(suite, receipt, count, join)
}
func (suite *NodeManageTestSuite) testNodeGroupConfigQuit() {
......@@ -222,9 +229,14 @@ func (suite *NodeManageTestSuite) testNodeGroupConfigQuit() {
receipt := nodeCommit(suite, PrivKeyB, tx)
checkGroupApplyReceipt(suite, receipt)
suite.Equal(int32(pt.TyLogParaNodeGroupConfig), receipt.Logs[0].Ty)
var g pt.ReceiptParaNodeGroupConfig
err = types.Decode(receipt.Logs[0].Log, &g)
suite.Nil(err)
config = &pt.ParaNodeGroupConfig{
Addrs: applyAddrs,
Op: pt.ParacrossNodeGroupQuit,
Id: g.Current.Id,
Op: pt.ParacrossNodeGroupQuit,
}
tx, err = pt.CreateRawNodeGroupApplyTx(config)
suite.Nil(err)
......@@ -247,9 +259,14 @@ func (suite *NodeManageTestSuite) testNodeGroupConfig() {
receipt := nodeCommit(suite, PrivKeyB, tx)
checkGroupApplyReceipt(suite, receipt)
suite.Equal(int32(pt.TyLogParaNodeGroupConfig), receipt.Logs[0].Ty)
var g pt.ReceiptParaNodeGroupConfig
err = types.Decode(receipt.Logs[0].Log, &g)
suite.Nil(err)
config = &pt.ParaNodeGroupConfig{
Addrs: applyAddrs,
Op: pt.ParacrossNodeGroupApprove,
Id: g.Current.Id,
Op: pt.ParacrossNodeGroupApprove,
}
tx, err = pt.CreateRawNodeGroupApplyTx(config)
suite.Nil(err)
......@@ -271,13 +288,18 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
receipt := nodeCommit(suite, PrivKey14K, tx)
checkJoinReceipt(suite, receipt)
suite.Equal(int32(pt.TyLogParaNodeConfig), receipt.Logs[0].Ty)
var g pt.ReceiptParaNodeConfig
err = types.Decode(receipt.Logs[0].Log, &g)
suite.Nil(err)
//vote test
voteTest(suite, Account14K, true)
voteTest(suite, g.Current.Id, true)
//Quit test
config = &pt.ParaNodeAddrConfig{
Op: pt.ParaNodeQuit,
Addr: Account1MC,
Op: pt.ParaNodeQuit,
Id: g.Current.Id,
}
tx, err = pt.CreateRawNodeConfigTx(config)
suite.Nil(err)
......@@ -285,7 +307,7 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
checkQuitReceipt(suite, receipt)
//vote test
voteTest(suite, Account1MC, false)
voteTest(suite, g.Current.Id, false)
}
func (suite *NodeManageTestSuite) TestExec() {
......@@ -310,22 +332,22 @@ func (suite *NodeManageTestSuite) TearDownSuite() {
func TestGetAddrGroup(t *testing.T) {
addrs := " 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4, 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR, 1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k, ,,, 1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs , "
retAddrs := getAddrGroup(addrs)
retAddrs := getConfigAddrs(addrs)
expectAddrs := []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4", "1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR", "1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k", "1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"}
assert.Equal(t, expectAddrs, retAddrs)
addrs = " 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4 , , "
retAddrs = getAddrGroup(addrs)
retAddrs = getConfigAddrs(addrs)
expectAddrs = []string{"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"}
assert.Equal(t, expectAddrs, retAddrs)
addrs = " , "
ret := getAddrGroup(addrs)
ret := getConfigAddrs(addrs)
assert.Equal(t, []string(nil), ret)
assert.Equal(t, 0, len(ret))
addrs = " "
ret = getAddrGroup(addrs)
ret = getConfigAddrs(addrs)
assert.Equal(t, []string(nil), ret)
assert.Equal(t, 0, len(ret))
......
......@@ -47,71 +47,77 @@ message ParacrossConsensusStatus {
string consensBlockHash = 4;
}
message ParaNodeAddrConfig{
message ParaNodeAddrConfig {
string title = 1;
string op = 2;
string addr = 3;
string value = 4;
int64 coinsFrozen = 5;
uint32 op = 2;
string id = 3;
string addr = 4;
uint32 value = 5;
int64 coinsFrozen = 6;
}
message ParaNodeVoteDetail{
message ParaNodeVoteDetail {
repeated string addrs = 1;
repeated string votes = 2;
}
message ParaNodeAddrStatus{
int32 status = 1;
string title = 2;
string applyAddr = 3;
int64 coinsFrozen = 4;
ParaNodeVoteDetail votes = 5;
string fromAddr = 6;
message ParaNodeAddrIdStatus {
string proposalId = 1;
}
message ParaNodeIdStatus {
string id = 1;
int32 status = 2;
string title = 3;
string targetAddr = 4;
int64 coinsFrozen = 5;
ParaNodeVoteDetail votes = 6;
string fromAddr = 7;
int64 height = 8;
}
message ReceiptParaNodeConfig {
string addr = 1;
ParaNodeAddrConfig config = 2;
ParaNodeAddrStatus prev = 3;
ParaNodeAddrStatus current = 4;
ParaNodeIdStatus prev = 3;
ParaNodeIdStatus current = 4;
}
message ReceiptParaNodeVoteRecord {
string fromAddr = 1;
string voteAddr = 2;
int32 value = 3;
}
message ReceiptParaNodeVoteDone {
string title = 1;
string targetAddr = 2;
int32 totalNodes = 3;
int32 totalVote = 4;
int32 mostVote = 5;
string voteRst = 6;
int32 doneStatus = 7;
string id = 1;
string title = 2;
string targetAddr = 3;
int32 totalNodes = 4;
int32 totalVote = 5;
int32 mostVote = 6;
string voteRst = 7;
int32 doneStatus = 8;
}
message ParaNodeGroupConfig {
string title = 1;
uint32 op = 2;
string addrs = 3;
int64 coinsFrozen = 4;
uint32 emptyBlockInterval = 5;
string id = 3;
string addrs = 4;
int64 coinsFrozen = 5;
uint32 emptyBlockInterval = 6;
}
message ParaNodeGroupStatus {
int32 status = 1;
string title = 2;
string applyAddr = 3;
int64 coinsFrozen = 4;
uint32 emptyBlockInterval = 5;
int64 mainHeight = 6;
string fromAddr = 7;
string id = 1;
int32 status = 2;
string title = 3;
string targetAddrs = 4;
int64 coinsFrozen = 5;
uint32 emptyBlockInterval = 6;
int64 mainHeight = 7;
string fromAddr = 8;
int64 height = 9;
}
message ReceiptParaNodeGroupConfig {
......@@ -125,16 +131,18 @@ message ReceiptParaNodeGroupConfig {
// node query
message ReqParacrossNodeInfo {
string title = 1;
string addr = 2;
int32 status = 3;
string id = 2;
string addr = 3;
int32 status = 4;
}
message RespParacrossNodeAddrs {
repeated ParaNodeAddrStatus addrs = 1;
repeated ParaNodeIdStatus ids = 1;
}
message RespParacrossNodeGroups {
repeated ParaNodeGroupStatus addrs = 1;
repeated ParaNodeGroupStatus ids = 1;
}
message ParaBlock2MainMap {
......
......@@ -180,13 +180,26 @@ func (c *Jrpc) GetBlock2MainInfo(req *types.ReqBlocks, result *interface{}) erro
}
// GetNodeStatus get super node status
func (c *channelClient) GetNodeStatus(ctx context.Context, req *pt.ReqParacrossNodeInfo) (*pt.ParaNodeAddrStatus, error) {
func (c *channelClient) GetNodeStatus(ctx context.Context, req *pt.ReqParacrossNodeInfo) (*pt.ParaNodeIdStatus, error) {
r := *req
data, err := c.Query(pt.GetExecName(), "GetNodeAddrInfo", &r)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.ParaNodeAddrStatus); ok {
if resp, ok := data.(*pt.ParaNodeIdStatus); ok {
return resp, nil
}
return nil, types.ErrDecode
}
// GetNodeStatus get super node status
func (c *channelClient) GetNodeIDStatus(ctx context.Context, req *pt.ReqParacrossNodeInfo) (*pt.ParaNodeIdStatus, error) {
r := *req
data, err := c.Query(pt.GetExecName(), "GetNodeIdInfo", &r)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.ParaNodeIdStatus); ok {
return resp, nil
}
return nil, types.ErrDecode
......@@ -194,7 +207,20 @@ func (c *channelClient) GetNodeStatus(ctx context.Context, req *pt.ReqParacrossN
// GetNodeStatus get super node status
func (c *Jrpc) GetNodeStatus(req *pt.ReqParacrossNodeInfo, result *interface{}) error {
data, err := c.cli.GetNodeStatus(context.Background(), req)
if req == nil || (req.Addr == "" && req.Id == "") {
return types.ErrInvalidParam
}
var data *pt.ParaNodeIdStatus
var err error
if req.Addr != "" {
data, err = c.cli.GetNodeStatus(context.Background(), req)
}
if req.Id != "" {
data, err = c.cli.GetNodeIDStatus(context.Background(), req)
}
*result = data
return err
}
......
......@@ -47,8 +47,6 @@ var (
ErrParaNodeGroupFrozenCoinsNotEnough = errors.New("ErrParaNodeGroupFrozenCoinsNotEnough")
//ErrParaNodeGroupStatusWrong node group process wrong status
ErrParaNodeGroupStatusWrong = errors.New("ErrParaNodeGroupStatusWrong")
//ErrParaNodeGroupAddrNotMatch group addrs not match with apply
ErrParaNodeGroupAddrNotMatch = errors.New("ErrParaNodeGroupAddrNotMatch")
//ErrParaConsensStopBlocksNotReach consensus stop blocks not reach
ErrParaConsensStopBlocksNotReach = errors.New("ErrParaConsensStopBlocksNotReach")
)
......@@ -37,12 +37,11 @@ const (
// TyLogParaAssetDeposit asset deposit log key
TyLogParaAssetDeposit = 656
// TyLogParaNodeConfig config super node log key
TyLogParaNodeConfig = 657
TyLogParaNodeVoteDone = 658
TyLogParaNodeGroupUpdate = 659
TyLogParaNodeGroupApply = 660
TyLogParaNodeGroupApprove = 661
TyLogParaNodeGroupQuit = 662
TyLogParaNodeConfig = 657
TyLogParaNodeVoteDone = 658
TyLogParaNodeGroupAddrsUpdate = 659
TyLogParaNodeGroupConfig = 660
TyLogParaNodeGroupStatusUpdate = 664
)
type paracrossCommitTx struct {
......@@ -90,19 +89,27 @@ const (
// node config op
const (
ParaNodeJoin = "join"
ParaNodeQuit = "quit"
ParaNodeVote = "vote"
ParaNodeJoin = iota + 1
ParaNodeVote
ParaNodeQuit
)
ParaNodeVoteYes = "yes"
ParaNodeVoteNo = "no"
// node vote op
const (
ParaNodeVoteInvalid = iota
ParaNodeVoteYes
ParaNodeVoteNo
ParaNodeVoteEnd
)
// ParaNodeVoteStr ...
var ParaNodeVoteStr = []string{"invalid", "yes", "no"}
const (
// ParacrossNodeAdding apply for adding group
ParacrossNodeAdding = iota + 1
// ParacrossNodeAdded pass to add by votes
ParacrossNodeAdded
// ParacrossNodeJoining apply for adding group
ParacrossNodeJoining = iota + 1
// ParacrossNodeJoined pass to add by votes
ParacrossNodeJoined
// ParacrossNodeQuiting apply for quiting
ParacrossNodeQuiting
// ParacrossNodeQuited pass to quite by votes
......@@ -116,6 +123,8 @@ const (
ParacrossNodeGroupApprove
//ParacrossNodeGroupQuit applyer quit the apply when not be approved
ParacrossNodeGroupQuit
//ParacrossNodeGroupModify applyer modify some parameters
ParacrossNodeGroupModify
)
var (
......@@ -179,6 +188,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, fee int64) (*ty
func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, error) {
config.Title = types.GetTitle()
config.Addr = strings.Trim(config.Addr, " ")
config.Id = strings.Trim(config.Id, " ")
action := &ParacrossAction{
Ty: ParacrossActionNodeConfig,
......@@ -195,6 +205,7 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction, error) {
apply.Title = types.GetTitle()
apply.EmptyBlockInterval = 4
apply.Id = strings.Trim(apply.Id, " ")
interval := types.Conf("config.consensus.sub.para").GInt("emptyBlockInterval")
if interval > 0 {
apply.EmptyBlockInterval = uint32(interval)
......
This diff is collapsed.
......@@ -54,19 +54,18 @@ func (p *ParacrossType) GetName() string {
// GetLogMap get receipt log map
func (p *ParacrossType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{
TyLogParacrossCommit: {Ty: reflect.TypeOf(ReceiptParacrossCommit{}), Name: "LogParacrossCommit"},
TyLogParacrossCommitDone: {Ty: reflect.TypeOf(ReceiptParacrossDone{}), Name: "LogParacrossCommitDone"},
TyLogParacrossCommitRecord: {Ty: reflect.TypeOf(ReceiptParacrossRecord{}), Name: "LogParacrossCommitRecord"},
TyLogParaAssetWithdraw: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetWithdraw"},
TyLogParaAssetTransfer: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetTransfer"},
TyLogParaAssetDeposit: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetDeposit"},
TyLogParacrossMiner: {Ty: reflect.TypeOf(ReceiptParacrossMiner{}), Name: "LogParacrossMiner"},
TyLogParaNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeConfig"},
TyLogParaNodeGroupUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaNodeGroupUpdate"},
TyLogParaNodeVoteDone: {Ty: reflect.TypeOf(ReceiptParaNodeVoteDone{}), Name: "LogParaNodeVoteDone"},
TyLogParaNodeGroupApply: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApply"},
TyLogParaNodeGroupApprove: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupApprove"},
TyLogParaNodeGroupQuit: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupQuit"},
TyLogParacrossCommit: {Ty: reflect.TypeOf(ReceiptParacrossCommit{}), Name: "LogParacrossCommit"},
TyLogParacrossCommitDone: {Ty: reflect.TypeOf(ReceiptParacrossDone{}), Name: "LogParacrossCommitDone"},
TyLogParacrossCommitRecord: {Ty: reflect.TypeOf(ReceiptParacrossRecord{}), Name: "LogParacrossCommitRecord"},
TyLogParaAssetWithdraw: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetWithdraw"},
TyLogParaAssetTransfer: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetTransfer"},
TyLogParaAssetDeposit: {Ty: reflect.TypeOf(types.ReceiptAccountTransfer{}), Name: "LogParaAssetDeposit"},
TyLogParacrossMiner: {Ty: reflect.TypeOf(ReceiptParacrossMiner{}), Name: "LogParacrossMiner"},
TyLogParaNodeConfig: {Ty: reflect.TypeOf(ReceiptParaNodeConfig{}), Name: "LogParaNodeConfig"},
TyLogParaNodeGroupAddrsUpdate: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogParaNodeGroupAddrsUpdate"},
TyLogParaNodeVoteDone: {Ty: reflect.TypeOf(ReceiptParaNodeVoteDone{}), Name: "LogParaNodeVoteDone"},
TyLogParaNodeGroupConfig: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupConfig"},
TyLogParaNodeGroupStatusUpdate: {Ty: reflect.TypeOf(ReceiptParaNodeGroupConfig{}), Name: "LogParaNodeGroupStatusUpdate"},
}
}
......
......@@ -78,7 +78,7 @@ pokerbull_QueryResult() {
echo "========== # pokerbull query result begin =========="
local req='"method":"Chain33.Query","params":[{"execer":"pokerbull","funcName":"QueryGameByID","payload":{"gameId":"'$GAME_ID'"}}]'
data=$(curl -ksd "{$req}" ${MAIN_HTTP} | jq -r ".result")
ok=$(jq '(.game.gameId == "$GAME_ID")' <<<"$data")
ok=$(jq '(.game.gameId == '"$GAME_ID"')' <<<"$data")
[ "$ok" == true ]
echo_rst "$FUNCNAME" "$?"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment