You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.2 KiB

9 years ago
9 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package types // nolint: goimports
  2. import (
  3. context "golang.org/x/net/context"
  4. )
  5. // Application is an interface that enables any finite, deterministic state machine
  6. // to be driven by a blockchain-based replication engine via the ABCI.
  7. // All methods take a RequestXxx argument and return a ResponseXxx argument,
  8. // except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
  9. type Application interface {
  10. // Info/Query Connection
  11. Info(RequestInfo) ResponseInfo // Return application info
  12. SetOption(RequestSetOption) ResponseSetOption // Set application option
  13. Query(RequestQuery) ResponseQuery // Query for state
  14. // Mempool Connection
  15. CheckTx(tx []byte) ResponseCheckTx // Validate a tx for the mempool
  16. // Consensus Connection
  17. InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain with validators and other info from TendermintCore
  18. BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
  19. DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
  20. EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
  21. Commit() ResponseCommit // Commit the state and return the application Merkle root hash
  22. }
  23. //------------------------------------
  24. // GRPCApplication is a GRPC wrapper for Application
  25. type GRPCApplication struct {
  26. app Application
  27. }
  28. func NewGRPCApplication(app Application) *GRPCApplication {
  29. return &GRPCApplication{app}
  30. }
  31. func (app *GRPCApplication) Echo(ctx context.Context, req *RequestEcho) (*ResponseEcho, error) {
  32. return &ResponseEcho{req.Message}, nil
  33. }
  34. func (app *GRPCApplication) Flush(ctx context.Context, req *RequestFlush) (*ResponseFlush, error) {
  35. return &ResponseFlush{}, nil
  36. }
  37. func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*ResponseInfo, error) {
  38. res := app.app.Info(*req)
  39. return &res, nil
  40. }
  41. func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
  42. res := app.app.SetOption(*req)
  43. return &res, nil
  44. }
  45. func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
  46. res := app.app.DeliverTx(req.Tx)
  47. return &res, nil
  48. }
  49. func (app *GRPCApplication) CheckTx(ctx context.Context, req *RequestCheckTx) (*ResponseCheckTx, error) {
  50. res := app.app.CheckTx(req.Tx)
  51. return &res, nil
  52. }
  53. func (app *GRPCApplication) Query(ctx context.Context, req *RequestQuery) (*ResponseQuery, error) {
  54. res := app.app.Query(*req)
  55. return &res, nil
  56. }
  57. func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*ResponseCommit, error) {
  58. res := app.app.Commit()
  59. return &res, nil
  60. }
  61. func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
  62. res := app.app.InitChain(*req)
  63. return &res, nil
  64. }
  65. func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
  66. res := app.app.BeginBlock(*req)
  67. return &res, nil
  68. }
  69. func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
  70. res := app.app.EndBlock(*req)
  71. return &res, nil
  72. }