types: methods convert pb types to use data.Bytes

This commit is contained in:
Ethan Buchman 2017-04-27 19:53:22 -04:00
parent 8339dc3b1a
commit 8d8e35ae53
1 changed files with 47 additions and 3 deletions

View File

@ -8,9 +8,9 @@ import (
// CONTRACT: a zero Result is OK.
type Result struct {
Code CodeType
Data data.Bytes
Log string // Can be non-deterministic
Code CodeType `json:"code"`
Data data.Bytes `json:"data"`
Log string `json:"log"` // Can be non-deterministic
}
func NewResult(code CodeType, data []byte, log string) Result {
@ -86,3 +86,47 @@ func NewError(code CodeType, log string) Result {
Log: log,
}
}
//----------------------------------------
// 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,
}
}
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,
}
}