mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-08 09:07:10 +00:00
remove gogoproto
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
)
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
@@ -21,7 +21,7 @@ func TestMarshalJSON(t *testing.T) {
|
||||
Code: 1,
|
||||
Data: []byte("hello"),
|
||||
GasWanted: 43,
|
||||
Tags: []cmn.KVPair{
|
||||
Tags: []*cmn.KVPair{
|
||||
{[]byte("pho"), []byte("bo")},
|
||||
},
|
||||
}
|
||||
@@ -82,8 +82,8 @@ func TestWriteReadMessage2(t *testing.T) {
|
||||
Data: []byte(phrase),
|
||||
Log: phrase,
|
||||
GasWanted: 10,
|
||||
Tags: []cmn.KVPair{
|
||||
cmn.KVPair{[]byte("abc"), []byte("def")},
|
||||
Tags: []*cmn.KVPair{
|
||||
{[]byte("abc"), []byte("def")},
|
||||
},
|
||||
// Fee: cmn.KI64Pair{
|
||||
},
|
||||
|
||||
+14
-3
@@ -35,8 +35,13 @@ type ParamsInitChain struct {
|
||||
}
|
||||
|
||||
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: req.Validators,
|
||||
Validators: vals,
|
||||
GenesisBytes: req.GenesisBytes,
|
||||
}
|
||||
}
|
||||
@@ -70,11 +75,17 @@ func ToParamsBeginBlock(req RequestBeginBlock) ParamsBeginBlock {
|
||||
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,
|
||||
Header: *req.Header,
|
||||
Validators: vals,
|
||||
ByzantineValidators: req.ByzantineValidators,
|
||||
ByzantineValidators: evidence,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
// +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)
|
||||
}
|
||||
+76
-24
@@ -1,6 +1,6 @@
|
||||
package types
|
||||
|
||||
import common "github.com/tendermint/tmlibs/common"
|
||||
import cmn "github.com/tendermint/tmlibs/common"
|
||||
|
||||
// nondeterministic
|
||||
type ResultException struct {
|
||||
@@ -41,7 +41,10 @@ type ResultInitChain struct {
|
||||
}
|
||||
|
||||
func FromResultInitChain(res ResultInitChain) ResponseInitChain {
|
||||
return ResponseInitChain(res)
|
||||
vals := valsToPointers(res.Validators)
|
||||
return ResponseInitChain{
|
||||
Validators: vals,
|
||||
}
|
||||
}
|
||||
|
||||
type ResultQuery struct {
|
||||
@@ -61,51 +64,80 @@ func FromResultQuery(res ResultQuery) ResponseQuery {
|
||||
}
|
||||
|
||||
type ResultBeginBlock struct {
|
||||
Tags []common.KVPair `json:"tags,omitempty"`
|
||||
Tags []cmn.KVPair `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock {
|
||||
return ResponseBeginBlock(res)
|
||||
tags := tagsToPointers(res.Tags)
|
||||
return ResponseBeginBlock{
|
||||
Tags: tags,
|
||||
}
|
||||
}
|
||||
|
||||
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 []common.KVPair `json:"tags,omitempty"`
|
||||
Fee common.KI64Pair `json:"fee"`
|
||||
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 {
|
||||
return ResponseCheckTx(res)
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
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 []common.KVPair `json:"tags,omitempty"`
|
||||
Fee common.KI64Pair `json:"fee"`
|
||||
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 {
|
||||
return ResponseDeliverTx(res)
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
type ResultEndBlock struct {
|
||||
ValidatorUpdates []Validator `json:"validator_updates"`
|
||||
ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"`
|
||||
Tags []common.KVPair `json:"tags,omitempty"`
|
||||
Tags []cmn.KVPair `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock {
|
||||
return ResponseEndBlock(res)
|
||||
tags := tagsToPointers(res.Tags)
|
||||
vals := valsToPointers(res.ValidatorUpdates)
|
||||
return ResponseEndBlock{
|
||||
ValidatorUpdates: vals,
|
||||
ConsensusParamUpdates: res.ConsensusParamUpdates,
|
||||
Tags: tags,
|
||||
}
|
||||
}
|
||||
|
||||
type ResultCommit struct {
|
||||
@@ -116,3 +148,23 @@ type ResultCommit struct {
|
||||
func FromResultCommit(res ResultCommit) ResponseCommit {
|
||||
return ResponseCommit(res)
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
+258
-261
File diff suppressed because it is too large
Load Diff
+13
-18
@@ -1,14 +1,9 @@
|
||||
syntax = "proto3";
|
||||
package types;
|
||||
|
||||
// For more information on gogo.proto, see:
|
||||
// https://github.com/gogo/protobuf/blob/master/extensions.md
|
||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
||||
import "github.com/tendermint/tmlibs/common/types.proto";
|
||||
|
||||
// This file is copied from http://github.com/tendermint/abci
|
||||
// NOTE: When using custom types, mind the warnings.
|
||||
// https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
|
||||
|
||||
//----------------------------------------
|
||||
// Request types
|
||||
@@ -47,7 +42,7 @@ message RequestSetOption {
|
||||
}
|
||||
|
||||
message RequestInitChain {
|
||||
repeated Validator validators = 1 [(gogoproto.nullable)=false];
|
||||
repeated Validator validators = 1;
|
||||
bytes genesis_bytes = 2;
|
||||
}
|
||||
|
||||
@@ -60,9 +55,9 @@ message RequestQuery {
|
||||
|
||||
message RequestBeginBlock {
|
||||
bytes hash = 1;
|
||||
Header header = 2 [(gogoproto.nullable)=false];
|
||||
Header header = 2;
|
||||
repeated SigningValidator validators = 3;
|
||||
repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false];
|
||||
repeated Evidence byzantine_validators = 4;
|
||||
}
|
||||
|
||||
message RequestCheckTx {
|
||||
@@ -128,7 +123,7 @@ message ResponseSetOption {
|
||||
}
|
||||
|
||||
message ResponseInitChain {
|
||||
repeated Validator validators = 1 [(gogoproto.nullable)=false];
|
||||
repeated Validator validators = 1;
|
||||
}
|
||||
|
||||
message ResponseQuery {
|
||||
@@ -144,7 +139,7 @@ message ResponseQuery {
|
||||
}
|
||||
|
||||
message ResponseBeginBlock {
|
||||
repeated common.KVPair tags = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
||||
repeated common.KVPair tags = 1;
|
||||
}
|
||||
|
||||
message ResponseCheckTx {
|
||||
@@ -154,8 +149,8 @@ message ResponseCheckTx {
|
||||
string info = 4; // nondeterministic
|
||||
int64 gas_wanted = 5;
|
||||
int64 gas_used = 6;
|
||||
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
||||
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
|
||||
repeated common.KVPair tags = 7;
|
||||
common.KI64Pair fee = 8;
|
||||
}
|
||||
|
||||
message ResponseDeliverTx {
|
||||
@@ -165,14 +160,14 @@ message ResponseDeliverTx {
|
||||
string info = 4; // nondeterministic
|
||||
int64 gas_wanted = 5;
|
||||
int64 gas_used = 6;
|
||||
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
||||
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
|
||||
repeated common.KVPair tags = 7;
|
||||
common.KI64Pair fee = 8;
|
||||
}
|
||||
|
||||
message ResponseEndBlock {
|
||||
repeated Validator validator_updates = 1 [(gogoproto.nullable)=false];
|
||||
repeated Validator validator_updates = 1;
|
||||
ConsensusParams consensus_param_updates = 2;
|
||||
repeated common.KVPair tags = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
||||
repeated common.KVPair tags = 3;
|
||||
}
|
||||
|
||||
message ResponseCommit {
|
||||
@@ -217,7 +212,7 @@ message BlockGossip {
|
||||
// just the minimum the app might need
|
||||
message Header {
|
||||
// basics
|
||||
string chain_id = 1 [(gogoproto.customname)="ChainID"];
|
||||
string chain_id = 1;
|
||||
int64 height = 2;
|
||||
int64 time = 3;
|
||||
|
||||
@@ -236,7 +231,7 @@ message Header {
|
||||
// Validator
|
||||
message Validator {
|
||||
bytes address = 1;
|
||||
PubKey pub_key = 2 [(gogoproto.nullable)=false];
|
||||
PubKey pub_key = 2;
|
||||
int64 power = 3;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ const (
|
||||
func Ed25519Validator(pubkey []byte, power int64) Validator {
|
||||
return Validator{
|
||||
// Address:
|
||||
PubKey: PubKey{
|
||||
PubKey: &PubKey{
|
||||
Type: PubKeyEd25519,
|
||||
Data: pubkey,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user