commit
ef79007433
|
@ -29,26 +29,15 @@
|
||||||
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
|
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
|
||||||
version = "v1.7.0"
|
version = "v1.7.0"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/gogo/protobuf"
|
|
||||||
packages = [
|
|
||||||
"gogoproto",
|
|
||||||
"jsonpb",
|
|
||||||
"proto",
|
|
||||||
"protoc-gen-gogo/descriptor",
|
|
||||||
"sortkeys",
|
|
||||||
"types"
|
|
||||||
]
|
|
||||||
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/golang/protobuf"
|
name = "github.com/golang/protobuf"
|
||||||
packages = [
|
packages = [
|
||||||
|
"jsonpb",
|
||||||
"proto",
|
"proto",
|
||||||
"ptypes",
|
"ptypes",
|
||||||
"ptypes/any",
|
"ptypes/any",
|
||||||
"ptypes/duration",
|
"ptypes/duration",
|
||||||
|
"ptypes/struct",
|
||||||
"ptypes/timestamp"
|
"ptypes/timestamp"
|
||||||
]
|
]
|
||||||
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
|
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
|
||||||
|
@ -58,7 +47,7 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/golang/snappy"
|
name = "github.com/golang/snappy"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "553a641470496b2327abcac10b36396bd98e45c9"
|
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/inconshreveable/mousetrap"
|
name = "github.com/inconshreveable/mousetrap"
|
||||||
|
@ -93,14 +82,14 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/spf13/cobra"
|
name = "github.com/spf13/cobra"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "a1f051bc3eba734da4772d60e2d677f47cf93ef4"
|
revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385"
|
||||||
version = "v0.0.2"
|
version = "v0.0.3"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/spf13/pflag"
|
name = "github.com/spf13/pflag"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
|
revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
|
||||||
version = "v1.0.0"
|
version = "v1.0.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/stretchr/testify"
|
name = "github.com/stretchr/testify"
|
||||||
|
@ -128,31 +117,31 @@
|
||||||
"leveldb/table",
|
"leveldb/table",
|
||||||
"leveldb/util"
|
"leveldb/util"
|
||||||
]
|
]
|
||||||
revision = "714f901b98fdb3aa954b4193d8cbd64a28d80cad"
|
revision = "5d6fca44a948d2be89a9702de7717f0168403d3d"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
branch = "develop"
|
||||||
name = "github.com/tendermint/tmlibs"
|
name = "github.com/tendermint/tmlibs"
|
||||||
packages = [
|
packages = [
|
||||||
"common",
|
"common",
|
||||||
"db",
|
"db",
|
||||||
"log"
|
"log"
|
||||||
]
|
]
|
||||||
revision = "2e24b64fc121dcdf1cabceab8dc2f7257675483c"
|
revision = "e0acf357bb8832faebdb79f07490d0f530afc7b1"
|
||||||
version = "v0.8.1"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = [
|
||||||
"context",
|
"context",
|
||||||
|
"http/httpguts",
|
||||||
"http2",
|
"http2",
|
||||||
"http2/hpack",
|
"http2/hpack",
|
||||||
"idna",
|
"idna",
|
||||||
"internal/timeseries",
|
"internal/timeseries",
|
||||||
"lex/httplex",
|
|
||||||
"trace"
|
"trace"
|
||||||
]
|
]
|
||||||
revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41"
|
revision = "89e543239a64caf31d3a6865872ea120b41446df"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "golang.org/x/text"
|
name = "golang.org/x/text"
|
||||||
|
@ -176,10 +165,9 @@
|
||||||
version = "v0.3.0"
|
version = "v0.3.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
|
||||||
name = "google.golang.org/genproto"
|
name = "google.golang.org/genproto"
|
||||||
packages = ["googleapis/rpc/status"]
|
packages = ["googleapis/rpc/status"]
|
||||||
revision = "ce84044298496ef4b54b4a0a0909ba593cc60e30"
|
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
|
@ -208,6 +196,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "e42d4a691fb0d0db9c717394e580dd00b36ba9e185541f99fc56689338470123"
|
inputs-digest = "5a730a9d84b37f95b1b10260a91bcd26a143a50b3301ec6dfb7483e89c44eabd"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
11
Gopkg.toml
11
Gopkg.toml
|
@ -32,7 +32,7 @@
|
||||||
# Use `~` for only minor version bumps.
|
# Use `~` for only minor version bumps.
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/gogo/protobuf"
|
name = "github.com/golang/protobuf"
|
||||||
version = "~1.0.0"
|
version = "~1.0.0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
|
@ -45,12 +45,19 @@
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/tmlibs"
|
name = "github.com/tendermint/tmlibs"
|
||||||
version = "0.8.1"
|
branch = "develop"
|
||||||
|
# version = "0.8.1"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
version = "~1.7.3"
|
version = "~1.7.3"
|
||||||
|
|
||||||
|
# this got updated and broke, so locked to an old working commit ...
|
||||||
|
[[override]]
|
||||||
|
name = "google.golang.org/genproto"
|
||||||
|
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
|
||||||
|
|
||||||
|
|
||||||
[prune]
|
[prune]
|
||||||
go-tests = true
|
go-tests = true
|
||||||
unused-packages = true
|
unused-packages = true
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -2,11 +2,10 @@ GOTOOLS = \
|
||||||
github.com/mitchellh/gox \
|
github.com/mitchellh/gox \
|
||||||
github.com/golang/dep/cmd/dep \
|
github.com/golang/dep/cmd/dep \
|
||||||
gopkg.in/alecthomas/gometalinter.v2 \
|
gopkg.in/alecthomas/gometalinter.v2 \
|
||||||
github.com/gogo/protobuf/protoc-gen-gogo \
|
github.com/golang/protobuf/protoc-gen-go
|
||||||
github.com/gogo/protobuf/gogoproto
|
GOTOOLS_CHECK = gox dep gometalinter.v2 protoc protoc-gen-go
|
||||||
GOTOOLS_CHECK = gox dep gometalinter.v2 protoc protoc-gen-gogo
|
|
||||||
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
|
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
|
||||||
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
|
INCLUDE = -I=. -I=${GOPATH}/src
|
||||||
|
|
||||||
all: check get_vendor_deps protoc build test install metalinter
|
all: check get_vendor_deps protoc build test install metalinter
|
||||||
|
|
||||||
|
@ -20,7 +19,7 @@ protoc:
|
||||||
## If you get the following error,
|
## If you get the following error,
|
||||||
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
|
## "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
|
||||||
## See https://stackoverflow.com/a/25518702
|
## See https://stackoverflow.com/a/25518702
|
||||||
protoc $(INCLUDE) --gogo_out=plugins=grpc:. types/*.proto
|
protoc $(INCLUDE) --go_out=plugins=grpc:. types/*.proto
|
||||||
@echo "--> adding nolint declarations to protobuf generated files"
|
@echo "--> adding nolint declarations to protobuf generated files"
|
||||||
@awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
|
@awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
|
||||||
@mv types/types.pb.go.new types/types.pb.go
|
@mv types/types.pb.go.new types/types.pb.go
|
||||||
|
|
|
@ -53,21 +53,21 @@ func (app *localClient) EchoAsync(msg string) *ReqRes {
|
||||||
|
|
||||||
func (app *localClient) InfoAsync(req types.RequestInfo) *ReqRes {
|
func (app *localClient) InfoAsync(req types.RequestInfo) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Info(req)
|
res := app.Application.Info(types.ToParamsInfo(req))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestInfo(req),
|
types.ToRequestInfo(req),
|
||||||
types.ToResponseInfo(res),
|
types.ToResponseInfo(types.FromResultInfo(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) SetOptionAsync(req types.RequestSetOption) *ReqRes {
|
func (app *localClient) SetOptionAsync(req types.RequestSetOption) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.SetOption(req)
|
res := app.Application.SetOption(types.ToParamsSetOption(req))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestSetOption(req),
|
types.ToRequestSetOption(req),
|
||||||
types.ToResponseSetOption(res),
|
types.ToResponseSetOption(types.FromResultSetOption(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (app *localClient) DeliverTxAsync(tx []byte) *ReqRes {
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestDeliverTx(tx),
|
types.ToRequestDeliverTx(tx),
|
||||||
types.ToResponseDeliverTx(res),
|
types.ToResponseDeliverTx(types.FromResultDeliverTx(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,17 +87,17 @@ func (app *localClient) CheckTxAsync(tx []byte) *ReqRes {
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestCheckTx(tx),
|
types.ToRequestCheckTx(tx),
|
||||||
types.ToResponseCheckTx(res),
|
types.ToResponseCheckTx(types.FromResultCheckTx(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) QueryAsync(req types.RequestQuery) *ReqRes {
|
func (app *localClient) QueryAsync(req types.RequestQuery) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Query(req)
|
res := app.Application.Query(types.ToParamsQuery(req))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestQuery(req),
|
types.ToRequestQuery(req),
|
||||||
types.ToResponseQuery(res),
|
types.ToResponseQuery(types.FromResultQuery(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,16 +107,16 @@ func (app *localClient) CommitAsync() *ReqRes {
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestCommit(),
|
types.ToRequestCommit(),
|
||||||
types.ToResponseCommit(res),
|
types.ToResponseCommit(types.FromResultCommit(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) InitChainAsync(req types.RequestInitChain) *ReqRes {
|
func (app *localClient) InitChainAsync(req types.RequestInitChain) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.InitChain(req)
|
res := app.Application.InitChain(types.ToParamsInitChain(req))
|
||||||
reqRes := app.callback(
|
reqRes := app.callback(
|
||||||
types.ToRequestInitChain(req),
|
types.ToRequestInitChain(req),
|
||||||
types.ToResponseInitChain(res),
|
types.ToResponseInitChain(types.FromResultInitChain(res)),
|
||||||
)
|
)
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return reqRes
|
return reqRes
|
||||||
|
@ -124,21 +124,21 @@ func (app *localClient) InitChainAsync(req types.RequestInitChain) *ReqRes {
|
||||||
|
|
||||||
func (app *localClient) BeginBlockAsync(req types.RequestBeginBlock) *ReqRes {
|
func (app *localClient) BeginBlockAsync(req types.RequestBeginBlock) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.BeginBlock(req)
|
res := app.Application.BeginBlock(types.ToParamsBeginBlock(req))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestBeginBlock(req),
|
types.ToRequestBeginBlock(req),
|
||||||
types.ToResponseBeginBlock(res),
|
types.ToResponseBeginBlock(types.FromResultBeginBlock(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) EndBlockAsync(req types.RequestEndBlock) *ReqRes {
|
func (app *localClient) EndBlockAsync(req types.RequestEndBlock) *ReqRes {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.EndBlock(req)
|
res := app.Application.EndBlock(types.ToParamsEndBlock(req))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return app.callback(
|
return app.callback(
|
||||||
types.ToRequestEndBlock(req),
|
types.ToRequestEndBlock(req),
|
||||||
types.ToResponseEndBlock(res),
|
types.ToResponseEndBlock(types.FromResultEndBlock(res)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,63 +154,63 @@ func (app *localClient) EchoSync(msg string) (*types.ResponseEcho, error) {
|
||||||
|
|
||||||
func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Info(req)
|
res := types.FromResultInfo(app.Application.Info(types.ToParamsInfo(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
|
func (app *localClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.SetOption(req)
|
res := types.FromResultSetOption(app.Application.SetOption(types.ToParamsSetOption(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
|
func (app *localClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.DeliverTx(tx)
|
res := types.FromResultDeliverTx(app.Application.DeliverTx(tx))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
|
func (app *localClient) CheckTxSync(tx []byte) (*types.ResponseCheckTx, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.CheckTx(tx)
|
res := types.FromResultCheckTx(app.Application.CheckTx(tx))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
func (app *localClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Query(req)
|
res := types.FromResultQuery(app.Application.Query(types.ToParamsQuery(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) CommitSync() (*types.ResponseCommit, error) {
|
func (app *localClient) CommitSync() (*types.ResponseCommit, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.Commit()
|
res := types.FromResultCommit(app.Application.Commit())
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) {
|
func (app *localClient) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.InitChain(req)
|
res := types.FromResultInitChain(app.Application.InitChain(types.ToParamsInitChain(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
|
func (app *localClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.BeginBlock(req)
|
res := types.FromResultBeginBlock(app.Application.BeginBlock(types.ToParamsBeginBlock(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *localClient) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
|
func (app *localClient) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
|
||||||
app.mtx.Lock()
|
app.mtx.Lock()
|
||||||
res := app.Application.EndBlock(req)
|
res := types.FromResultEndBlock(app.Application.EndBlock(types.ToParamsEndBlock(req)))
|
||||||
app.mtx.Unlock()
|
app.mtx.Unlock()
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ func NewCounterApplication(serial bool) *CounterApplication {
|
||||||
return &CounterApplication{serial: serial}
|
return &CounterApplication{serial: serial}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Info(req types.RequestInfo) types.ResponseInfo {
|
func (app *CounterApplication) Info(req types.ParamsInfo) types.ResultInfo {
|
||||||
return types.ResponseInfo{Data: cmn.Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
|
return types.ResultInfo{Data: cmn.Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption {
|
func (app *CounterApplication) SetOption(req types.ParamsSetOption) types.ResultSetOption {
|
||||||
key, value := req.Key, req.Value
|
key, value := req.Key, req.Value
|
||||||
if key == "serial" && value == "on" {
|
if key == "serial" && value == "on" {
|
||||||
app.serial = true
|
app.serial = true
|
||||||
|
@ -33,20 +33,20 @@ func (app *CounterApplication) SetOption(req types.RequestSetOption) types.Respo
|
||||||
/*
|
/*
|
||||||
TODO Panic and have the ABCI server pass an exception.
|
TODO Panic and have the ABCI server pass an exception.
|
||||||
The client can call SetOptionSync() and get an `error`.
|
The client can call SetOptionSync() and get an `error`.
|
||||||
return types.ResponseSetOption{
|
return types.ResultSetOption{
|
||||||
Error: cmn.Fmt("Unknown key (%s) or value (%s)", key, value),
|
Error: cmn.Fmt("Unknown key (%s) or value (%s)", key, value),
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return types.ResponseSetOption{}
|
return types.ResultSetOption{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.ResponseSetOption{}
|
return types.ResultSetOption{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
func (app *CounterApplication) DeliverTx(tx []byte) types.ResultDeliverTx {
|
||||||
if app.serial {
|
if app.serial {
|
||||||
if len(tx) > 8 {
|
if len(tx) > 8 {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
|
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
|
||||||
}
|
}
|
||||||
|
@ -54,19 +54,19 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
||||||
copy(tx8[len(tx8)-len(tx):], tx)
|
copy(tx8[len(tx8)-len(tx):], tx)
|
||||||
txValue := binary.BigEndian.Uint64(tx8)
|
txValue := binary.BigEndian.Uint64(tx8)
|
||||||
if txValue != uint64(app.txCount) {
|
if txValue != uint64(app.txCount) {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeBadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.txCount++
|
app.txCount++
|
||||||
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
|
return types.ResultDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx {
|
func (app *CounterApplication) CheckTx(tx []byte) types.ResultCheckTx {
|
||||||
if app.serial {
|
if app.serial {
|
||||||
if len(tx) > 8 {
|
if len(tx) > 8 {
|
||||||
return types.ResponseCheckTx{
|
return types.ResultCheckTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
|
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx))}
|
||||||
}
|
}
|
||||||
|
@ -74,31 +74,31 @@ func (app *CounterApplication) CheckTx(tx []byte) types.ResponseCheckTx {
|
||||||
copy(tx8[len(tx8)-len(tx):], tx)
|
copy(tx8[len(tx8)-len(tx):], tx)
|
||||||
txValue := binary.BigEndian.Uint64(tx8)
|
txValue := binary.BigEndian.Uint64(tx8)
|
||||||
if txValue < uint64(app.txCount) {
|
if txValue < uint64(app.txCount) {
|
||||||
return types.ResponseCheckTx{
|
return types.ResultCheckTx{
|
||||||
Code: code.CodeTypeBadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return types.ResponseCheckTx{Code: code.CodeTypeOK}
|
return types.ResultCheckTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Commit() (resp types.ResponseCommit) {
|
func (app *CounterApplication) Commit() (resp types.ResultCommit) {
|
||||||
app.hashCount++
|
app.hashCount++
|
||||||
if app.txCount == 0 {
|
if app.txCount == 0 {
|
||||||
return types.ResponseCommit{}
|
return types.ResultCommit{}
|
||||||
}
|
}
|
||||||
hash := make([]byte, 8)
|
hash := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
||||||
return types.ResponseCommit{Data: hash}
|
return types.ResultCommit{Data: hash}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery {
|
func (app *CounterApplication) Query(reqQuery types.ParamsQuery) types.ResultQuery {
|
||||||
switch reqQuery.Path {
|
switch reqQuery.Path {
|
||||||
case "hash":
|
case "hash":
|
||||||
return types.ResponseQuery{Value: []byte(cmn.Fmt("%v", app.hashCount))}
|
return types.ResultQuery{Value: []byte(cmn.Fmt("%v", app.hashCount))}
|
||||||
case "tx":
|
case "tx":
|
||||||
return types.ResponseQuery{Value: []byte(cmn.Fmt("%v", app.txCount))}
|
return types.ResultQuery{Value: []byte(cmn.Fmt("%v", app.txCount))}
|
||||||
default:
|
default:
|
||||||
return types.ResponseQuery{Log: cmn.Fmt("Invalid query path. Expected hash or tx, got %v", reqQuery.Path)}
|
return types.ResultQuery{Log: cmn.Fmt("Invalid query path. Expected hash or tx, got %v", reqQuery.Path)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func RandVals(cnt int) []types.Validator {
|
||||||
// which allows tests to pass and is fine as long as you
|
// which allows tests to pass and is fine as long as you
|
||||||
// don't make any tx that modify the validator state
|
// don't make any tx that modify the validator state
|
||||||
func InitKVStore(app *PersistentKVStoreApplication) {
|
func InitKVStore(app *PersistentKVStoreApplication) {
|
||||||
app.InitChain(types.RequestInitChain{
|
app.InitChain(types.ParamsInitChain{
|
||||||
Validators: RandVals(1),
|
Validators: RandVals(1),
|
||||||
GenesisBytes: []byte("[]"),
|
GenesisBytes: []byte("[]"),
|
||||||
})
|
})
|
||||||
|
|
|
@ -64,12 +64,12 @@ func NewKVStoreApplication() *KVStoreApplication {
|
||||||
return &KVStoreApplication{state: state}
|
return &KVStoreApplication{state: state}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *KVStoreApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) {
|
func (app *KVStoreApplication) Info(req types.ParamsInfo) (resInfo types.ResultInfo) {
|
||||||
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size)}
|
return types.ResultInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx is either "key=value" or just arbitrary bytes
|
// tx is either "key=value" or just arbitrary bytes
|
||||||
func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResultDeliverTx {
|
||||||
var key, value []byte
|
var key, value []byte
|
||||||
parts := bytes.Split(tx, []byte("="))
|
parts := bytes.Split(tx, []byte("="))
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
|
@ -84,24 +84,24 @@ func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
||||||
{[]byte("app.creator"), []byte("jae")},
|
{[]byte("app.creator"), []byte("jae")},
|
||||||
{[]byte("app.key"), key},
|
{[]byte("app.key"), key},
|
||||||
}
|
}
|
||||||
return types.ResponseDeliverTx{Code: code.CodeTypeOK, Tags: tags}
|
return types.ResultDeliverTx{Code: code.CodeTypeOK, Tags: tags}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *KVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx {
|
func (app *KVStoreApplication) CheckTx(tx []byte) types.ResultCheckTx {
|
||||||
return types.ResponseCheckTx{Code: code.CodeTypeOK}
|
return types.ResultCheckTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *KVStoreApplication) Commit() types.ResponseCommit {
|
func (app *KVStoreApplication) Commit() types.ResultCommit {
|
||||||
// Using a memdb - just return the big endian size of the db
|
// Using a memdb - just return the big endian size of the db
|
||||||
appHash := make([]byte, 8)
|
appHash := make([]byte, 8)
|
||||||
binary.PutVarint(appHash, app.state.Size)
|
binary.PutVarint(appHash, app.state.Size)
|
||||||
app.state.AppHash = appHash
|
app.state.AppHash = appHash
|
||||||
app.state.Height += 1
|
app.state.Height += 1
|
||||||
saveState(app.state)
|
saveState(app.state)
|
||||||
return types.ResponseCommit{Data: appHash}
|
return types.ResultCommit{Data: appHash}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *KVStoreApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
|
func (app *KVStoreApplication) Query(reqQuery types.ParamsQuery) (resQuery types.ResultQuery) {
|
||||||
if reqQuery.Prove {
|
if reqQuery.Prove {
|
||||||
value := app.state.db.Get(prefixKey(reqQuery.Data))
|
value := app.state.db.Get(prefixKey(reqQuery.Data))
|
||||||
resQuery.Index = -1 // TODO make Proof return index
|
resQuery.Index = -1 // TODO make Proof return index
|
||||||
|
|
|
@ -25,7 +25,7 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
|
||||||
require.False(t, ar.IsErr(), ar)
|
require.False(t, ar.IsErr(), ar)
|
||||||
|
|
||||||
// make sure query is fine
|
// make sure query is fine
|
||||||
resQuery := app.Query(types.RequestQuery{
|
resQuery := app.Query(types.ParamsQuery{
|
||||||
Path: "/store",
|
Path: "/store",
|
||||||
Data: []byte(key),
|
Data: []byte(key),
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,7 @@ func testKVStore(t *testing.T, app types.Application, tx []byte, key, value stri
|
||||||
require.Equal(t, value, string(resQuery.Value))
|
require.Equal(t, value, string(resQuery.Value))
|
||||||
|
|
||||||
// make sure proof is fine
|
// make sure proof is fine
|
||||||
resQuery = app.Query(types.RequestQuery{
|
resQuery = app.Query(types.ParamsQuery{
|
||||||
Path: "/store",
|
Path: "/store",
|
||||||
Data: []byte(key),
|
Data: []byte(key),
|
||||||
Prove: true,
|
Prove: true,
|
||||||
|
@ -79,7 +79,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
|
||||||
InitKVStore(kvstore)
|
InitKVStore(kvstore)
|
||||||
height := int64(0)
|
height := int64(0)
|
||||||
|
|
||||||
resInfo := kvstore.Info(types.RequestInfo{})
|
resInfo := kvstore.Info(types.ParamsInfo{})
|
||||||
if resInfo.LastBlockHeight != height {
|
if resInfo.LastBlockHeight != height {
|
||||||
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
||||||
}
|
}
|
||||||
|
@ -90,11 +90,11 @@ func TestPersistentKVStoreInfo(t *testing.T) {
|
||||||
header := types.Header{
|
header := types.Header{
|
||||||
Height: int64(height),
|
Height: int64(height),
|
||||||
}
|
}
|
||||||
kvstore.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil})
|
kvstore.BeginBlock(types.ParamsBeginBlock{hash, header, nil, nil})
|
||||||
kvstore.EndBlock(types.RequestEndBlock{header.Height})
|
kvstore.EndBlock(types.ParamsEndBlock{header.Height})
|
||||||
kvstore.Commit()
|
kvstore.Commit()
|
||||||
|
|
||||||
resInfo = kvstore.Info(types.RequestInfo{})
|
resInfo = kvstore.Info(types.ParamsInfo{})
|
||||||
if resInfo.LastBlockHeight != height {
|
if resInfo.LastBlockHeight != height {
|
||||||
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func TestValUpdates(t *testing.T) {
|
||||||
nInit := 5
|
nInit := 5
|
||||||
vals := RandVals(total)
|
vals := RandVals(total)
|
||||||
// iniitalize with the first nInit
|
// iniitalize with the first nInit
|
||||||
kvstore.InitChain(types.RequestInitChain{
|
kvstore.InitChain(types.ParamsInitChain{
|
||||||
Validators: vals[:nInit],
|
Validators: vals[:nInit],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -176,13 +176,13 @@ func makeApplyBlock(t *testing.T, kvstore types.Application, heightInt int, diff
|
||||||
Height: height,
|
Height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
kvstore.BeginBlock(types.RequestBeginBlock{hash, header, nil, nil})
|
kvstore.BeginBlock(types.ParamsBeginBlock{hash, header, nil, nil})
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
if r := kvstore.DeliverTx(tx); r.IsErr() {
|
if r := kvstore.DeliverTx(tx); r.IsErr() {
|
||||||
t.Fatal(r)
|
t.Fatal(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resEndBlock := kvstore.EndBlock(types.RequestEndBlock{header.Height})
|
resEndBlock := kvstore.EndBlock(types.ParamsEndBlock{header.Height})
|
||||||
kvstore.Commit()
|
kvstore.Commit()
|
||||||
|
|
||||||
valsEqual(t, diff, resEndBlock.ValidatorUpdates)
|
valsEqual(t, diff, resEndBlock.ValidatorUpdates)
|
||||||
|
|
|
@ -50,19 +50,19 @@ func (app *PersistentKVStoreApplication) SetLogger(l log.Logger) {
|
||||||
app.logger = l
|
app.logger = l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *PersistentKVStoreApplication) Info(req types.RequestInfo) types.ResponseInfo {
|
func (app *PersistentKVStoreApplication) Info(req types.ParamsInfo) types.ResultInfo {
|
||||||
res := app.app.Info(req)
|
res := app.app.Info(req)
|
||||||
res.LastBlockHeight = app.app.state.Height
|
res.LastBlockHeight = app.app.state.Height
|
||||||
res.LastBlockAppHash = app.app.state.AppHash
|
res.LastBlockAppHash = app.app.state.AppHash
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *PersistentKVStoreApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption {
|
func (app *PersistentKVStoreApplication) SetOption(req types.ParamsSetOption) types.ResultSetOption {
|
||||||
return app.app.SetOption(req)
|
return app.app.SetOption(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx is either "val:pubkey/power" or "key=value" or just arbitrary bytes
|
// tx is either "val:pubkey/power" or "key=value" or just arbitrary bytes
|
||||||
func (app *PersistentKVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {
|
func (app *PersistentKVStoreApplication) DeliverTx(tx []byte) types.ResultDeliverTx {
|
||||||
// if it starts with "val:", update the validator set
|
// if it starts with "val:", update the validator set
|
||||||
// format is "val:pubkey/power"
|
// format is "val:pubkey/power"
|
||||||
if isValidatorTx(tx) {
|
if isValidatorTx(tx) {
|
||||||
|
@ -75,40 +75,40 @@ func (app *PersistentKVStoreApplication) DeliverTx(tx []byte) types.ResponseDeli
|
||||||
return app.app.DeliverTx(tx)
|
return app.app.DeliverTx(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *PersistentKVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx {
|
func (app *PersistentKVStoreApplication) CheckTx(tx []byte) types.ResultCheckTx {
|
||||||
return app.app.CheckTx(tx)
|
return app.app.CheckTx(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit will panic if InitChain was not called
|
// Commit will panic if InitChain was not called
|
||||||
func (app *PersistentKVStoreApplication) Commit() types.ResponseCommit {
|
func (app *PersistentKVStoreApplication) Commit() types.ResultCommit {
|
||||||
return app.app.Commit()
|
return app.app.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *PersistentKVStoreApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery {
|
func (app *PersistentKVStoreApplication) Query(reqQuery types.ParamsQuery) types.ResultQuery {
|
||||||
return app.app.Query(reqQuery)
|
return app.app.Query(reqQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the validators in the merkle tree
|
// Save the validators in the merkle tree
|
||||||
func (app *PersistentKVStoreApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain {
|
func (app *PersistentKVStoreApplication) InitChain(req types.ParamsInitChain) types.ResultInitChain {
|
||||||
for _, v := range req.Validators {
|
for _, v := range req.Validators {
|
||||||
r := app.updateValidator(v)
|
r := app.updateValidator(v)
|
||||||
if r.IsErr() {
|
if r.IsErr() {
|
||||||
app.logger.Error("Error updating validators", "r", r)
|
app.logger.Error("Error updating validators", "r", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return types.ResponseInitChain{}
|
return types.ResultInitChain{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track the block hash and header information
|
// Track the block hash and header information
|
||||||
func (app *PersistentKVStoreApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
|
func (app *PersistentKVStoreApplication) BeginBlock(req types.ParamsBeginBlock) types.ResultBeginBlock {
|
||||||
// reset valset changes
|
// reset valset changes
|
||||||
app.ValUpdates = make([]types.Validator, 0)
|
app.ValUpdates = make([]types.Validator, 0)
|
||||||
return types.ResponseBeginBlock{}
|
return types.ResultBeginBlock{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the validator set
|
// Update the validator set
|
||||||
func (app *PersistentKVStoreApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
|
func (app *PersistentKVStoreApplication) EndBlock(req types.ParamsEndBlock) types.ResultEndBlock {
|
||||||
return types.ResponseEndBlock{ValidatorUpdates: app.ValUpdates}
|
return types.ResultEndBlock{ValidatorUpdates: app.ValUpdates}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
|
@ -129,7 +129,7 @@ func (app *PersistentKVStoreApplication) Validators() (validators []types.Valida
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeValSetChangeTx(pubkey types.PubKey, power int64) []byte {
|
func MakeValSetChangeTx(pubkey *types.PubKey, power int64) []byte {
|
||||||
return []byte(cmn.Fmt("val:%X/%d", pubkey.Data, power))
|
return []byte(cmn.Fmt("val:%X/%d", pubkey.Data, power))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,13 +139,13 @@ func isValidatorTx(tx []byte) bool {
|
||||||
|
|
||||||
// format is "val:pubkey/power"
|
// format is "val:pubkey/power"
|
||||||
// pubkey is raw 32-byte ed25519 key
|
// pubkey is raw 32-byte ed25519 key
|
||||||
func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.ResponseDeliverTx {
|
func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.ResultDeliverTx {
|
||||||
tx = tx[len(ValidatorSetChangePrefix):]
|
tx = tx[len(ValidatorSetChangePrefix):]
|
||||||
|
|
||||||
//get the pubkey and power
|
//get the pubkey and power
|
||||||
pubKeyAndPower := strings.Split(string(tx), "/")
|
pubKeyAndPower := strings.Split(string(tx), "/")
|
||||||
if len(pubKeyAndPower) != 2 {
|
if len(pubKeyAndPower) != 2 {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower)}
|
Log: fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower)}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
|
||||||
// decode the pubkey
|
// decode the pubkey
|
||||||
pubkey, err := hex.DecodeString(pubkeyS)
|
pubkey, err := hex.DecodeString(pubkeyS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS)}
|
Log: fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS)}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
|
||||||
// decode the power
|
// decode the power
|
||||||
power, err := strconv.ParseInt(powerS, 10, 64)
|
power, err := strconv.ParseInt(powerS, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Power (%s) is not an int", powerS)}
|
Log: fmt.Sprintf("Power (%s) is not an int", powerS)}
|
||||||
}
|
}
|
||||||
|
@ -172,12 +172,12 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon
|
||||||
}
|
}
|
||||||
|
|
||||||
// add, update, or remove a validator
|
// add, update, or remove a validator
|
||||||
func (app *PersistentKVStoreApplication) updateValidator(v types.Validator) types.ResponseDeliverTx {
|
func (app *PersistentKVStoreApplication) updateValidator(v types.Validator) types.ResultDeliverTx {
|
||||||
key := []byte("val:" + string(v.PubKey.Data))
|
key := []byte("val:" + string(v.PubKey.Data))
|
||||||
if v.Power == 0 {
|
if v.Power == 0 {
|
||||||
// remove validator
|
// remove validator
|
||||||
if !app.app.state.db.Has(key) {
|
if !app.app.state.db.Has(key) {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeUnauthorized,
|
Code: code.CodeTypeUnauthorized,
|
||||||
Log: fmt.Sprintf("Cannot remove non-existent validator %X", key)}
|
Log: fmt.Sprintf("Cannot remove non-existent validator %X", key)}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func (app *PersistentKVStoreApplication) updateValidator(v types.Validator) type
|
||||||
// add or update validator
|
// add or update validator
|
||||||
value := bytes.NewBuffer(make([]byte, 0))
|
value := bytes.NewBuffer(make([]byte, 0))
|
||||||
if err := types.WriteMessage(&v, value); err != nil {
|
if err := types.WriteMessage(&v, value); err != nil {
|
||||||
return types.ResponseDeliverTx{
|
return types.ResultDeliverTx{
|
||||||
Code: code.CodeTypeEncodingError,
|
Code: code.CodeTypeEncodingError,
|
||||||
Log: fmt.Sprintf("Error encoding validator: %v", err)}
|
Log: fmt.Sprintf("Error encoding validator: %v", err)}
|
||||||
}
|
}
|
||||||
|
@ -196,5 +196,5 @@ func (app *PersistentKVStoreApplication) updateValidator(v types.Validator) type
|
||||||
// we only update the changes array if we successfully updated the tree
|
// we only update the changes array if we successfully updated the tree
|
||||||
app.ValUpdates = append(app.ValUpdates, v)
|
app.ValUpdates = append(app.ValUpdates, v)
|
||||||
|
|
||||||
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
|
return types.ResultDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,32 +172,32 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
|
||||||
case *types.Request_Flush:
|
case *types.Request_Flush:
|
||||||
responses <- types.ToResponseFlush()
|
responses <- types.ToResponseFlush()
|
||||||
case *types.Request_Info:
|
case *types.Request_Info:
|
||||||
res := s.app.Info(*r.Info)
|
res := s.app.Info(types.ToParamsInfo(*r.Info))
|
||||||
responses <- types.ToResponseInfo(res)
|
responses <- types.ToResponseInfo(types.FromResultInfo(res))
|
||||||
case *types.Request_SetOption:
|
case *types.Request_SetOption:
|
||||||
res := s.app.SetOption(*r.SetOption)
|
res := s.app.SetOption(types.ToParamsSetOption(*r.SetOption))
|
||||||
responses <- types.ToResponseSetOption(res)
|
responses <- types.ToResponseSetOption(types.FromResultSetOption(res))
|
||||||
case *types.Request_DeliverTx:
|
case *types.Request_DeliverTx:
|
||||||
res := s.app.DeliverTx(r.DeliverTx.Tx)
|
res := s.app.DeliverTx(r.DeliverTx.Tx)
|
||||||
responses <- types.ToResponseDeliverTx(res)
|
responses <- types.ToResponseDeliverTx(types.FromResultDeliverTx(res))
|
||||||
case *types.Request_CheckTx:
|
case *types.Request_CheckTx:
|
||||||
res := s.app.CheckTx(r.CheckTx.Tx)
|
res := s.app.CheckTx(r.CheckTx.Tx)
|
||||||
responses <- types.ToResponseCheckTx(res)
|
responses <- types.ToResponseCheckTx(types.FromResultCheckTx(res))
|
||||||
case *types.Request_Commit:
|
case *types.Request_Commit:
|
||||||
res := s.app.Commit()
|
res := s.app.Commit()
|
||||||
responses <- types.ToResponseCommit(res)
|
responses <- types.ToResponseCommit(types.FromResultCommit(res))
|
||||||
case *types.Request_Query:
|
case *types.Request_Query:
|
||||||
res := s.app.Query(*r.Query)
|
res := s.app.Query(types.ToParamsQuery(*r.Query))
|
||||||
responses <- types.ToResponseQuery(res)
|
responses <- types.ToResponseQuery(types.FromResultQuery(res))
|
||||||
case *types.Request_InitChain:
|
case *types.Request_InitChain:
|
||||||
res := s.app.InitChain(*r.InitChain)
|
res := s.app.InitChain(types.ToParamsInitChain(*r.InitChain))
|
||||||
responses <- types.ToResponseInitChain(res)
|
responses <- types.ToResponseInitChain(types.FromResultInitChain(res))
|
||||||
case *types.Request_BeginBlock:
|
case *types.Request_BeginBlock:
|
||||||
res := s.app.BeginBlock(*r.BeginBlock)
|
res := s.app.BeginBlock(types.ToParamsBeginBlock(*r.BeginBlock))
|
||||||
responses <- types.ToResponseBeginBlock(res)
|
responses <- types.ToResponseBeginBlock(types.FromResultBeginBlock(res))
|
||||||
case *types.Request_EndBlock:
|
case *types.Request_EndBlock:
|
||||||
res := s.app.EndBlock(*r.EndBlock)
|
res := s.app.EndBlock(types.ToParamsEndBlock(*r.EndBlock))
|
||||||
responses <- types.ToResponseEndBlock(res)
|
responses <- types.ToResponseEndBlock(types.FromResultEndBlock(res))
|
||||||
default:
|
default:
|
||||||
responses <- types.ToResponseException("Unknown request")
|
responses <- types.ToResponseException("Unknown request")
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,12 @@ import (
|
||||||
|
|
||||||
func InitChain(client abcicli.Client) error {
|
func InitChain(client abcicli.Client) error {
|
||||||
total := 10
|
total := 10
|
||||||
vals := make([]types.Validator, total)
|
vals := make([]*types.Validator, total)
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
pubkey := cmn.RandBytes(33)
|
pubkey := cmn.RandBytes(33)
|
||||||
power := cmn.RandInt()
|
power := cmn.RandInt()
|
||||||
vals[i] = types.Ed25519Validator(pubkey, int64(power))
|
v := types.Ed25519Validator(pubkey, int64(power))
|
||||||
|
vals[i] = &v
|
||||||
}
|
}
|
||||||
_, err := client.InitChainSync(types.RequestInitChain{
|
_, err := client.InitChainSync(types.RequestInitChain{
|
||||||
Validators: vals,
|
Validators: vals,
|
||||||
|
|
|
@ -6,23 +6,23 @@ import (
|
||||||
|
|
||||||
// Application is an interface that enables any finite, deterministic state machine
|
// Application is an interface that enables any finite, deterministic state machine
|
||||||
// to be driven by a blockchain-based replication engine via the ABCI.
|
// to be driven by a blockchain-based replication engine via the ABCI.
|
||||||
// All methods take a RequestXxx argument and return a ResponseXxx argument,
|
// All methods take a ParamsXxx argument and return a ResultXxx argument,
|
||||||
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
|
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
|
||||||
type Application interface {
|
type Application interface {
|
||||||
// Info/Query Connection
|
// Info/Query Connection
|
||||||
Info(RequestInfo) ResponseInfo // Return application info
|
Info(ParamsInfo) ResultInfo // Return application info
|
||||||
SetOption(RequestSetOption) ResponseSetOption // Set application option
|
SetOption(ParamsSetOption) ResultSetOption // Set application option
|
||||||
Query(RequestQuery) ResponseQuery // Query for state
|
Query(ParamsQuery) ResultQuery // Query for state
|
||||||
|
|
||||||
// Mempool Connection
|
// Mempool Connection
|
||||||
CheckTx(tx []byte) ResponseCheckTx // Validate a tx for the mempool
|
CheckTx(tx []byte) ResultCheckTx // Validate a tx for the mempool
|
||||||
|
|
||||||
// Consensus Connection
|
// Consensus Connection
|
||||||
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain with validators and other info from TendermintCore
|
InitChain(ParamsInitChain) ResultInitChain // Initialize blockchain with validators and other info from TendermintCore
|
||||||
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
|
BeginBlock(ParamsBeginBlock) ResultBeginBlock // Signals the beginning of a block
|
||||||
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
|
DeliverTx(tx []byte) ResultDeliverTx // Deliver a tx for full processing
|
||||||
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
|
EndBlock(ParamsEndBlock) ResultEndBlock // Signals the end of a block, returns changes to the validator set
|
||||||
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
|
Commit() ResultCommit // Commit the state and return the application Merkle root hash
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
@ -37,40 +37,40 @@ func NewBaseApplication() *BaseApplication {
|
||||||
return &BaseApplication{}
|
return &BaseApplication{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) Info(req RequestInfo) ResponseInfo {
|
func (BaseApplication) Info(req ParamsInfo) ResultInfo {
|
||||||
return ResponseInfo{}
|
return ResultInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) SetOption(req RequestSetOption) ResponseSetOption {
|
func (BaseApplication) SetOption(req ParamsSetOption) ResultSetOption {
|
||||||
return ResponseSetOption{}
|
return ResultSetOption{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) DeliverTx(tx []byte) ResponseDeliverTx {
|
func (BaseApplication) DeliverTx(tx []byte) ResultDeliverTx {
|
||||||
return ResponseDeliverTx{Code: CodeTypeOK}
|
return ResultDeliverTx{Code: CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) CheckTx(tx []byte) ResponseCheckTx {
|
func (BaseApplication) CheckTx(tx []byte) ResultCheckTx {
|
||||||
return ResponseCheckTx{Code: CodeTypeOK}
|
return ResultCheckTx{Code: CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) Commit() ResponseCommit {
|
func (BaseApplication) Commit() ResultCommit {
|
||||||
return ResponseCommit{}
|
return ResultCommit{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) Query(req RequestQuery) ResponseQuery {
|
func (BaseApplication) Query(req ParamsQuery) ResultQuery {
|
||||||
return ResponseQuery{Code: CodeTypeOK}
|
return ResultQuery{Code: CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
|
func (BaseApplication) InitChain(req ParamsInitChain) ResultInitChain {
|
||||||
return ResponseInitChain{}
|
return ResultInitChain{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
|
func (BaseApplication) BeginBlock(req ParamsBeginBlock) ResultBeginBlock {
|
||||||
return ResponseBeginBlock{}
|
return ResultBeginBlock{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
|
func (BaseApplication) EndBlock(req ParamsEndBlock) ResultEndBlock {
|
||||||
return ResponseEndBlock{}
|
return ResultEndBlock{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
@ -93,46 +93,55 @@ func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*Resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
|
func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
|
||||||
res := app.app.Info(*req)
|
res := app.app.Info(ToParamsInfo(*req))
|
||||||
return &res, nil
|
r := FromResultInfo(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
|
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
|
||||||
res := app.app.SetOption(*req)
|
res := app.app.SetOption(ToParamsSetOption(*req))
|
||||||
return &res, nil
|
r := FromResultSetOption(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
|
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
|
||||||
res := app.app.DeliverTx(req.Tx)
|
res := app.app.DeliverTx(req.Tx)
|
||||||
return &res, nil
|
r := FromResultDeliverTx(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
|
func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
|
||||||
res := app.app.CheckTx(req.Tx)
|
res := app.app.CheckTx(req.Tx)
|
||||||
return &res, nil
|
r := FromResultCheckTx(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
|
func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
|
||||||
res := app.app.Query(*req)
|
res := app.app.Query(ToParamsQuery(*req))
|
||||||
return &res, nil
|
r := FromResultQuery(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
|
func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
|
||||||
res := app.app.Commit()
|
res := app.app.Commit()
|
||||||
return &res, nil
|
r := FromResultCommit(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
|
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
|
||||||
res := app.app.InitChain(*req)
|
res := app.app.InitChain(ToParamsInitChain(*req))
|
||||||
return &res, nil
|
r := FromResultInitChain(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
|
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
|
||||||
res := app.app.BeginBlock(*req)
|
res := app.app.BeginBlock(ToParamsBeginBlock(*req))
|
||||||
return &res, nil
|
r := FromResultBeginBlock(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
|
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
|
||||||
res := app.app.EndBlock(*req)
|
res := app.app.EndBlock(ToParamsEndBlock(*req))
|
||||||
return &res, nil
|
r := FromResultEndBlock(res)
|
||||||
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
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
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
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)
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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 {
|
func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
|
||||||
// binary.ReadVarint takes an io.ByteReader, eg. a bufio.Reader
|
// binary.ReadUvarint takes an io.ByteReader, eg. a bufio.Reader
|
||||||
reader, ok := r.(*bufio.Reader)
|
reader, ok := r.(*bufio.Reader)
|
||||||
if !ok {
|
if !ok {
|
||||||
reader = bufio.NewReader(r)
|
reader = bufio.NewReader(r)
|
||||||
}
|
}
|
||||||
length64, err := binary.ReadVarint(reader)
|
length64, err := binary.ReadUvarint(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// NOTE: we copied wire.EncodeByteSlice from go-wire rather than keep
|
// NOTE: we copied wire.EncodeByteSlice from go-amino rather than keep
|
||||||
// go-wire as a dep
|
// go-amino as a dep
|
||||||
|
|
||||||
func encodeByteSlice(w io.Writer, bz []byte) (err error) {
|
func encodeByteSlice(w io.Writer, bz []byte) (err error) {
|
||||||
err = encodeVarint(w, int64(len(bz)))
|
err = encodeUvarint(w, uint64(len(bz)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ func encodeByteSlice(w io.Writer, bz []byte) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeVarint(w io.Writer, i int64) (err error) {
|
func encodeUvarint(w io.Writer, u uint64) (err error) {
|
||||||
var buf [10]byte
|
var buf [10]byte
|
||||||
n := binary.PutVarint(buf[:], i)
|
n := binary.PutUvarint(buf[:], u)
|
||||||
_, err = w.Write(buf[0:n])
|
_, err = w.Write(buf[0:n])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ func TestMarshalJSON(t *testing.T) {
|
||||||
Code: 1,
|
Code: 1,
|
||||||
Data: []byte("hello"),
|
Data: []byte("hello"),
|
||||||
GasWanted: 43,
|
GasWanted: 43,
|
||||||
Tags: []cmn.KVPair{
|
Tags: []*cmn.KVPair{
|
||||||
{[]byte("pho"), []byte("bo")},
|
{[]byte("pho"), []byte("bo")},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ func TestWriteReadMessage2(t *testing.T) {
|
||||||
Data: []byte(phrase),
|
Data: []byte(phrase),
|
||||||
Log: phrase,
|
Log: phrase,
|
||||||
GasWanted: 10,
|
GasWanted: 10,
|
||||||
Tags: []cmn.KVPair{
|
Tags: []*cmn.KVPair{
|
||||||
cmn.KVPair{[]byte("abc"), []byte("def")},
|
{[]byte("abc"), []byte("def")},
|
||||||
},
|
},
|
||||||
// Fee: cmn.KI64Pair{
|
// Fee: cmn.KI64Pair{
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
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 {
|
||||||
|
}
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
const (
|
|
||||||
PubKeyEd25519 = "ed25519"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Ed25519Validator(pubkey []byte, power int64) Validator {
|
|
||||||
return Validator{
|
|
||||||
// Address:
|
|
||||||
PubKey: PubKey{
|
|
||||||
Type: PubKeyEd25519,
|
|
||||||
Data: pubkey,
|
|
||||||
},
|
|
||||||
Power: power,
|
|
||||||
}
|
|
||||||
}
|
|
213
types/result.go
213
types/result.go
|
@ -1,121 +1,170 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import cmn "github.com/tendermint/tmlibs/common"
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/gogo/protobuf/jsonpb"
|
// nondeterministic
|
||||||
)
|
type ResultException struct {
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
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.
|
type ResultEcho struct {
|
||||||
func (r ResponseCheckTx) IsErr() bool {
|
Message string `json:"message,omitempty"`
|
||||||
return r.Code != CodeTypeOK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOK returns true if Code is OK.
|
type ResultFlush struct {
|
||||||
func (r ResponseDeliverTx) IsOK() bool {
|
|
||||||
return r.Code == CodeTypeOK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsErr returns true if Code is something other than OK.
|
type ResultInfo struct {
|
||||||
func (r ResponseDeliverTx) IsErr() bool {
|
Data string `json:"data,omitempty"`
|
||||||
return r.Code != CodeTypeOK
|
Version string `json:"version,omitempty"`
|
||||||
|
LastBlockHeight int64 `json:"last_block_height,omitempty"`
|
||||||
|
LastBlockAppHash []byte `json:"last_block_app_hash,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsOK returns true if Code is OK.
|
func FromResultInfo(res ResultInfo) ResponseInfo {
|
||||||
func (r ResponseQuery) IsOK() bool {
|
return ResponseInfo(res)
|
||||||
return r.Code == CodeTypeOK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsErr returns true if Code is something other than OK.
|
type ResultSetOption struct {
|
||||||
func (r ResponseQuery) IsErr() bool {
|
Code uint32 `json:"code,omitempty"`
|
||||||
return r.Code != CodeTypeOK
|
// bytes data = 2;
|
||||||
|
Log string `json:"log,omitempty"`
|
||||||
|
Info string `json:"info,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
func FromResultSetOption(res ResultSetOption) ResponseSetOption {
|
||||||
// override JSON marshalling so we dont emit defaults (ie. disable omitempty)
|
return ResponseSetOption(res)
|
||||||
// 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 (
|
type ResultInitChain struct {
|
||||||
jsonpbMarshaller = jsonpb.Marshaler{
|
Validators []Validator `json:"validators"`
|
||||||
EnumsAsInts: true,
|
}
|
||||||
EmitDefaults: false,
|
|
||||||
|
func FromResultInitChain(res ResultInitChain) ResponseInitChain {
|
||||||
|
vals := valsToPointers(res.Validators)
|
||||||
|
return ResponseInitChain{
|
||||||
|
Validators: vals,
|
||||||
}
|
}
|
||||||
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 {
|
type ResultQuery struct {
|
||||||
reader := bytes.NewBuffer(b)
|
Code uint32 `json:"code,omitempty"`
|
||||||
return jsonpbUnmarshaller.Unmarshal(reader, r)
|
// 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 *ResponseCheckTx) MarshalJSON() ([]byte, error) {
|
func FromResultQuery(res ResultQuery) ResponseQuery {
|
||||||
s, err := jsonpbMarshaller.MarshalToString(r)
|
return ResponseQuery(res)
|
||||||
return []byte(s), err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
|
type ResultBeginBlock struct {
|
||||||
reader := bytes.NewBuffer(b)
|
Tags []cmn.KVPair `json:"tags,omitempty"`
|
||||||
return jsonpbUnmarshaller.Unmarshal(reader, r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) {
|
func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock {
|
||||||
s, err := jsonpbMarshaller.MarshalToString(r)
|
tags := tagsToPointers(res.Tags)
|
||||||
return []byte(s), err
|
return ResponseBeginBlock{
|
||||||
|
Tags: tags,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error {
|
type ResultCheckTx struct {
|
||||||
reader := bytes.NewBuffer(b)
|
Code uint32 `json:"code,omitempty"`
|
||||||
return jsonpbUnmarshaller.Unmarshal(reader, r)
|
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) MarshalJSON() ([]byte, error) {
|
func FromResultCheckTx(res ResultCheckTx) ResponseCheckTx {
|
||||||
s, err := jsonpbMarshaller.MarshalToString(r)
|
tags := tagsToPointers(res.Tags)
|
||||||
return []byte(s), err
|
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) UnmarshalJSON(b []byte) error {
|
type ResultDeliverTx struct {
|
||||||
reader := bytes.NewBuffer(b)
|
Code uint32 `json:"code,omitempty"`
|
||||||
return jsonpbUnmarshaller.Unmarshal(reader, r)
|
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 *ResponseCommit) MarshalJSON() ([]byte, error) {
|
func FromResultDeliverTx(res ResultDeliverTx) ResponseDeliverTx {
|
||||||
s, err := jsonpbMarshaller.MarshalToString(r)
|
tags := tagsToPointers(res.Tags)
|
||||||
return []byte(s), err
|
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) UnmarshalJSON(b []byte) error {
|
type ResultEndBlock struct {
|
||||||
reader := bytes.NewBuffer(b)
|
ValidatorUpdates []Validator `json:"validator_updates"`
|
||||||
return jsonpbUnmarshaller.Unmarshal(reader, r)
|
ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"`
|
||||||
|
Tags []cmn.KVPair `json:"tags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some compile time assertions to ensure we don't
|
func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock {
|
||||||
// have accidental runtime surprises later on.
|
tags := tagsToPointers(res.Tags)
|
||||||
|
vals := valsToPointers(res.ValidatorUpdates)
|
||||||
// jsonEncodingRoundTripper ensures that asserted
|
return ResponseEndBlock{
|
||||||
// interfaces implement both MarshalJSON and UnmarshalJSON
|
ValidatorUpdates: vals,
|
||||||
type jsonRoundTripper interface {
|
ConsensusParamUpdates: res.ConsensusParamUpdates,
|
||||||
json.Marshaler
|
Tags: tags,
|
||||||
json.Unmarshaler
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ jsonRoundTripper = (*ResponseCommit)(nil)
|
type ResultCommit struct {
|
||||||
var _ jsonRoundTripper = (*ResponseQuery)(nil)
|
// reserve 1
|
||||||
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
|
Data []byte `json:"data,omitempty"`
|
||||||
var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
|
}
|
||||||
var _ jsonRoundTripper = (*ResponseSetOption)(nil)
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +1,9 @@
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package types;
|
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";
|
import "github.com/tendermint/tmlibs/common/types.proto";
|
||||||
|
|
||||||
// This file is copied from http://github.com/tendermint/abci
|
// 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
|
// Request types
|
||||||
|
@ -47,7 +42,7 @@ message RequestSetOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
message RequestInitChain {
|
message RequestInitChain {
|
||||||
repeated Validator validators = 1 [(gogoproto.nullable)=false];
|
repeated Validator validators = 1;
|
||||||
bytes genesis_bytes = 2;
|
bytes genesis_bytes = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +55,9 @@ message RequestQuery {
|
||||||
|
|
||||||
message RequestBeginBlock {
|
message RequestBeginBlock {
|
||||||
bytes hash = 1;
|
bytes hash = 1;
|
||||||
Header header = 2 [(gogoproto.nullable)=false];
|
Header header = 2;
|
||||||
repeated SigningValidator validators = 3;
|
repeated SigningValidator validators = 3;
|
||||||
repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false];
|
repeated Evidence byzantine_validators = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RequestCheckTx {
|
message RequestCheckTx {
|
||||||
|
@ -128,7 +123,7 @@ message ResponseSetOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseInitChain {
|
message ResponseInitChain {
|
||||||
repeated Validator validators = 1 [(gogoproto.nullable)=false];
|
repeated Validator validators = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseQuery {
|
message ResponseQuery {
|
||||||
|
@ -144,7 +139,7 @@ message ResponseQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseBeginBlock {
|
message ResponseBeginBlock {
|
||||||
repeated common.KVPair tags = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
repeated common.KVPair tags = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseCheckTx {
|
message ResponseCheckTx {
|
||||||
|
@ -154,8 +149,8 @@ message ResponseCheckTx {
|
||||||
string info = 4; // nondeterministic
|
string info = 4; // nondeterministic
|
||||||
int64 gas_wanted = 5;
|
int64 gas_wanted = 5;
|
||||||
int64 gas_used = 6;
|
int64 gas_used = 6;
|
||||||
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
repeated common.KVPair tags = 7;
|
||||||
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
|
common.KI64Pair fee = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseDeliverTx {
|
message ResponseDeliverTx {
|
||||||
|
@ -165,14 +160,14 @@ message ResponseDeliverTx {
|
||||||
string info = 4; // nondeterministic
|
string info = 4; // nondeterministic
|
||||||
int64 gas_wanted = 5;
|
int64 gas_wanted = 5;
|
||||||
int64 gas_used = 6;
|
int64 gas_used = 6;
|
||||||
repeated common.KVPair tags = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
repeated common.KVPair tags = 7;
|
||||||
common.KI64Pair fee = 8 [(gogoproto.nullable)=false];
|
common.KI64Pair fee = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseEndBlock {
|
message ResponseEndBlock {
|
||||||
repeated Validator validator_updates = 1 [(gogoproto.nullable)=false];
|
repeated Validator validator_updates = 1;
|
||||||
ConsensusParams consensus_param_updates = 2;
|
ConsensusParams consensus_param_updates = 2;
|
||||||
repeated common.KVPair tags = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="tags,omitempty"];
|
repeated common.KVPair tags = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ResponseCommit {
|
message ResponseCommit {
|
||||||
|
@ -217,7 +212,7 @@ message BlockGossip {
|
||||||
// just the minimum the app might need
|
// just the minimum the app might need
|
||||||
message Header {
|
message Header {
|
||||||
// basics
|
// basics
|
||||||
string chain_id = 1 [(gogoproto.customname)="ChainID"];
|
string chain_id = 1;
|
||||||
int64 height = 2;
|
int64 height = 2;
|
||||||
int64 time = 3;
|
int64 time = 3;
|
||||||
|
|
||||||
|
@ -236,7 +231,7 @@ message Header {
|
||||||
// Validator
|
// Validator
|
||||||
message Validator {
|
message Validator {
|
||||||
bytes address = 1;
|
bytes address = 1;
|
||||||
PubKey pub_key = 2 [(gogoproto.nullable)=false];
|
PubKey pub_key = 2;
|
||||||
int64 power = 3;
|
int64 power = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,21 @@ import (
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
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
|
// Validators is a list of validators that implements the Sort interface
|
Loading…
Reference in New Issue