gitlab.com/gpdionisio/tendermint@v0.34.19-dev2/types/results.go (about) 1 package types 2 3 import ( 4 abci "github.com/tendermint/tendermint/abci/types" 5 "github.com/tendermint/tendermint/crypto/merkle" 6 ) 7 8 // ABCIResults wraps the deliver tx results to return a proof. 9 type ABCIResults []*abci.ResponseDeliverTx 10 11 // NewResults strips non-deterministic fields from ResponseDeliverTx responses 12 // and returns ABCIResults. 13 func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults { 14 res := make(ABCIResults, len(responses)) 15 for i, d := range responses { 16 res[i] = deterministicResponseDeliverTx(d) 17 } 18 return res 19 } 20 21 // Hash returns a merkle hash of all results. 22 func (a ABCIResults) Hash() []byte { 23 return merkle.HashFromByteSlices(a.toByteSlices()) 24 } 25 26 // ProveResult returns a merkle proof of one result from the set 27 func (a ABCIResults) ProveResult(i int) merkle.Proof { 28 _, proofs := merkle.ProofsFromByteSlices(a.toByteSlices()) 29 return *proofs[i] 30 } 31 32 func (a ABCIResults) toByteSlices() [][]byte { 33 l := len(a) 34 bzs := make([][]byte, l) 35 for i := 0; i < l; i++ { 36 bz, err := a[i].Marshal() 37 if err != nil { 38 panic(err) 39 } 40 bzs[i] = bz 41 } 42 return bzs 43 } 44 45 // deterministicResponseDeliverTx strips non-deterministic fields from 46 // ResponseDeliverTx and returns another ResponseDeliverTx. 47 func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.ResponseDeliverTx { 48 return &abci.ResponseDeliverTx{ 49 Code: response.Code, 50 Data: response.Data, 51 GasWanted: response.GasWanted, 52 GasUsed: response.GasUsed, 53 } 54 }