2017-12-22 08:59:52 -08:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
abci "github.com/tendermint/abci/types"
|
|
|
|
wire "github.com/tendermint/go-wire"
|
|
|
|
"github.com/tendermint/go-wire/data"
|
|
|
|
"github.com/tendermint/tmlibs/merkle"
|
|
|
|
)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-12-25 10:47:16 -08:00
|
|
|
// ABCIResult is the deterministic component of a ResponseDeliverTx.
|
2017-12-26 16:53:26 -08:00
|
|
|
// TODO: add Tags
|
2017-12-22 08:59:52 -08:00
|
|
|
type ABCIResult struct {
|
|
|
|
Code uint32 `json:"code"`
|
|
|
|
Data data.Bytes `json:"data"`
|
|
|
|
}
|
|
|
|
|
2017-12-26 16:53:26 -08:00
|
|
|
// Hash returns the canonical hash of the ABCIResult
|
2017-12-22 08:59:52 -08:00
|
|
|
func (a ABCIResult) Hash() []byte {
|
2017-12-26 16:53:26 -08:00
|
|
|
return wire.BinaryRipemd160(a)
|
2017-12-22 08:59:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ABCIResults wraps the deliver tx results to return a proof
|
|
|
|
type ABCIResults []ABCIResult
|
|
|
|
|
|
|
|
// NewResults creates ABCIResults from ResponseDeliverTx
|
|
|
|
func NewResults(del []*abci.ResponseDeliverTx) ABCIResults {
|
|
|
|
res := make(ABCIResults, len(del))
|
|
|
|
for i, d := range del {
|
2017-12-25 10:47:16 -08:00
|
|
|
res[i] = NewResultFromResponse(d)
|
2017-12-22 08:59:52 -08:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2017-12-25 10:47:16 -08:00
|
|
|
func NewResultFromResponse(response *abci.ResponseDeliverTx) ABCIResult {
|
|
|
|
return ABCIResult{
|
|
|
|
Code: response.Code,
|
|
|
|
Data: response.Data,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 08:59:52 -08:00
|
|
|
// Bytes serializes the ABCIResponse using go-wire
|
|
|
|
func (a ABCIResults) Bytes() []byte {
|
|
|
|
return wire.BinaryBytes(a)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hash returns a merkle hash of all results
|
|
|
|
func (a ABCIResults) Hash() []byte {
|
2018-02-03 00:23:10 -08:00
|
|
|
return merkle.SimpleHashFromHashers(a.toHashers())
|
2017-12-22 08:59:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProveResult returns a merkle proof of one result from the set
|
|
|
|
func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
|
2018-02-03 00:23:10 -08:00
|
|
|
_, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
|
2017-12-22 08:59:52 -08:00
|
|
|
return *proofs[i]
|
|
|
|
}
|
|
|
|
|
2018-02-03 00:23:10 -08:00
|
|
|
func (a ABCIResults) toHashers() []merkle.Hasher {
|
2017-12-22 08:59:52 -08:00
|
|
|
l := len(a)
|
2018-02-03 00:23:10 -08:00
|
|
|
hashers := make([]merkle.Hasher, l)
|
2017-12-22 08:59:52 -08:00
|
|
|
for i := 0; i < l; i++ {
|
2018-02-03 00:23:10 -08:00
|
|
|
hashers[i] = a[i]
|
2017-12-22 08:59:52 -08:00
|
|
|
}
|
2018-02-03 00:23:10 -08:00
|
|
|
return hashers
|
2017-12-22 08:59:52 -08:00
|
|
|
}
|