2016-03-20 17:10:13 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-27 19:18:53 -04:00
|
|
|
|
|
|
|
"github.com/tendermint/go-wire/data"
|
2016-03-20 17:10:13 -07:00
|
|
|
)
|
|
|
|
|
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 {
|
|
|
|
Code CodeType
|
2017-04-27 19:18:53 -04:00
|
|
|
Data data.Bytes
|
2016-03-20 17:10:13 -07:00
|
|
|
Log string // Can be non-deterministic
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|