Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package solomachine
|
|
|
|
import (
|
|
"strings"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
|
|
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
|
|
"github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
)
|
|
|
|
var _ exported.ConsensusState = (*ConsensusState)(nil)
|
|
|
|
// ClientType returns Solo Machine type.
|
|
func (ConsensusState) ClientType() string {
|
|
return exported.Solomachine
|
|
}
|
|
|
|
// GetTimestamp returns zero.
|
|
func (cs ConsensusState) GetTimestamp() uint64 {
|
|
return cs.Timestamp
|
|
}
|
|
|
|
// GetPubKey unmarshals the public key into a cryptotypes.PubKey type.
|
|
// An error is returned if the public key is nil or the cached value
|
|
// is not a PubKey.
|
|
func (cs ConsensusState) GetPubKey() (cryptotypes.PubKey, error) {
|
|
if cs.PublicKey == nil {
|
|
return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey cannot be nil")
|
|
}
|
|
|
|
publicKey, ok := cs.PublicKey.GetCachedValue().(cryptotypes.PubKey)
|
|
if !ok {
|
|
return nil, errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "consensus state PublicKey is not cryptotypes.PubKey")
|
|
}
|
|
|
|
return publicKey, nil
|
|
}
|
|
|
|
// ValidateBasic defines basic validation for the solo machine consensus state.
|
|
func (cs ConsensusState) ValidateBasic() error {
|
|
if cs.Timestamp == 0 {
|
|
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "timestamp cannot be 0")
|
|
}
|
|
if cs.Diversifier != "" && strings.TrimSpace(cs.Diversifier) == "" {
|
|
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "diversifier cannot contain only spaces")
|
|
}
|
|
|
|
publicKey, err := cs.GetPubKey()
|
|
if err != nil || publicKey == nil || len(publicKey.Bytes()) == 0 {
|
|
return errorsmod.Wrap(clienttypes.ErrInvalidConsensus, "public key cannot be empty")
|
|
}
|
|
|
|
return nil
|
|
}
|