@@ -13,6 +13,7 @@ import (
13
13
"strconv"
14
14
15
15
"github.com/golang/protobuf/proto"
16
+ "github.com/golang/protobuf/ptypes"
16
17
"github.com/spf13/cobra"
17
18
"go.uber.org/zap"
18
19
"google.golang.org/grpc/codes"
@@ -54,27 +55,29 @@ func getActionByHash(args []string) (string, error) {
54
55
cli := iotexapi .NewAPIServiceClient (conn )
55
56
ctx := context .Background ()
56
57
57
- requestCheckPending := iotexapi.GetActionsRequest {
58
+ // search action on blockchain
59
+ requestGetActionByHash := & iotexapi.GetActionByHashRequest {
60
+ ActionHash : hash ,
61
+ CheckPending : false ,
62
+ }
63
+ requestGetAction := iotexapi.GetActionsRequest {
58
64
Lookup : & iotexapi.GetActionsRequest_ByHash {
59
- ByHash : & iotexapi.GetActionByHashRequest {
60
- ActionHash : hash ,
61
- CheckPending : true ,
62
- },
65
+ ByHash : requestGetActionByHash ,
63
66
},
64
67
}
65
- response , err := cli .GetActions (ctx , & requestCheckPending )
68
+ response , err := cli .GetActions (ctx , & requestGetAction )
66
69
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
70
75
}
71
- return "" , err
72
76
}
73
77
if len (response .ActionInfo ) == 0 {
74
78
return "" , fmt .Errorf ("no action info returned" )
75
79
}
76
- action := response .ActionInfo [0 ]
77
- output , err := printActionProto (action .Action )
80
+ output , err := printAction (response .ActionInfo [0 ])
78
81
if err != nil {
79
82
return "" , err
80
83
}
@@ -95,6 +98,23 @@ func getActionByHash(args []string) (string, error) {
95
98
printReceiptProto (responseReceipt .ReceiptInfo .Receipt ), nil
96
99
}
97
100
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
+
98
118
func printActionProto (action * iotextypes.Action ) (string , error ) {
99
119
pubKey , err := keypair .BytesToPublicKey (action .SenderPubKey )
100
120
if err != nil {
0 commit comments