mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 21:01:21 +00:00
Revert "delete everything" (includes everything non-go-crypto)
This reverts commit 96a3502
This commit is contained in:
1
scripts/README.md
Normal file
1
scripts/README.md
Normal file
@ -0,0 +1 @@
|
||||
* http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
14
scripts/dep_utils/parse.sh
Normal file
14
scripts/dep_utils/parse.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#! /bin/bash
|
||||
|
||||
set +u
|
||||
if [[ "$DEP" == "" ]]; then
|
||||
DEP=$GOPATH/src/github.com/tendermint/tendermint/Gopkg.lock
|
||||
fi
|
||||
set -u
|
||||
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LIB=$1
|
||||
|
||||
grep -A100 "$LIB" "$DEP" | grep revision | head -n1 | grep -o '"[^"]\+"' | cut -d '"' -f 2
|
81
scripts/dist.sh
Executable file
81
scripts/dist.sh
Executable file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# WARN: non hermetic build (people must run this script inside docker to
|
||||
# produce deterministic binaries).
|
||||
|
||||
# Get the version from the environment, or try to figure it out.
|
||||
if [ -z $VERSION ]; then
|
||||
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
|
||||
fi
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Please specify a version."
|
||||
exit 1
|
||||
fi
|
||||
echo "==> Building version $VERSION..."
|
||||
|
||||
# Delete the old dir
|
||||
echo "==> Removing old directory..."
|
||||
rm -rf build/pkg
|
||||
mkdir -p build/pkg
|
||||
|
||||
# Get the git commit
|
||||
GIT_COMMIT="$(git rev-parse --short=8 HEAD)"
|
||||
GIT_IMPORT="github.com/tendermint/tendermint/version"
|
||||
|
||||
# Determine the arch/os combos we're building for
|
||||
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
|
||||
XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"}
|
||||
XC_EXCLUDE=${XC_EXCLUDE:-" darwin/arm solaris/amd64 solaris/386 solaris/arm freebsd/amd64 windows/arm "}
|
||||
|
||||
# Make sure build tools are available.
|
||||
make get_tools
|
||||
|
||||
# Get VENDORED dependencies
|
||||
make get_vendor_deps
|
||||
|
||||
# Build!
|
||||
# ldflags: -s Omit the symbol table and debug information.
|
||||
# -w Omit the DWARF symbol table.
|
||||
echo "==> Building..."
|
||||
IFS=' ' read -ra arch_list <<< "$XC_ARCH"
|
||||
IFS=' ' read -ra os_list <<< "$XC_OS"
|
||||
for arch in "${arch_list[@]}"; do
|
||||
for os in "${os_list[@]}"; do
|
||||
if [[ "$XC_EXCLUDE" != *" $os/$arch "* ]]; then
|
||||
echo "--> $os/$arch"
|
||||
GOOS=${os} GOARCH=${arch} go build -ldflags "-s -w -X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}" -tags="${BUILD_TAGS}" -o "build/pkg/${os}_${arch}/tendermint" ./cmd/tendermint
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Zip all the files.
|
||||
echo "==> Packaging..."
|
||||
for PLATFORM in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type d); do
|
||||
OSARCH=$(basename "${PLATFORM}")
|
||||
echo "--> ${OSARCH}"
|
||||
|
||||
pushd "$PLATFORM" >/dev/null 2>&1
|
||||
zip "../${OSARCH}.zip" ./*
|
||||
popd >/dev/null 2>&1
|
||||
done
|
||||
|
||||
# Add "tendermint" and $VERSION prefix to package name.
|
||||
rm -rf ./build/dist
|
||||
mkdir -p ./build/dist
|
||||
for FILENAME in $(find ./build/pkg -mindepth 1 -maxdepth 1 -type f); do
|
||||
FILENAME=$(basename "$FILENAME")
|
||||
cp "./build/pkg/${FILENAME}" "./build/dist/tendermint_${VERSION}_${FILENAME}"
|
||||
done
|
||||
|
||||
# Make the checksums.
|
||||
pushd ./build/dist
|
||||
shasum -a256 ./* > "./tendermint_${VERSION}_SHA256SUMS"
|
||||
popd
|
||||
|
||||
# Done
|
||||
echo
|
||||
echo "==> Results:"
|
||||
ls -hl ./build/dist
|
||||
|
||||
exit 0
|
54
scripts/install/install_tendermint_bsd.sh
Normal file
54
scripts/install/install_tendermint_bsd.sh
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/tcsh
|
||||
|
||||
# XXX: this script is intended to be run from
|
||||
# a fresh Digital Ocean droplet with FreeBSD
|
||||
# Just run tcsh install_tendermint_bsd.sh
|
||||
|
||||
# upon its completion, you must either reset
|
||||
# your terminal or run `source ~/.tcshrc`
|
||||
|
||||
# This assumes your installing it through tcsh as root.
|
||||
# Change the relevant lines from tcsh to csh if your
|
||||
# installing as a different user, along with changing the
|
||||
# gopath.
|
||||
|
||||
# change this to a specific release or branch
|
||||
set BRANCH=master
|
||||
|
||||
sudo pkg update
|
||||
|
||||
sudo pkg upgrade -y
|
||||
sudo pkg install -y gmake
|
||||
sudo pkg install -y git
|
||||
|
||||
# get and unpack golang
|
||||
curl -O https://storage.googleapis.com/golang/go1.10.freebsd-amd64.tar.gz
|
||||
tar -xvf go1.10.freebsd-amd64.tar.gz
|
||||
|
||||
# move go binary and add to path
|
||||
mv go /usr/local
|
||||
set path=($path /usr/local/go/bin)
|
||||
|
||||
|
||||
# create the go directory, set GOPATH, and put it on PATH
|
||||
mkdir go
|
||||
echo "setenv GOPATH /root/go" >> ~/.tcshrc
|
||||
setenv GOPATH /root/go
|
||||
echo "set path=($path $GOPATH/bin)" >> ~/.tcshrc
|
||||
|
||||
source ~/.tcshrc
|
||||
|
||||
# get the code and move into repo
|
||||
set REPO=github.com/tendermint/tendermint
|
||||
go get $REPO
|
||||
cd $GOPATH/src/$REPO
|
||||
|
||||
# build & install master
|
||||
git checkout $BRANCH
|
||||
gmake get_tools
|
||||
gmake get_vendor_deps
|
||||
gmake install
|
||||
|
||||
# the binary is located in $GOPATH/bin
|
||||
# run `source ~/.profile` or reset your terminal
|
||||
# to persist the changes
|
49
scripts/install/install_tendermint_ubuntu.sh
Normal file
49
scripts/install/install_tendermint_ubuntu.sh
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# XXX: this script is intended to be run from
|
||||
# a fresh Digital Ocean droplet with Ubuntu
|
||||
|
||||
# upon its completion, you must either reset
|
||||
# your terminal or run `source ~/.profile`
|
||||
|
||||
# as written, this script will install
|
||||
# tendermint core from master branch
|
||||
REPO=github.com/tendermint/tendermint
|
||||
|
||||
# change this to a specific release or branch
|
||||
BRANCH=master
|
||||
|
||||
sudo apt-get update -y
|
||||
sudo apt-get upgrade -y
|
||||
sudo apt-get install -y make
|
||||
|
||||
# get and unpack golang
|
||||
curl -O https://storage.googleapis.com/golang/go1.10.linux-amd64.tar.gz
|
||||
tar -xvf go1.10.linux-amd64.tar.gz
|
||||
|
||||
# move go binary and add to path
|
||||
mv go /usr/local
|
||||
echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.profile
|
||||
|
||||
# create the goApps directory, set GOPATH, and put it on PATH
|
||||
mkdir goApps
|
||||
echo "export GOPATH=/root/goApps" >> ~/.profile
|
||||
echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
|
||||
|
||||
source ~/.profile
|
||||
|
||||
# get the code and move into repo
|
||||
go get $REPO
|
||||
cd $GOPATH/src/$REPO
|
||||
|
||||
# build & install
|
||||
git checkout $BRANCH
|
||||
# XXX: uncomment if branch isn't master
|
||||
# git fetch origin $BRANCH
|
||||
make get_tools
|
||||
make get_vendor_deps
|
||||
make install
|
||||
|
||||
# the binary is located in $GOPATH/bin
|
||||
# run `source ~/.profile` or reset your terminal
|
||||
# to persist the changes
|
12
scripts/install_abci_apps.sh
Normal file
12
scripts/install_abci_apps.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#! /bin/bash
|
||||
|
||||
# get the abci commit used by tendermint
|
||||
COMMIT=$(bash scripts/dep_utils/parse.sh abci)
|
||||
echo "Checking out vendored commit for abci: $COMMIT"
|
||||
|
||||
go get -d github.com/tendermint/abci
|
||||
cd "$GOPATH/src/github.com/tendermint/abci" || exit
|
||||
git checkout "$COMMIT"
|
||||
make get_tools
|
||||
make get_vendor_deps
|
||||
make install
|
20
scripts/publish.sh
Executable file
20
scripts/publish.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
VERSION=$1
|
||||
DIST_DIR=./build/dist
|
||||
|
||||
# Get the version from the environment, or try to figure it out.
|
||||
if [ -z $VERSION ]; then
|
||||
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
|
||||
fi
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Please specify a version."
|
||||
exit 1
|
||||
fi
|
||||
echo "==> Copying ${DIST_DIR} to S3..."
|
||||
|
||||
# copy to s3
|
||||
aws s3 cp --recursive ${DIST_DIR} s3://tendermint/binaries/tendermint/v${VERSION} --acl public-read
|
||||
|
||||
exit 0
|
53
scripts/release.sh
Executable file
53
scripts/release.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Get the version from the environment, or try to figure it out.
|
||||
if [ -z $VERSION ]; then
|
||||
VERSION=$(awk -F\" '/Version =/ { print $2; exit }' < version/version.go)
|
||||
fi
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Please specify a version."
|
||||
exit 1
|
||||
fi
|
||||
echo "==> Releasing version $VERSION..."
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||
|
||||
# Change into that dir because we expect that.
|
||||
cd "$DIR"
|
||||
|
||||
# Building binaries
|
||||
sh -c "'$DIR/scripts/dist.sh'"
|
||||
|
||||
# Pushing binaries to S3
|
||||
sh -c "'$DIR/scripts/publish.sh'"
|
||||
|
||||
# echo "==> Crafting a Github release"
|
||||
# today=$(date +"%B-%d-%Y")
|
||||
# ghr -b "https://github.com/tendermint/tendermint/blob/master/CHANGELOG.md#${VERSION//.}-${today,}" "v$VERSION" "$DIR/build/dist"
|
||||
|
||||
# Build and push Docker image
|
||||
|
||||
## Get SHA256SUM of the linux archive
|
||||
SHA256SUM=$(shasum -a256 "${DIR}/build/dist/tendermint_${VERSION}_linux_amd64.zip" | awk '{print $1;}')
|
||||
|
||||
## Replace TM_VERSION and TM_SHA256SUM with the new values
|
||||
sed -i -e "s/TM_VERSION .*/TM_VERSION $VERSION/g" "$DIR/DOCKER/Dockerfile"
|
||||
sed -i -e "s/TM_SHA256SUM .*/TM_SHA256SUM $SHA256SUM/g" "$DIR/DOCKER/Dockerfile"
|
||||
git commit -m "update Dockerfile" -a "$DIR/DOCKER/Dockerfile"
|
||||
echo "==> TODO: update DOCKER/README.md (latest Dockerfile's hash is $(git rev-parse HEAD)) and copy it's content to https://store.docker.com/community/images/tendermint/tendermint"
|
||||
|
||||
pushd "$DIR/DOCKER"
|
||||
|
||||
## Build Docker image
|
||||
TAG=$VERSION sh -c "'./build.sh'"
|
||||
|
||||
## Push Docker image
|
||||
TAG=$VERSION sh -c "'./push.sh'"
|
||||
|
||||
popd
|
||||
|
||||
exit 0
|
77
scripts/slate.sh
Normal file
77
scripts/slate.sh
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$CIRCLE_BRANCH" == "" ]; then
|
||||
echo "this script is meant to be run on CircleCI, exiting"
|
||||
echo 1
|
||||
fi
|
||||
|
||||
# check for changes in the `rpc/core` directory
|
||||
did_rpc_change=$(git diff --name-status $CIRCLE_BRANCH origin/master | grep rpc/core)
|
||||
|
||||
if [ "$did_rpc_change" == "" ]; then
|
||||
echo "no changes detected in rpc/core, exiting"
|
||||
exit 0
|
||||
else
|
||||
echo "changes detected in rpc/core, continuing"
|
||||
fi
|
||||
|
||||
# only run this script on changes to rpc/core committed to develop
|
||||
if [ "$CIRCLE_BRANCH" != "master" ]; then
|
||||
echo "the branch being built isn't master, exiting"
|
||||
exit 0
|
||||
else
|
||||
echo "on master, building the RPC docs"
|
||||
fi
|
||||
|
||||
# godoc2md used to convert the go documentation from
|
||||
# `rpc/core` into a markdown file consumed by Slate
|
||||
go get github.com/davecheney/godoc2md
|
||||
|
||||
# slate works via forks, and we'll be committing to
|
||||
# master branch, which will trigger our fork to run
|
||||
# the `./deploy.sh` and publish via the `gh-pages` branch
|
||||
slate_repo=github.com/tendermint/slate
|
||||
slate_path="$GOPATH"/src/"$slate_repo"
|
||||
|
||||
if [ ! -d "$slate_path" ]; then
|
||||
git clone https://"$slate_repo".git $slate_path
|
||||
fi
|
||||
|
||||
# the main file we need to update if rpc/core changed
|
||||
destination="$slate_path"/source/index.html.md
|
||||
|
||||
# we remove it then re-create it with the latest changes
|
||||
rm $destination
|
||||
|
||||
header="---
|
||||
title: RPC Reference
|
||||
|
||||
language_tabs:
|
||||
- shell
|
||||
- go
|
||||
|
||||
toc_footers:
|
||||
- <a href='https://tendermint.com/'>Tendermint</a>
|
||||
- <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a>
|
||||
|
||||
search: true
|
||||
---"
|
||||
|
||||
# write header to the main slate file
|
||||
echo "$header" > "$destination"
|
||||
|
||||
# generate a markdown from the godoc comments, using a template
|
||||
rpc_docs=$(godoc2md -template rpc/core/doc_template.txt github.com/tendermint/tendermint/rpc/core | grep -v -e "pipe.go" -e "routes.go" -e "dev.go" | sed 's$/src/target$https://github.com/tendermint/tendermint/tree/master/rpc/core$')
|
||||
|
||||
# append core RPC docs
|
||||
echo "$rpc_docs" >> "$destination"
|
||||
|
||||
# commit the changes
|
||||
cd $slate_path
|
||||
|
||||
git config --global user.email "github@tendermint.com"
|
||||
git config --global user.name "tenderbot"
|
||||
|
||||
git commit -a -m "Update tendermint RPC docs via CircleCI"
|
||||
git push -q https://${GITHUB_ACCESS_TOKEN}@github.com/tendermint/slate.git master
|
19
scripts/txs/random.sh
Normal file
19
scripts/txs/random.sh
Normal file
@ -0,0 +1,19 @@
|
||||
#! /bin/bash
|
||||
set -u
|
||||
|
||||
function toHex() {
|
||||
echo -n $1 | hexdump -ve '1/1 "%.2X"'
|
||||
}
|
||||
|
||||
N=$1
|
||||
PORT=$2
|
||||
|
||||
for i in `seq 1 $N`; do
|
||||
# store key value pair
|
||||
KEY=$(head -c 10 /dev/urandom)
|
||||
VALUE="$i"
|
||||
echo $(toHex $KEY=$VALUE)
|
||||
curl 127.0.0.1:$PORT/broadcast_tx_sync?tx=0x$(toHex $KEY=$VALUE)
|
||||
done
|
||||
|
||||
|
59
scripts/wal2json/main.go
Normal file
59
scripts/wal2json/main.go
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
wal2json converts binary WAL file to JSON.
|
||||
|
||||
Usage:
|
||||
wal2json <path-to-wal>
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
cs "github.com/tendermint/tendermint/consensus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("missing one argument: <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()
|
||||
|
||||
dec := cs.NewWALDecoder(f)
|
||||
for {
|
||||
msg, err := dec.Decode()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
panic(fmt.Errorf("failed to decode msg: %v", err))
|
||||
}
|
||||
|
||||
json, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to marshal msg: %v", err))
|
||||
}
|
||||
|
||||
_, err = os.Stdout.Write(json)
|
||||
if err == nil {
|
||||
_, err = os.Stdout.Write([]byte("\n"))
|
||||
}
|
||||
if err == nil {
|
||||
if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
|
||||
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height))) // nolint: errcheck, gas
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("Failed to write message", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
181
scripts/wire2amino.go
Normal file
181
scripts/wire2amino.go
Normal file
@ -0,0 +1,181 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/go-amino"
|
||||
crypto "github.com/tendermint/tendermint/crypto"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
type GenesisValidator struct {
|
||||
PubKey Data `json:"pub_key"`
|
||||
Power int64 `json:"power"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Genesis struct {
|
||||
GenesisTime time.Time `json:"genesis_time"`
|
||||
ChainID string `json:"chain_id"`
|
||||
ConsensusParams *types.ConsensusParams `json:"consensus_params,omitempty"`
|
||||
Validators []GenesisValidator `json:"validators"`
|
||||
AppHash cmn.HexBytes `json:"app_hash"`
|
||||
AppStateJSON json.RawMessage `json:"app_state,omitempty"`
|
||||
AppOptions json.RawMessage `json:"app_options,omitempty"` // DEPRECATED
|
||||
|
||||
}
|
||||
|
||||
type NodeKey struct {
|
||||
PrivKey Data `json:"priv_key"`
|
||||
}
|
||||
|
||||
type PrivVal struct {
|
||||
Address cmn.HexBytes `json:"address"`
|
||||
LastHeight int64 `json:"last_height"`
|
||||
LastRound int `json:"last_round"`
|
||||
LastStep int8 `json:"last_step"`
|
||||
PubKey Data `json:"pub_key"`
|
||||
PrivKey Data `json:"priv_key"`
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Type string `json:"type"`
|
||||
Data cmn.HexBytes `json:"data"`
|
||||
}
|
||||
|
||||
func convertNodeKey(cdc *amino.Codec, jsonBytes []byte) ([]byte, error) {
|
||||
var nodeKey NodeKey
|
||||
err := json.Unmarshal(jsonBytes, &nodeKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var privKey crypto.PrivKeyEd25519
|
||||
copy(privKey[:], nodeKey.PrivKey.Data)
|
||||
|
||||
nodeKeyNew := p2p.NodeKey{privKey}
|
||||
|
||||
bz, err := cdc.MarshalJSON(nodeKeyNew)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bz, nil
|
||||
}
|
||||
|
||||
func convertPrivVal(cdc *amino.Codec, jsonBytes []byte) ([]byte, error) {
|
||||
var privVal PrivVal
|
||||
err := json.Unmarshal(jsonBytes, &privVal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var privKey crypto.PrivKeyEd25519
|
||||
copy(privKey[:], privVal.PrivKey.Data)
|
||||
|
||||
var pubKey crypto.PubKeyEd25519
|
||||
copy(pubKey[:], privVal.PubKey.Data)
|
||||
|
||||
privValNew := privval.FilePV{
|
||||
Address: pubKey.Address(),
|
||||
PubKey: pubKey,
|
||||
LastHeight: privVal.LastHeight,
|
||||
LastRound: privVal.LastRound,
|
||||
LastStep: privVal.LastStep,
|
||||
PrivKey: privKey,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(privValNew)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bz, nil
|
||||
}
|
||||
|
||||
func convertGenesis(cdc *amino.Codec, jsonBytes []byte) ([]byte, error) {
|
||||
var genesis Genesis
|
||||
err := json.Unmarshal(jsonBytes, &genesis)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
genesisNew := types.GenesisDoc{
|
||||
GenesisTime: genesis.GenesisTime,
|
||||
ChainID: genesis.ChainID,
|
||||
ConsensusParams: genesis.ConsensusParams,
|
||||
// Validators
|
||||
AppHash: genesis.AppHash,
|
||||
AppStateJSON: genesis.AppStateJSON,
|
||||
}
|
||||
|
||||
if genesis.AppOptions != nil {
|
||||
genesisNew.AppStateJSON = genesis.AppOptions
|
||||
}
|
||||
|
||||
for _, v := range genesis.Validators {
|
||||
var pubKey crypto.PubKeyEd25519
|
||||
copy(pubKey[:], v.PubKey.Data)
|
||||
genesisNew.Validators = append(
|
||||
genesisNew.Validators,
|
||||
types.GenesisValidator{
|
||||
PubKey: pubKey,
|
||||
Power: v.Power,
|
||||
Name: v.Name,
|
||||
},
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(genesisNew)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bz, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
cdc := amino.NewCodec()
|
||||
crypto.RegisterAmino(cdc)
|
||||
|
||||
args := os.Args[1:]
|
||||
if len(args) != 1 {
|
||||
fmt.Println("Please specify a file to convert")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
filePath := args[0]
|
||||
fileName := filepath.Base(filePath)
|
||||
|
||||
fileBytes, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var bz []byte
|
||||
|
||||
switch fileName {
|
||||
case "node_key.json":
|
||||
bz, err = convertNodeKey(cdc, fileBytes)
|
||||
case "priv_validator.json":
|
||||
bz, err = convertPrivVal(cdc, fileBytes)
|
||||
case "genesis.json":
|
||||
bz, err = convertGenesis(cdc, fileBytes)
|
||||
default:
|
||||
fmt.Println("Expected file name to be in (node_key.json, priv_validator.json, genesis.json)")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(string(bz))
|
||||
|
||||
}
|
Reference in New Issue
Block a user