consolidate saveResults/SaveABCIResponses

This commit is contained in:
Ethan Buchman
2017-12-26 19:24:45 -05:00
parent d65234ed51
commit 73fb1c3a17
6 changed files with 120 additions and 154 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ type Header struct {
LastCommitHash data.Bytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash data.Bytes `json:"data_hash"` // transactions
// hashes from the app
// hashes from the app output from the prev block
ValidatorsHash data.Bytes `json:"validators_hash"` // validators for the current block
ConsensusHash data.Bytes `json:"consensus_hash"` // consensus params for current block
AppHash data.Bytes `json:"app_hash"` // state after txs from the previous block
+10 -7
View File
@@ -13,14 +13,13 @@ import (
//-----------------------------------------------------------------------------
// ABCIResult is just the essential info to prove
// success/failure of a DeliverTx
// ABCIResult is the deterministic component of a ResponseDeliverTx.
type ABCIResult struct {
Code uint32 `json:"code"`
Data data.Bytes `json:"data"`
}
// Hash creates a canonical json hash of the ABCIResult
// Hash returns the canonical json hash of the ABCIResult
func (a ABCIResult) Hash() []byte {
// stupid canonical json output, easy to check in any language
bs := fmt.Sprintf(`{"code":%d,"data":"%s"}`, a.Code, a.Data)
@@ -36,14 +35,18 @@ type ABCIResults []ABCIResult
func NewResults(del []*abci.ResponseDeliverTx) ABCIResults {
res := make(ABCIResults, len(del))
for i, d := range del {
res[i] = ABCIResult{
Code: d.Code,
Data: d.Data,
}
res[i] = NewResultFromResponse(d)
}
return res
}
func NewResultFromResponse(response *abci.ResponseDeliverTx) ABCIResult {
return ABCIResult{
Code: response.Code,
Data: response.Data,
}
}
// Bytes serializes the ABCIResponse using go-wire
func (a ABCIResults) Bytes() []byte {
return wire.BinaryBytes(a)