mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 20:21:56 +00:00
Group (code,data,log) return values into types.Result
This commit is contained in:
@@ -10,16 +10,16 @@ type Application interface {
|
||||
SetOption(key string, value string) (log string)
|
||||
|
||||
// Append a tx
|
||||
AppendTx(tx []byte) (code CodeType, result []byte, log string)
|
||||
AppendTx(tx []byte) Result
|
||||
|
||||
// Validate a tx for the mempool
|
||||
CheckTx(tx []byte) (code CodeType, result []byte, log string)
|
||||
CheckTx(tx []byte) Result
|
||||
|
||||
// Return the application Merkle root hash
|
||||
Commit() (hash []byte, log string)
|
||||
|
||||
// Query for state
|
||||
Query(query []byte) (code CodeType, result []byte, log string)
|
||||
Query(query []byte) Result
|
||||
}
|
||||
|
||||
// Some applications can choose to implement BlockchainAware
|
||||
|
37
types/result.go
Normal file
37
types/result.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
Code CodeType
|
||||
Data []byte
|
||||
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
|
||||
}
|
||||
|
||||
func (res Result) Error() string {
|
||||
return fmt.Sprintf("TMSP error code:%v, data:%X, log:%v", res.Code, res.Data, res.Log)
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
func NewResultOK(data []byte, log string) Result {
|
||||
return Result{
|
||||
Code: CodeType_OK,
|
||||
Data: data,
|
||||
Log: log,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user