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-09-18 12:51:48 -07:00
|
|
|
// Result is a common result object for ABCI calls.
|
2016-03-22 15:18:03 -07:00
|
|
|
// CONTRACT: a zero Result is OK.
|
2016-03-20 17:10:13 -07:00
|
|
|
type Result struct {
|
2017-04-27 16:53:22 -07:00
|
|
|
Code CodeType `json:"code"`
|
|
|
|
Data data.Bytes `json:"data"`
|
|
|
|
Log string `json:"log"` // Can be non-deterministic
|
2017-11-09 13:52:52 -08:00
|
|
|
Tags []*KVPair `json:"tags"`
|
2016-03-20 17:10:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewResult(code CodeType, data []byte, log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: code,
|
|
|
|
Data: data,
|
|
|
|
Log: log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res Result) IsOK() bool {
|
|
|
|
return res.Code == CodeType_OK
|
|
|
|
}
|
|
|
|
|
2016-03-23 02:50:29 -07:00
|
|
|
func (res Result) IsErr() bool {
|
|
|
|
return res.Code != CodeType_OK
|
|
|
|
}
|
|
|
|
|
2017-05-13 16:08:04 -07:00
|
|
|
func (res Result) IsSameCode(compare Result) bool {
|
|
|
|
return res.Code == compare.Code
|
|
|
|
}
|
|
|
|
|
2016-03-20 17:10:13 -07:00
|
|
|
func (res Result) Error() string {
|
2017-01-15 14:43:16 -08:00
|
|
|
return fmt.Sprintf("ABCI{code:%v, data:%X, log:%v}", res.Code, res.Data, res.Log)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res Result) String() string {
|
|
|
|
return fmt.Sprintf("ABCI{code:%v, data:%X, log:%v}", res.Code, res.Data, res.Log)
|
2016-03-20 17:10:13 -07:00
|
|
|
}
|
|
|
|
|
2016-03-21 15:33:16 -07:00
|
|
|
func (res Result) PrependLog(log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: res.Code,
|
|
|
|
Data: res.Data,
|
|
|
|
Log: log + ";" + res.Log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res Result) AppendLog(log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: res.Code,
|
|
|
|
Data: res.Data,
|
|
|
|
Log: res.Log + ";" + log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res Result) SetLog(log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: res.Code,
|
|
|
|
Data: res.Data,
|
|
|
|
Log: log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (res Result) SetData(data []byte) Result {
|
|
|
|
return Result{
|
|
|
|
Code: res.Code,
|
|
|
|
Data: data,
|
|
|
|
Log: res.Log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-20 17:10:13 -07:00
|
|
|
//----------------------------------------
|
|
|
|
|
2016-03-22 15:18:03 -07:00
|
|
|
// NOTE: if data == nil and log == "", same as zero Result.
|
2016-03-20 17:10:13 -07:00
|
|
|
func NewResultOK(data []byte, log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: CodeType_OK,
|
|
|
|
Data: data,
|
|
|
|
Log: log,
|
|
|
|
}
|
|
|
|
}
|
2016-03-20 17:20:41 -07:00
|
|
|
|
|
|
|
func NewError(code CodeType, log string) Result {
|
|
|
|
return Result{
|
|
|
|
Code: code,
|
|
|
|
Log: log,
|
|
|
|
}
|
|
|
|
}
|
2017-04-27 16:53:22 -07:00
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// Convenience methods for turning the
|
|
|
|
// pb type into one using data.Bytes
|
|
|
|
|
|
|
|
// Convert ResponseCheckTx to standard Result
|
|
|
|
func (r *ResponseCheckTx) Result() Result {
|
|
|
|
return Result{
|
|
|
|
Code: r.Code,
|
|
|
|
Data: r.Data,
|
|
|
|
Log: r.Log,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert ResponseDeliverTx to standard Result
|
|
|
|
func (r *ResponseDeliverTx) Result() Result {
|
|
|
|
return Result{
|
|
|
|
Code: r.Code,
|
|
|
|
Data: r.Data,
|
|
|
|
Log: r.Log,
|
2017-11-09 13:52:52 -08:00
|
|
|
Tags: r.Tags,
|
2017-04-27 16:53:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResultQuery struct {
|
|
|
|
Code CodeType `json:"code"`
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|