github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/types/results.go (about) 1 package types 2 3 import ( 4 abci "github.com/ari-anchor/sei-tendermint/abci/types" 5 "github.com/ari-anchor/sei-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 func (a ABCIResults) Hash() []byte { 22 return merkle.HashFromByteSlices(a.toByteSlices()) 23 } 24 25 func (a ABCIResults) ProveResult(i int) merkle.Proof { 26 _, proofs := merkle.ProofsFromByteSlices(a.toByteSlices()) 27 return *proofs[i] 28 } 29 30 func (a ABCIResults) toByteSlices() [][]byte { 31 l := len(a) 32 bzs := make([][]byte, l) 33 for i := 0; i < l; i++ { 34 bz, err := a[i].Marshal() 35 if err != nil { 36 panic(err) 37 } 38 bzs[i] = bz 39 } 40 return bzs 41 } 42 43 func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.ResponseDeliverTx { 44 return &abci.ResponseDeliverTx{ 45 Code: response.Code, 46 Data: response.Data, 47 GasWanted: response.GasWanted, 48 GasUsed: response.GasUsed, 49 } 50 }