mukan-ibc/modules/light-clients/06-solomachine/header.go
Mukan Erkin Törük 6852832fe8
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
initial: sovereign Mukan Network fork
2026-05-11 03:18:28 +03:00

61 lines
1.8 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"
)
// SentinelHeaderPath defines a placeholder path value used for headers in solomachine client updates
const SentinelHeaderPath = "solomachine:header"
var _ exported.ClientMessage = (*Header)(nil)
// ClientType defines that the Header is a Solo Machine.
func (Header) ClientType() string {
return exported.Solomachine
}
// GetPubKey unmarshals the new public key into a cryptotypes.PubKey type.
// An error is returned if the new public key is nil or the cached value
// is not a PubKey.
func (h Header) GetPubKey() (cryptotypes.PubKey, error) {
if h.NewPublicKey == nil {
return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey cannot be nil")
}
publicKey, ok := h.NewPublicKey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return nil, errorsmod.Wrap(ErrInvalidHeader, "header NewPublicKey is not cryptotypes.PubKey")
}
return publicKey, nil
}
// ValidateBasic ensures that the timestamp, signature and public key have all
// been initialized.
func (h Header) ValidateBasic() error {
if h.Timestamp == 0 {
return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "timestamp cannot be zero")
}
if h.NewDiversifier != "" && strings.TrimSpace(h.NewDiversifier) == "" {
return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "diversifier cannot contain only spaces")
}
if len(h.Signature) == 0 {
return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "signature cannot be empty")
}
newPublicKey, err := h.GetPubKey()
if err != nil || newPublicKey == nil || len(newPublicKey.Bytes()) == 0 {
return errorsmod.Wrap(clienttypes.ErrInvalidHeader, "new public key cannot be empty")
}
return nil
}