OSDN Git Service

Optimize tx test tool log printing
authorYahtoo Ma <yahtoo.ma@gmail.com>
Sat, 21 Apr 2018 10:58:23 +0000 (18:58 +0800)
committerwz <mars@bytom.io>
Mon, 23 Apr 2018 06:47:21 +0000 (14:47 +0800)
tools/sendbulktx/core/send_tx.go
tools/sendbulktx/core/tool.go
tools/sendbulktx/core/util.go

index 4b9ff80..cc723ec 100644 (file)
@@ -5,6 +5,7 @@ import (
        "fmt"
        "os"
        "strings"
+       "sync/atomic"
 
        "github.com/bytom/api"
        "github.com/bytom/blockchain/txbuilder"
@@ -185,7 +186,7 @@ func SendReq(method string, args []string) (interface{}, bool) {
 }
 
 // Sendbulktx send asset tx
-func Sendbulktx(threadTxNum int, txBtmNum string, sendAcct string, sendasset string, controlPrograms []string, txidChan chan string) {
+func Sendbulktx(threadTxNum int, txBtmNum string, sendAcct string, sendasset string, controlPrograms []string, txidChan chan string, index *uint64) {
        arrayLen := len(controlPrograms)
        for i := 0; i < threadTxNum; i++ {
                //build tx
@@ -222,6 +223,9 @@ func Sendbulktx(threadTxNum int, txBtmNum string, sendAcct string, sendasset str
                        txidChan <- ""
                        continue
                }
+
+               atomic.AddUint64(index, 1)
+               fmt.Println("tx num:", atomic.LoadUint64(index), " txid:", resp)
                type txID struct {
                        Txid string `json:"tx_id"`
                }
index f1622d1..37cdbaf 100644 (file)
@@ -74,8 +74,9 @@ var sendTxCmd = &cobra.Command{
                txBtm := fmt.Sprintf("%d", assetNum)
                fmt.Println("*****************send tx start*****************")
                // send btm to account
+               index := uint64(0)
                for i := 0; i < thdNum; i++ {
-                       go Sendbulktx(thdTxNum, txBtm, sendAcct, sendasset, controlPrograms, txidChan)
+                       go Sendbulktx(thdTxNum, txBtm, sendAcct, sendasset, controlPrograms, txidChan, &index)
                }
 
                txs := list.New()
index 97d084a..5443f74 100644 (file)
@@ -6,6 +6,7 @@ import (
        "github.com/bytom/api"
        "github.com/bytom/blockchain/rpc"
        "github.com/bytom/env"
+       jww "github.com/spf13/jwalterweatherman"
 )
 
 const (
@@ -44,11 +45,11 @@ func ClientCall(path string, req ...interface{}) (interface{}, int) {
 
        client := MustRPCClient()
        client.Call(context.Background(), path, request, response)
-
        switch response.Status {
        case api.FAIL:
                return nil, ErrRemote
        case "":
+               jww.ERROR.Println("Unable to connect to the bytomd")
                return nil, ErrConnect
        }