OSDN Git Service

modify send tx tool
authorwz <mars@bytom.io>
Sat, 21 Apr 2018 07:58:40 +0000 (15: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 [new file with mode: 0644]

index 1b94731..4b9ff80 100644 (file)
@@ -177,7 +177,7 @@ func SendReq(method string, args []string) (interface{}, bool) {
        default:
                return "", false
        }
-       data, exitCode := util.ClientCall(methodPath, &param)
+       data, exitCode := ClientCall(methodPath, &param)
        if exitCode != util.Success {
                return "", false
        }
index 9a41260..f1622d1 100644 (file)
@@ -29,7 +29,7 @@ type config struct {
 func init() {
        sendTxCmd.PersistentFlags().IntVar(&thdTxNum, "thdtxnum", 10, " The number of transactions per goroutine")
        sendTxCmd.PersistentFlags().IntVar(&thdNum, "thdnum", 5, "goroutine num")
-       sendTxCmd.PersistentFlags().IntVar(&assetNum, "assetnum", 10, "Number of transactions asset")
+       sendTxCmd.PersistentFlags().IntVar(&assetNum, "assetnum", 100000000, "Number of transactions asset,unit: neu")
        sendTxCmd.PersistentFlags().StringVar(&configFile, "config", "./config.toml", "config file")
 }
 
diff --git a/tools/sendbulktx/core/util.go b/tools/sendbulktx/core/util.go
new file mode 100644 (file)
index 0000000..97d084a
--- /dev/null
@@ -0,0 +1,56 @@
+package core
+
+import (
+       "context"
+
+       "github.com/bytom/api"
+       "github.com/bytom/blockchain/rpc"
+       "github.com/bytom/env"
+)
+
+const (
+       // Success indicates the rpc calling is successful.
+       Success = iota
+       // ErrLocalExe indicates error occurs before the rpc calling.
+       ErrLocalExe
+       // ErrConnect indicates error occurs connecting to the bytomd, e.g.,
+       // bytomd can't parse the received arguments.
+       ErrConnect
+       // ErrLocalParse indicates error occurs locally when parsing the response.
+       ErrLocalParse
+       // ErrRemote indicates error occurs in bytomd.
+       ErrRemote
+)
+
+var (
+       coreURL = env.String("BYTOM_URL", "http://localhost:9888")
+)
+
+// Wraper rpc's client
+func MustRPCClient() *rpc.Client {
+       env.Parse()
+       return &rpc.Client{BaseURL: *coreURL}
+}
+
+// Wrapper rpc call api.
+func ClientCall(path string, req ...interface{}) (interface{}, int) {
+
+       var response = &api.Response{}
+       var request interface{}
+
+       if req != nil {
+               request = req[0]
+       }
+
+       client := MustRPCClient()
+       client.Call(context.Background(), path, request, response)
+
+       switch response.Status {
+       case api.FAIL:
+               return nil, ErrRemote
+       case "":
+               return nil, ErrConnect
+       }
+
+       return response.Data, Success
+}