Revert "Merge pull request #247 from tendermint/bucky/no-gogo"

This reverts commit ef79007433, reversing
changes made to bcfdd6dbaf.
This commit is contained in:
Ethan Buchman
2018-05-31 21:45:14 -04:00
parent ef79007433
commit 90c3a469ff
23 changed files with 622 additions and 876 deletions
+43 -52
View File
@@ -6,23 +6,23 @@ import (
// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI.
// All methods take a ParamsXxx argument and return a ResultXxx argument,
// All methods take a RequestXxx argument and return a ResponseXxx argument,
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
type Application interface {
// Info/Query Connection
Info(ParamsInfo) ResultInfo // Return application info
SetOption(ParamsSetOption) ResultSetOption // Set application option
Query(ParamsQuery) ResultQuery // Query for state
Info(RequestInfo) ResponseInfo // Return application info
SetOption(RequestSetOption) ResponseSetOption // Set application option
Query(RequestQuery) ResponseQuery // Query for state
// Mempool Connection
CheckTx(tx []byte) ResultCheckTx // Validate a tx for the mempool
CheckTx(tx []byte) ResponseCheckTx // Validate a tx for the mempool
// Consensus Connection
InitChain(ParamsInitChain) ResultInitChain // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(ParamsBeginBlock) ResultBeginBlock // Signals the beginning of a block
DeliverTx(tx []byte) ResultDeliverTx // Deliver a tx for full processing
EndBlock(ParamsEndBlock) ResultEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResultCommit // Commit the state and return the application Merkle root hash
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
}
//-------------------------------------------------------
@@ -37,40 +37,40 @@ func NewBaseApplication() *BaseApplication {
return &BaseApplication{}
}
func (BaseApplication) Info(req ParamsInfo) ResultInfo {
return ResultInfo{}
func (BaseApplication) Info(req RequestInfo) ResponseInfo {
return ResponseInfo{}
}
func (BaseApplication) SetOption(req ParamsSetOption) ResultSetOption {
return ResultSetOption{}
func (BaseApplication) SetOption(req RequestSetOption) ResponseSetOption {
return ResponseSetOption{}
}
func (BaseApplication) DeliverTx(tx []byte) ResultDeliverTx {
return ResultDeliverTx{Code: CodeTypeOK}
func (BaseApplication) DeliverTx(tx []byte) ResponseDeliverTx {
return ResponseDeliverTx{Code: CodeTypeOK}
}
func (BaseApplication) CheckTx(tx []byte) ResultCheckTx {
return ResultCheckTx{Code: CodeTypeOK}
func (BaseApplication) CheckTx(tx []byte) ResponseCheckTx {
return ResponseCheckTx{Code: CodeTypeOK}
}
func (BaseApplication) Commit() ResultCommit {
return ResultCommit{}
func (BaseApplication) Commit() ResponseCommit {
return ResponseCommit{}
}
func (BaseApplication) Query(req ParamsQuery) ResultQuery {
return ResultQuery{Code: CodeTypeOK}
func (BaseApplication) Query(req RequestQuery) ResponseQuery {
return ResponseQuery{Code: CodeTypeOK}
}
func (BaseApplication) InitChain(req ParamsInitChain) ResultInitChain {
return ResultInitChain{}
func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
return ResponseInitChain{}
}
func (BaseApplication) BeginBlock(req ParamsBeginBlock) ResultBeginBlock {
return ResultBeginBlock{}
func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
return ResponseBeginBlock{}
}
func (BaseApplication) EndBlock(req ParamsEndBlock) ResultEndBlock {
return ResultEndBlock{}
func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
return ResponseEndBlock{}
}
//-------------------------------------------------------
@@ -93,55 +93,46 @@ func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*Resp
}
func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
res := app.app.Info(ToParamsInfo(*req))
r := FromResultInfo(res)
return &r, nil
res := app.app.Info(*req)
return &res, nil
}
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
res := app.app.SetOption(ToParamsSetOption(*req))
r := FromResultSetOption(res)
return &r, nil
res := app.app.SetOption(*req)
return &res, nil
}
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
res := app.app.DeliverTx(req.Tx)
r := FromResultDeliverTx(res)
return &r, nil
return &res, nil
}
func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
res := app.app.CheckTx(req.Tx)
r := FromResultCheckTx(res)
return &r, nil
return &res, nil
}
func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
res := app.app.Query(ToParamsQuery(*req))
r := FromResultQuery(res)
return &r, nil
res := app.app.Query(*req)
return &res, nil
}
func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
res := app.app.Commit()
r := FromResultCommit(res)
return &r, nil
return &res, nil
}
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
res := app.app.InitChain(ToParamsInitChain(*req))
r := FromResultInitChain(res)
return &r, nil
res := app.app.InitChain(*req)
return &res, nil
}
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
res := app.app.BeginBlock(ToParamsBeginBlock(*req))
r := FromResultBeginBlock(res)
return &r, nil
res := app.app.BeginBlock(*req)
return &res, nil
}
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
res := app.app.EndBlock(ToParamsEndBlock(*req))
r := FromResultEndBlock(res)
return &r, nil
res := app.app.EndBlock(*req)
return &res, nil
}
-67
View File
@@ -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
}
-87
View File
@@ -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)
+8 -8
View File
@@ -5,7 +5,7 @@ import (
"encoding/binary"
"io"
"github.com/golang/protobuf/proto"
"github.com/gogo/protobuf/proto"
)
const (
@@ -27,12 +27,12 @@ func ReadMessage(r io.Reader, msg proto.Message) error {
}
func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
// binary.ReadUvarint takes an io.ByteReader, eg. a bufio.Reader
// binary.ReadVarint takes an io.ByteReader, eg. a bufio.Reader
reader, ok := r.(*bufio.Reader)
if !ok {
reader = bufio.NewReader(r)
}
length64, err := binary.ReadUvarint(reader)
length64, err := binary.ReadVarint(reader)
if err != nil {
return err
}
@@ -48,11 +48,11 @@ func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
}
//-----------------------------------------------------------------------
// NOTE: we copied wire.EncodeByteSlice from go-amino rather than keep
// go-amino as a dep
// NOTE: we copied wire.EncodeByteSlice from go-wire rather than keep
// go-wire as a dep
func encodeByteSlice(w io.Writer, bz []byte) (err error) {
err = encodeUvarint(w, uint64(len(bz)))
err = encodeVarint(w, int64(len(bz)))
if err != nil {
return
}
@@ -60,9 +60,9 @@ func encodeByteSlice(w io.Writer, bz []byte) (err error) {
return
}
func encodeUvarint(w io.Writer, u uint64) (err error) {
func encodeVarint(w io.Writer, i int64) (err error) {
var buf [10]byte
n := binary.PutUvarint(buf[:], u)
n := binary.PutVarint(buf[:], i)
_, err = w.Write(buf[0:n])
return
}
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/golang/protobuf/proto"
"github.com/gogo/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{
{[]byte("abc"), []byte("def")},
Tags: []cmn.KVPair{
cmn.KVPair{[]byte("abc"), []byte("def")},
},
// Fee: cmn.KI64Pair{
},
-111
View File
@@ -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 {
}
+55
View File
@@ -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)
}
+16
View File
@@ -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,
}
}
+82 -131
View File
@@ -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"
)
const (
CodeTypeOK uint32 = 0
)
// IsOK returns true if Code is OK.
func (r ResponseCheckTx) IsOK() bool {
return r.Code == CodeTypeOK
}
type ResultEcho struct {
Message string `json:"message,omitempty"`
// IsErr returns true if Code is something other than OK.
func (r ResponseCheckTx) IsErr() bool {
return r.Code != CodeTypeOK
}
type ResultFlush struct {
// IsOK returns true if Code is OK.
func (r ResponseDeliverTx) 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 ResponseDeliverTx) IsErr() bool {
return r.Code != CodeTypeOK
}
func FromResultInfo(res ResultInfo) ResponseInfo {
return ResponseInfo(res)
// IsOK returns true if Code is OK.
func (r ResponseQuery) 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 ResponseQuery) IsErr() bool {
return r.Code != CodeTypeOK
}
func FromResultSetOption(res ResultSetOption) ResponseSetOption {
return ResponseSetOption(res)
}
//---------------------------------------------------------------------------
// 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
type ResultInitChain struct {
Validators []Validator `json:"validators"`
}
func FromResultInitChain(res ResultInitChain) ResponseInitChain {
vals := valsToPointers(res.Validators)
return ResponseInitChain{
Validators: vals,
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
}
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) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func FromResultQuery(res ResultQuery) ResponseQuery {
return ResponseQuery(res)
func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
type ResultBeginBlock struct {
Tags []cmn.KVPair `json:"tags,omitempty"`
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock {
tags := tagsToPointers(res.Tags)
return ResponseBeginBlock{
Tags: tags,
}
func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
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 (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
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 *ResponseQuery) 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 (r *ResponseQuery) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
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 *ResponseCommit) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
type ResultEndBlock struct {
ValidatorUpdates []Validator `json:"validator_updates"`
ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"`
Tags []cmn.KVPair `json:"tags,omitempty"`
func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock {
tags := tagsToPointers(res.Tags)
vals := valsToPointers(res.ValidatorUpdates)
return ResponseEndBlock{
ValidatorUpdates: vals,
ConsensusParamUpdates: res.ConsensusParamUpdates,
Tags: tags,
}
// 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
}
type ResultCommit struct {
// reserve 1
Data []byte `json:"data,omitempty"`
}
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
}
var _ jsonRoundTripper = (*ResponseCommit)(nil)
var _ jsonRoundTripper = (*ResponseQuery)(nil)
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
var _ jsonRoundTripper = (*ResponseSetOption)(nil)
+261 -258
View File
File diff suppressed because it is too large Load Diff
+18 -13
View File
@@ -1,9 +1,14 @@
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
@@ -42,7 +47,7 @@ message RequestSetOption {
}
message RequestInitChain {
repeated Validator validators = 1;
repeated Validator validators = 1 [(gogoproto.nullable)=false];
bytes genesis_bytes = 2;
}
@@ -55,9 +60,9 @@ message RequestQuery {
message RequestBeginBlock {
bytes hash = 1;
Header header = 2;
Header header = 2 [(gogoproto.nullable)=false];
repeated SigningValidator validators = 3;
repeated Evidence byzantine_validators = 4;
repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false];
}
message RequestCheckTx {
@@ -123,7 +128,7 @@ message ResponseSetOption {
}
message ResponseInitChain {
repeated Validator validators = 1;
repeated Validator validators = 1 [(gogoproto.nullable)=false];
}
message ResponseQuery {
@@ -139,7 +144,7 @@ message ResponseQuery {
}
message ResponseBeginBlock {
repeated common.KVPair tags = 1;
repeated common.KVPair tags = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
}
message ResponseCheckTx {
@@ -149,8 +154,8 @@ message ResponseCheckTx {
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated common.KVPair tags = 7;
common.KI64Pair fee = 8;
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
}
message ResponseDeliverTx {
@@ -160,14 +165,14 @@ message ResponseDeliverTx {
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated common.KVPair tags = 7;
common.KI64Pair fee = 8;
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
}
message ResponseEndBlock {
repeated Validator validator_updates = 1;
repeated Validator validator_updates = 1 [(gogoproto.nullable)=false];
ConsensusParams consensus_param_updates = 2;
repeated common.KVPair tags = 3;
repeated common.KVPair tags = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
}
message ResponseCommit {
@@ -212,7 +217,7 @@ message BlockGossip {
// just the minimum the app might need
message Header {
// basics
string chain_id = 1;
string chain_id = 1 [(gogoproto.customname)="ChainID"];
int64 height = 2;
int64 time = 3;
@@ -231,7 +236,7 @@ message Header {
// Validator
message Validator {
bytes address = 1;
PubKey pub_key = 2;
PubKey pub_key = 2 [(gogoproto.nullable)=false];
int64 power = 3;
}
-15
View File
@@ -8,21 +8,6 @@ import (
cmn "github.com/tendermint/tmlibs/common"
)
const (
PubKeyEd25519 = "ed25519"
)
func Ed25519Validator(pubkey []byte, power int64) Validator {
return Validator{
// Address:
PubKey: &PubKey{
Type: PubKeyEd25519,
Data: pubkey,
},
Power: power,
}
}
//------------------------------------------------------------------------------
// Validators is a list of validators that implements the Sort interface