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.

81 lines
2.0 KiB

  1. package types
  2. import (
  3. "fmt"
  4. "github.com/tendermint/go-wire/data"
  5. )
  6. // IsErr returns true if Code is something other than OK.
  7. func (r ResponseCheckTx) IsErr() bool {
  8. return r.Code != CodeType_OK
  9. }
  10. // Error implements error interface by formatting response as string.
  11. func (r ResponseCheckTx) Error() string {
  12. return fmtError(r.Code, r.Log)
  13. }
  14. // IsErr returns true if Code is something other than OK.
  15. func (r ResponseDeliverTx) IsErr() bool {
  16. return r.Code != CodeType_OK
  17. }
  18. // Error implements error interface by formatting response as string.
  19. func (r ResponseDeliverTx) Error() string {
  20. return fmtError(r.Code, r.Log)
  21. }
  22. // IsErr returns true if Code is something other than OK.
  23. func (r ResponseCommit) IsErr() bool {
  24. return r.Code != CodeType_OK
  25. }
  26. // Error implements error interface by formatting response as string.
  27. func (r ResponseCommit) Error() string {
  28. return fmtError(r.Code, r.Log)
  29. }
  30. func fmtError(code CodeType, log string) string {
  31. codeAsStr, ok := code2string[code]
  32. if ok {
  33. return fmt.Sprintf("%s (%d): %s", codeAsStr, code, log)
  34. } else {
  35. return fmt.Sprintf("Unknown error (%d): %s", code, log)
  36. }
  37. }
  38. // ResultQuery is a wrapper around ResponseQuery using data.Bytes instead of
  39. // raw byte slices.
  40. type ResultQuery struct {
  41. Code CodeType `json:"code"`
  42. Index int64 `json:"index"`
  43. Key data.Bytes `json:"key"`
  44. Value data.Bytes `json:"value"`
  45. Proof data.Bytes `json:"proof"`
  46. Height uint64 `json:"height"`
  47. Log string `json:"log"`
  48. }
  49. // Result converts response query to ResultQuery.
  50. func (r *ResponseQuery) Result() *ResultQuery {
  51. return &ResultQuery{
  52. Code: r.Code,
  53. Index: r.Index,
  54. Key: r.Key,
  55. Value: r.Value,
  56. Proof: r.Proof,
  57. Height: r.Height,
  58. Log: r.Log,
  59. }
  60. }
  61. // IsErr returns true if Code is something other than OK.
  62. func (r *ResultQuery) IsErr() bool {
  63. return r.Code != CodeType_OK
  64. }
  65. // Error implements error interface by formatting result as string.
  66. func (r *ResultQuery) Error() string {
  67. return fmtError(r.Code, r.Log)
  68. }