github.com/aakash4dev/cometbft@v0.38.2/types/results.go (about)

     1  package types
     2  
     3  import (
     4  	abci "github.com/aakash4dev/cometbft/abci/types"
     5  	"github.com/aakash4dev/cometbft/crypto/merkle"
     6  )
     7  
     8  // ABCIResults wraps the deliver tx results to return a proof.
     9  type ABCIResults []*abci.ExecTxResult
    10  
    11  // NewResults strips non-deterministic fields from ExecTxResult responses
    12  // and returns ABCIResults.
    13  func NewResults(responses []*abci.ExecTxResult) ABCIResults {
    14  	res := make(ABCIResults, len(responses))
    15  	for i, d := range responses {
    16  		res[i] = abci.DeterministicExecTxResult(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  }