/
main.go
64 lines (56 loc) · 1.24 KB
/
main.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
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"os"
"github.com/aergoio/aergo/cmd/aergocli/util"
"github.com/aergoio/aergo/internal/enc"
"github.com/aergoio/aergo/types"
"github.com/gogo/protobuf/proto"
)
func main() {
argsWithoutProg := os.Args[1:]
if 0 == len(argsWithoutProg) {
panic("Usage: mpdiag /path/to/mempool.dump>")
}
filename := argsWithoutProg[0]
file, err := os.Open(filename)
if err != nil {
fmt.Println("error: failed to open file")
return
}
reader := csv.NewReader(bufio.NewReader(file))
var count int
for {
buf := types.Tx{}
rc, err := reader.Read()
if err != nil {
if err != io.EOF {
fmt.Println("error: read file err")
}
break
}
count++
dataBuf, err := enc.ToBytes(rc[0])
if err != nil {
fmt.Println("error: decode tx err, continue")
continue
}
err = proto.Unmarshal(dataBuf, &buf)
if err != nil {
fmt.Println("error: unmarshall tx err, continue")
continue
}
//mp.put(types.NewTransaction(&buf)) // nolint: errcheck
b, e := json.MarshalIndent(util.ConvTx(types.NewTransaction(&buf).GetTx()), "", " ")
if e == nil {
fmt.Printf("%s\n", b)
} else {
fmt.Println("error: convert to json ")
}
}
//fmt.Println("total ", count, "txs")
}