-
Notifications
You must be signed in to change notification settings - Fork 17
/
cmd-x-index-sig2cid.go
78 lines (73 loc) · 1.8 KB
/
cmd-x-index-sig2cid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"fmt"
"time"
"github.com/urfave/cli/v2"
"k8s.io/klog/v2"
)
func newCmd_Index_sig2cid() *cli.Command {
var verify bool
return &cli.Command{
Name: "sig-to-cid",
Description: "Given a CAR file containing a Solana epoch, create an index of the file that maps transaction signatures to CIDs.",
ArgsUsage: "<car-path> <index-dir>",
Before: func(c *cli.Context) error {
return nil
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verify",
Usage: "verify the index after creating it",
Destination: &verify,
},
&cli.StringFlag{
Name: "tmp-dir",
Usage: "temporary directory to use for storing intermediate files",
Value: "",
},
},
Subcommands: []*cli.Command{},
Action: func(c *cli.Context) error {
carPath := c.Args().Get(0)
indexDir := c.Args().Get(1)
tmpDir := c.String("tmp-dir")
if ok, err := isDirectory(indexDir); err != nil {
return err
} else if !ok {
return fmt.Errorf("index-dir is not a directory")
}
{
startedAt := time.Now()
defer func() {
klog.Infof("Finished in %s", time.Since(startedAt))
}()
klog.Infof("Creating Sig-to-CID index for %s", carPath)
indexFilepath, err := CreateIndex_sig2cid(
context.TODO(),
tmpDir,
carPath,
indexDir,
)
if err != nil {
panic(err)
}
klog.Info("Index created")
if verify {
klog.Infof("Verifying index for %s located at %s", carPath, indexFilepath)
startedAt := time.Now()
defer func() {
klog.Infof("Finished in %s", time.Since(startedAt))
}()
err := VerifyIndex_sig2cid(context.TODO(), carPath, indexFilepath)
if err != nil {
return cli.Exit(err, 1)
}
klog.Info("Index verified")
return nil
}
}
return nil
},
}
}