From dfcde30d5acb7defef98edb7ab2c67f9406428ec Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 16 Jul 2019 10:00:04 +0200 Subject: [PATCH] Makefile Additions (#1) * makefile adds * add files and commands * remove make tools and lint * changelog add --- .circleci/config.yml | 22 ++++++++++++++++ CHANGELOG.md | 9 +++++++ CHANGELOG_PENDING.md | 9 +++++++ CONTRIBUTING.md | 8 ++++++ common/bytes.go | 62 ++++++++++++++++++++++++++++++++++++++++++++ makefile | 23 +++++++++++++--- 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 CHANGELOG.md create mode 100644 CHANGELOG_PENDING.md create mode 100644 CONTRIBUTING.md create mode 100644 common/bytes.go diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..588ac4b1d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,22 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.12.0 + + steps: + - checkout + - restore_cache: + keys: + - go-mod-v1-{{ checksum "go.sum" }} + - run: + name: test + command: | + export PATH="$GOBIN:$PATH" + go env + go version + make test + - save_cache: + key: go-mod-v1-{{ checksum "go.sum" }} + paths: + - "/go/pkg/mod" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ad07d0510 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +## 0.1 + +**2019-07-16** + +Special thanks to external contributors on this release: + +### Initial Release + +- `db`, `random.go`, `bytes.go` and `os.go` from the tendermint repo. diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md new file mode 100644 index 000000000..1f48f1d0f --- /dev/null +++ b/CHANGELOG_PENDING.md @@ -0,0 +1,9 @@ +## 0.2 + +\*\* **YYYY-MM-DD** + +Special thanks to external contributors on this release: + +### BREAKING CHANGES + +### IMPROVEMENTS diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..aed11c22f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,8 @@ +# Contributing + +Thank you for considering making contributions to IAVL+! +This repository follows the [contribution guidelines] of tendermint and the corresponding [coding repo]. +Please take a look if you are not already familiar with those. + +[contribution guidelines]: https://github.com/tendermint/tendermint/blob/master/CONTRIBUTING.md +[coding repo]: https://github.com/tendermint/coding diff --git a/common/bytes.go b/common/bytes.go new file mode 100644 index 000000000..711720aa7 --- /dev/null +++ b/common/bytes.go @@ -0,0 +1,62 @@ +package common + +import ( + "encoding/hex" + "fmt" + "strings" +) + +// The main purpose of HexBytes is to enable HEX-encoding for json/encoding. +type HexBytes []byte + +// Marshal needed for protobuf compatibility +func (bz HexBytes) Marshal() ([]byte, error) { + return bz, nil +} + +// Unmarshal needed for protobuf compatibility +func (bz *HexBytes) Unmarshal(data []byte) error { + *bz = data + return nil +} + +// This is the point of Bytes. +func (bz HexBytes) MarshalJSON() ([]byte, error) { + s := strings.ToUpper(hex.EncodeToString(bz)) + jbz := make([]byte, len(s)+2) + jbz[0] = '"' + copy(jbz[1:], []byte(s)) + jbz[len(jbz)-1] = '"' + return jbz, nil +} + +// This is the point of Bytes. +func (bz *HexBytes) UnmarshalJSON(data []byte) error { + if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { + return fmt.Errorf("Invalid hex string: %s", data) + } + bz2, err := hex.DecodeString(string(data[1 : len(data)-1])) + if err != nil { + return err + } + *bz = bz2 + return nil +} + +// Allow it to fulfill various interfaces in light-client, etc... +func (bz HexBytes) Bytes() []byte { + return bz +} + +func (bz HexBytes) String() string { + return strings.ToUpper(hex.EncodeToString(bz)) +} + +func (bz HexBytes) Format(s fmt.State, verb rune) { + switch verb { + case 'p': + s.Write([]byte(fmt.Sprintf("%p", bz))) + default: + s.Write([]byte(fmt.Sprintf("%X", []byte(bz)))) + } +} diff --git a/makefile b/makefile index 60e7f3340..97a85ddfa 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,4 @@ -GOTOOLS = \ - github.com/golangci/golangci-lint/cmd/golangci-lint \ -GOBIN?=${GOPATH}/bin +GOTOOLS = github.com/golangci/golangci-lint/cmd/golangci-lint PACKAGES=$(shell go list ./...) export GO111MODULE = on @@ -14,4 +12,21 @@ test: lint: @echo "--> Running linter" - @golangci-lint run \ No newline at end of file + @golangci-lint run + +tools: + go get -v $(GOTOOLS) + +# generates certificates for TLS testing in remotedb +gen_certs: clean_certs + certstrap init --common-name "tendermint.com" --passphrase "" + certstrap request-cert --common-name "remotedb" -ip "127.0.0.1" --passphrase "" + certstrap sign "remotedb" --CA "tendermint.com" --passphrase "" + mv out/remotedb.crt db/remotedb/test.crt + mv out/remotedb.key db/remotedb/test.key + rm -rf out + +clean_certs: + rm -f db/remotedb/test.crt + rm -f db/remotedb/test.key + \ No newline at end of file