Group (code,data,log) return values into types.Result

This commit is contained in:
Jae Kwon
2016-03-20 17:10:13 -07:00
parent 29a6d511b4
commit 55e2ce9de2
6 changed files with 74 additions and 29 deletions

View File

@@ -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
View 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,
}
}