-
Notifications
You must be signed in to change notification settings - Fork 0
/
bechdecode.go
51 lines (43 loc) · 935 Bytes
/
bechdecode.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
package main
import (
"encoding/csv"
"io"
"log"
"os"
"github.com/btcsuite/btcutil/bech32"
)
func decode(encoded string) string {
_, _, err := bech32.Decode(encoded)
if err != nil {
//fmt.Println("ERROR:", err)
return "ERR"
} else {
return "OK"
}
}
func main() {
csvfile, err := os.Open("validators")
if err != nil {
log.Fatalln("Couldn't open the csv file", err)
}
csvfile_result, err := os.OpenFile("validators_corrected", os.O_CREATE|os.O_RDWR, os.ModeAppend|os.ModePerm)
if err != nil {
log.Fatalln("Couldn't open the csv file", err)
}
r := csv.NewReader(csvfile)
for {
record, err := r.Read()
if err == io.EOF {
break
}
check := decode(record[0])
if check == "OK" {
w := csv.NewWriter(csvfile_result)
if err := w.Write(record); err != nil {
log.Fatalln("ERROR: failed to write file", err)
}
w.Flush()
}
//fmt.Printf("%v::%v\n", record[0], decode(record[0]))
}
}