@@ -33,20 +33,30 @@ func initBlockCmd() *cobra.Command {
33
33
if err != nil {
34
34
return err
35
35
}
36
- chain = defaultChainFallback (chain )
36
+ chain , err = defaultChainFallback (chain )
37
+ if err != nil {
38
+ return err
39
+ }
37
40
ctx := context .Background ()
38
41
client := cliclients .WaspClientWithVersionCheck (ctx , node )
39
42
40
- bi := fetchBlockInfo (ctx , client , args )
43
+ bi , err := fetchBlockInfo (ctx , client , args )
44
+ if err != nil {
45
+ return err
46
+ }
41
47
log .Printf ("Block index: %d\n " , bi .BlockIndex )
42
48
log .Printf ("Timestamp: %s\n " , bi .Timestamp .UTC ().Format (time .RFC3339 ))
43
49
log .Printf ("Total requests: %d\n " , bi .TotalRequests )
44
50
log .Printf ("Successful requests: %d\n " , bi .NumSuccessfulRequests )
45
51
log .Printf ("Off-ledger requests: %d\n " , bi .NumOffLedgerRequests )
46
52
log .Printf ("\n " )
47
- logRequestsInBlock (ctx , client , bi .BlockIndex )
53
+ if err := logRequestsInBlock (ctx , client , bi .BlockIndex ); err != nil {
54
+ return err
55
+ }
48
56
log .Printf ("\n " )
49
- logEventsInBlock (ctx , client , bi .BlockIndex )
57
+ if err := logEventsInBlock (ctx , client , bi .BlockIndex ); err != nil {
58
+ return err
59
+ }
50
60
return nil
51
61
},
52
62
}
@@ -55,76 +65,87 @@ func initBlockCmd() *cobra.Command {
55
65
return cmd
56
66
}
57
67
58
- func fetchBlockInfo (ctx context.Context , client * apiclient.APIClient , args []string ) * apiclient.BlockInfoResponse {
68
+ func fetchBlockInfo (ctx context.Context , client * apiclient.APIClient , args []string ) ( * apiclient.BlockInfoResponse , error ) {
59
69
if len (args ) == 0 {
60
70
blockInfo , _ , err := client .
61
71
CorecontractsAPI .
62
72
BlocklogGetLatestBlockInfo (ctx ).
63
73
Execute () //nolint:bodyclose // false positive
64
-
65
- log .Check (err )
66
- return blockInfo
74
+ if err != nil {
75
+ return nil , err
76
+ }
77
+ return blockInfo , nil
67
78
}
68
79
69
80
blockIndexStr := args [0 ]
70
81
index , err := strconv .ParseUint (blockIndexStr , 10 , 32 )
71
- log .Check (err )
82
+ if err != nil {
83
+ return nil , fmt .Errorf ("invalid block index '%s': %w" , blockIndexStr , err )
84
+ }
72
85
73
86
blockInfo , _ , err := client .
74
87
CorecontractsAPI .
75
88
BlocklogGetBlockInfo (ctx , uint32 (index )).
76
89
Block (blockIndexStr ).
77
90
Execute () //nolint:bodyclose // false positive
78
-
79
- log .Check (err )
80
- return blockInfo
91
+ if err != nil {
92
+ return nil , err
93
+ }
94
+ return blockInfo , nil
81
95
}
82
96
83
- func logRequestsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) {
97
+ func logRequestsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) error {
84
98
receipts , _ , err := client .CorecontractsAPI .
85
99
BlocklogGetRequestReceiptsOfBlock (ctx , index ).
86
100
Block (fmt .Sprintf ("%d" , index )).
87
101
Execute () //nolint:bodyclose // false positive
88
-
89
- log .Check (err )
102
+ if err != nil {
103
+ return err
104
+ }
90
105
91
106
for i , receipt := range receipts {
92
107
r := receipt
93
108
util .LogReceipt (r , i )
94
109
}
110
+ return nil
95
111
}
96
112
97
- func logEventsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) {
113
+ func logEventsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) error {
98
114
events , _ , err := client .CorecontractsAPI .
99
115
BlocklogGetEventsOfBlock (ctx , index ).
100
116
Block (fmt .Sprintf ("%d" , index )).
101
117
Execute () //nolint:bodyclose // false positive
102
-
103
- log .Check (err )
118
+ if err != nil {
119
+ return err
120
+ }
104
121
logEvents (events )
122
+ return nil
105
123
}
106
124
107
125
func hexLenFromByteLen (length int ) int {
108
126
return (length * 2 ) + 2
109
127
}
110
128
111
- func reqIDFromString (s string ) isc.RequestID {
129
+ func reqIDFromString (s string ) ( isc.RequestID , error ) {
112
130
switch len (s ) {
113
131
case hexLenFromByteLen (iotago .AddressLen ):
114
132
// isc ReqID
115
133
reqID , err := isc .RequestIDFromString (s )
116
- log .Check (err )
117
- return reqID
134
+ if err != nil {
135
+ return isc.RequestID {}, fmt .Errorf ("invalid isc requestID: %w" , err )
136
+ }
137
+ return reqID , nil
118
138
case hexLenFromByteLen (common .HashLength ):
119
139
bytes , err := cryptolib .DecodeHex (s )
120
- log .Check (err )
140
+ if err != nil {
141
+ return isc.RequestID {}, fmt .Errorf ("invalid evm tx hash: %w" , err )
142
+ }
121
143
var txHash common.Hash
122
144
copy (txHash [:], bytes )
123
- return isc .RequestIDFromEVMTxHash (txHash )
145
+ return isc .RequestIDFromEVMTxHash (txHash ), nil
124
146
default :
125
- log . Fatalf ("invalid requestID length: %d" , len (s ))
147
+ return isc. RequestID {}, fmt . Errorf ("invalid requestID length: %d" , len (s ))
126
148
}
127
- panic ("unreachable" )
128
149
}
129
150
130
151
func initRequestCmd () * cobra.Command {
@@ -140,11 +161,17 @@ func initRequestCmd() *cobra.Command {
140
161
if err != nil {
141
162
return err
142
163
}
143
- chain = defaultChainFallback (chain )
164
+ chain , err = defaultChainFallback (chain )
165
+ if err != nil {
166
+ return err
167
+ }
144
168
ctx := context .Background ()
145
169
client := cliclients .WaspClientWithVersionCheck (ctx , node )
146
170
147
- reqID := reqIDFromString (args [0 ])
171
+ reqID , err := reqIDFromString (args [0 ])
172
+ if err != nil {
173
+ return err
174
+ }
148
175
149
176
// TODO add optional block param?
150
177
receipt , _ , err := client .ChainsAPI .
@@ -158,7 +185,9 @@ func initRequestCmd() *cobra.Command {
158
185
util .LogReceipt (* receipt )
159
186
160
187
log .Printf ("\n " )
161
- logEventsInRequest (ctx , client , reqID )
188
+ if err := logEventsInRequest (ctx , client , reqID ); err != nil {
189
+ return err
190
+ }
162
191
log .Printf ("\n " )
163
192
return nil
164
193
},
@@ -168,13 +197,15 @@ func initRequestCmd() *cobra.Command {
168
197
return cmd
169
198
}
170
199
171
- func logEventsInRequest (ctx context.Context , client * apiclient.APIClient , reqID isc.RequestID ) {
200
+ func logEventsInRequest (ctx context.Context , client * apiclient.APIClient , reqID isc.RequestID ) error {
172
201
events , _ , err := client .CorecontractsAPI .
173
202
BlocklogGetEventsOfRequest (ctx , reqID .String ()).
174
203
Execute () //nolint:bodyclose // false positive
175
-
176
- log .Check (err )
204
+ if err != nil {
205
+ return err
206
+ }
177
207
logEvents (events )
208
+ return nil
178
209
}
179
210
180
211
func logEvents (ret * apiclient.EventsResponse ) {
0 commit comments