-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.go
68 lines (61 loc) · 1.62 KB
/
info.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
package main
import (
"context"
"fmt"
"github.com/nbd-wtf/opentimestamps"
"github.com/urfave/cli/v3"
)
var info = &cli.Command{
Name: "info",
Description: `reads an .ots file and displays its contents in a readable way.`,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "only-final",
Aliases: []string{"f"},
Usage: "filter out all pending sequences, leaving only Bitcoin-attested sequences",
},
&cli.BoolFlag{
Name: "oldest",
Aliases: []string{"o"},
Usage: "leave only the oldest Bitcoin block attestation",
},
&cli.BoolFlag{
Name: "only-pending",
Aliases: []string{"p"},
Usage: "filter out all Bitcoin-attested sequences, leaving only pending sequences",
},
&cli.BoolFlag{
Name: "with-partials",
Usage: "print all partial computation steps",
},
},
ArgsUsage: "[file]",
Action: func(ctx context.Context, c *cli.Command) error {
b, err := readFromStdinOrFile(c)
if err != nil {
return err
}
ts, err := opentimestamps.ReadFromFile(b)
if err != nil {
return err
}
if c.Bool("onlyfinal") {
ts.Sequences = ts.GetBitcoinAttestedSequences()
} else if c.Bool("onlypending") {
ts.Sequences = ts.GetPendingSequences()
}
if c.Bool("oldest") {
sequences := []opentimestamps.Sequence{}
oldest := 0 // we'll invert everything for brevity
for _, seq := range ts.GetBitcoinAttestedSequences() {
if bbh := seq.GetAttestation().BitcoinBlockHeight; -1*int(bbh) < oldest {
oldest = int(bbh)
sequences = []opentimestamps.Sequence{seq}
}
}
ts.Sequences = sequences
}
fmt.Println(ts.Human(c.Bool("with-partials")))
return nil
},
}