Skip to content

Commit

Permalink
Merge pull request #77 from hyperledger-labs/query-header
Browse files Browse the repository at this point in the history
Add QueryHeader method to ProverI

Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
  • Loading branch information
bluele authored Sep 20, 2022
2 parents e51bc1f + c96e1bd commit cffbe7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion chains/tendermint/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ func (pr *Prover) QueryPacketAcknowledgementCommitmentWithProof(height int64, se
return pr.chain.queryPacketAcknowledgementCommitment(height, seq, true)
}

// QueryHeader returns the header corresponding to the height
func (pr *Prover) QueryHeader(height int64) (out core.HeaderI, err error) {
return pr.queryHeaderAtHeight(height)
}

// QueryLatestHeader returns the latest header from the chain
func (pr *Prover) QueryLatestHeader() (out core.HeaderI, err error) {
var h int64
if h, err = pr.chain.GetLatestHeight(); err != nil {
return nil, err
}
return pr.queryHeaderAtHeight(h)
return pr.QueryHeader(h)
}

// GetLatestLightHeight uses the CLI utilities to pull the latest height from a given chain
Expand Down
3 changes: 3 additions & 0 deletions core/provers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type LightClientI interface {
// GetChainID returns the chain ID
GetChainID() string

// QueryHeader returns the header corresponding to the height
QueryHeader(height int64) (out HeaderI, err error)

// QueryLatestHeader returns the latest header from the chain
QueryLatestHeader() (out HeaderI, err error)

Expand Down
9 changes: 9 additions & 0 deletions provers/mock/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mock
import (
"context"
"crypto/sha256"
"fmt"
"time"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -46,6 +47,14 @@ func (pr *Prover) GetChainID() string {
return pr.chain.ChainID()
}

// QueryHeader returns the header corresponding to the height
func (pr *Prover) QueryHeader(height int64) (out core.HeaderI, err error) {
if height != int64(pr.sequence) {
return nil, fmt.Errorf("mock prover does not support querying old headers: got=%v latest=%v", height, pr.sequence)
}
return pr.QueryLatestHeader()
}

// QueryLatestHeader returns the latest header from the chain
func (pr *Prover) QueryLatestHeader() (out core.HeaderI, err error) {
var header = mocktypes.Header{
Expand Down

0 comments on commit cffbe7b

Please sign in to comment.