From: wz Date: Sat, 21 Apr 2018 07:58:40 +0000 (+0800) Subject: modify send tx tool X-Git-Tag: v1.0.5~38^2~2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f9a562eeb033d85745f43d556f237f631d56c7de;p=bytom%2Fbytom.git modify send tx tool --- diff --git a/tools/sendbulktx/core/send_tx.go b/tools/sendbulktx/core/send_tx.go index 1b947315..4b9ff805 100644 --- a/tools/sendbulktx/core/send_tx.go +++ b/tools/sendbulktx/core/send_tx.go @@ -177,7 +177,7 @@ func SendReq(method string, args []string) (interface{}, bool) { default: return "", false } - data, exitCode := util.ClientCall(methodPath, ¶m) + data, exitCode := ClientCall(methodPath, ¶m) if exitCode != util.Success { return "", false } diff --git a/tools/sendbulktx/core/tool.go b/tools/sendbulktx/core/tool.go index 9a41260a..f1622d18 100644 --- a/tools/sendbulktx/core/tool.go +++ b/tools/sendbulktx/core/tool.go @@ -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 index 00000000..97d084ae --- /dev/null +++ b/tools/sendbulktx/core/util.go @@ -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 +}