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