2016-03-20 17:10:13 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-27 16:18:53 -07:00
|
|
|
|
|
|
|
"github.com/tendermint/go-wire/data"
|
2016-03-20 17:10:13 -07:00
|
|
|
)
|
|
|
|
|
2017-11-30 11:29:12 -08:00
|
|
|
// type CodeType uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
CodeTypeOK uint32 = 0
|
|
|
|
)
|
|
|
|
|
2017-11-21 15:33:34 -08:00
|
|
|
// IsErr returns true if Code is something other than OK.
|
2017-11-20 18:26:37 -08:00
|
|
|
func (r ResponseCheckTx) IsErr() bool {
|
2017-11-30 11:29:12 -08:00
|
|
|
return r.Code != CodeTypeOK
|
2017-11-20 18:26:37 -08:00
|
|
|
}
|
|
|
|
|
2017-11-22 14:17:34 -08:00
|
|
|
// Error implements error interface by formatting response as string.
|
|
|
|
func (r ResponseCheckTx) Error() string {
|
|
|
|
return fmtError(r.Code, r.Log)
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:33:34 -08:00
|
|
|
// IsErr returns true if Code is something other than OK.
|
2017-11-20 18:26:37 -08:00
|
|
|
func (r ResponseDeliverTx) IsErr() bool {
|
2017-11-30 11:29:12 -08:00
|
|
|
return r.Code != CodeTypeOK
|
2017-11-20 18:26:37 -08:00
|
|
|
}
|
|
|
|
|
2017-11-22 14:17:34 -08:00
|
|
|
// Error implements error interface by formatting response as string.
|
|
|
|
func (r ResponseDeliverTx) Error() string {
|
|
|
|
return fmtError(r.Code, r.Log)
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:44:39 -08:00
|
|
|
// IsErr returns true if Code is something other than OK.
|
|
|
|
func (r ResponseCommit) IsErr() bool {
|
2017-11-30 11:29:12 -08:00
|
|
|
return r.Code != CodeTypeOK
|
2017-11-22 15:44:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error implements error interface by formatting response as string.
|
|
|
|
func (r ResponseCommit) Error() string {
|
|
|
|
return fmtError(r.Code, r.Log)
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:29:12 -08:00
|
|
|
func fmtError(code uint32, log string) string {
|
|
|
|
return fmt.Sprintf("Error code (%d): %s", code, log)
|
2017-11-22 15:44:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResultQuery is a wrapper around ResponseQuery using data.Bytes instead of
|
|
|
|
// raw byte slices.
|
2017-04-27 16:53:22 -07:00
|
|
|
type ResultQuery struct {
|
2017-11-30 11:29:12 -08:00
|
|
|
Code uint32 `json:"code"`
|
2017-04-27 16:53:22 -07:00
|
|
|
Index int64 `json:"index"`
|
|
|
|
Key data.Bytes `json:"key"`
|
|
|
|
Value data.Bytes `json:"value"`
|
|
|
|
Proof data.Bytes `json:"proof"`
|
|
|
|
Height uint64 `json:"height"`
|
|
|
|
Log string `json:"log"`
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:44:39 -08:00
|
|
|
// Result converts response query to ResultQuery.
|
2017-04-27 16:53:22 -07:00
|
|
|
func (r *ResponseQuery) Result() *ResultQuery {
|
|
|
|
return &ResultQuery{
|
|
|
|
Code: r.Code,
|
|
|
|
Index: r.Index,
|
|
|
|
Key: r.Key,
|
|
|
|
Value: r.Value,
|
|
|
|
Proof: r.Proof,
|
|
|
|
Height: r.Height,
|
|
|
|
Log: r.Log,
|
|
|
|
}
|
|
|
|
}
|
2017-11-22 16:19:41 -08:00
|
|
|
|
|
|
|
// IsErr returns true if Code is something other than OK.
|
|
|
|
func (r *ResultQuery) IsErr() bool {
|
2017-11-30 11:29:12 -08:00
|
|
|
return r.Code != CodeTypeOK
|
2017-11-22 16:19:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error implements error interface by formatting result as string.
|
|
|
|
func (r *ResultQuery) Error() string {
|
|
|
|
return fmtError(r.Code, r.Log)
|
|
|
|
}
|