Skip to content

Commit

Permalink
[ioctl] print action hash when send action (#4323)
Browse files Browse the repository at this point in the history
Co-authored-by: dustinxie <dahuaxie@gmail.com>
  • Loading branch information
envestcc and dustinxie authored Jul 9, 2024
1 parent e96d2c8 commit d143b74
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions ioctl/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,7 @@ func SendRaw(selp *iotextypes.Action) error {

shash := hash.Hash256b(byteutil.Must(proto.Marshal(selp)))
txhash := hex.EncodeToString(shash[:])
message := sendMessage{Info: "Action has been sent to blockchain.", TxHash: txhash, URL: "https://"}
switch config.ReadConfig.Explorer {
case "iotexscan":
if strings.Contains(config.ReadConfig.Endpoint, "testnet") {
message.URL += "testnet."
}
message.URL += "iotexscan.io/action/" + txhash
case "iotxplorer":
message.URL = "iotxplorer.io/actions/" + txhash
default:
message.URL = config.ReadConfig.Explorer + txhash
}
fmt.Println(message.String())
outputActionInfo(txhash)
return nil
}

Expand Down Expand Up @@ -262,8 +250,12 @@ func SendRawAndRespond(selp *iotextypes.Action) (*iotexapi.SendActionResponse, e

// SendAction sends signed action to blockchain
func SendAction(elp action.Envelope, signer string) error {
_, err := SendActionAndResponse(elp, signer)
return err
resp, err := SendActionAndResponse(elp, signer)
if err != nil {
return err
}
outputActionInfo(resp.ActionHash)
return nil
}

// SendActionAndResponse sends signed action to blockchain with response and error return
Expand Down Expand Up @@ -424,3 +416,19 @@ func isBalanceEnough(address string, act *action.SealedEnvelope) error {
}
return nil
}

func outputActionInfo(txhash string) {
message := sendMessage{Info: "Action has been sent to blockchain.", TxHash: txhash, URL: "https://"}
switch config.ReadConfig.Explorer {
case "iotexscan":
if strings.Contains(config.ReadConfig.Endpoint, "testnet") {
message.URL += "testnet."
}
message.URL += "iotexscan.io/action/" + txhash
case "iotxplorer":
message.URL = "iotxplorer.io/actions/" + txhash
default:
message.URL = config.ReadConfig.Explorer + txhash
}
fmt.Println(message.String())
}

0 comments on commit d143b74

Please sign in to comment.