From 8d8e35ae537538c9cf6808be3ca9dd7dab81b7f6 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 27 Apr 2017 19:53:22 -0400 Subject: [PATCH] types: methods convert pb types to use data.Bytes --- types/result.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/types/result.go b/types/result.go index d7e231d80..c7f2d565c 100644 --- a/types/result.go +++ b/types/result.go @@ -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, + } +}