File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change
1
+ package common
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "path"
7
+ )
8
+
9
+ func WriteToJSON (data []byte , filePath string ) error {
10
+ // Write JSON data to a file
11
+ file , err := os .Create (path .Clean (filePath ))
12
+ if err != nil {
13
+ fmt .Println ("Error creating file:" , err )
14
+ return err
15
+ }
16
+ defer file .Close ()
17
+
18
+ _ , err = file .Write (data )
19
+ if err != nil {
20
+ fmt .Println ("Error writing to file:" , err )
21
+ return err
22
+ }
23
+
24
+ return nil
25
+ }
Original file line number Diff line number Diff line change 1
1
package rewards
2
2
3
3
import (
4
+ "encoding/json"
4
5
"errors"
5
6
"fmt"
6
7
"log/slog"
@@ -214,9 +215,24 @@ func Claim(cCtx *cli.Context, p utils.Prompter) error {
214
215
common .PrintTransactionInfo (receipt .TxHash .String (), config .ChainID )
215
216
} else {
216
217
solidityClaim := claimgen .FormatProofForSolidity (accounts .Root (), claim )
217
- fmt .Println ("------- Claim generated -------" )
218
- common .PrettyPrintStruct (* solidityClaim )
219
- fmt .Println ("-------------------------------" )
218
+ if ! common .IsEmptyString (config .Output ) {
219
+ jsonData , err := json .MarshalIndent (solidityClaim , "" , " " )
220
+ if err != nil {
221
+ fmt .Println ("Error marshaling JSON:" , err )
222
+ return err
223
+ }
224
+
225
+ err = common .WriteToJSON (jsonData , config .Output )
226
+ if err != nil {
227
+ return err
228
+ }
229
+ logger .Infof ("Claim written to file: %s" , config .Output )
230
+ } else {
231
+ fmt .Println ("------- Claim generated -------" )
232
+ common .PrettyPrintStruct (* solidityClaim )
233
+ fmt .Println ("-------------------------------" )
234
+ fmt .Println ("To write to a file, use the --output flag" )
235
+ }
220
236
fmt .Println ("To broadcast the claim, use the --broadcast flag" )
221
237
}
222
238
You can’t perform that action at this time.
0 commit comments