@@ -33,20 +33,30 @@ func initBlockCmd() *cobra.Command {
3333 if err != nil {
3434 return err
3535 }
36- chain = defaultChainFallback (chain )
36+ chain , err = defaultChainFallback (chain )
37+ if err != nil {
38+ return err
39+ }
3740 ctx := context .Background ()
3841 client := cliclients .WaspClientWithVersionCheck (ctx , node )
3942
40- bi := fetchBlockInfo (ctx , client , args )
43+ bi , err := fetchBlockInfo (ctx , client , args )
44+ if err != nil {
45+ return err
46+ }
4147 log .Printf ("Block index: %d\n " , bi .BlockIndex )
4248 log .Printf ("Timestamp: %s\n " , bi .Timestamp .UTC ().Format (time .RFC3339 ))
4349 log .Printf ("Total requests: %d\n " , bi .TotalRequests )
4450 log .Printf ("Successful requests: %d\n " , bi .NumSuccessfulRequests )
4551 log .Printf ("Off-ledger requests: %d\n " , bi .NumOffLedgerRequests )
4652 log .Printf ("\n " )
47- logRequestsInBlock (ctx , client , bi .BlockIndex )
53+ if err := logRequestsInBlock (ctx , client , bi .BlockIndex ); err != nil {
54+ return err
55+ }
4856 log .Printf ("\n " )
49- logEventsInBlock (ctx , client , bi .BlockIndex )
57+ if err := logEventsInBlock (ctx , client , bi .BlockIndex ); err != nil {
58+ return err
59+ }
5060 return nil
5161 },
5262 }
@@ -55,76 +65,87 @@ func initBlockCmd() *cobra.Command {
5565 return cmd
5666}
5767
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 ) {
5969 if len (args ) == 0 {
6070 blockInfo , _ , err := client .
6171 CorecontractsAPI .
6272 BlocklogGetLatestBlockInfo (ctx ).
6373 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
6778 }
6879
6980 blockIndexStr := args [0 ]
7081 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+ }
7285
7386 blockInfo , _ , err := client .
7487 CorecontractsAPI .
7588 BlocklogGetBlockInfo (ctx , uint32 (index )).
7689 Block (blockIndexStr ).
7790 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
8195}
8296
83- func logRequestsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) {
97+ func logRequestsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) error {
8498 receipts , _ , err := client .CorecontractsAPI .
8599 BlocklogGetRequestReceiptsOfBlock (ctx , index ).
86100 Block (fmt .Sprintf ("%d" , index )).
87101 Execute () //nolint:bodyclose // false positive
88-
89- log .Check (err )
102+ if err != nil {
103+ return err
104+ }
90105
91106 for i , receipt := range receipts {
92107 r := receipt
93108 util .LogReceipt (r , i )
94109 }
110+ return nil
95111}
96112
97- func logEventsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) {
113+ func logEventsInBlock (ctx context.Context , client * apiclient.APIClient , index uint32 ) error {
98114 events , _ , err := client .CorecontractsAPI .
99115 BlocklogGetEventsOfBlock (ctx , index ).
100116 Block (fmt .Sprintf ("%d" , index )).
101117 Execute () //nolint:bodyclose // false positive
102-
103- log .Check (err )
118+ if err != nil {
119+ return err
120+ }
104121 logEvents (events )
122+ return nil
105123}
106124
107125func hexLenFromByteLen (length int ) int {
108126 return (length * 2 ) + 2
109127}
110128
111- func reqIDFromString (s string ) isc.RequestID {
129+ func reqIDFromString (s string ) ( isc.RequestID , error ) {
112130 switch len (s ) {
113131 case hexLenFromByteLen (iotago .AddressLen ):
114132 // isc ReqID
115133 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
118138 case hexLenFromByteLen (common .HashLength ):
119139 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+ }
121143 var txHash common.Hash
122144 copy (txHash [:], bytes )
123- return isc .RequestIDFromEVMTxHash (txHash )
145+ return isc .RequestIDFromEVMTxHash (txHash ), nil
124146 default :
125- log . Fatalf ("invalid requestID length: %d" , len (s ))
147+ return isc. RequestID {}, fmt . Errorf ("invalid requestID length: %d" , len (s ))
126148 }
127- panic ("unreachable" )
128149}
129150
130151func initRequestCmd () * cobra.Command {
@@ -140,11 +161,17 @@ func initRequestCmd() *cobra.Command {
140161 if err != nil {
141162 return err
142163 }
143- chain = defaultChainFallback (chain )
164+ chain , err = defaultChainFallback (chain )
165+ if err != nil {
166+ return err
167+ }
144168 ctx := context .Background ()
145169 client := cliclients .WaspClientWithVersionCheck (ctx , node )
146170
147- reqID := reqIDFromString (args [0 ])
171+ reqID , err := reqIDFromString (args [0 ])
172+ if err != nil {
173+ return err
174+ }
148175
149176 // TODO add optional block param?
150177 receipt , _ , err := client .ChainsAPI .
@@ -158,7 +185,9 @@ func initRequestCmd() *cobra.Command {
158185 util .LogReceipt (* receipt )
159186
160187 log .Printf ("\n " )
161- logEventsInRequest (ctx , client , reqID )
188+ if err := logEventsInRequest (ctx , client , reqID ); err != nil {
189+ return err
190+ }
162191 log .Printf ("\n " )
163192 return nil
164193 },
@@ -168,13 +197,15 @@ func initRequestCmd() *cobra.Command {
168197 return cmd
169198}
170199
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 {
172201 events , _ , err := client .CorecontractsAPI .
173202 BlocklogGetEventsOfRequest (ctx , reqID .String ()).
174203 Execute () //nolint:bodyclose // false positive
175-
176- log .Check (err )
204+ if err != nil {
205+ return err
206+ }
177207 logEvents (events )
208+ return nil
178209}
179210
180211func logEvents (ret * apiclient.EventsResponse ) {
0 commit comments