1
0
mirror of https://github.com/fluencelabs/tendermint synced 2025-06-26 03:01:42 +00:00
Files
.circleci
.github
DOCKER
abci
benchmarks
blockchain
cmd
config
consensus
crypto
docs
evidence
libs
lite
mempool
networks
node
p2p
privval
proxy
rpc
scripts
install
json2wal
main.go
txs
wal2json
README.md
dist.sh
get_tools.sh
linkify_changelog.py
localnet-blocks-test.sh
publish.sh
release.sh
wire2amino.go
state
test
tools
types
version
.editorconfig
.gitignore
CHANGELOG.md
CHANGELOG_PENDING.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
ROADMAP.md
SECURITY.md
UPGRADING.md
Vagrantfile
appveyor.yml
codecov.yml
docker-compose.yml

75 lines
1.4 KiB
Go
Raw Permalink Normal View History

/*
json2wal converts JSON file to binary WAL file.
Usage:
json2wal <path-to-JSON> <path-to-wal>
*/
package main
import (
2018-08-15 03:16:18 +04:00
"bufio"
"fmt"
"io"
2018-08-15 03:16:18 +04:00
"os"
"strings"
"github.com/tendermint/go-amino"
cs "github.com/tendermint/tendermint/consensus"
"github.com/tendermint/tendermint/types"
)
var cdc = amino.NewCodec()
func init() {
cs.RegisterConsensusMessages(cdc)
cs.RegisterWALMessages(cdc)
types.RegisterBlockAmino(cdc)
}
func main() {
if len(os.Args) < 3 {
fmt.Fprintln(os.Stderr, "missing arguments: Usage:json2wal <path-to-JSON> <path-to-wal>")
os.Exit(1)
}
f, err := os.Open(os.Args[1])
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer f.Close()
2018-08-15 03:16:18 +04:00
walFile, err := os.OpenFile(os.Args[2], os.O_EXCL|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
panic(fmt.Errorf("failed to open WAL file: %v", err))
}
defer walFile.Close()
br := bufio.NewReader(f)
dec := cs.NewWALEncoder(walFile)
for {
msgJson, _, err := br.ReadLine()
2018-08-15 03:16:18 +04:00
if err == io.EOF {
break
2018-08-15 03:16:18 +04:00
} else if err != nil {
panic(fmt.Errorf("failed to read file: %v", err))
}
// ignore the ENDHEIGHT in json.File
2018-08-15 03:16:18 +04:00
if strings.HasPrefix(string(msgJson), "ENDHEIGHT") {
continue
}
var msg cs.TimedWALMessage
2018-08-15 03:16:18 +04:00
err = cdc.UnmarshalJSON(msgJson, &msg)
if err != nil {
panic(fmt.Errorf("failed to unmarshal json: %v", err))
}
err = dec.Encode(&msg)
2018-08-15 03:16:18 +04:00
if err != nil {
panic(fmt.Errorf("failed to encode msg: %v", err))
}
}
}