Some checks failed
CodeQL / Analyze (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
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package solomachine
|
|
|
|
import (
|
|
"strings"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
|
|
cryptotypes "git.cw.tr/mukan-network/mukan-sdk/crypto/types"
|
|
|
|
clienttypes "git.cw.tr/mukan-network/mukan-ibc/modules/core/02-client/types"
|
|
"git.cw.tr/mukan-network/mukan-ibc/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
|
|
}
|