Skip to content

Commit

Permalink
Use tm ResponseCheckTx
Browse files Browse the repository at this point in the history
  • Loading branch information
ulbqb committed Aug 8, 2023
1 parent 474e6aa commit 83f6119
Show file tree
Hide file tree
Showing 49 changed files with 220 additions and 1,889 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ proto-gen: check-proto-deps
@echo "Generating Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf generate
@mv ./proto/ostracon/abci/types.pb.go ./abci/types/
@mv ./proto/ostracon/rpc/grpc/types.pb.go ./rpc/grpc/
@rm -rf ./proto/tendermint
.PHONY: proto-gen

Expand Down
2 changes: 1 addition & 1 deletion abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Client interface {
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
SetOptionSync(types.RequestSetOption) (*types.ResponseSetOption, error)
DeliverTxSync(types.RequestDeliverTx) (*types.ResponseDeliverTx, error)
CheckTxSync(types.RequestCheckTx) (*ocabci.ResponseCheckTx, error)
CheckTxSync(types.RequestCheckTx) (*types.ResponseCheckTx, error)
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
CommitSync() (*types.ResponseCommit, error)
InitChainSync(types.RequestInitChain) (*types.ResponseInitChain, error)
Expand Down
2 changes: 1 addition & 1 deletion abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (cli *grpcClient) DeliverTxSync(params types.RequestDeliverTx) (*types.Resp
return reqres.Response.GetDeliverTx(), cli.Error()
}

func (cli *grpcClient) CheckTxSync(params types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (cli *grpcClient) CheckTxSync(params types.RequestCheckTx) (*types.ResponseCheckTx, error) {
reqres := cli.CheckTxAsync(params, nil)
reqres.Wait()
return reqres.Response.GetCheckTx(), cli.Error()
Expand Down
4 changes: 2 additions & 2 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (app *localClient) CheckTxAsync(req types.RequestCheckTx, cb ResponseCallba

reqRes := NewReqRes(ocabci.ToRequestCheckTx(req), cb)

app.Application.CheckTxAsync(req, func(r ocabci.ResponseCheckTx) {
app.Application.CheckTxAsync(req, func(r types.ResponseCheckTx) {
res := ocabci.ToResponseCheckTx(r)
app.done(reqRes, res)
})
Expand Down Expand Up @@ -257,7 +257,7 @@ func (app *localClient) DeliverTxSync(req types.RequestDeliverTx) (*types.Respon
return &res, nil
}

func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
// NOTE: commented out for performance. delete all after commenting out all `app.mtx`
// app.mtx.Lock()
// defer app.mtx.Unlock()
Expand Down
10 changes: 5 additions & 5 deletions abci/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (cli *socketClient) DeliverTxSync(req types.RequestDeliverTx) (*types.Respo
return reqres.Response.GetDeliverTx(), cli.Error()
}

func (cli *socketClient) CheckTxSync(req types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (cli *socketClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
reqres := cli.queueRequest(ocabci.ToRequestCheckTx(req), nil)
if _, err := cli.FlushSync(); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ func printResponse(cmd *cobra.Command, args []string, rsp response) {
}

// Always print the status code.
if rsp.Code == ocabci.CodeTypeOK {
if rsp.Code == types.CodeTypeOK {
fmt.Printf("-> code: OK\n")
} else {
fmt.Printf("-> code: %d\n", rsp.Code)
Expand Down
10 changes: 5 additions & 5 deletions abci/example/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
}

func (app *Application) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.checkTx(req)
}

func (app *Application) CheckTxAsync(req types.RequestCheckTx, callback ocabci.CheckTxCallback) {
callback(app.checkTx(req))
}

func (app *Application) checkTx(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) checkTx(req types.RequestCheckTx) types.ResponseCheckTx {
if app.serial {
if len(req.Tx) > 8 {
return ocabci.ResponseCheckTx{
return types.ResponseCheckTx{
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(req.Tx))}
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(req.Tx):], req.Tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
return ocabci.ResponseCheckTx{
return types.ResponseCheckTx{
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)}
}
}
return ocabci.ResponseCheckTx{Code: code.CodeTypeOK}
return types.ResponseCheckTx{Code: code.CodeTypeOK}
}

func (app *Application) Commit() (resp types.ResponseCommit) {
Expand Down
6 changes: 3 additions & 3 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
return types.ResponseDeliverTx{Code: code.CodeTypeOK, Events: events}
}

func (app *Application) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.checkTx(req)
}

func (app *Application) CheckTxAsync(req types.RequestCheckTx, callback ocabci.CheckTxCallback) {
callback(app.checkTx(req))
}

func (app *Application) checkTx(req types.RequestCheckTx) ocabci.ResponseCheckTx {
return ocabci.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}
func (app *Application) checkTx(req types.RequestCheckTx) types.ResponseCheckTx {
return types.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}
}

func (app *Application) Commit() types.ResponseCommit {
Expand Down
2 changes: 1 addition & 1 deletion abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (app *PersistentKVStoreApplication) DeliverTx(req types.RequestDeliverTx) t
return app.app.DeliverTx(req)
}

func (app *PersistentKVStoreApplication) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *PersistentKVStoreApplication) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.app.CheckTxSync(req)
}

Expand Down
3 changes: 2 additions & 1 deletion abci/tests/test_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"os/exec"
"time"

"github.com/tendermint/tendermint/abci/types"

"github.com/Finschia/ostracon/abci/example/code"
"github.com/Finschia/ostracon/abci/types"
)

var abciType string
Expand Down
20 changes: 10 additions & 10 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

//go:generate ../../scripts/mockery_generate.sh Application

type CheckTxCallback func(ResponseCheckTx)
type CheckTxCallback func(types.ResponseCheckTx)

// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI.
Expand All @@ -21,7 +21,7 @@ type Application interface {
Query(types.RequestQuery) types.ResponseQuery // Query for state

// Mempool Connection
CheckTxSync(types.RequestCheckTx) ResponseCheckTx // Validate a tx for the mempool
CheckTxSync(types.RequestCheckTx) types.ResponseCheckTx // Validate a tx for the mempool
CheckTxAsync(types.RequestCheckTx, CheckTxCallback) // Asynchronously validate a tx for the mempool
BeginRecheckTx(RequestBeginRecheckTx) ResponseBeginRecheckTx // Signals the beginning of rechecking
EndRecheckTx(RequestEndRecheckTx) ResponseEndRecheckTx // Signals the end of rechecking
Expand Down Expand Up @@ -61,31 +61,31 @@ func (BaseApplication) SetOption(req types.RequestSetOption) types.ResponseSetOp
}

func (BaseApplication) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverTx {
return types.ResponseDeliverTx{Code: CodeTypeOK}
return types.ResponseDeliverTx{Code: types.CodeTypeOK}
}

func (BaseApplication) CheckTxSync(req types.RequestCheckTx) ResponseCheckTx {
return ResponseCheckTx{Code: CodeTypeOK}
func (BaseApplication) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return types.ResponseCheckTx{Code: types.CodeTypeOK}
}

func (BaseApplication) CheckTxAsync(req types.RequestCheckTx, callback CheckTxCallback) {
callback(ResponseCheckTx{Code: CodeTypeOK})
callback(types.ResponseCheckTx{Code: types.CodeTypeOK})
}

func (BaseApplication) BeginRecheckTx(req RequestBeginRecheckTx) ResponseBeginRecheckTx {
return ResponseBeginRecheckTx{Code: CodeTypeOK}
return ResponseBeginRecheckTx{Code: types.CodeTypeOK}
}

func (BaseApplication) EndRecheckTx(req RequestEndRecheckTx) ResponseEndRecheckTx {
return ResponseEndRecheckTx{Code: CodeTypeOK}
return ResponseEndRecheckTx{Code: types.CodeTypeOK}
}

func (BaseApplication) Commit() types.ResponseCommit {
return types.ResponseCommit{}
}

func (BaseApplication) Query(req types.RequestQuery) types.ResponseQuery {
return types.ResponseQuery{Code: CodeTypeOK}
return types.ResponseQuery{Code: types.CodeTypeOK}
}

func (BaseApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain {
Expand Down Expand Up @@ -150,7 +150,7 @@ func (app *GRPCApplication) DeliverTx(ctx context.Context, req *types.RequestDel
return &res, nil
}

func (app *GRPCApplication) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*ResponseCheckTx, error) {
func (app *GRPCApplication) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
res := app.app.CheckTxSync(*req)
return &res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func ToResponseDeliverTx(res types.ResponseDeliverTx) *Response {
}
}

func ToResponseCheckTx(res ResponseCheckTx) *Response {
func ToResponseCheckTx(res types.ResponseCheckTx) *Response {
return &Response{
Value: &Response_CheckTx{&res},
}
Expand Down
8 changes: 4 additions & 4 deletions abci/types/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMarshalJSON(t *testing.T) {
assert.Nil(t, err)
// include empty fields.
assert.True(t, strings.Contains(string(b), "code"))
r1 := ResponseCheckTx{
r1 := types.ResponseCheckTx{
Code: 1,
Data: []byte("hello"),
GasWanted: 43,
Expand All @@ -34,7 +34,7 @@ func TestMarshalJSON(t *testing.T) {
b, err = json.Marshal(&r1)
assert.Nil(t, err)

var r2 ResponseCheckTx
var r2 types.ResponseCheckTx
err = json.Unmarshal(b, &r2)
assert.Nil(t, err)
assert.Equal(t, r1, r2)
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestWriteReadMessage(t *testing.T) {
func TestWriteReadMessage2(t *testing.T) {
phrase := "hello-world"
cases := []proto.Message{
&ResponseCheckTx{
&types.ResponseCheckTx{
Data: []byte(phrase),
Log: phrase,
GasWanted: 10,
Expand All @@ -106,7 +106,7 @@ func TestWriteReadMessage2(t *testing.T) {
err := WriteMessage(c, buf)
assert.Nil(t, err)

msg := new(ResponseCheckTx)
msg := new(types.ResponseCheckTx)
err = ReadMessage(buf, msg)
assert.Nil(t, err)

Expand Down
8 changes: 4 additions & 4 deletions abci/types/mocks/application.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 0 additions & 54 deletions abci/types/result.go

This file was deleted.

Loading

0 comments on commit 83f6119

Please sign in to comment.