This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
examine.go
91 lines (76 loc) · 2.54 KB
/
examine.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
79
80
81
82
83
84
85
86
87
88
89
90
91
package commands
import (
"encoding/json"
"github.com/hyperledger/burrow/bcm"
"github.com/hyperledger/burrow/txs"
cli "github.com/jawher/mow.cli"
"github.com/tendermint/tendermint/libs/db"
)
func Examine(output Output) func(cmd *cli.Cmd) {
return func(dump *cli.Cmd) {
configOpt := dump.StringOpt("c config", "", "Use the a specified burrow config file")
var explorer *bcm.BlockStore
dump.Before = func() {
conf, err := obtainBurrowConfig(*configOpt, "")
if err != nil {
output.Fatalf("Could not obtain config: %v", err)
}
tmConf := conf.Tendermint.TendermintConfig()
explorer = bcm.NewBlockExplorer(db.DBBackendType(tmConf.DBBackend), tmConf.DBDir())
}
dump.Command("blocks", "dump blocks to stdout", func(cmd *cli.Cmd) {
rangeArg := cmd.StringArg("RANGE", "", "Range as START_HEIGHT:END_HEIGHT where omitting "+
"either endpoint implicitly describes the start/end and a negative index counts back from the last block")
cmd.Spec = "[RANGE]"
cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
_, err = explorer.Blocks(start, end,
func(block *bcm.Block) (stop bool) {
bs, err := json.Marshal(block)
if err != nil {
output.Fatalf("Could not serialise block: %v", err)
}
output.Printf(string(bs))
return false
})
if err != nil {
output.Fatalf("Error iterating over blocks: %v", err)
}
}
})
dump.Command("txs", "dump transactions to stdout", func(cmd *cli.Cmd) {
rangeArg := cmd.StringArg("RANGE", "", "Range as START_HEIGHT:END_HEIGHT where omitting "+
"either endpoint implicitly describes the start/end and a negative index counts back from the last block")
cmd.Spec = "[RANGE]"
cmd.Action = func() {
start, end, err := parseRange(*rangeArg)
_, err = explorer.Blocks(start, end,
func(block *bcm.Block) (stop bool) {
stopped, err := block.Transactions(func(txEnv *txs.Envelope) (stop bool) {
wrapper := struct {
Height int64
Tx *txs.Envelope
}{
Height: block.Height,
Tx: txEnv,
}
bs, err := json.Marshal(wrapper)
if err != nil {
output.Fatalf("Could not deserialise transaction: %v", err)
}
output.Printf(string(bs))
return false
})
if err != nil {
output.Fatalf("Error iterating over transactions: %v", err)
}
// If we stopped transactions stop everything
return stopped
})
if err != nil {
output.Fatalf("Error iterating over blocks: %v", err)
}
}
})
}
}