github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/types/results.go (about) 1 package types 2 3 import ( 4 "github.com/gnolang/gno/tm2/pkg/amino" 5 abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types" 6 "github.com/gnolang/gno/tm2/pkg/crypto/merkle" 7 ) 8 9 //----------------------------------------------------------------------------- 10 11 // ABCIResult is the deterministic component of a ResponseDeliverTx. 12 // TODO: add tags and other fields 13 // https://github.com/tendermint/classic/issues/1007 14 type ABCIResult struct { 15 Error abci.Error `json:"error"` 16 Data []byte `json:"data"` 17 Events []abci.Event `json:"events"` 18 } 19 20 // Bytes returns the amino encoded ABCIResult 21 func (a ABCIResult) Bytes() []byte { 22 return bytesOrNil(a) 23 } 24 25 // ABCIResults wraps the deliver tx results to return a proof 26 type ABCIResults []ABCIResult 27 28 // NewResults creates ABCIResults from the list of ResponseDeliverTx. 29 func NewResults(responses []abci.ResponseDeliverTx) ABCIResults { 30 res := make(ABCIResults, len(responses)) 31 for i, d := range responses { 32 res[i] = NewResultFromResponse(d) 33 } 34 return res 35 } 36 37 // NewResultFromResponse creates ABCIResult from ResponseDeliverTx. 38 func NewResultFromResponse(response abci.ResponseDeliverTx) ABCIResult { 39 return ABCIResult{ 40 Error: response.Error, 41 Data: response.Data, 42 Events: response.Events, 43 } 44 } 45 46 // Bytes serializes the ABCIResponse using amino 47 func (a ABCIResults) Bytes() []byte { 48 bz, err := amino.MarshalSized(a) // XXX: not length-prefixed 49 if err != nil { 50 panic(err) 51 } 52 return bz 53 } 54 55 // Hash returns a merkle hash of all results 56 func (a ABCIResults) Hash() []byte { 57 // NOTE: we copy the impl of the merkle tree for txs - 58 // we should be consistent and either do it for both or not. 59 return merkle.SimpleHashFromByteSlices(a.toByteSlices()) 60 } 61 62 // ProveResult returns a merkle proof of one result from the set 63 func (a ABCIResults) ProveResult(i int) merkle.SimpleProof { 64 _, proofs := merkle.SimpleProofsFromByteSlices(a.toByteSlices()) 65 return *proofs[i] 66 } 67 68 func (a ABCIResults) toByteSlices() [][]byte { 69 l := len(a) 70 bzs := make([][]byte, l) 71 for i := 0; i < l; i++ { 72 bzs[i] = a[i].Bytes() 73 } 74 return bzs 75 }