mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 05:25:35 +00:00
remove gas from merklization in headers Im not sure where to change docs since main points to the spec repo but that repo is archived. Maybe someone can help me?
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package types
|
|
|
|
import (
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/crypto/merkle"
|
|
)
|
|
|
|
// ABCIResults wraps the deliver tx results to return a proof.
|
|
type ABCIResults []*abci.ResponseDeliverTx
|
|
|
|
// NewResults strips non-deterministic fields from ResponseDeliverTx responses
|
|
// and returns ABCIResults.
|
|
func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults {
|
|
res := make(ABCIResults, len(responses))
|
|
for i, d := range responses {
|
|
res[i] = deterministicResponseDeliverTx(d)
|
|
}
|
|
return res
|
|
}
|
|
|
|
// Hash returns a merkle hash of all results.
|
|
func (a ABCIResults) Hash() []byte {
|
|
return merkle.HashFromByteSlices(a.toByteSlices())
|
|
}
|
|
|
|
// ProveResult returns a merkle proof of one result from the set
|
|
func (a ABCIResults) ProveResult(i int) merkle.Proof {
|
|
_, proofs := merkle.ProofsFromByteSlices(a.toByteSlices())
|
|
return *proofs[i]
|
|
}
|
|
|
|
func (a ABCIResults) toByteSlices() [][]byte {
|
|
l := len(a)
|
|
bzs := make([][]byte, l)
|
|
for i := 0; i < l; i++ {
|
|
bz, err := a[i].Marshal()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
bzs[i] = bz
|
|
}
|
|
return bzs
|
|
}
|
|
|
|
// deterministicResponseDeliverTx strips non-deterministic fields from
|
|
// ResponseDeliverTx and returns another ResponseDeliverTx.
|
|
func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.ResponseDeliverTx {
|
|
return &abci.ResponseDeliverTx{
|
|
Code: response.Code,
|
|
Data: response.Data,
|
|
}
|
|
}
|