Commit 9bcfc5e5 authored by kingwang's avatar kingwang Committed by 33cn

update chain33 04.19

parent 95c421c8
...@@ -11,5 +11,7 @@ All notable changes to this project will be documented in this file. ...@@ -11,5 +11,7 @@ All notable changes to this project will be documented in this file.
- Update configuration files from p2p/verMix to p2p/verMin from[@libangzhu](https://github.com/libangzhu). - Update configuration files from p2p/verMix to p2p/verMin from[@libangzhu](https://github.com/libangzhu).
- Update p2p version Logic(if you do not fill in the range of p2p version,then verMin=version,verMax=verMin+1) from[@libangzhu](https://github.com/libangzhu). - Update p2p version Logic(if you do not fill in the range of p2p version,then verMin=version,verMax=verMin+1) from[@libangzhu](https://github.com/libangzhu).
# [6.2]
### Changed
- Update dapp coins command line name, 'bty' not supported any more, 'coins' recommended
...@@ -86,7 +86,7 @@ function start() { ...@@ -86,7 +86,7 @@ function start() {
#fi #fi
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -95,7 +95,7 @@ function start() { ...@@ -95,7 +95,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -80,14 +80,14 @@ function start_chain33() { ...@@ -80,14 +80,14 @@ function start_chain33() {
${CLI} block last_header ${CLI} block last_header
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
fi fi
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -93,14 +93,14 @@ function start_chain33() { ...@@ -93,14 +93,14 @@ function start_chain33() {
${CLI} block last_header ${CLI} block last_header
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
fi fi
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -130,7 +130,7 @@ function start() { ...@@ -130,7 +130,7 @@ function start() {
#fi #fi
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -139,7 +139,7 @@ function start() { ...@@ -139,7 +139,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -128,7 +128,7 @@ function start() { ...@@ -128,7 +128,7 @@ function start() {
echo "peersCount=${peersCount}" echo "peersCount=${peersCount}"
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -137,7 +137,7 @@ function start() { ...@@ -137,7 +137,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -132,7 +132,7 @@ function start() { ...@@ -132,7 +132,7 @@ function start() {
#fi #fi
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -141,7 +141,7 @@ function start() { ...@@ -141,7 +141,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
...@@ -173,7 +173,7 @@ function start() { ...@@ -173,7 +173,7 @@ function start() {
## 2nd mining ## 2nd mining
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(${CLI4} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(${CLI4} seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -182,7 +182,7 @@ function start() { ...@@ -182,7 +182,7 @@ function start() {
sleep 1 sleep 1
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(${CLI4} wallet unlock -p 1314 -t 0 | jq ".isok") result=$(${CLI4} wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
...@@ -444,7 +444,7 @@ function optDockerPart3() { ...@@ -444,7 +444,7 @@ function optDockerPart3() {
echo "======sleep 20s======" echo "======sleep 20s======"
sleep 5 sleep 5
result=$($CLI4 wallet unlock -p 1314 -t 0 | jq ".isok") result=$($CLI4 wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "wallet1 unlock fail" echo "wallet1 unlock fail"
exit 1 exit 1
...@@ -494,7 +494,7 @@ function optDockerPart4() { ...@@ -494,7 +494,7 @@ function optDockerPart4() {
echo "======sleep 20s======" echo "======sleep 20s======"
sleep 5 sleep 5
result=$($CLI wallet unlock -p 1314 -t 0 | jq ".isok") result=$($CLI wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "wallet2 unlock fail" echo "wallet2 unlock fail"
exit 1 exit 1
...@@ -618,7 +618,7 @@ function type2_optDockerPart3() { ...@@ -618,7 +618,7 @@ function type2_optDockerPart3() {
sleep 20 sleep 20
echo "======开启第二组docker节点挖矿======" echo "======开启第二组docker节点挖矿======"
result=$($CLI wallet unlock -p 1314 -t 0 | jq ".isok") result=$($CLI wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "wallet1 unlock fail" echo "wallet1 unlock fail"
exit 1 exit 1
...@@ -632,7 +632,7 @@ function type2_optDockerPart3() { ...@@ -632,7 +632,7 @@ function type2_optDockerPart3() {
fi fi
sleep 1 sleep 1
result=$($CLI4 wallet unlock -p 1314 -t 0 | jq ".isok") result=$($CLI4 wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "wallet2 unlock fail" echo "wallet2 unlock fail"
exit 1 exit 1
......
...@@ -6,8 +6,8 @@ function SendToPrivacyExec() { ...@@ -6,8 +6,8 @@ function SendToPrivacyExec() {
execAdd=$3 execAdd=$3
note=$4 note=$4
amount=$5 amount=$5
#sudo docker exec -it $name ./chain33-cli send bty transfer -k $fromAdd -t $execAdd -n $note -a $amount #sudo docker exec -it $name ./chain33-cli send coins transfer -k $fromAdd -t $execAdd -n $note -a $amount
result=$($name send bty transfer -k "${fromAdd}" -t "${execAdd}" -n "${note}" -a "${amount}") result=$($name send coins transfer -k "${fromAdd}" -t "${execAdd}" -n "${note}" -a "${amount}")
echo "hash : $result" echo "hash : $result"
} }
...@@ -41,7 +41,7 @@ function showPrivacyBalance() { ...@@ -41,7 +41,7 @@ function showPrivacyBalance() {
function init() { function init() {
echo "=========== # start set wallet 1 =============" echo "=========== # start set wallet 1 ============="
echo "=========== # save seed to wallet =============" echo "=========== # save seed to wallet ============="
result=$(./chain33-cli seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok") result=$(./chain33-cli seed save -p 1314fuzamei -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}" echo "save seed to wallet error seed, result: ${result}"
exit 1 exit 1
...@@ -50,7 +50,7 @@ function init() { ...@@ -50,7 +50,7 @@ function init() {
sleep 2 sleep 2
echo "=========== # unlock wallet =============" echo "=========== # unlock wallet ============="
result=$(./chain33-cli wallet unlock -p 1314 -t 0 | jq ".isok") result=$(./chain33-cli wallet unlock -p 1314fuzamei -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then if [ "${result}" = "false" ]; then
exit 1 exit 1
fi fi
......
...@@ -62,7 +62,7 @@ filename = "token.toml" ...@@ -62,7 +62,7 @@ filename = "token.toml"
``` ```
[[TransferCase]] [[TransferCase]]
id = "btyTrans1" id = "btyTrans1"
command = "send bty transfer -a 10 -t 1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" command = "send coins transfer -a 10 -t 1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
from = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" from = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
to = "1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt" to = "1D9xKRnLvV2zMtSxSx33ow1GF4pcbLcNRt"
amount = "10" amount = "10"
......
...@@ -117,18 +117,19 @@ func (client *client) WaitTimeout(msg *Message, timeout time.Duration) (*Message ...@@ -117,18 +117,19 @@ func (client *client) WaitTimeout(msg *Message, timeout time.Duration) (*Message
if msg.chReply == nil { if msg.chReply == nil {
return &Message{}, errors.New("empty wait channel") return &Message{}, errors.New("empty wait channel")
} }
if timeout == -1 {
msg = <-msg.chReply var t <-chan time.Time
return msg, msg.Err() if timeout > 0 {
timer := time.NewTimer(timeout)
defer timer.Stop()
t = timer.C
} }
t := time.NewTimer(timeout)
defer t.Stop()
select { select {
case msg = <-msg.chReply: case msg = <-msg.chReply:
return msg, msg.Err() return msg, msg.Err()
case <-client.done: case <-client.done:
return &Message{}, ErrIsQueueClosed return &Message{}, ErrIsQueueClosed
case <-t.C: case <-t:
return &Message{}, ErrQueueTimeout return &Message{}, ErrQueueTimeout
} }
} }
......
...@@ -58,6 +58,21 @@ func TestTimeout(t *testing.T) { ...@@ -58,6 +58,21 @@ func TestTimeout(t *testing.T) {
} }
} }
func TestClient_WaitTimeout(t *testing.T) {
q := New("channel")
client := q.Client()
msg := client.NewMessage("mempool", types.EventTx, "hello")
err := client.SendTimeout(msg, true, 0)
if err != nil {
t.Error(err)
return
}
_, err = client.WaitTimeout(msg, time.Second*5)
assert.Equal(t, ErrQueueTimeout, err)
}
func TestMultiTopic(t *testing.T) { func TestMultiTopic(t *testing.T) {
q := New("channel") q := New("channel")
......
...@@ -14,7 +14,7 @@ command = "account import_key -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d826 ...@@ -14,7 +14,7 @@ command = "account import_key -k 0xd165c84ed37c2a427fea487470ee671b7a0495d68d826
[[TransferCase]] [[TransferCase]]
id = "btyTrans1" id = "btyTrans1"
command = "send bty transfer -a 10 -t 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" command = "send coins transfer -a 10 -t 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
from = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" from = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
to = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" to = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
amount = "10" amount = "10"
...@@ -24,7 +24,7 @@ dep = ["import1"] ...@@ -24,7 +24,7 @@ dep = ["import1"]
[[TransferCase]] [[TransferCase]]
id = "btyTrans2" id = "btyTrans2"
command = "send bty transfer -a 1 -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" command = "send coins transfer -a 1 -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
to = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" to = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
amount = "1" amount = "1"
...@@ -35,7 +35,7 @@ dep = ["btyTrans1"] ...@@ -35,7 +35,7 @@ dep = ["btyTrans1"]
[[TransferCase]] [[TransferCase]]
id = "failBtyTrans" id = "failBtyTrans"
command = "send bty transfer -a 15 -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" command = "send coins transfer -a 15 -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
to = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv" to = "12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
amount = "15" amount = "15"
...@@ -46,7 +46,7 @@ fail = true ...@@ -46,7 +46,7 @@ fail = true
[[TransferCase]] [[TransferCase]]
id = "btyTrans3" id = "btyTrans3"
command = "send bty transfer -a 1 -t 1GaHYpWmqAJsqRwrpoNcB8VvgKtSwjcHqt -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" command = "send coins transfer -a 1 -t 1GaHYpWmqAJsqRwrpoNcB8VvgKtSwjcHqt -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" from = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
to = "1GaHYpWmqAJsqRwrpoNcB8VvgKtSwjcHqt" to = "1GaHYpWmqAJsqRwrpoNcB8VvgKtSwjcHqt"
amount = "1" amount = "1"
...@@ -56,7 +56,7 @@ dep = ["btyTrans1"] ...@@ -56,7 +56,7 @@ dep = ["btyTrans1"]
[[WithdrawCase]] [[WithdrawCase]]
id = "btyWithdraw" id = "btyWithdraw"
command = "send bty withdraw -a 0.1 -e coins -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" command = "send coins withdraw -a 0.1 -e coins -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
addr = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" addr = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
amount = "0.1" amount = "0.1"
checkItem = ["balance"] checkItem = ["balance"]
...@@ -66,7 +66,7 @@ dep = ["btyTrans3"] ...@@ -66,7 +66,7 @@ dep = ["btyTrans3"]
[[WithdrawCase]] [[WithdrawCase]]
id = "failWithdraw" id = "failWithdraw"
command = "send bty withdraw -a 1.1 -e coins -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" command = "send coins withdraw -a 1.1 -e coins -k 1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
addr = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj" addr = "1Ka7EPFRqs3v9yreXG6qA4RQbNmbPJCZPj"
amount = "1.1" amount = "1.1"
checkItem = ["balance"] checkItem = ["balance"]
......
...@@ -17,22 +17,6 @@ import ( ...@@ -17,22 +17,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// BTYCmd bty command
func BTYCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bty",
Short: "Construct BTY transactions",
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(
CreateRawTransferCmd(),
CreateRawWithdrawCmd(),
CreateRawSendToExecCmd(),
CreateTxGroupCmd(),
)
return cmd
}
// CoinsCmd coins command func // CoinsCmd coins command func
func CoinsCmd() *cobra.Command { func CoinsCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
...@@ -107,12 +91,14 @@ func createWithdraw(cmd *cobra.Command, args []string) { ...@@ -107,12 +91,14 @@ func createWithdraw(cmd *cobra.Command, args []string) {
exec, _ := cmd.Flags().GetString("exec") exec, _ := cmd.Flags().GetString("exec")
amount, _ := cmd.Flags().GetFloat64("amount") amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note") note, _ := cmd.Flags().GetString("note")
execAddr, err := commandtypes.GetExecAddr(exec) paraName, _ := cmd.Flags().GetString("paraName")
realExec := getRealExecName(paraName, exec)
execAddr, err := commandtypes.GetExecAddr(realExec)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
} }
txHex, err := commandtypes.CreateRawTx(cmd, execAddr, amount, note, true, "", exec) txHex, err := commandtypes.CreateRawTx(cmd, execAddr, amount, note, true, "", realExec)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
...@@ -145,12 +131,14 @@ func sendToExec(cmd *cobra.Command, args []string) { ...@@ -145,12 +131,14 @@ func sendToExec(cmd *cobra.Command, args []string) {
exec, _ := cmd.Flags().GetString("exec") exec, _ := cmd.Flags().GetString("exec")
amount, _ := cmd.Flags().GetFloat64("amount") amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note") note, _ := cmd.Flags().GetString("note")
execAddr, err := commandtypes.GetExecAddr(exec) paraName, _ := cmd.Flags().GetString("paraName")
realExec := getRealExecName(paraName, exec)
execAddr, err := commandtypes.GetExecAddr(realExec)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
} }
txHex, err := commandtypes.CreateRawTx(cmd, execAddr, amount, note, false, "", exec) txHex, err := commandtypes.CreateRawTx(cmd, execAddr, amount, note, false, "", realExec)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
...@@ -158,79 +146,6 @@ func sendToExec(cmd *cobra.Command, args []string) { ...@@ -158,79 +146,6 @@ func sendToExec(cmd *cobra.Command, args []string) {
fmt.Println(txHex) fmt.Println(txHex)
} }
// TransferCmd send to address
func TransferCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer",
Short: "Send coins to address",
Run: transfer,
}
addTransferFlags(cmd)
return cmd
}
func addTransferFlags(cmd *cobra.Command) {
cmd.Flags().StringP("from", "f", "", "sender account address")
cmd.MarkFlagRequired("from")
cmd.Flags().StringP("to", "t", "", "receiver account address")
cmd.MarkFlagRequired("to")
cmd.Flags().Float64P("amount", "a", 0.0, "transfer amount, at most 4 decimal places")
cmd.MarkFlagRequired("amount")
cmd.Flags().StringP("note", "n", "", "transaction note info")
}
func transfer(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
fromAddr, _ := cmd.Flags().GetString("from")
toAddr, _ := cmd.Flags().GetString("to")
amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note")
amountInt64 := int64(amount*types.InputPrecision) * types.Multiple1E4 //支持4位小数输入,多余的输入将被截断
commandtypes.SendToAddress(rpcLaddr, fromAddr, toAddr, amountInt64, note, false, "", false)
}
// WithdrawFromExecCmd withdraw from executor
func WithdrawFromExecCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw",
Short: "Withdraw coin from executor",
Run: withdraw,
}
addWithdrawFlags(cmd)
return cmd
}
func addWithdrawFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "t", "", "withdraw account address")
cmd.MarkFlagRequired("addr")
cmd.Flags().StringP("exec", "e", "", "execer withdrawn from")
cmd.MarkFlagRequired("exec")
cmd.Flags().Float64P("amount", "a", 0.0, "transfer amount, at most 4 decimal places")
cmd.MarkFlagRequired("amount")
cmd.Flags().StringP("note", "n", "", "transaction note info")
}
func withdraw(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
addr, _ := cmd.Flags().GetString("addr")
exec, _ := cmd.Flags().GetString("exec")
amount, _ := cmd.Flags().GetFloat64("amount")
note, _ := cmd.Flags().GetString("note")
execAddr, err := commandtypes.GetExecAddr(exec)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
amountInt64 := int64(amount*types.InputPrecision) * types.Multiple1E4 //支持4位小数输入,多余的输入将被截断
commandtypes.SendToAddress(rpcLaddr, addr, execAddr, amountInt64, note, false, "", true)
}
// CreateTxGroupCmd create tx group // CreateTxGroupCmd create tx group
func CreateTxGroupCmd() *cobra.Command { func CreateTxGroupCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
......
...@@ -104,7 +104,7 @@ func addSaveSeedFlags(cmd *cobra.Command) { ...@@ -104,7 +104,7 @@ func addSaveSeedFlags(cmd *cobra.Command) {
cmd.Flags().StringP("seed", "s", "", "15 seed characters separated by space") cmd.Flags().StringP("seed", "s", "", "15 seed characters separated by space")
cmd.MarkFlagRequired("seed") cmd.MarkFlagRequired("seed")
cmd.Flags().StringP("pwd", "p", "", "password used to encrypt seed") cmd.Flags().StringP("pwd", "p", "", "password used to encrypt seed, [8-30]letter and digit")
cmd.MarkFlagRequired("pwd") cmd.MarkFlagRequired("pwd")
} }
......
...@@ -127,5 +127,5 @@ func OneStepSend(args []string) { ...@@ -127,5 +127,5 @@ func OneStepSend(args []string) {
func loadHelp() { func loadHelp() {
fmt.Println("Use similarly as bty/token/trade/bind_miner raw transaction creation, in addition to the parameter of private key or from address input following \"-k\".") fmt.Println("Use similarly as bty/token/trade/bind_miner raw transaction creation, in addition to the parameter of private key or from address input following \"-k\".")
fmt.Println("e.g.: cli send bty transfer -a 1 -n note -t toAddr -k privKey/fromAddr") fmt.Println("e.g.: cli send coins transfer -a 1 -n note -t toAddr -k privKey/fromAddr")
} }
...@@ -90,15 +90,13 @@ func CreateRawTx(cmd *cobra.Command, to string, amount float64, note string, isW ...@@ -90,15 +90,13 @@ func CreateRawTx(cmd *cobra.Command, to string, amount float64, note string, isW
paraName, _ := cmd.Flags().GetString("paraName") paraName, _ := cmd.Flags().GetString("paraName")
amountInt64 := int64(math.Trunc((amount+0.0000001)*1e4)) * 1e4 amountInt64 := int64(math.Trunc((amount+0.0000001)*1e4)) * 1e4
initExecName := execName
execName = getRealExecName(paraName, execName)
if execName != "" && !types.IsAllowExecName([]byte(execName), []byte(execName)) { if execName != "" && !types.IsAllowExecName([]byte(execName), []byte(execName)) {
return "", types.ErrExecNameNotMatch return "", types.ErrExecNameNotMatch
} }
var tx *types.Transaction var tx *types.Transaction
transfer := &cty.CoinsAction{} transfer := &cty.CoinsAction{}
if !isWithdraw { if !isWithdraw {
if initExecName != "" { if execName != "" {
v := &cty.CoinsAction_TransferToExec{TransferToExec: &types.AssetsTransferToExec{Amount: amountInt64, Note: []byte(note), ExecName: execName, To: to}} v := &cty.CoinsAction_TransferToExec{TransferToExec: &types.AssetsTransferToExec{Amount: amountInt64, Note: []byte(note), ExecName: execName, To: to}}
transfer.Value = v transfer.Value = v
transfer.Ty = cty.CoinsActionTransferToExec transfer.Ty = cty.CoinsActionTransferToExec
......
...@@ -136,7 +136,7 @@ func addSetPwdFlags(cmd *cobra.Command) { ...@@ -136,7 +136,7 @@ func addSetPwdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("old", "o", "", "old password") cmd.Flags().StringP("old", "o", "", "old password")
cmd.MarkFlagRequired("old") cmd.MarkFlagRequired("old")
cmd.Flags().StringP("new", "n", "", "new password") cmd.Flags().StringP("new", "n", "", "new password,[8-30]letter and digit")
cmd.MarkFlagRequired("new") cmd.MarkFlagRequired("new")
} }
......
...@@ -624,7 +624,7 @@ func updateGlobalMemTree(node *Node) { ...@@ -624,7 +624,7 @@ func updateGlobalMemTree(node *Node) {
memN.data[0] = node.leftHash memN.data[0] = node.leftHash
memN.data[1] = node.rightHash memN.data[1] = node.rightHash
memN.data[2] = node.key memN.data[2] = node.key
if(isTkCloseNode) { if isTkCloseNode {
tkCloseCache.Add(uintkey(farm.Hash64(node.hash)), memN) tkCloseCache.Add(uintkey(farm.Hash64(node.hash)), memN)
} else { } else {
memTree.Add(uintkey(farm.Hash64(node.hash)), memN) memTree.Add(uintkey(farm.Hash64(node.hash)), memN)
......
...@@ -230,7 +230,7 @@ func S(key string, value interface{}) { ...@@ -230,7 +230,7 @@ func S(key string, value interface{}) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
if strings.HasPrefix(key, "config.") { if strings.HasPrefix(key, "config.") {
if !isLocal() { //only local can modify for test if !isLocal() && !isTestPara() { //only local and test para can modify for test
panic("prefix config. is readonly") panic("prefix config. is readonly")
} else { } else {
tlog.Error("modify " + key + " is only for test") tlog.Error("modify " + key + " is only for test")
...@@ -351,6 +351,10 @@ func isPara() bool { ...@@ -351,6 +351,10 @@ func isPara() bool {
return strings.Count(title, ".") == 3 && strings.HasPrefix(title, ParaKeyX) return strings.Count(title, ".") == 3 && strings.HasPrefix(title, ParaKeyX)
} }
func isTestPara() bool {
return strings.Count(title, ".") == 3 && strings.HasPrefix(title, ParaKeyX) && strings.HasSuffix(title, "test.")
}
// IsPara 是否平行链 // IsPara 是否平行链
func IsPara() bool { func IsPara() bool {
mu.Lock() mu.Lock()
...@@ -369,6 +373,23 @@ func IsMyParaExecName(exec string) bool { ...@@ -369,6 +373,23 @@ func IsMyParaExecName(exec string) bool {
return IsParaExecName(exec) && strings.HasPrefix(exec, GetTitle()) return IsParaExecName(exec) && strings.HasPrefix(exec, GetTitle())
} }
//IsSpecificParaExecName 是否是某一个平行链的执行器
func IsSpecificParaExecName(title, exec string) bool {
return IsParaExecName(exec) && strings.HasPrefix(exec, title)
}
//GetParaExecTitleName 如果是平行链执行器,获取对应title
func GetParaExecTitleName(exec string) (string, bool) {
if IsParaExecName(exec) {
for i := len(ParaKey); i < len(exec); i++ {
if exec[i] == '.' {
return exec[:i+1], true
}
}
}
return "", false
}
func setTestNet(isTestNet bool) { func setTestNet(isTestNet bool) {
if !isTestNet { if !isTestNet {
setChainConfig("TestNet", false) setChainConfig("TestNet", false)
......
...@@ -47,3 +47,19 @@ func TestBityuanInit(t *testing.T) { ...@@ -47,3 +47,19 @@ func TestBityuanInit(t *testing.T) {
assert.Equal(t, int64(0), cfg.Fork.Sub["token"]["Enable"]) assert.Equal(t, int64(0), cfg.Fork.Sub["token"]["Enable"])
assert.Nil(t, err) assert.Nil(t, err)
} }
func TestGetParaExecTitleName(t *testing.T) {
_, exist := GetParaExecTitleName("token")
assert.Equal(t, false, exist)
_, exist = GetParaExecTitleName("user.p.para")
assert.Equal(t, false, exist)
title, exist := GetParaExecTitleName("user.p.para.")
assert.Equal(t, true, exist)
assert.Equal(t, "user.p.para.", title)
title, exist = GetParaExecTitleName("user.p.guodux.token")
assert.Equal(t, true, exist)
assert.Equal(t, "user.p.guodux.", title)
}
...@@ -135,7 +135,7 @@ var ( ...@@ -135,7 +135,7 @@ var (
ErrFromHex = errors.New("ErrFromHex") ErrFromHex = errors.New("ErrFromHex")
ErrPrivKeyFromBytes = errors.New("ErrFromHex") ErrPrivKeyFromBytes = errors.New("ErrFromHex")
ErrParentHash = errors.New("ErrParentHash") ErrParentHash = errors.New("ErrParentHash")
ErrInvalidPassWord = errors.New("ErrInvalidPassWord")
//ErrPing p2p模块错误类型 //ErrPing p2p模块错误类型
ErrPing = errors.New("ErrPingSignature") ErrPing = errors.New("ErrPingSignature")
ErrVersion = errors.New("ErrVersionNoSupport") ErrVersion = errors.New("ErrVersionNoSupport")
...@@ -163,6 +163,7 @@ var ( ...@@ -163,6 +163,7 @@ var (
ErrDataBaseDamage = errors.New("ErrDataBaseDamage") ErrDataBaseDamage = errors.New("ErrDataBaseDamage")
ErrIndex = errors.New("ErrIndex") ErrIndex = errors.New("ErrIndex")
ErrTxGroupParaCount = errors.New("ErrTxGroupParaCount") ErrTxGroupParaCount = errors.New("ErrTxGroupParaCount")
ErrTxGroupParaMainMixed = errors.New("ErrTxGroupParaMainMixed")
//ErrInvalidMainnetRPCAddr rpc模块的错误类型 //ErrInvalidMainnetRPCAddr rpc模块的错误类型
ErrInvalidMainnetRPCAddr = errors.New("ErrInvalidMainnetRPCAddr") ErrInvalidMainnetRPCAddr = errors.New("ErrInvalidMainnetRPCAddr")
......
...@@ -163,18 +163,26 @@ func (txgroup *Transactions) Check(height, minfee, maxFee int64) error { ...@@ -163,18 +163,26 @@ func (txgroup *Transactions) Check(height, minfee, maxFee int64) error {
if err != nil { if err != nil {
return err return err
} }
name := string(txs[i].Execer) if title, ok := GetParaExecTitleName(string(txs[i].Execer)); ok {
if IsParaExecName(name) { para[title] = true
para[name] = true
} }
} }
//txgroup 只允许一条平行链的交易 //txgroup 只允许一条平行链的交易, 且平行链txgroup须全部是平行链tx
if IsEnableFork(height, "ForkV24TxGroupPara", EnableTxGroupParaFork) { if IsFork(height, "ForkTxGroupPara") {
if len(para) > 1 { if len(para) > 1 {
tlog.Info("txgroup has multi para transaction") tlog.Info("txgroup has multi para transaction")
return ErrTxGroupParaCount return ErrTxGroupParaCount
} }
if len(para) > 0 {
for _, tx := range txs {
if !IsParaExecName(string(tx.Execer)) {
tlog.Error("para txgroup has main chain transaction")
return ErrTxGroupParaMainMixed
}
}
}
} }
for i := 1; i < len(txs); i++ { for i := 1; i < len(txs); i++ {
if txs[i].Fee != 0 { if txs[i].Fee != 0 {
return ErrTxGroupFeeNotZero return ErrTxGroupFeeNotZero
......
...@@ -47,6 +47,66 @@ func TestCreateGroupTx(t *testing.T) { ...@@ -47,6 +47,66 @@ func TestCreateGroupTx(t *testing.T) {
t.Log(grouptx) t.Log(grouptx)
} }
func TestCreateParaGroupTx(t *testing.T) {
tempTitle := GetTitle()
SetTitleOnlyForTest("chain33")
testHeight := int64(806578 + 1)
tx1 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630f1cdebc8f7efa5e9283a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx2 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630de92c3828ad194b26d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx3 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630b0d6c895c4d28efe5d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx11, _ := hex.DecodeString(tx1)
tx21, _ := hex.DecodeString(tx2)
tx31, _ := hex.DecodeString(tx3)
var tx12 Transaction
Decode(tx11, &tx12)
var tx22 Transaction
Decode(tx21, &tx22)
var tx32 Transaction
Decode(tx31, &tx32)
tx12.Execer = []byte("user.p.test.token")
tx22.Execer = []byte("token")
tx32.Execer = []byte("user.p.test.ticket")
//SetFork("", "ForkTxGroupPara", 0)
group, err := CreateTxGroup([]*Transaction{&tx12, &tx22, &tx32})
if err != nil {
t.Error(err)
return
}
err = group.Check(testHeight, GInt("MinFee"), GInt("MaxFee"))
if err != nil {
for i := 0; i < len(group.Txs); i++ {
t.Log(group.Txs[i].JSON())
}
//t.Error(err)
}
assert.Equal(t, ErrTxGroupParaMainMixed, err)
tx22.Execer = []byte("user.p.para.token")
group, err = CreateTxGroup([]*Transaction{&tx12, &tx22, &tx32})
if err != nil {
t.Error(err)
return
}
err = group.Check(testHeight, GInt("MinFee"), GInt("MaxFee"))
assert.Equal(t, ErrTxGroupParaCount, err)
tx22.Execer = []byte("user.p.test.paracross")
group, err = CreateTxGroup([]*Transaction{&tx12, &tx22, &tx32})
if err != nil {
t.Error(err)
return
}
err = group.Check(testHeight, GInt("MinFee"), GInt("MaxFee"))
assert.Nil(t, err)
newtx := group.Tx()
grouptx := hex.EncodeToString(Encode(newtx))
t.Log(grouptx)
SetTitleOnlyForTest(tempTitle)
}
func TestCreateGroupTxWithSize(t *testing.T) { func TestCreateGroupTxWithSize(t *testing.T) {
tx1 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630f1cdebc8f7efa5e9283a22313271796f6361794e46374c7636433971573461767873324537553431664b536676" tx1 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630f1cdebc8f7efa5e9283a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx2 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630de92c3828ad194b26d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676" tx2 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630de92c3828ad194b26d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
......
...@@ -5,45 +5,27 @@ ...@@ -5,45 +5,27 @@
package util package util
import ( import (
"bytes"
"math/big" "math/big"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
) )
//CalcBitMap big-end mode, that is bytes [0] [1] //CalcBitMap subs are align with subData,get the bases' tx's bitmap from subs result
// tx index: fedcba98 76543210 // if the tx ty is OK in subs, find the tx in base and set the index to 1, this function return base's bitmap
//cur is subset of ori, receipts are align with cur txs,
// if the tx ty is OK in cur, find the tx in ori and set the index to 1, this function return ori's bitmap
//if all tx failed, the setBit will normalize result and just return nil slice //if all tx failed, the setBit will normalize result and just return nil slice
func CalcBitMap(ori, cur [][]byte, data []*types.ReceiptData) []byte { func CalcBitMap(bases, subs [][]byte, subData []*types.ReceiptData) []byte {
rst := big.NewInt(0) rst := big.NewInt(0)
for i, curHash := range cur { subMap := make(map[string]bool)
for index, ori := range ori { for i, sub := range subs {
if bytes.Equal(ori, curHash) { if subData[i].Ty == types.ExecOk {
if data[i].Ty == types.ExecOk { subMap[string(sub)] = true
rst.SetBit(rst, index, 1)
}
}
} }
} }
return rst.Bytes() for i, base := range bases {
} if _, exist := subMap[string(base)]; exist {
rst.SetBit(rst, i, 1)
//CalcSubBitMap : cur is subset of ori, data are align with ori, this function return cur's bitmap
//if all tx failed, the setBit will normalize result and just return nil slice
func CalcSubBitMap(ori, sub [][]byte, data []*types.ReceiptData) []byte {
rst := big.NewInt(0)
for i, subHash := range sub {
for index, ori := range ori {
if bytes.Equal(ori, subHash) {
if data[index].Ty == types.ExecOk {
rst.SetBit(rst, i, 1)
}
}
} }
} }
......
...@@ -7,6 +7,7 @@ package util ...@@ -7,6 +7,7 @@ package util
import ( import (
"testing" "testing"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -14,12 +15,12 @@ import ( ...@@ -14,12 +15,12 @@ import (
func TestCalcByteBitMap(t *testing.T) { func TestCalcByteBitMap(t *testing.T) {
ori := [][]byte{} //{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} ori := [][]byte{} //{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}
for i := 0; i < 18; i++ { for i := 0; i < 18; i++ {
ori = append(ori, []byte{byte(i)}) ori = append(ori, common.Sha256([]byte(string(i))))
} }
cur := [][]byte{} cur := [][]byte{}
arry := []byte{3, 7, 8, 11, 15, 17} arry := []byte{3, 7, 8, 11, 15, 17}
for _, v := range arry { for _, v := range arry {
cur = append(cur, []byte{byte(v)}) cur = append(cur, common.Sha256([]byte(string(v))))
} }
d0 := &types.ReceiptData{Ty: types.ExecOk} d0 := &types.ReceiptData{Ty: types.ExecOk}
...@@ -42,12 +43,12 @@ func TestCalcByteBitMap(t *testing.T) { ...@@ -42,12 +43,12 @@ func TestCalcByteBitMap(t *testing.T) {
func TestCalcSubBitMap(t *testing.T) { func TestCalcSubBitMap(t *testing.T) {
ori := [][]byte{} //{0,1,2,3,4,5,6,7,8,9} ori := [][]byte{} //{0,1,2,3,4,5,6,7,8,9}
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
ori = append(ori, []byte{byte(i)}) ori = append(ori, common.Sha256([]byte(string(i))))
} }
sub := [][]byte{} sub := [][]byte{}
arry := []byte{0, 2, 4, 6, 7, 9} arry := []byte{0, 2, 4, 6, 7, 9}
for _, v := range arry { for _, v := range arry {
sub = append(sub, []byte{byte(v)}) sub = append(sub, common.Sha256([]byte(string(v))))
} }
d0 := &types.ReceiptData{Ty: types.ExecOk} d0 := &types.ReceiptData{Ty: types.ExecOk}
...@@ -62,7 +63,7 @@ func TestCalcSubBitMap(t *testing.T) { ...@@ -62,7 +63,7 @@ func TestCalcSubBitMap(t *testing.T) {
d9 := &types.ReceiptData{Ty: types.ExecPack} d9 := &types.ReceiptData{Ty: types.ExecPack}
data := []*types.ReceiptData{d0, d1, d2, d3, d4, d5, d6, d7, d8, d9} data := []*types.ReceiptData{d0, d1, d2, d3, d4, d5, d6, d7, d8, d9}
rst := CalcSubBitMap(ori, sub, data) rst := CalcBitMap(sub, ori, data)
//t.Log(rst) //t.Log(rst)
check := []byte{0x17} check := []byte{0x17}
assert.Equal(t, check, rst) assert.Equal(t, check, rst)
......
...@@ -51,7 +51,6 @@ func init() { ...@@ -51,7 +51,6 @@ func init() {
commands.CertCmd(), commands.CertCmd(),
commands.AccountCmd(), commands.AccountCmd(),
commands.BlockCmd(), commands.BlockCmd(),
commands.BTYCmd(),
commands.CoinsCmd(), commands.CoinsCmd(),
commands.ExecCmd(), commands.ExecCmd(),
commands.MempoolCmd(), commands.MempoolCmd(),
......
...@@ -250,13 +250,13 @@ func (mock *Chain33Mock) SendAndSignNonce(priv crypto.PrivKey, hextx string, non ...@@ -250,13 +250,13 @@ func (mock *Chain33Mock) SendAndSignNonce(priv crypto.PrivKey, hextx string, non
func newWalletRealize(qAPI client.QueueProtocolAPI) { func newWalletRealize(qAPI client.QueueProtocolAPI) {
seed := &types.SaveSeedByPw{ seed := &types.SaveSeedByPw{
Seed: "subject hamster apple parent vital can adult chapter fork business humor pen tiger void elephant", Seed: "subject hamster apple parent vital can adult chapter fork business humor pen tiger void elephant",
Passwd: "123456", Passwd: "123456fuzamei",
} }
reply, err := qAPI.SaveSeed(seed) reply, err := qAPI.SaveSeed(seed)
if !reply.IsOk && err != nil { if !reply.IsOk && err != nil {
panic(err) panic(err)
} }
reply, err = qAPI.WalletUnLock(&types.WalletUnLock{Passwd: "123456"}) reply, err = qAPI.WalletUnLock(&types.WalletUnLock{Passwd: "123456fuzamei"})
if !reply.IsOk && err != nil { if !reply.IsOk && err != nil {
panic(err) panic(err)
} }
......
...@@ -13,10 +13,11 @@ import ( ...@@ -13,10 +13,11 @@ import (
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"unicode" "unicode"
"strings"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto" "github.com/33cn/chain33/common/crypto"
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"strings" "strings"
"sync/atomic" "sync/atomic"
"time" "time"
"unicode"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
...@@ -758,6 +759,10 @@ func (wallet *Wallet) ProcWalletSetPasswd(Passwd *types.ReqWalletSetPasswd) erro ...@@ -758,6 +759,10 @@ func (wallet *Wallet) ProcWalletSetPasswd(Passwd *types.ReqWalletSetPasswd) erro
if !isok && err == types.ErrSaveSeedFirst { if !isok && err == types.ErrSaveSeedFirst {
return err return err
} }
// 新密码合法性校验
if !isValidPassWord(Passwd.NewPass) {
return types.ErrInvalidPassWord
}
//保存钱包的锁状态,需要暂时的解锁,函数退出时再恢复回去 //保存钱包的锁状态,需要暂时的解锁,函数退出时再恢复回去
tempislock := atomic.LoadInt32(&wallet.isWalletLocked) tempislock := atomic.LoadInt32(&wallet.isWalletLocked)
//wallet.isWalletLocked = false //wallet.isWalletLocked = false
...@@ -1191,6 +1196,11 @@ func (wallet *Wallet) saveSeed(password string, seed string) (bool, error) { ...@@ -1191,6 +1196,11 @@ func (wallet *Wallet) saveSeed(password string, seed string) (bool, error) {
return false, types.ErrInvalidParam return false, types.ErrInvalidParam
} }
// 密码合法性校验
if !isValidPassWord(password) {
return false, types.ErrInvalidPassWord
}
seedarry := strings.Fields(seed) seedarry := strings.Fields(seed)
curseedlen := len(seedarry) curseedlen := len(seedarry)
if curseedlen < SaveSeedLong { if curseedlen < SaveSeedLong {
...@@ -1277,3 +1287,24 @@ func (wallet *Wallet) setFatalFailure(reportErrEvent *types.ReportErrEvent) { ...@@ -1277,3 +1287,24 @@ func (wallet *Wallet) setFatalFailure(reportErrEvent *types.ReportErrEvent) {
func (wallet *Wallet) getFatalFailure() int32 { func (wallet *Wallet) getFatalFailure() int32 {
return atomic.LoadInt32(&wallet.fatalFailureFlag) return atomic.LoadInt32(&wallet.fatalFailureFlag)
} }
//密码合法性校验,密码长度在8-30位之间。必须是数字+字母的组合
func isValidPassWord(password string) bool {
pwLen := len(password)
if pwLen < 8 || pwLen > 30 {
return false
}
var char bool
var digit bool
for _, s := range password {
if unicode.IsLetter(s) {
char = true
} else if unicode.IsDigit(s) {
digit = true
} else {
return false
}
}
return char && digit
}
...@@ -199,7 +199,7 @@ func testSeed(t *testing.T, wallet *Wallet) { ...@@ -199,7 +199,7 @@ func testSeed(t *testing.T, wallet *Wallet) {
seed := seedRes.GetData().(*types.ReplySeed).Seed seed := seedRes.GetData().(*types.ReplySeed).Seed
println("seed: ", seed) println("seed: ", seed)
password := "password" password := "password123"
saveSeedByPw := &types.SaveSeedByPw{Seed: "", Passwd: ""} saveSeedByPw := &types.SaveSeedByPw{Seed: "", Passwd: ""}
msgSaveEmpty := wallet.client.NewMessage("wallet", types.EventSaveSeed, saveSeedByPw) msgSaveEmpty := wallet.client.NewMessage("wallet", types.EventSaveSeed, saveSeedByPw)
wallet.client.Send(msgSaveEmpty, true) wallet.client.Send(msgSaveEmpty, true)
...@@ -575,7 +575,7 @@ func testProcWalletSetPasswd(t *testing.T, wallet *Wallet) { ...@@ -575,7 +575,7 @@ func testProcWalletSetPasswd(t *testing.T, wallet *Wallet) {
println("TestProcWalletSetPasswd begin") println("TestProcWalletSetPasswd begin")
passwd := &types.ReqWalletSetPasswd{ passwd := &types.ReqWalletSetPasswd{
OldPass: "wrongpassword", OldPass: "wrongpassword",
NewPass: "Newpass", NewPass: "Newpass123",
} }
msg := wallet.client.NewMessage("wallet", types.EventWalletSetPasswd, passwd) msg := wallet.client.NewMessage("wallet", types.EventWalletSetPasswd, passwd)
wallet.client.Send(msg, true) wallet.client.Send(msg, true)
...@@ -584,7 +584,7 @@ func testProcWalletSetPasswd(t *testing.T, wallet *Wallet) { ...@@ -584,7 +584,7 @@ func testProcWalletSetPasswd(t *testing.T, wallet *Wallet) {
t.Error("testProcWalletSetPasswd failed") t.Error("testProcWalletSetPasswd failed")
} }
passwd.OldPass = "password" passwd.OldPass = "password123"
msg = wallet.client.NewMessage("wallet", types.EventWalletSetPasswd, passwd) msg = wallet.client.NewMessage("wallet", types.EventWalletSetPasswd, passwd)
wallet.client.Send(msg, true) wallet.client.Send(msg, true)
_, err := wallet.client.Wait(msg) _, err := wallet.client.Wait(msg)
...@@ -628,12 +628,12 @@ func testProcWalletLock(t *testing.T, wallet *Wallet) { ...@@ -628,12 +628,12 @@ func testProcWalletLock(t *testing.T, wallet *Wallet) {
t.Error("test input wrong password failed") t.Error("test input wrong password failed")
} }
walletUnLock.Passwd = "Newpass" walletUnLock.Passwd = "Newpass123"
msg = wallet.client.NewMessage("wallet", types.EventWalletUnLock, walletUnLock) msg = wallet.client.NewMessage("wallet", types.EventWalletUnLock, walletUnLock)
wallet.client.Send(msg, true) wallet.client.Send(msg, true)
wallet.client.Wait(msg) wallet.client.Wait(msg)
msgGetSeed := wallet.client.NewMessage("wallet", types.EventGetSeed, &types.GetSeedByPw{Passwd: "Newpass"}) msgGetSeed := wallet.client.NewMessage("wallet", types.EventGetSeed, &types.GetSeedByPw{Passwd: "Newpass123"})
wallet.client.Send(msgGetSeed, true) wallet.client.Send(msgGetSeed, true)
resp, _ = wallet.client.Wait(msgGetSeed) resp, _ = wallet.client.Wait(msgGetSeed)
println("seed:", resp.GetData().(*types.ReplySeed).Seed) println("seed:", resp.GetData().(*types.ReplySeed).Seed)
......
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