[CLI] fix 'tojson' flag of 'contract call' command
@@ -281,47 +281,36 @@ func runCallCmd(cmd *cobra.Command, args []string) {
os.Exit(1)
}
tx.Body.ChainIdHash = rawCidHash
+ } else {
+ if errStr := fillChainId(tx); errStr != "" {
+ cmd.Printf(errStr)
+ return
+ }
}
- if toJson {
- if chainIdHash == "" {
- status, err := client.Blockchain(context.Background(), &types.Empty{})
- if err != nil {
- cmd.Printf("Failed: %s\n", err.Error())
+ if cmd.Flags().Changed("path") {
+ if errStr := fillSign(tx, dataDir, pw, caller); errStr != "" {
+ cmd.Printf(errStr)
return
}
- tx.Body.ChainIdHash = status.BestChainIdHash
- }
+ } else {
sign, err := client.SignTX(context.Background(), tx)
if err != nil || sign == nil {
log.Fatal(err)
}
- fmt.Println(util.TxConvBase58Addr(sign))
- return
+ tx = sign
}
- if cmd.Flags().Changed("path") {
- var msgs *types.CommitResultList
- if errStr := fillChainId(tx); errStr != "" {
- cmd.Printf(errStr)
- return
- }
- if errStr := fillSign(tx, dataDir, pw, caller); errStr != "" {
- cmd.Printf(errStr)
- return
- }
+ if toJson {
+ cmd.Println(util.TxConvBase58Addr(tx))
+ } else {
txs := []*types.Tx{tx}
+ var msgs *types.CommitResultList
msgs, err = client.CommitTX(context.Background(), &types.TxList{Txs: txs})
if err != nil {
log.Fatal("Failed request to aergo server\n" + err.Error())
}
cmd.Println(util.JSON(msgs))
- } else {
- msg, err := client.SendTX(context.Background(), tx)
- if err != nil || msg == nil {
- log.Fatal(err)
- }
- cmd.Println(util.JSON(msg))
}
}
