Revert "Merge pull request #247 from tendermint/bucky/no-gogo"pull/1780/head
@ -1,67 +0,0 @@ | |||
package types | |||
const ( | |||
CodeTypeOK uint32 = 0 | |||
) | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseCheckTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseCheckTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseDeliverTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseDeliverTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseQuery) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseQuery) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
//---------------------------------------------------- | |||
// IsOK returns true if Code is OK. | |||
func (r ResultCheckTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResultCheckTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
// IsOK returns true if Code is OK. | |||
func (r ResultDeliverTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResultDeliverTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
// IsOK returns true if Code is OK. | |||
func (r ResultQuery) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResultQuery) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} |
@ -1,87 +0,0 @@ | |||
package types | |||
import ( | |||
"bytes" | |||
"encoding/json" | |||
"github.com/golang/protobuf/jsonpb" | |||
) | |||
//--------------------------------------------------------------------------- | |||
// override JSON marshalling so we dont emit defaults (ie. disable omitempty) | |||
// note we need Unmarshal functions too because protobuf had the bright idea | |||
// to marshal int64->string. cool. cool, cool, cool: https://developers.google.com/protocol-buffers/docs/proto3#json | |||
var ( | |||
jsonpbMarshaller = jsonpb.Marshaler{ | |||
EnumsAsInts: true, | |||
EmitDefaults: false, | |||
} | |||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | |||
) | |||
func (r *ResponseSetOption) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func (r *ResponseSetOption) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
func (r *ResponseQuery) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func (r *ResponseQuery) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
func (r *ResponseCommit) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func (r *ResponseCommit) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
// Some compile time assertions to ensure we don't | |||
// have accidental runtime surprises later on. | |||
// jsonEncodingRoundTripper ensures that asserted | |||
// interfaces implement both MarshalJSON and UnmarshalJSON | |||
type jsonRoundTripper interface { | |||
json.Marshaler | |||
json.Unmarshaler | |||
} | |||
var _ jsonRoundTripper = (*ResponseCommit)(nil) | |||
var _ jsonRoundTripper = (*ResponseQuery)(nil) | |||
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil) | |||
var _ jsonRoundTripper = (*ResponseCheckTx)(nil) | |||
var _ jsonRoundTripper = (*ResponseSetOption)(nil) |
@ -1,111 +0,0 @@ | |||
package types | |||
type ParamsEcho struct { | |||
Message string `json:"message,omitempty"` | |||
} | |||
type ParamsFlush struct { | |||
} | |||
type ParamsInfo struct { | |||
Version string `json:"version,omitempty"` | |||
} | |||
func ToParamsInfo(req RequestInfo) ParamsInfo { | |||
return ParamsInfo{ | |||
Version: req.Version, | |||
} | |||
} | |||
type ParamsSetOption struct { | |||
Key string `json:"key,omitempty"` | |||
Value string `json:"value,omitempty"` | |||
} | |||
func ToParamsSetOption(req RequestSetOption) ParamsSetOption { | |||
return ParamsSetOption{ | |||
Key: req.Key, | |||
Value: req.Value, | |||
} | |||
} | |||
type ParamsInitChain struct { | |||
Validators []Validator `json:"validators"` | |||
GenesisBytes []byte `json:"genesis_bytes,omitempty"` | |||
} | |||
func ToParamsInitChain(req RequestInitChain) ParamsInitChain { | |||
vals := make([]Validator, len(req.Validators)) | |||
for i := 0; i < len(vals); i++ { | |||
v := req.Validators[i] | |||
vals[i] = *v | |||
} | |||
return ParamsInitChain{ | |||
Validators: vals, | |||
GenesisBytes: req.GenesisBytes, | |||
} | |||
} | |||
type ParamsQuery struct { | |||
Data []byte `json:"data,omitempty"` | |||
Path string `json:"path,omitempty"` | |||
Height int64 `json:"height,omitempty"` | |||
Prove bool `json:"prove,omitempty"` | |||
} | |||
func ToParamsQuery(req RequestQuery) ParamsQuery { | |||
return ParamsQuery{ | |||
Data: req.Data, | |||
Path: req.Path, | |||
Height: req.Height, | |||
Prove: req.Prove, | |||
} | |||
} | |||
type ParamsBeginBlock struct { | |||
Hash []byte `json:"hash,omitempty"` | |||
Header Header `json:"header"` | |||
Validators []SigningValidator `json:"validators,omitempty"` | |||
ByzantineValidators []Evidence `json:"byzantine_validators"` | |||
} | |||
func ToParamsBeginBlock(req RequestBeginBlock) ParamsBeginBlock { | |||
vals := make([]SigningValidator, len(req.Validators)) | |||
for i := 0; i < len(vals); i++ { | |||
v := req.Validators[i] | |||
vals[i] = *v | |||
} | |||
evidence := make([]Evidence, len(req.ByzantineValidators)) | |||
for i := 0; i < len(evidence); i++ { | |||
ev := req.ByzantineValidators[i] | |||
evidence[i] = *ev | |||
} | |||
return ParamsBeginBlock{ | |||
Hash: req.Hash, | |||
Header: *req.Header, | |||
Validators: vals, | |||
ByzantineValidators: evidence, | |||
} | |||
} | |||
type ParamsCheckTx struct { | |||
Tx []byte `json:"tx,omitempty"` | |||
} | |||
type ParamsDeliverTx struct { | |||
Tx []byte `json:"tx,omitempty"` | |||
} | |||
type ParamsEndBlock struct { | |||
Height int64 `json:"height,omitempty"` | |||
} | |||
func ToParamsEndBlock(req RequestEndBlock) ParamsEndBlock { | |||
return ParamsEndBlock{ | |||
Height: req.Height, | |||
} | |||
} | |||
type ParamsCommit struct { | |||
} |
@ -0,0 +1,55 @@ | |||
// +build ignore | |||
package main | |||
import ( | |||
"bytes" | |||
"fmt" | |||
"io/ioutil" | |||
"os" | |||
"os/exec" | |||
"regexp" | |||
"strings" | |||
) | |||
// This script replaces most `[]byte` with `data.Bytes` in a `.pb.go` file. | |||
// It was written before we realized we could use `gogo/protobuf` to achieve | |||
// this more natively. So it's here for safe keeping in case we ever need to | |||
// abandon `gogo/protobuf`. | |||
func main() { | |||
bytePattern := regexp.MustCompile("[[][]]byte") | |||
const oldPath = "types/types.pb.go" | |||
const tmpPath = "types/types.pb.new" | |||
content, err := ioutil.ReadFile(oldPath) | |||
if err != nil { | |||
panic("cannot read " + oldPath) | |||
os.Exit(1) | |||
} | |||
lines := bytes.Split(content, []byte("\n")) | |||
outFile, _ := os.Create(tmpPath) | |||
wroteImport := false | |||
for _, line_bytes := range lines { | |||
line := string(line_bytes) | |||
gotPackageLine := strings.HasPrefix(line, "package ") | |||
writeImportTime := strings.HasPrefix(line, "import ") | |||
containsDescriptor := strings.Contains(line, "Descriptor") | |||
containsByteArray := strings.Contains(line, "[]byte") | |||
if containsByteArray && !containsDescriptor { | |||
line = string(bytePattern.ReplaceAll([]byte(line), []byte("data.Bytes"))) | |||
} | |||
if writeImportTime && !wroteImport { | |||
wroteImport = true | |||
fmt.Fprintf(outFile, "import \"github.com/tendermint/go-wire/data\"\n") | |||
} | |||
if gotPackageLine { | |||
fmt.Fprintf(outFile, "%s\n", "//nolint: gas") | |||
} | |||
fmt.Fprintf(outFile, "%s\n", line) | |||
} | |||
outFile.Close() | |||
os.Remove(oldPath) | |||
os.Rename(tmpPath, oldPath) | |||
exec.Command("goimports", "-w", oldPath) | |||
} |
@ -0,0 +1,16 @@ | |||
package types | |||
const ( | |||
PubKeyEd25519 = "ed25519" | |||
) | |||
func Ed25519Validator(pubkey []byte, power int64) Validator { | |||
return Validator{ | |||
// Address: | |||
PubKey: PubKey{ | |||
Type: PubKeyEd25519, | |||
Data: pubkey, | |||
}, | |||
Power: power, | |||
} | |||
} |
@ -1,170 +1,121 @@ | |||
package types | |||
import cmn "github.com/tendermint/tmlibs/common" | |||
import ( | |||
"bytes" | |||
"encoding/json" | |||
// nondeterministic | |||
type ResultException struct { | |||
Error string `json:"error,omitempty"` | |||
} | |||
"github.com/gogo/protobuf/jsonpb" | |||
) | |||
type ResultEcho struct { | |||
Message string `json:"message,omitempty"` | |||
} | |||
const ( | |||
CodeTypeOK uint32 = 0 | |||
) | |||
type ResultFlush struct { | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseCheckTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
type ResultInfo struct { | |||
Data string `json:"data,omitempty"` | |||
Version string `json:"version,omitempty"` | |||
LastBlockHeight int64 `json:"last_block_height,omitempty"` | |||
LastBlockAppHash []byte `json:"last_block_app_hash,omitempty"` | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseCheckTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
func FromResultInfo(res ResultInfo) ResponseInfo { | |||
return ResponseInfo(res) | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseDeliverTx) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
type ResultSetOption struct { | |||
Code uint32 `json:"code,omitempty"` | |||
// bytes data = 2; | |||
Log string `json:"log,omitempty"` | |||
Info string `json:"info,omitempty"` | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseDeliverTx) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
func FromResultSetOption(res ResultSetOption) ResponseSetOption { | |||
return ResponseSetOption(res) | |||
// IsOK returns true if Code is OK. | |||
func (r ResponseQuery) IsOK() bool { | |||
return r.Code == CodeTypeOK | |||
} | |||
type ResultInitChain struct { | |||
Validators []Validator `json:"validators"` | |||
// IsErr returns true if Code is something other than OK. | |||
func (r ResponseQuery) IsErr() bool { | |||
return r.Code != CodeTypeOK | |||
} | |||
func FromResultInitChain(res ResultInitChain) ResponseInitChain { | |||
vals := valsToPointers(res.Validators) | |||
return ResponseInitChain{ | |||
Validators: vals, | |||
//--------------------------------------------------------------------------- | |||
// override JSON marshalling so we dont emit defaults (ie. disable omitempty) | |||
// note we need Unmarshal functions too because protobuf had the bright idea | |||
// to marshal int64->string. cool. cool, cool, cool: https://developers.google.com/protocol-buffers/docs/proto3#json | |||
var ( | |||
jsonpbMarshaller = jsonpb.Marshaler{ | |||
EnumsAsInts: true, | |||
EmitDefaults: false, | |||
} | |||
} | |||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | |||
) | |||
type ResultQuery struct { | |||
Code uint32 `json:"code,omitempty"` | |||
// bytes data = 2; // use "value" instead. | |||
Log string `json:"log,omitempty"` | |||
Info string `json:"info,omitempty"` | |||
Index int64 `json:"index,omitempty"` | |||
Key []byte `json:"key,omitempty"` | |||
Value []byte `json:"value,omitempty"` | |||
Proof []byte `json:"proof,omitempty"` | |||
Height int64 `json:"height,omitempty"` | |||
func (r *ResponseSetOption) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func FromResultQuery(res ResultQuery) ResponseQuery { | |||
return ResponseQuery(res) | |||
func (r *ResponseSetOption) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
type ResultBeginBlock struct { | |||
Tags []cmn.KVPair `json:"tags,omitempty"` | |||
func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock { | |||
tags := tagsToPointers(res.Tags) | |||
return ResponseBeginBlock{ | |||
Tags: tags, | |||
} | |||
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
type ResultCheckTx struct { | |||
Code uint32 `json:"code,omitempty"` | |||
Data []byte `json:"data,omitempty"` | |||
Log string `json:"log,omitempty"` | |||
Info string `json:"info,omitempty"` | |||
GasWanted int64 `json:"gas_wanted,omitempty"` | |||
GasUsed int64 `json:"gas_used,omitempty"` | |||
Tags []cmn.KVPair `json:"tags,omitempty"` | |||
Fee cmn.KI64Pair `json:"fee"` | |||
} | |||
func FromResultCheckTx(res ResultCheckTx) ResponseCheckTx { | |||
tags := tagsToPointers(res.Tags) | |||
return ResponseCheckTx{ | |||
Code: res.Code, | |||
Data: res.Data, | |||
Log: res.Log, | |||
Info: res.Info, | |||
GasWanted: res.GasWanted, | |||
GasUsed: res.GasUsed, | |||
Tags: tags, | |||
Fee: &res.Fee, | |||
} | |||
func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
type ResultDeliverTx struct { | |||
Code uint32 `json:"code,omitempty"` | |||
Data []byte `json:"data,omitempty"` | |||
Log string `json:"log,omitempty"` | |||
Info string `json:"info,omitempty"` | |||
GasWanted int64 `json:"gas_wanted,omitempty"` | |||
GasUsed int64 `json:"gas_used,omitempty"` | |||
Tags []cmn.KVPair `json:"tags,omitempty"` | |||
Fee cmn.KI64Pair `json:"fee"` | |||
} | |||
func FromResultDeliverTx(res ResultDeliverTx) ResponseDeliverTx { | |||
tags := tagsToPointers(res.Tags) | |||
return ResponseDeliverTx{ | |||
Code: res.Code, | |||
Data: res.Data, | |||
Log: res.Log, | |||
Info: res.Info, | |||
GasWanted: res.GasWanted, | |||
GasUsed: res.GasUsed, | |||
Tags: tags, | |||
Fee: &res.Fee, | |||
} | |||
func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
type ResultEndBlock struct { | |||
ValidatorUpdates []Validator `json:"validator_updates"` | |||
ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"` | |||
Tags []cmn.KVPair `json:"tags,omitempty"` | |||
func (r *ResponseQuery) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock { | |||
tags := tagsToPointers(res.Tags) | |||
vals := valsToPointers(res.ValidatorUpdates) | |||
return ResponseEndBlock{ | |||
ValidatorUpdates: vals, | |||
ConsensusParamUpdates: res.ConsensusParamUpdates, | |||
Tags: tags, | |||
} | |||
func (r *ResponseQuery) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
type ResultCommit struct { | |||
// reserve 1 | |||
Data []byte `json:"data,omitempty"` | |||
func (r *ResponseCommit) MarshalJSON() ([]byte, error) { | |||
s, err := jsonpbMarshaller.MarshalToString(r) | |||
return []byte(s), err | |||
} | |||
func FromResultCommit(res ResultCommit) ResponseCommit { | |||
return ResponseCommit(res) | |||
func (r *ResponseCommit) UnmarshalJSON(b []byte) error { | |||
reader := bytes.NewBuffer(b) | |||
return jsonpbUnmarshaller.Unmarshal(reader, r) | |||
} | |||
//------------------------------------------------------- | |||
// Some compile time assertions to ensure we don't | |||
// have accidental runtime surprises later on. | |||
func tagsToPointers(tags []cmn.KVPair) []*cmn.KVPair { | |||
tagPtrs := make([]*cmn.KVPair, len(tags)) | |||
for i := 0; i < len(tags); i++ { | |||
t := tags[i] | |||
tagPtrs[i] = &t | |||
} | |||
return tagPtrs | |||
// jsonEncodingRoundTripper ensures that asserted | |||
// interfaces implement both MarshalJSON and UnmarshalJSON | |||
type jsonRoundTripper interface { | |||
json.Marshaler | |||
json.Unmarshaler | |||
} | |||
func valsToPointers(vals []Validator) []*Validator { | |||
valPtrs := make([]*Validator, len(vals)) | |||
for i := 0; i < len(vals); i++ { | |||
v := vals[i] | |||
valPtrs[i] = &v | |||
} | |||
return valPtrs | |||
} | |||
var _ jsonRoundTripper = (*ResponseCommit)(nil) | |||
var _ jsonRoundTripper = (*ResponseQuery)(nil) | |||
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil) | |||
var _ jsonRoundTripper = (*ResponseCheckTx)(nil) | |||
var _ jsonRoundTripper = (*ResponseSetOption)(nil) |