Skip to content

Commit 73733a3

Browse files
authored
Print time stamp in action hash cmd for ioctl (iotexproject#1064)
1 parent 96fd250 commit 73733a3

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

cli/ioctl/cmd/action/actionhash.go

+32-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strconv"
1414

1515
"github.com/golang/protobuf/proto"
16+
"github.com/golang/protobuf/ptypes"
1617
"github.com/spf13/cobra"
1718
"go.uber.org/zap"
1819
"google.golang.org/grpc/codes"
@@ -54,27 +55,29 @@ func getActionByHash(args []string) (string, error) {
5455
cli := iotexapi.NewAPIServiceClient(conn)
5556
ctx := context.Background()
5657

57-
requestCheckPending := iotexapi.GetActionsRequest{
58+
// search action on blockchain
59+
requestGetActionByHash := &iotexapi.GetActionByHashRequest{
60+
ActionHash: hash,
61+
CheckPending: false,
62+
}
63+
requestGetAction := iotexapi.GetActionsRequest{
5864
Lookup: &iotexapi.GetActionsRequest_ByHash{
59-
ByHash: &iotexapi.GetActionByHashRequest{
60-
ActionHash: hash,
61-
CheckPending: true,
62-
},
65+
ByHash: requestGetActionByHash,
6366
},
6467
}
65-
response, err := cli.GetActions(ctx, &requestCheckPending)
68+
response, err := cli.GetActions(ctx, &requestGetAction)
6669
if err != nil {
67-
sta, ok := status.FromError(err)
68-
if ok {
69-
return "", fmt.Errorf(sta.Message())
70+
// search action in action pool
71+
requestGetActionByHash.CheckPending = true
72+
response, err = cli.GetActions(ctx, &requestGetAction)
73+
if err != nil {
74+
return "", err
7075
}
71-
return "", err
7276
}
7377
if len(response.ActionInfo) == 0 {
7478
return "", fmt.Errorf("no action info returned")
7579
}
76-
action := response.ActionInfo[0]
77-
output, err := printActionProto(action.Action)
80+
output, err := printAction(response.ActionInfo[0])
7881
if err != nil {
7982
return "", err
8083
}
@@ -95,6 +98,23 @@ func getActionByHash(args []string) (string, error) {
9598
printReceiptProto(responseReceipt.ReceiptInfo.Receipt), nil
9699
}
97100

101+
func printAction(actionInfo *iotexapi.ActionInfo) (string, error) {
102+
output, err := printActionProto(actionInfo.Action)
103+
if err != nil {
104+
return "", err
105+
}
106+
if actionInfo.Timestamp != nil {
107+
ts, err := ptypes.Timestamp(actionInfo.Timestamp)
108+
if err != nil {
109+
return "", err
110+
}
111+
output += fmt.Sprintf("timeStamp: %d\n", ts.Unix())
112+
output += fmt.Sprintf("blkHash: %s\n", actionInfo.BlkHash)
113+
}
114+
output += fmt.Sprintf("actHash: %s\n", actionInfo.ActHash)
115+
return output, nil
116+
}
117+
98118
func printActionProto(action *iotextypes.Action) (string, error) {
99119
pubKey, err := keypair.BytesToPublicKey(action.SenderPubKey)
100120
if err != nil {

0 commit comments

Comments
 (0)