diff --git a/abci/extend_vote.go b/abci/extend_vote.go new file mode 100644 index 00000000..b2a5e25d --- /dev/null +++ b/abci/extend_vote.go @@ -0,0 +1,24 @@ +package vote_ext + +import ( + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { + return func(ctx sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) { + + if req.GetHeight() < 3 { + return &abci.ResponseExtendVote{VoteExtension: []byte{}}, nil + } + + body, err := h.constructVoteExtBody(ctx, req.GetHeight()) + if err != nil { + return nil, err + } + + bz := h.secondaryKey.SignVoteExtBody(body) + + return &abci.ResponseExtendVote{VoteExtension: bz}, nil + } +} diff --git a/abci/handler.go b/abci/handler.go new file mode 100644 index 00000000..4ce74ec8 --- /dev/null +++ b/abci/handler.go @@ -0,0 +1,30 @@ +package vote_ext + +import ( + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/node101-io/mina-signer-go/keys" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + votepersistence "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" +) + +type SecondaryKey struct { + SecretKey *keys.PrivateKey + PublicKey *keys.PublicKey +} + +type AbciHandler struct { + secondaryKey SecondaryKey + stakingKeeper stakingkeeper.Keeper + keyregistryKeeper keyregistrykeeper.Keeper + votePersistenceKeeper votepersistence.Keeper +} + +func NewABCIHandler(secondaryKey SecondaryKey, stakingKeeper stakingkeeper.Keeper, + keyregistryKeeper keyregistrykeeper.Keeper, votepersistenceKeeper votepersistence.Keeper) *AbciHandler { + return &AbciHandler{ + secondaryKey: secondaryKey, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + votePersistenceKeeper: votepersistenceKeeper, + } +} diff --git a/abci/helpers.go b/abci/helpers.go new file mode 100644 index 00000000..63a35db4 --- /dev/null +++ b/abci/helpers.go @@ -0,0 +1,367 @@ +package vote_ext + +import ( + "bytes" + "context" + "encoding/hex" + "math/big" + "sort" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/mina-signer-go/poseidon" + minasignature "github.com/node101-io/mina-signer-go/signature" + abcipb "github.com/node101-io/pulsar-chain/api/pulsarchain/abci" + keyregistryTypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + votepersistenceTypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func (s *SecondaryKey) SignVoteExtBody(voteExtBody votepersistenceTypes.VoteExtBody) []byte { + if s == nil || s.SecretKey == nil { + return nil + } + + msg, err := voteExtBody.Marshal() + if err != nil { + return nil + } + + sig, err := s.SecretKey.SignMessage(hex.EncodeToString(msg), "testnet") + if err != nil { + return nil + } + + bz, err := sig.MarshalBytes() + if err != nil { + return nil + } + + return bz +} + +func VerifyVoteExtSig(signature []byte, message votepersistenceTypes.VoteExtBody, minaKey []byte, reducedRoot string) bool { + if message.ActionsReducedRoot != reducedRoot { + return false + } + + var pubKey keys.PublicKey + if err := pubKey.Unmarshal(minaKey); err != nil { + return false + } + + var sig minasignature.Signature + if err := sig.UnmarshalBytes(signature); err != nil { + return false + } + + msg, err := message.Marshal() + if err != nil { + return false + } + + return pubKey.VerifyMessage(&sig, hex.EncodeToString(msg), "testnet") +} + +func extractPayload(txs [][]byte) (abcipb.Payload, error) { + + if len(txs) == 0 { + return abcipb.Payload{}, nil + } + + if !bytes.HasPrefix(txs[0], []byte(VoteExtMarker)) { + return abcipb.Payload{}, types.ErrVoteExtMarkerNotFound + } + + voteExtensionTx := txs[0][len([]byte(VoteExtMarker)):] + + var pl abcipb.Payload + + err := pl.Unmarshal(voteExtensionTx) + if err != nil { + return abcipb.Payload{}, err + } + return pl, nil +} + +func (h *AbciHandler) verifyVoteExtension(ctx context.Context, pl abcipb.Payload, body votepersistenceTypes.VoteExtBody) error { + + for _, vote := range pl.Votes { + + pk, err := hex.DecodeString(vote.ConsensusPublicKey) + if err != nil { + return err + } + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, pk) + if err != nil { + return err + } + if !exists { + return keyregistryTypes.ErrValidatorNotRegistered + } + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, pk) + if err != nil { + return err + } + + if !VerifyVoteExtSig(vote.VoteExtension, body, minaKey, ActionsReducedRoot) { + return types.ErrInvalidVoteExtension.Wrap("invalid signature") + } + + } + + return nil +} + +// Use if you need the validator set of block < N where N is the current block number. +func (h *AbciHandler) getValidatorSet(ctx sdk.Context, currentBlockHeight int64) ([]stakingTypes.ValidatorI, error) { + + var valInfo []stakingTypes.ValidatorI + + if ctx.BlockHeight() == currentBlockHeight { + err := h.stakingKeeper.IterateLastValidators(ctx, func(index int64, validator stakingTypes.ValidatorI) (stop bool) { + valInfo = append(valInfo, validator) + return false + }) + + if err != nil { + return nil, err + } + sortValidatorsByPower(valInfo) + + return valInfo, nil + } + + historicalData, err := h.stakingKeeper.GetHistoricalInfo(ctx, currentBlockHeight) + if err != nil { + return nil, err + } + for _, validator := range historicalData.Valset { + valInfo = append(valInfo, validator) + } + + sortValidatorsByPower(valInfo) + + return valInfo, nil +} + +func sortValidatorsByPower(validators []stakingTypes.ValidatorI) { + sort.SliceStable(validators, func(i, j int) bool { + leftPower := validators[i].GetConsensusPower(sdk.DefaultPowerReduction) + rightPower := validators[j].GetConsensusPower(sdk.DefaultPowerReduction) + + if leftPower == rightPower { + leftAddr, err := validators[i].GetConsAddr() + if err != nil { + return false + } + rightAddr, err := validators[j].GetConsAddr() + if err != nil { + return false + } + + return bytes.Compare(leftAddr, rightAddr) == -1 + } + + return leftPower > rightPower + }) +} + +// TODO: Move this helper to mina-signer-go +func (h *AbciHandler) calculateValidatorSetRoot(ctx sdk.Context, valInfo []stakingTypes.ValidatorI, poseidonHash *poseidon.Poseidon) (*big.Int, error) { + + input := []*big.Int{big.NewInt(0)} + merkleRoot := poseidonHash.Hash(input) + + for _, validator := range valInfo { + input = []*big.Int{} + + consAddr, err := validator.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, consAddr) + if err != nil { + return nil, err + } + + cosmosValidatorPubKey, err := cosmosValidatorInfo.ConsPubKey() + if err != nil { + return nil, err + } + + minaPubKeyExists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, err + } + if !minaPubKeyExists { + return nil, err + } + + minaPubKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, err + } + + var MinaPublicKey keys.PublicKey + err = MinaPublicKey.Unmarshal(minaPubKey) + if err != nil { + return nil, err + } + + input = append(input, MinaPublicKey.X) + if MinaPublicKey.IsOdd { + input = append(input, big.NewInt(1)) + } else { + input = append(input, big.NewInt(0)) + } + power := new(big.Int).SetInt64(validator.GetConsensusPower(sdk.DefaultPowerReduction)) + input = append(input, power) + + hashOfAddr := poseidonHash.Hash(input) + + input = []*big.Int{merkleRoot, hashOfAddr} + + merkleRoot = poseidonHash.Hash(input) + } + + return merkleRoot, nil + +} + +func (h *AbciHandler) checkStakePower(ctx sdk.Context, blockHeight int64, pl abcipb.Payload) (bool, error) { + var signedStakePower int64 + var currentValidatorStakePower int64 + + valInfoMap := make(map[string]stakingTypes.ValidatorI) + + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + if err != nil { + return false, err + } + + // Require at least 2/3 signed power to prevent proposer-side signature withholding. + for _, val := range currentValidatorSet { + + consAddr, err := val.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, consAddr) + if err != nil { + return false, err + } + + valInfoMap[hex.EncodeToString(cosmosValidatorPubKey)] = val + currentValidatorStakePower += val.GetConsensusPower(sdk.DefaultPowerReduction) + } + + for _, vote := range pl.Votes { + validatorInfo, ok := valInfoMap[vote.ConsensusPublicKey] + if ok { + signedStakePower += validatorInfo.GetConsensusPower(sdk.DefaultPowerReduction) + } + } + if signedStakePower*3 < currentValidatorStakePower*2 { + return false, nil + } + + return true, nil +} + +func (h *AbciHandler) constructVoteExtBody(ctx sdk.Context, blockHeight int64) (votepersistenceTypes.VoteExtBody, error) { + + nextValidatorSet, err := h.getValidatorSet(ctx, blockHeight) + if err != nil { + return votepersistenceTypes.VoteExtBody{}, err + } + + currentBlockInfo, err := h.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) + if err != nil { + return votepersistenceTypes.VoteExtBody{}, err + } + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + + nextValidatorSetHash, err := h.calculateValidatorSetRoot(ctx, nextValidatorSet, poseidonHash) + if err != nil { + return votepersistenceTypes.VoteExtBody{}, err + } + if nextValidatorSetHash == nil { + return votepersistenceTypes.VoteExtBody{}, err + } + + return votepersistenceTypes.VoteExtBody{ + NextValidatorSetHash: nextValidatorSetHash.Bytes(), + CurrentStateRoot: currentBlockInfo.Header.AppHash, + CurrentBlockHeight: blockHeight - 1, + ActionsReducedRoot: ActionsReducedRoot, + }, nil +} + +func (h *AbciHandler) getValidatorPublicKey(ctx sdk.Context, validatorAddr []byte) ([]byte, error) { + + cosmosValidatorInfo, err := h.stakingKeeper.GetValidatorByConsAddr(ctx, validatorAddr) + if err != nil { + return nil, err + } + cosmosValidatorPubKey, err := cosmosValidatorInfo.ConsPubKey() + if err != nil { + return nil, err + } + + return cosmosValidatorPubKey.Bytes(), nil +} + +func (h *AbciHandler) constructPayload(ctx sdk.Context, blockHeight int64, voteExtensions []abci.ExtendedVoteInfo) (abcipb.Payload, error) { + + var voteExtsForGivenBlock []*abcipb.Votes + + currentValidatorSetMap := make(map[string]bool) + + currentValidatorSet, err := h.getValidatorSet(ctx, blockHeight-2) + if err != nil { + return abcipb.Payload{}, err + } + + for _, currentValidator := range currentValidatorSet { + + consAddr, err := currentValidator.GetConsAddr() + if err != nil { + continue + } + + currentValidatorSetMap[string(consAddr)] = true + } + + for _, vote := range voteExtensions { + + if !currentValidatorSetMap[string(vote.Validator.Address)] { + continue + } + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, vote.Validator.Address) + if err != nil { + return abcipb.Payload{}, err + } + + voteExtsForGivenBlock = append(voteExtsForGivenBlock, &abcipb.Votes{ + ConsensusPublicKey: hex.EncodeToString(cosmosValidatorPubKey), + VoteExtension: vote.VoteExtension, + }) + } + + if len(voteExtsForGivenBlock) == 0 { + return abcipb.Payload{}, nil + } + + return abcipb.Payload{Height: blockHeight - 1, Votes: voteExtsForGivenBlock}, nil +} diff --git a/abci/pre_blocker.go b/abci/pre_blocker.go new file mode 100644 index 00000000..d709710e --- /dev/null +++ b/abci/pre_blocker.go @@ -0,0 +1,81 @@ +package vote_ext + +import ( + "encoding/hex" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" + keyregistryTypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func (h *AbciHandler) PreBlocker() sdk.PreBlocker { + return func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) { + + // If height is smaller than 4, we won't have any votes thus skip the proposal + if req.GetHeight() < 4 { + return &sdk.ResponsePreBlock{}, nil + } + + err := h.votePersistenceKeeper.Clear(ctx) + if err != nil { + return nil, err + } + + pl, err := extractPayload(req.Txs) + if err != nil { + return nil, err + } + + currentValidatorSet, err := h.getValidatorSet(ctx, req.GetHeight()-2) + if err != nil { + return nil, err + } + + currentValidatorSetMap := make(map[string][]byte) + + for _, currentValidator := range currentValidatorSet { + + consAddr, err := currentValidator.GetConsAddr() + if err != nil { + continue + } + + cosmosValidatorPublicKey, err := h.getValidatorPublicKey(ctx, consAddr) + if err != nil { + return nil, err + } + + currentValidatorSetMap[hex.EncodeToString(cosmosValidatorPublicKey)] = cosmosValidatorPublicKey + } + + for _, vote := range pl.Votes { + + cosmosValidatorPublicKey, ok := currentValidatorSetMap[vote.ConsensusPublicKey] + if !ok { + continue + } + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPublicKey) + if err != nil { + return nil, err + } + + if !exists { + return nil, keyregistryTypes.ErrValidatorNotRegistered + } + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPublicKey) + if err != nil { + return nil, err + } + + err = h.votePersistenceKeeper.SetVote(ctx, req.GetHeight()-2, minaKey, vote.VoteExtension) + if err != nil { + return nil, err + } + + } + + return &sdk.ResponsePreBlock{}, nil + } +} diff --git a/abci/prepare_proposal.go b/abci/prepare_proposal.go new file mode 100644 index 00000000..2a6d1a10 --- /dev/null +++ b/abci/prepare_proposal.go @@ -0,0 +1,39 @@ +package vote_ext + +import ( + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { + + return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { + + // to construct the payload we need to get the N-2th block's vote extensions. + // Hence, enabling prepare proposal on blocks < 4 will result in error. + if req.Height < 4 { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil + } + + votes := req.LocalLastCommit.Votes + pl, err := h.constructPayload(ctx, req.GetHeight(), votes) + if err != nil { + return &abci.ResponsePrepareProposal{Txs: req.Txs}, err + } + + bz, err := pl.Marshal() + if err != nil { + return nil, err + } + + // prefix makes it easier to identify the vote extension + extTx := append([]byte(VoteExtMarker), bz...) + + // prepend to existing txs + txs := make([][]byte, 0, len(req.Txs)+1) + txs = append(txs, extTx) + txs = append(txs, req.Txs...) + + return &abci.ResponsePrepareProposal{Txs: txs}, nil + } +} diff --git a/abci/process_proposal.go b/abci/process_proposal.go new file mode 100644 index 00000000..f640deac --- /dev/null +++ b/abci/process_proposal.go @@ -0,0 +1,45 @@ +package vote_ext + +import ( + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) ProcessProposalHandler() sdk.ProcessProposalHandler { + + return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { + + // If height is less than 4, we won't have any votes thus skip the proposal + if req.GetHeight() < 4 { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil + } + + body, err := h.constructVoteExtBody(ctx, req.GetHeight()-1) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err + } + + pl, err := extractPayload(req.Txs) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err + } + + err = h.verifyVoteExtension(ctx, pl, body) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err + } + + isEnoughStakePower, err := h.checkStakePower(ctx, req.GetHeight(), pl) + if err != nil { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err + } + + if !isEnoughStakePower { + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, ErrNotEnoughStakePower + } + + // Vote extension successfully verified + return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil + } + +} diff --git a/abci/types.go b/abci/types.go new file mode 100644 index 00000000..6cffd353 --- /dev/null +++ b/abci/types.go @@ -0,0 +1,9 @@ +package vote_ext + +import "errors" + +const ActionsReducedRoot string = "pulsar" + +var VoteExtMarker string = "VOTEEXT:" + +var ErrNotEnoughStakePower error = errors.New("not enough stake power") diff --git a/abci/verify_vote_ext.go b/abci/verify_vote_ext.go new file mode 100644 index 00000000..82cf9430 --- /dev/null +++ b/abci/verify_vote_ext.go @@ -0,0 +1,51 @@ +package vote_ext + +import ( + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (h *AbciHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteExtensionHandler { + return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) { + if req.GetHeight() < 3 { + if len(req.VoteExtension) == 0 { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil + } + + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, fmt.Errorf("rejected") + } + + cosmosValidatorPubKey, err := h.getValidatorPublicKey(ctx, req.ValidatorAddress) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + exists, err := h.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + if !exists { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + minaKey, err := h.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + body, err := h.constructVoteExtBody(ctx, req.GetHeight()) + if err != nil { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + sigValidity := VerifyVoteExtSig(req.VoteExtension, body, minaKey, ActionsReducedRoot) + if !sigValidity { + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, err + } + + return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil + } +} diff --git a/api/pulsarchain/abci/payload.pb.go b/api/pulsarchain/abci/payload.pb.go new file mode 100644 index 00000000..6adc1b07 --- /dev/null +++ b/api/pulsarchain/abci/payload.pb.go @@ -0,0 +1,590 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/abci/payload.proto + +package abcipb + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Payload struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Votes []*Votes `protobuf:"bytes,2,rep,name=votes,proto3" json:"votes,omitempty"` +} + +func (m *Payload) Reset() { *m = Payload{} } +func (m *Payload) String() string { return proto.CompactTextString(m) } +func (*Payload) ProtoMessage() {} +func (*Payload) Descriptor() ([]byte, []int) { + return fileDescriptor_5a138d1c833ef562, []int{0} +} +func (m *Payload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Payload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Payload.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Payload) XXX_Merge(src proto.Message) { + xxx_messageInfo_Payload.Merge(m, src) +} +func (m *Payload) XXX_Size() int { + return m.Size() +} +func (m *Payload) XXX_DiscardUnknown() { + xxx_messageInfo_Payload.DiscardUnknown(m) +} + +var xxx_messageInfo_Payload proto.InternalMessageInfo + +func (m *Payload) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Payload) GetVotes() []*Votes { + if m != nil { + return m.Votes + } + return nil +} + +type Votes struct { + ConsensusPublicKey string `protobuf:"bytes,1,opt,name=consensus_public_key,json=consensusPublicKey,proto3" json:"consensus_public_key,omitempty"` + VoteExtension []byte `protobuf:"bytes,2,opt,name=vote_extension,json=voteExtension,proto3" json:"vote_extension,omitempty"` +} + +func (m *Votes) Reset() { *m = Votes{} } +func (m *Votes) String() string { return proto.CompactTextString(m) } +func (*Votes) ProtoMessage() {} +func (*Votes) Descriptor() ([]byte, []int) { + return fileDescriptor_5a138d1c833ef562, []int{1} +} +func (m *Votes) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Votes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Votes.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Votes) XXX_Merge(src proto.Message) { + xxx_messageInfo_Votes.Merge(m, src) +} +func (m *Votes) XXX_Size() int { + return m.Size() +} +func (m *Votes) XXX_DiscardUnknown() { + xxx_messageInfo_Votes.DiscardUnknown(m) +} + +var xxx_messageInfo_Votes proto.InternalMessageInfo + +func (m *Votes) GetConsensusPublicKey() string { + if m != nil { + return m.ConsensusPublicKey + } + return "" +} + +func (m *Votes) GetVoteExtension() []byte { + if m != nil { + return m.VoteExtension + } + return nil +} + +func init() { + proto.RegisterType((*Payload)(nil), "pulsarchain.abci.Payload") + proto.RegisterType((*Votes)(nil), "pulsarchain.abci.Votes") +} + +func init() { proto.RegisterFile("pulsarchain/abci/payload.proto", fileDescriptor_5a138d1c833ef562) } + +var fileDescriptor_5a138d1c833ef562 = []byte{ + // 260 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x4f, 0x4c, 0x4a, 0xce, 0xd4, 0x2f, 0x48, 0xac, + 0xcc, 0xc9, 0x4f, 0x4c, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x40, 0x92, 0xd7, 0x03, + 0xc9, 0x2b, 0x05, 0x70, 0xb1, 0x07, 0x40, 0x94, 0x08, 0x89, 0x71, 0xb1, 0x65, 0xa4, 0x66, 0xa6, + 0x67, 0x94, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x30, 0x07, 0x41, 0x79, 0x42, 0xba, 0x5c, 0xac, 0x65, + 0xf9, 0x25, 0xa9, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xe2, 0x7a, 0xe8, 0x86, 0xe8, + 0x85, 0x81, 0xa4, 0x83, 0x20, 0xaa, 0x94, 0x12, 0xb8, 0x58, 0xc1, 0x7c, 0x21, 0x03, 0x2e, 0x91, + 0xe4, 0xfc, 0xbc, 0xe2, 0xd4, 0xbc, 0xe2, 0xd2, 0xe2, 0xf8, 0x82, 0xd2, 0xa4, 0x9c, 0xcc, 0xe4, + 0xf8, 0xec, 0xd4, 0x4a, 0xb0, 0xe9, 0x9c, 0x41, 0x42, 0x70, 0xb9, 0x00, 0xb0, 0x94, 0x77, 0x6a, + 0xa5, 0x90, 0x2a, 0x17, 0x1f, 0xc8, 0x8c, 0xf8, 0xd4, 0x8a, 0x92, 0xd4, 0xbc, 0xe2, 0xcc, 0xfc, + 0x3c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x5e, 0x90, 0xa8, 0x2b, 0x4c, 0xd0, 0x29, 0xe2, + 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, + 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xec, 0xd2, 0x33, 0x4b, 0x32, 0x4a, + 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xf3, 0xf2, 0x53, 0x52, 0x0d, 0x0d, 0x0c, 0x75, 0x33, 0xf3, + 0xf5, 0x21, 0x0e, 0xd6, 0x85, 0x06, 0x4b, 0x41, 0xa6, 0x3e, 0x7a, 0x30, 0x59, 0x83, 0x88, 0x82, + 0xa4, 0x24, 0x36, 0x70, 0x30, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x85, 0xf8, 0xb6, 0x21, + 0x48, 0x01, 0x00, 0x00, +} + +func (m *Payload) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Payload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Payload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Votes) > 0 { + for iNdEx := len(m.Votes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Votes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPayload(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Height != 0 { + i = encodeVarintPayload(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Votes) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Votes) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Votes) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.VoteExtension) > 0 { + i -= len(m.VoteExtension) + copy(dAtA[i:], m.VoteExtension) + i = encodeVarintPayload(dAtA, i, uint64(len(m.VoteExtension))) + i-- + dAtA[i] = 0x12 + } + if len(m.ConsensusPublicKey) > 0 { + i -= len(m.ConsensusPublicKey) + copy(dAtA[i:], m.ConsensusPublicKey) + i = encodeVarintPayload(dAtA, i, uint64(len(m.ConsensusPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPayload(dAtA []byte, offset int, v uint64) int { + offset -= sovPayload(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Payload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovPayload(uint64(m.Height)) + } + if len(m.Votes) > 0 { + for _, e := range m.Votes { + l = e.Size() + n += 1 + l + sovPayload(uint64(l)) + } + } + return n +} + +func (m *Votes) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConsensusPublicKey) + if l > 0 { + n += 1 + l + sovPayload(uint64(l)) + } + l = len(m.VoteExtension) + if l > 0 { + n += 1 + l + sovPayload(uint64(l)) + } + return n +} + +func sovPayload(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPayload(x uint64) (n int) { + return sovPayload(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Payload) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Payload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Payload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Votes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPayload + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Votes = append(m.Votes, &Votes{}) + if err := m.Votes[len(m.Votes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPayload(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPayload + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Votes) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Votes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Votes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusPublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPayload + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusPublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VoteExtension", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPayload + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPayload + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPayload + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.VoteExtension = append(m.VoteExtension[:0], dAtA[iNdEx:postIndex]...) + if m.VoteExtension == nil { + m.VoteExtension = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPayload(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPayload + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPayload(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPayload + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPayload + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPayload + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPayload + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPayload = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPayload = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPayload = fmt.Errorf("proto: unexpected end of group") +) diff --git a/app/app.go b/app/app.go index b63ee207..122cbc6f 100644 --- a/app/app.go +++ b/app/app.go @@ -1,7 +1,10 @@ package app import ( + "encoding/base64" + "fmt" "io" + "math/big" clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/core/appmodule" @@ -45,9 +48,12 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper" + "github.com/node101-io/mina-signer-go/keys" + vote_ext "github.com/node101-io/pulsar-chain/abci" "github.com/node101-io/pulsar-chain/docs" keyregistrymodulekeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" pulsarmodulekeeper "github.com/node101-io/pulsar-chain/x/pulsar/keeper" + votepersistencemodulekeeper "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" ) const ( @@ -100,9 +106,12 @@ type App struct { TransferKeeper ibctransferkeeper.Keeper // simulation manager - sm *module.SimulationManager - PulsarKeeper pulsarmodulekeeper.Keeper - KeyregistryKeeper keyregistrymodulekeeper.Keeper + sm *module.SimulationManager + PulsarKeeper pulsarmodulekeeper.Keeper + KeyregistryKeeper keyregistrymodulekeeper.Keeper + VotepersistenceKeeper votepersistencemodulekeeper.Keeper + + AbciHandler *vote_ext.AbciHandler } func init() { @@ -184,10 +193,41 @@ func New( &app.ParamsKeeper, &app.PulsarKeeper, &app.KeyregistryKeeper, + &app.VotepersistenceKeeper, ); err != nil { panic(err) } + minaPrivKey := appOpts.Get("vote_extension.priv_key") + keyStr, ok := minaPrivKey.(string) + if !ok { + panic("vote_extension.priv_key is not a string") + } + + // Decode base64 -> bytes + keyBytes, err := base64.StdEncoding.DecodeString(keyStr) + if err != nil { + panic(fmt.Sprintf("failed to decode base64 priv key: %v", err)) + } + + // Bytes -> big.Int + prv := new(big.Int).SetBytes(keyBytes) + priv := keys.PrivateKey{ + Value: prv, + } + public := priv.ToPublicKey() + secondaryKey := vote_ext.SecondaryKey{ + SecretKey: &priv, + PublicKey: &public, + } + + app.AbciHandler = vote_ext.NewABCIHandler( + secondaryKey, + *app.StakingKeeper, + app.KeyregistryKeeper, + app.VotepersistenceKeeper, + ) + // add to default baseapp options // enable optimistic execution baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution()) @@ -195,6 +235,12 @@ func New( // build app app.App = appBuilder.Build(db, traceStore, baseAppOptions...) + app.SetExtendVoteHandler(app.AbciHandler.ExtendVoteHandler()) + app.SetVerifyVoteExtensionHandler(app.AbciHandler.VerifyVoteExtensionHandler()) + app.SetPrepareProposal(app.AbciHandler.PrepareProposalHandler()) + app.SetProcessProposal(app.AbciHandler.ProcessProposalHandler()) + app.SetPreBlocker(app.AbciHandler.PreBlocker()) + // register legacy modules if err := app.registerIBCModules(appOpts); err != nil { panic(err) diff --git a/app/app_config.go b/app/app_config.go index db90a02e..dc747fa5 100644 --- a/app/app_config.go +++ b/app/app_config.go @@ -7,6 +7,8 @@ import ( keyregistrymoduletypes "github.com/node101-io/pulsar-chain/x/keyregistry/types" _ "github.com/node101-io/pulsar-chain/x/pulsar/module" pulsarmoduletypes "github.com/node101-io/pulsar-chain/x/pulsar/types" + _ "github.com/node101-io/pulsar-chain/x/votepersistence/module" + votepersistencemoduletypes "github.com/node101-io/pulsar-chain/x/votepersistence/types" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" @@ -130,6 +132,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/beginBlockers }, EndBlockers: []string{ @@ -140,6 +143,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/endBlockers }, // The following is mostly only needed when ModuleName != StoreKey name. @@ -178,6 +182,7 @@ var ( // chain modules pulsarmoduletypes.ModuleName, keyregistrymoduletypes.ModuleName, + votepersistencemoduletypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis }, }), @@ -282,6 +287,10 @@ var ( Name: keyregistrymoduletypes.ModuleName, Config: appconfig.WrapAny(&keyregistrymoduletypes.Module{}), }, + { + Name: votepersistencemoduletypes.ModuleName, + Config: appconfig.WrapAny(&votepersistencemoduletypes.Module{}), + }, // this line is used by starport scaffolding # stargate/app/moduleConfig }, }) diff --git a/buf.lock b/buf.lock index ffa7ce8c..fd28dbd0 100644 --- a/buf.lock +++ b/buf.lock @@ -17,8 +17,8 @@ deps: commit: dc427cb4519143d8996361c045a29ad7 digest: b5:8693e72e230bfaf58a88a47a4093ba99f6252c1957a45582567959b38a8563e2abd11443372283d75f4f2306a7e3cc9bf63604d284a016c11966fca4b74b7a28 - name: buf.build/googleapis/googleapis - commit: 004180b77378443887d3b55cabc00384 - digest: b5:e8f475fe3330f31f5fd86ac689093bcd274e19611a09db91f41d637cb9197881ce89882b94d13a58738e53c91c6e4bae7dc1feba85f590164c975a89e25115dc + commit: c17df5b2beca46928cc87d5656bd5343 + digest: b5:648a01e0170d4512dea7d564016165decd1ed6e34bef79fe54753e51ad7e27545709ad9157d7551270147d551155c595a2fb0bf5bb33b1c83040ddbce915c604 - name: buf.build/protocolbuffers/wellknowntypes commit: 9d16d599a978406980f6e2f081331a93 digest: b5:dd06e497a5c52f5ddf6ec02b3c7d289cc6c0432093fc2f6bf7a4fb5fae786c3e4c893e55d2759ffb6833268daf3de0bce303a406fed15725790528f2c27dc219 diff --git a/config.yml b/config.yml index 6d7a3ec2..2c85602e 100644 --- a/config.yml +++ b/config.yml @@ -14,22 +14,35 @@ client: openapi: path: docs/static/openapi.json faucet: - name: bob coins: - 5token - 100000stake validators: - name: alice bonded: 100000000pmina + app: + vote_extension: + priv_key: "OhOfQtGMXqcrbfCRPEe4DjLUNHaOcD3RrWuRPBGO82M=" - name: validator1 bonded: 200000000pmina - name: validator2 bonded: 100000000pmina + + genesis: app_state: keyregistry: params: {} - key_pairs: - # - mina_key: "SC/6aqoZ19ObLka8NIQVMs1qPim+uD6epPLuQS4x2n4Z" - # cosmos_key: "UdDr3CCO+4HVrBtbzqLTM3P2xAMNCIrPeCTeVfb5sw1y" + user_key_pairs: + # Mina compressed public key placeholder: zero bytes, 33 bytes. + #- mina_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + # Cosmos user public key placeholder: secp256k1 compressed, zero bytes, 33 bytes. + #cosmos_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + validator_key_pairs: + # - mina_key: "3IvK1eWmmcfdlIb+T04+ck9Q5bjbqHqiT0ucGJITzyY=" + # cosmos_key: "A8saw69s1DQWvUjseeOtG8hGavmYiInrQ5M1aOPa4QkP" + consensus: + params: + abci: + vote_extensions_enable_height: "1" diff --git a/docs/static/openapi.json b/docs/static/openapi.json index 8340f427..016726bb 100644 --- a/docs/static/openapi.json +++ b/docs/static/openapi.json @@ -1 +1 @@ -{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_cosmos_pub_key/{mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetCosmosPubKey Queries a list of GetCosmosPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_mina_pub_key/{cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetMinaPubKey Queries a list of GetMinaPubKey items.","operationId":"GithubComnode101IopulsarChainQuery_GetMinaPubKey","parameters":[{"type":"string","format":"byte","name":"cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin7","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse":{"description":"QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message.","type":"object","properties":{"cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse":{"description":"QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message.","type":"object","properties":{"mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}}},"tags":[{"name":"Query"},{"name":"Msg"}]} \ No newline at end of file +{"id":"github.com/node101-io/pulsar-chain","consumes":["application/json"],"produces":["application/json"],"swagger":"2.0","info":{"description":"Chain github.com/node101-io/pulsar-chain REST API","title":"HTTP API Console","contact":{"name":"github.com/node101-io/pulsar-chain"},"version":"version not set"},"paths":{"/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_address/{user_mina_address}":{"get":{"tags":["Query"],"summary":"GetUserCosmosAddress Queries a list of GetUserCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserCosmosAddress","parameters":[{"type":"string","format":"byte","name":"user_mina_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_address/{user_cosmos_address}":{"get":{"tags":["Query"],"summary":"GetUserMinaAddress Queries a list of GetUserMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetUserMinaAddress","parameters":[{"type":"string","format":"byte","name":"user_cosmos_address","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorCosmosAddress Queries a list of GetValidatorCosmosAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorCosmosPubKey","parameters":[{"type":"string","format":"byte","name":"validator_mina_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}":{"get":{"tags":["Query"],"summary":"GetValidatorMinaAddress Queries a list of GetValidatorMinaAddress items.","operationId":"GithubComnode101IopulsarChainQuery_GetValidatorMinaPubKey","parameters":[{"type":"string","format":"byte","name":"validator_cosmos_pub_key","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/keyregistry/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin8","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.keyregistry.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_ParamsMixin12","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/node101-io/pulsar-chain/votepersistence/v1/vote_ext_body_by_height/{block_height}":{"get":{"tags":["Query"],"summary":"VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items.","operationId":"GithubComnode101IopulsarChainQuery_VoteExtBodyByHeight","parameters":[{"type":"string","format":"int64","name":"block_height","in":"path","required":true}],"responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}},"/pulsar/pulsar/v1/params":{"get":{"tags":["Query"],"summary":"Parameters queries the parameters of the module.","operationId":"GithubComnode101IopulsarChainQuery_Params","responses":{"200":{"description":"A successful response.","schema":{"$ref":"#/definitions/pulsar.pulsar.v1.QueryParamsResponse"}},"default":{"description":"An unexpected error response.","schema":{"$ref":"#/definitions/google.rpc.Status"}}}}}},"definitions":{"google.protobuf.Any":{"type":"object","properties":{"@type":{"type":"string"}},"additionalProperties":{}},"google.rpc.Status":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"details":{"type":"array","items":{"type":"object","$ref":"#/definitions/google.protobuf.Any"}},"message":{"type":"string"}}},"pulsar.pulsar.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsar.pulsar.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsar.pulsar.v1.Params"}}},"pulsarchain.keyregistry.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.keyregistry.v1.QueryGetUserCosmosAddressResponse":{"description":"QueryGetUserCosmosAddressResponse defines the QueryGetUserCosmosAddressResponse message.","type":"object","properties":{"user_cosmos_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetUserMinaAddressResponse":{"description":"QueryGetUserMinaAddressResponse defines the QueryGetUserMinaAddressResponse message.","type":"object","properties":{"user_mina_address":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse":{"description":"QueryGetValidatorCosmosAddressResponse defines the QueryGetValidatorCosmosAddressResponse message.","type":"object","properties":{"validator_cosmos_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse":{"description":"QueryGetValidatorMinaAddressResponse defines the QueryGetValidatorMinaAddressResponse message.","type":"object","properties":{"validator_mina_pub_key":{"type":"string","format":"byte"}}},"pulsarchain.keyregistry.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.keyregistry.v1.Params"}}},"pulsarchain.votepersistence.v1.Params":{"description":"Params defines the parameters for the module.","type":"object"},"pulsarchain.votepersistence.v1.QueryParamsResponse":{"description":"QueryParamsResponse is response type for the Query/Params RPC method.","type":"object","properties":{"params":{"description":"params holds all the parameters of this module.","$ref":"#/definitions/pulsarchain.votepersistence.v1.Params"}}},"pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightResponse":{"description":"QueryVoteExtBodyByHeightResponse defines the QueryVoteExtBodyByHeightResponse message.","type":"object"}},"tags":[{"name":"Query"},{"name":"Msg"}]} diff --git a/proto/pulsarchain/abci/payload.proto b/proto/pulsarchain/abci/payload.proto new file mode 100644 index 00000000..e3982816 --- /dev/null +++ b/proto/pulsarchain/abci/payload.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package pulsarchain.abci; + +option go_package = "github.com/node101-io/pulsar-chain/api/pulsarchain/abci;abcipb"; + +message Payload { + int64 height = 1; + repeated Votes votes = 2; +} + +message Votes { + string consensus_public_key = 1; + bytes vote_extension = 2; +} diff --git a/proto/pulsarchain/keyregistry/v1/genesis.proto b/proto/pulsarchain/keyregistry/v1/genesis.proto index 0f0a5554..a15fcf04 100644 --- a/proto/pulsarchain/keyregistry/v1/genesis.proto +++ b/proto/pulsarchain/keyregistry/v1/genesis.proto @@ -4,11 +4,10 @@ package pulsarchain.keyregistry.v1; import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "pulsarchain/keyregistry/v1/params.proto"; -import "pulsarchain/keyregistry/v1/key_pair.proto"; +import "pulsarchain/keyregistry/v1/public_key_pair.proto"; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; - // GenesisState defines the keyregistry module's genesis state. message GenesisState { // params defines all the parameters of the module. @@ -16,5 +15,6 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; - repeated KeyPair key_pairs = 2; + repeated UserPublicKeyPair user_key_pairs = 2; + repeated ValidatorPublicKeyPair validator_key_pairs = 3; } diff --git a/proto/pulsarchain/keyregistry/v1/key_update_type.proto b/proto/pulsarchain/keyregistry/v1/key_update_type.proto new file mode 100644 index 00000000..07e62970 --- /dev/null +++ b/proto/pulsarchain/keyregistry/v1/key_update_type.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package pulsarchain.keyregistry.v1; + +option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; + +enum ActorType { + UNSPECIFIED = 0; + USER = 1; + VALIDATOR = 2; +} diff --git a/proto/pulsarchain/keyregistry/v1/key_pair.proto b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto similarity index 67% rename from proto/pulsarchain/keyregistry/v1/key_pair.proto rename to proto/pulsarchain/keyregistry/v1/public_key_pair.proto index ed7d22e6..474b7d87 100644 --- a/proto/pulsarchain/keyregistry/v1/key_pair.proto +++ b/proto/pulsarchain/keyregistry/v1/public_key_pair.proto @@ -4,7 +4,11 @@ package pulsarchain.keyregistry.v1; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; // KeyPair defines the KeyPair message. -message KeyPair { +message UserPublicKeyPair { + bytes mina_key = 1; + bytes cosmos_key = 2; +} +message ValidatorPublicKeyPair { bytes mina_key = 1; bytes cosmos_key = 2; } diff --git a/proto/pulsarchain/keyregistry/v1/query.proto b/proto/pulsarchain/keyregistry/v1/query.proto index b1fd2c73..87c61d22 100644 --- a/proto/pulsarchain/keyregistry/v1/query.proto +++ b/proto/pulsarchain/keyregistry/v1/query.proto @@ -17,14 +17,24 @@ service Query { option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/params"; } - // GetMinaPubKey Queries a list of GetMinaPubKey items. - rpc GetMinaPubKey(QueryGetMinaPubKeyRequest) returns (QueryGetMinaPubKeyResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_mina_pub_key/{cosmos_pub_key}"; + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. + rpc GetUserMinaPublicKey(QueryGetUserMinaPublicKeyRequest) returns (QueryGetUserMinaPublicKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_mina_public_key/{user_cosmos_public_key}"; } - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - rpc GetCosmosPubKey(QueryGetCosmosPubKeyRequest) returns (QueryGetCosmosPubKeyResponse) { - option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_cosmos_pub_key/{mina_pub_key}"; + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. + rpc GetUserCosmosPublicKey(QueryGetUserCosmosPublicKeyRequest) returns (QueryGetUserCosmosPublicKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_user_cosmos_public_key/{user_mina_public_key}"; + } + + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. + rpc GetValidatorMinaPubKey(QueryGetValidatorMinaPubKeyRequest) returns (QueryGetValidatorMinaPubKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_mina_pub_key/{validator_cosmos_pub_key}"; + } + + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. + rpc GetValidatorCosmosPubKey(QueryGetValidatorCosmosPubKeyRequest) returns (QueryGetValidatorCosmosPubKeyResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/keyregistry/v1/get_validator_cosmos_pub_key/{validator_mina_pub_key}"; } } @@ -40,22 +50,42 @@ message QueryParamsResponse { ]; } -// QueryGetMinaPubKeyRequest defines the QueryGetMinaPubKeyRequest message. -message QueryGetMinaPubKeyRequest { - bytes cosmos_pub_key = 1; +// QueryGetUserMinaPublicKeyRequest defines the QueryGetUserMinaPublicKeyRequest message. +message QueryGetUserMinaPublicKeyRequest { + bytes user_cosmos_public_key = 1; +} + +// QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message. +message QueryGetUserMinaPublicKeyResponse { + bytes user_mina_public_key = 1; +} + +// QueryGetUserCosmosPublicKeyRequest defines the QueryGetUserCosmosPublicKeyRequest message. +message QueryGetUserCosmosPublicKeyRequest { + bytes user_mina_public_key = 1; +} + +// QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message. +message QueryGetUserCosmosPublicKeyResponse { + bytes user_cosmos_public_key = 1; +} + +// QueryGetValidatorMinaPubKeyRequest defines the QueryGetValidatorMinaPubKeyRequest message. +message QueryGetValidatorMinaPubKeyRequest { + bytes validator_cosmos_pub_key = 1; } -// QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message. -message QueryGetMinaPubKeyResponse { - bytes mina_pub_key = 1; +// QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message. +message QueryGetValidatorMinaPubKeyResponse { + bytes validator_mina_pub_key = 1; } -// QueryGetCosmosPubKeyRequest defines the QueryGetCosmosPubKeyRequest message. -message QueryGetCosmosPubKeyRequest { - bytes mina_pub_key = 1; +// QueryGetValidatorCosmosPubKeyRequest defines the QueryGetValidatorCosmosPubKeyRequest message. +message QueryGetValidatorCosmosPubKeyRequest { + bytes validator_mina_pub_key = 1; } -// QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message. -message QueryGetCosmosPubKeyResponse { - bytes cosmos_pub_key = 1; +// QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message. +message QueryGetValidatorCosmosPubKeyResponse { + bytes validator_cosmos_pub_key = 1; } diff --git a/proto/pulsarchain/keyregistry/v1/tx.proto b/proto/pulsarchain/keyregistry/v1/tx.proto index 1841b99d..3c8a4dae 100644 --- a/proto/pulsarchain/keyregistry/v1/tx.proto +++ b/proto/pulsarchain/keyregistry/v1/tx.proto @@ -7,6 +7,7 @@ import "cosmos/msg/v1/msg.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "pulsarchain/keyregistry/v1/params.proto"; +import "pulsarchain/keyregistry/v1/key_update_type.proto"; option go_package = "github.com/node101-io/pulsar-chain/x/keyregistry/types"; @@ -20,6 +21,9 @@ service Msg { // RegisterKeys defines the RegisterKeys RPC. rpc RegisterKeys(MsgRegisterKeys) returns (MsgRegisterKeysResponse); + + // UpdateKeys defines the UpdateKeys RPC. + rpc UpdateKeys(MsgUpdateKeys) returns (MsgUpdateKeysResponse); } // MsgUpdateParams is the Msg/UpdateParams request type. @@ -47,11 +51,26 @@ message MsgUpdateParamsResponse {} message MsgRegisterKeys { option (cosmos.msg.v1.signer) = "creator"; string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - string cosmos_signature = 2; - string mina_signature = 3; - bytes cosmos_public_key = 4; - bytes mina_public_key = 5; + bytes cosmos_public_key = 2; + bytes mina_public_key = 3; + bytes cosmos_signature = 4; + bytes mina_signature = 5; + ActorType actor_type = 6; } // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. message MsgRegisterKeysResponse {} + +// MsgUpdateKeys defines the MsgUpdateKeys message. +message MsgUpdateKeys { + option (cosmos.msg.v1.signer) = "creator"; + string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + bytes prev_mina_public_key = 2; + bytes new_mina_public_key = 3; + bytes cosmos_signature = 4; + bytes new_mina_signature = 5; + ActorType actor_type = 6; +} + +// MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. +message MsgUpdateKeysResponse {} diff --git a/proto/pulsarchain/votepersistence/module/v1/module.proto b/proto/pulsarchain/votepersistence/module/v1/module.proto new file mode 100644 index 00000000..95cef682 --- /dev/null +++ b/proto/pulsarchain/votepersistence/module/v1/module.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Module is the config object for the module. +message Module { + option (cosmos.app.v1alpha1.module) = {go_import: "github.com/node101-io/pulsar-chain/x/votepersistence"}; + + // authority defines the custom module authority. + // If not set, defaults to the governance module. + string authority = 1; +} diff --git a/proto/pulsarchain/votepersistence/v1/genesis.proto b/proto/pulsarchain/votepersistence/v1/genesis.proto new file mode 100644 index 00000000..dd13c4a6 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/genesis.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// GenesisState defines the votepersistence module's genesis state. +message GenesisState { + // params defines all the parameters of the module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} diff --git a/proto/pulsarchain/votepersistence/v1/params.proto b/proto/pulsarchain/votepersistence/v1/params.proto new file mode 100644 index 00000000..35085c91 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/params.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Params defines the parameters for the module. +message Params { + option (amino.name) = "pulsarchain/x/votepersistence/Params"; + option (gogoproto.equal) = true; +} diff --git a/proto/pulsarchain/votepersistence/v1/query.proto b/proto/pulsarchain/votepersistence/v1/query.proto new file mode 100644 index 00000000..215bd80d --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/query.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; +import "pulsarchain/votepersistence/v1/vote_ext_body.proto"; + + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/params"; + } + + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + rpc VoteExtBodyByHeight(QueryVoteExtBodyByHeightRequest) returns (VoteExtBody) { + option (google.api.http).get = "/node101-io/pulsar-chain/votepersistence/v1/vote_ext_body_by_height/{block_height}"; + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// QueryVoteExtBodyByHeightRequest defines the QueryVoteExtBodyByHeightRequest message. +message QueryVoteExtBodyByHeightRequest { + int64 block_height = 1; +} + diff --git a/proto/pulsarchain/votepersistence/v1/tx.proto b/proto/pulsarchain/votepersistence/v1/tx.proto new file mode 100644 index 00000000..dd98a36c --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/tx.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "pulsarchain/votepersistence/v1/params.proto"; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// Msg defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// MsgUpdateParams is the Msg/UpdateParams request type. +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "pulsarchain/x/votepersistence/MsgUpdateParams"; + + // authority is the address that controls the module (defaults to x/gov unless overwritten). + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // params defines the module parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +message MsgUpdateParamsResponse {} diff --git a/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto b/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto new file mode 100644 index 00000000..a7cf3128 --- /dev/null +++ b/proto/pulsarchain/votepersistence/v1/vote_ext_body.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package pulsarchain.votepersistence.v1; + +option go_package = "github.com/node101-io/pulsar-chain/x/votepersistence/types"; + +// VoteExtBody defines the VoteExtBody message. +message VoteExtBody { + bytes next_validator_set_hash = 1; + bytes current_state_root = 2; + int64 current_block_height = 3; + string actions_reduced_root = 4; +} diff --git a/scripts/derive_mina_pub.go b/scripts/derive_mina_pub.go new file mode 100644 index 00000000..a7da84ca --- /dev/null +++ b/scripts/derive_mina_pub.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/base64" + "fmt" + "math/big" + "os" + + "github.com/node101-io/mina-signer-go/keys" +) + +func main() { + if len(os.Args) != 2 { + panic("usage: derive_mina_pub.go ") + } + + privB64 := os.Args[1] + keyBytes, err := base64.StdEncoding.DecodeString(privB64) + if err != nil { + panic(err) + } + + priv := keys.PrivateKey{Value: new(big.Int).SetBytes(keyBytes)} + pub := priv.ToPublicKey() + bz, err := pub.Marshal() + if err != nil { + panic(err) + } + + fmt.Print(base64.StdEncoding.EncodeToString(bz)) +} diff --git a/scripts/setup_local_testnet.sh b/scripts/setup_local_testnet.sh new file mode 100755 index 00000000..c31094d9 --- /dev/null +++ b/scripts/setup_local_testnet.sh @@ -0,0 +1,198 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" +PYTHON_HELPER="$SCRIPT_DIR/setup_local_testnet_helper.py" +GO_HELPER="$SCRIPT_DIR/derive_mina_pub.go" + +LEGACY_CHAIN_HOME="${CHAIN_HOME:-$HOME/.pulsar}" +NODE1_HOME="${NODE1_HOME:-$HOME/.pulsar-node1}" +NODE2_HOME="${NODE2_HOME:-$HOME/.pulsar-node2}" +CHAIN_ID="${CHAIN_ID:-mytestnet}" +NODE1_MONIKER="${NODE1_MONIKER:-node1}" +NODE2_MONIKER="${NODE2_MONIKER:-node2}" +NODE1_KEY_NAME="${NODE1_KEY_NAME:-validator1}" +NODE2_KEY_NAME="${NODE2_KEY_NAME:-validator2}" +KEYRING_BACKEND="${KEYRING_BACKEND:-test}" +DENOM="${DENOM:-pmina}" +STAKE_AMOUNT="${STAKE_AMOUNT:-1000000000}" +BOND_AMOUNT="${BOND_AMOUNT:-100000000}" +MIN_GAS_PRICE="${MIN_GAS_PRICE:-0.0001pmina}" +VOTE_EXT_ENABLE_HEIGHT="${VOTE_EXT_ENABLE_HEIGHT:-3}" +NODE1_MINA_PRIV_KEY="${NODE1_MINA_PRIV_KEY:-ES17xFroE2/QOa9yCLXsQ9sJMeIUVwr2ZXcdWGjNLlM=}" +NODE2_MINA_PRIV_KEY="${NODE2_MINA_PRIV_KEY:-PKeRXivUb4gZ/nMKxUK5beEnVJwIrzN71mAf7JVKsng=}" +NODE1_P2P_PORT="${NODE1_P2P_PORT:-26656}" +NODE1_RPC_PORT="${NODE1_RPC_PORT:-26657}" +NODE2_P2P_PORT="${NODE2_P2P_PORT:-26666}" +NODE2_RPC_PORT="${NODE2_RPC_PORT:-26667}" +NODE1_GRPC_PORT="${NODE1_GRPC_PORT:-9090}" +NODE2_GRPC_PORT="${NODE2_GRPC_PORT:-9091}" +NODE1_API_PORT="${NODE1_API_PORT:-1317}" +NODE2_API_PORT="${NODE2_API_PORT:-1318}" +BIN_DIR="${BIN_DIR:-$HOME/go/bin}" +BINARY_PATH="${BINARY_PATH:-$BIN_DIR/pulsard}" +COMPAT_BINARY_PATH="${COMPAT_BINARY_PATH:-$BIN_DIR/pulsar-chaind}" + +require_cmd() { + if ! command -v "$1" >/dev/null 2>&1; then + echo "missing required command: $1" >&2 + exit 1 + fi +} + +derive_mina_pub_key() { + go run "$GO_HELPER" "$1" +} + +read_consensus_pub_key() { + python3 "$PYTHON_HELPER" read-consensus-pub-key --priv-validator-key "$1" +} + +configure_node() { + local home="$1" + local rpc_port="$2" + local p2p_port="$3" + local api_port="$4" + local grpc_port="$5" + local persistent_peers="$6" + local mina_priv_key="$7" + + sed -i.bak "s|laddr = \"tcp://127.0.0.1:26657\"|laddr = \"tcp://0.0.0.0:${rpc_port}\"|" "$home/config/config.toml" + sed -i.bak "s|laddr = \"tcp://0.0.0.0:26656\"|laddr = \"tcp://0.0.0.0:${p2p_port}\"|" "$home/config/config.toml" + sed -i.bak "s|persistent_peers = \"\"|persistent_peers = \"${persistent_peers}\"|" "$home/config/config.toml" + sed -i.bak 's|addr_book_strict = true|addr_book_strict = false|' "$home/config/config.toml" + sed -i.bak 's|allow_duplicate_ip = false|allow_duplicate_ip = true|' "$home/config/config.toml" + + sed -i.bak "s|address = \"tcp://localhost:1317\"|address = \"tcp://localhost:${api_port}\"|" "$home/config/app.toml" + sed -i.bak "s|address = \"localhost:9090\"|address = \"localhost:${grpc_port}\"|" "$home/config/app.toml" + + python3 "$PYTHON_HELPER" update-app-config \ + --app "$home/config/app.toml" \ + --min-gas-price "$MIN_GAS_PRICE" \ + --mina-priv-key "$mina_priv_key" +} + +require_cmd go +require_cmd python3 + +NODE1_MINA_PUB_KEY="$(derive_mina_pub_key "$NODE1_MINA_PRIV_KEY")" +NODE2_MINA_PUB_KEY="$(derive_mina_pub_key "$NODE2_MINA_PRIV_KEY")" + +NODE1_GENESIS_FILE="$NODE1_HOME/config/genesis.json" +NODE2_GENESIS_FILE="$NODE2_HOME/config/genesis.json" + +echo "==> Cleaning previous homes..." +rm -rf "$LEGACY_CHAIN_HOME" "$NODE1_HOME" "$NODE2_HOME" + +echo "==> Building binary..." +mkdir -p "$BIN_DIR" +( + cd "$REPO_ROOT" + go build -o "$BINARY_PATH" ./cmd/pulsard +) + +if [[ "$COMPAT_BINARY_PATH" != "$BINARY_PATH" ]]; then + cp "$BINARY_PATH" "$COMPAT_BINARY_PATH" +fi + +echo "==> Initializing nodes..." +"$BINARY_PATH" init "$NODE1_MONIKER" --chain-id "$CHAIN_ID" --home "$NODE1_HOME" >/dev/null 2>&1 +"$BINARY_PATH" init "$NODE2_MONIKER" --chain-id "$CHAIN_ID" --home "$NODE2_HOME" >/dev/null 2>&1 + +echo "==> Setting vote extension enable height..." +python3 "$PYTHON_HELPER" set-vote-extension-height \ + --genesis "$NODE1_GENESIS_FILE" \ + --height "$VOTE_EXT_ENABLE_HEIGHT" + +echo "==> Creating validator keys..." +"$BINARY_PATH" keys add "$NODE1_KEY_NAME" --home "$NODE1_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 +"$BINARY_PATH" keys add "$NODE2_KEY_NAME" --home "$NODE2_HOME" --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 + +NODE1_ADDR="$("$BINARY_PATH" keys show "$NODE1_KEY_NAME" --address --home "$NODE1_HOME" --keyring-backend "$KEYRING_BACKEND")" +NODE2_ADDR="$("$BINARY_PATH" keys show "$NODE2_KEY_NAME" --address --home "$NODE2_HOME" --keyring-backend "$KEYRING_BACKEND")" + +echo "==> Adding genesis accounts..." +"$BINARY_PATH" genesis add-genesis-account "$NODE1_ADDR" "${STAKE_AMOUNT}${DENOM}" --home "$NODE1_HOME" >/dev/null 2>&1 +"$BINARY_PATH" genesis add-genesis-account "$NODE2_ADDR" "${STAKE_AMOUNT}${DENOM}" --home "$NODE1_HOME" >/dev/null 2>&1 + +echo "==> Creating gentx for ${NODE1_KEY_NAME}..." +"$BINARY_PATH" genesis gentx "$NODE1_KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ + --chain-id "$CHAIN_ID" \ + --home "$NODE1_HOME" \ + --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 + +echo "==> Copying shared genesis to node2..." +cp "$NODE1_GENESIS_FILE" "$NODE2_GENESIS_FILE" + +echo "==> Creating gentx for ${NODE2_KEY_NAME}..." +"$BINARY_PATH" genesis gentx "$NODE2_KEY_NAME" "${BOND_AMOUNT}${DENOM}" \ + --chain-id "$CHAIN_ID" \ + --home "$NODE2_HOME" \ + --keyring-backend "$KEYRING_BACKEND" >/dev/null 2>&1 + +echo "==> Collecting gentxs..." +cp "$NODE2_HOME"/config/gentx/*.json "$NODE1_HOME/config/gentx/" +"$BINARY_PATH" genesis collect-gentxs --home "$NODE1_HOME" >/dev/null 2>&1 + +NODE1_COSMOS_PUB_KEY="$(read_consensus_pub_key "$NODE1_HOME/config/priv_validator_key.json")" +NODE2_COSMOS_PUB_KEY="$(read_consensus_pub_key "$NODE2_HOME/config/priv_validator_key.json")" + +echo "==> Patching keyregistry validator key pairs..." +python3 "$PYTHON_HELPER" patch-keyregistry \ + --genesis "$NODE1_GENESIS_FILE" \ + --cosmos-key "$NODE1_COSMOS_PUB_KEY" \ + --mina-pub-key "$NODE1_MINA_PUB_KEY" \ + --cosmos-key "$NODE2_COSMOS_PUB_KEY" \ + --mina-pub-key "$NODE2_MINA_PUB_KEY" >/dev/null + +echo "==> Validating final genesis..." +"$BINARY_PATH" genesis validate-genesis --home "$NODE1_HOME" >/dev/null 2>&1 + +echo "==> Copying final genesis to node2..." +cp "$NODE1_GENESIS_FILE" "$NODE2_GENESIS_FILE" + +NODE1_ID="$("$BINARY_PATH" tendermint show-node-id --home "$NODE1_HOME")" +NODE2_ID="$("$BINARY_PATH" tendermint show-node-id --home "$NODE2_HOME")" + +echo "==> Configuring node1..." +configure_node \ + "$NODE1_HOME" \ + "$NODE1_RPC_PORT" \ + "$NODE1_P2P_PORT" \ + "$NODE1_API_PORT" \ + "$NODE1_GRPC_PORT" \ + "$NODE2_ID@127.0.0.1:$NODE2_P2P_PORT" \ + "$NODE1_MINA_PRIV_KEY" + +echo "==> Configuring node2..." +configure_node \ + "$NODE2_HOME" \ + "$NODE2_RPC_PORT" \ + "$NODE2_P2P_PORT" \ + "$NODE2_API_PORT" \ + "$NODE2_GRPC_PORT" \ + "$NODE1_ID@127.0.0.1:$NODE1_P2P_PORT" \ + "$NODE2_MINA_PRIV_KEY" + +echo "" +echo "Setup complete." +echo " binary: $BINARY_PATH" +echo " compat binary: $COMPAT_BINARY_PATH" +echo " node1 home: $NODE1_HOME" +echo " node2 home: $NODE2_HOME" +echo " node1 address: $NODE1_ADDR" +echo " node2 address: $NODE2_ADDR" +echo " node1 cosmos key: $NODE1_COSMOS_PUB_KEY" +echo " node2 cosmos key: $NODE2_COSMOS_PUB_KEY" +echo " node1 mina key: $NODE1_MINA_PUB_KEY" +echo " node2 mina key: $NODE2_MINA_PUB_KEY" +echo "" +echo "Start the nodes in separate terminals:" +echo " $BINARY_PATH start --home $NODE1_HOME" +echo " $BINARY_PATH start --home $NODE2_HOME" +echo "" +echo "Validation examples:" +echo " curl -s http://localhost:$NODE1_RPC_PORT/validators | python3 -m json.tool | grep total" +echo " $BINARY_PATH query votepersistence vote-ext-body-by-height 5 --home $NODE1_HOME" diff --git a/scripts/setup_local_testnet_helper.py b/scripts/setup_local_testnet_helper.py new file mode 100644 index 00000000..a84917d1 --- /dev/null +++ b/scripts/setup_local_testnet_helper.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 + +import argparse +import json +import re +import sys +from pathlib import Path +from typing import Optional + + +def read_text(path_str: str) -> str: + return Path(path_str).read_text(encoding="utf-8") + + +def write_text(path_str: str, content: str) -> None: + Path(path_str).write_text(content, encoding="utf-8") + + +def read_json(path_str: str): + return json.loads(read_text(path_str)) + + +def write_json(path_str: str, payload) -> None: + write_text(path_str, json.dumps(payload, indent=2) + "\n") + + +def read_mina_priv_key(config_path: str) -> int: + content = read_text(config_path) + match = re.search(r'vote_extension:\s*\n\s*priv_key:\s*"([^"]+)"', content) + if not match: + raise SystemExit( + f"could not find validators[].app.vote_extension.priv_key in {config_path}" + ) + + print(match.group(1)) + return 0 + + +def set_vote_extension_height(genesis_path: str, height: str) -> int: + genesis = read_json(genesis_path) + genesis["consensus"]["params"]["abci"]["vote_extensions_enable_height"] = height + write_json(genesis_path, genesis) + return 0 + + +def read_consensus_pub_key(priv_validator_key_path: str) -> int: + priv_validator_key = read_json(priv_validator_key_path) + print(priv_validator_key["pub_key"]["value"]) + return 0 + + +def extract_gentx_consensus_pub_keys(genesis) -> list[str]: + gentxs = genesis["app_state"]["genutil"]["gen_txs"] + cosmos_keys = [] + + for gentx in gentxs: + messages = gentx.get("body", {}).get("messages", []) + if not messages: + continue + + pub_key = messages[0].get("pubkey", {}).get("key") + if pub_key: + cosmos_keys.append(pub_key) + + return cosmos_keys + + +def patch_keyregistry( + genesis_path: str, mina_pub_keys: list[str], cosmos_keys: Optional[list[str]] = None +) -> int: + genesis = read_json(genesis_path) + + if not mina_pub_keys: + raise SystemExit("at least one --mina-pub-key is required") + + if cosmos_keys is None: + cosmos_keys = extract_gentx_consensus_pub_keys(genesis) + + if len(cosmos_keys) != len(mina_pub_keys): + raise SystemExit( + "validator key pair count mismatch: " + f"{len(cosmos_keys)} cosmos keys for {len(mina_pub_keys)} mina keys" + ) + + keyregistry = genesis["app_state"].setdefault("keyregistry", {}) + keyregistry["params"] = keyregistry.get("params", {}) + keyregistry["user_key_pairs"] = [] + keyregistry["validator_key_pairs"] = [ + { + "cosmos_key": cosmos_key, + "mina_key": mina_pub_key, + } + for cosmos_key, mina_pub_key in zip(cosmos_keys, mina_pub_keys) + ] + + write_json(genesis_path, genesis) + print("\n".join(cosmos_keys)) + return 0 + + +def update_app_config(app_path: str, min_gas_price: str, mina_priv_key: str) -> int: + app_toml = read_text(app_path) + app_toml = app_toml.replace( + 'minimum-gas-prices = ""', + f'minimum-gas-prices = "{min_gas_price}"', + 1, + ) + + vote_extension_block = f'[vote_extension]\npriv_key = "{mina_priv_key}"\n' + + if "\n[vote_extension]\n" in app_toml: + start = app_toml.index("\n[vote_extension]\n") + 1 + end = app_toml.find("\n[", start + 1) + if end == -1: + app_toml = app_toml[:start] + vote_extension_block + else: + app_toml = app_toml[:start] + vote_extension_block + app_toml[end + 1 :] + else: + app_toml = app_toml.rstrip() + f"\n\n{vote_extension_block}" + + write_text(app_path, app_toml) + return 0 + + +def build_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Helpers for local testnet setup.") + subparsers = parser.add_subparsers(dest="command", required=True) + + read_key = subparsers.add_parser("read-mina-priv-key") + read_key.add_argument("--config", required=True) + + read_consensus_key = subparsers.add_parser("read-consensus-pub-key") + read_consensus_key.add_argument("--priv-validator-key", required=True) + + set_height = subparsers.add_parser("set-vote-extension-height") + set_height.add_argument("--genesis", required=True) + set_height.add_argument("--height", required=True) + + patch_registry = subparsers.add_parser("patch-keyregistry") + patch_registry.add_argument("--genesis", required=True) + patch_registry.add_argument("--cosmos-key", action="append") + patch_registry.add_argument("--mina-pub-key", action="append", required=True) + + update_app = subparsers.add_parser("update-app-config") + update_app.add_argument("--app", required=True) + update_app.add_argument("--min-gas-price", required=True) + update_app.add_argument("--mina-priv-key", required=True) + + return parser + + +def main() -> int: + parser = build_parser() + args = parser.parse_args() + + if args.command == "read-mina-priv-key": + return read_mina_priv_key(args.config) + if args.command == "read-consensus-pub-key": + return read_consensus_pub_key(args.priv_validator_key) + if args.command == "set-vote-extension-height": + return set_vote_extension_height(args.genesis, args.height) + if args.command == "patch-keyregistry": + return patch_keyregistry(args.genesis, args.mina_pub_key, args.cosmos_key) + if args.command == "update-app-config": + return update_app_config(args.app, args.min_gas_price, args.mina_priv_key) + + parser.print_help(sys.stderr) + return 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/x/keyregistry/keeper/genesis.go b/x/keyregistry/keeper/genesis.go index 8bbcbd8a..67ddbf71 100644 --- a/x/keyregistry/keeper/genesis.go +++ b/x/keyregistry/keeper/genesis.go @@ -1,24 +1,36 @@ package keeper import ( + "bytes" "context" + errorsmod "cosmossdk.io/errors" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) // InitGenesis initializes the module's state from a provided genesis state. func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { + if err := genState.Validate(); err != nil { + return err + } - keyPairs := genState.KeyPairs - - // Insert genesis key pairs. - for _, keyPair := range keyPairs { + for _, keyPair := range genState.UserKeyPairs { + err := k.userCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) + if err != nil { + return err + } + err = k.userMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + if err != nil { + return err + } + } - err := k.cosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) + for _, keyPair := range genState.ValidatorKeyPairs { + err := k.validatorCosmosToMina.Set(ctx, keyPair.CosmosKey, keyPair.MinaKey) if err != nil { return err } - err = k.minaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) + err = k.validatorMinaToCosmos.Set(ctx, keyPair.MinaKey, keyPair.CosmosKey) if err != nil { return err } @@ -37,72 +49,147 @@ func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) return nil, err } - var keyPairs []*types.KeyPair + genesis.UserKeyPairs, err = k.exportUserGenesisKeyPairs(ctx) + if err != nil { + return nil, err + } - var existenceMap = make(map[string]bool) + genesis.ValidatorKeyPairs, err = k.exportValidatorGenesisKeyPairs(ctx) + if err != nil { + return nil, err + } - // Iterate over CosmosToMina map first and collect all key pairs. - cosmosIterator, err := k.cosmosToMina.Iterate(ctx, nil) + if err := genesis.Validate(); err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, err.Error()) + } + + return genesis, nil +} + +func (k Keeper) exportUserGenesisKeyPairs(ctx context.Context) ([]*types.UserPublicKeyPair, error) { + userCosmosToMinaIterator, err := k.userCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer cosmosIterator.Close() + defer userCosmosToMinaIterator.Close() - for cosmosIterator.Valid() { - cosmosKey, err := cosmosIterator.Key() + var userKeyPairs []*types.UserPublicKeyPair + + for userCosmosToMinaIterator.Valid() { + cosmosKey, err := userCosmosToMinaIterator.Key() + if err != nil { + return nil, err + } + minaKey, err := userCosmosToMinaIterator.Value() if err != nil { - return genesis, err + return nil, err } - minaKey, err := cosmosIterator.Value() + reverseCosmosKey, err := k.userMinaToCosmos.Get(ctx, minaKey) if err != nil { - return genesis, err + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user key pair missing reverse index") + } + if !bytes.Equal(reverseCosmosKey, cosmosKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user key pair reverse index mismatch") } - keyPair := &types.KeyPair{ + + userKeyPairs = append(userKeyPairs, &types.UserPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, + }) + + userCosmosToMinaIterator.Next() + } + + userMinaToCosmosIterator, err := k.userMinaToCosmos.Iterate(ctx, nil) + if err != nil { + return nil, err + } + defer userMinaToCosmosIterator.Close() + + for userMinaToCosmosIterator.Valid() { + minaKey, err := userMinaToCosmosIterator.Key() + if err != nil { + return nil, err + } + cosmosKey, err := userMinaToCosmosIterator.Value() + if err != nil { + return nil, err } - keyPairs = append(keyPairs, keyPair) - existenceMap[keyPair.String()] = true - cosmosIterator.Next() + forwardMinaKey, err := k.userCosmosToMina.Get(ctx, cosmosKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user reverse key pair missing forward index") + } + if !bytes.Equal(forwardMinaKey, minaKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "user reverse key pair forward index mismatch") + } + + userMinaToCosmosIterator.Next() } - // Iterate over MinaToCosmos map and collect any key pairs that are not - // already present in the CosmosToMina map. Although both maps are expected - // to be in sync, this ensures no key pairs are lost in case of any inconsistency - // between the two maps during export. + return userKeyPairs, nil +} - // ExportGenesis intentionally does not enforce consistency between the two maps. - // Returning an error here could prevent the state from being exported and lead - // to potential state loss. Consistency checks should instead be handled at the - // message implementation level where the mappings are created or updated. - minaIterator, err := k.minaToCosmos.Iterate(ctx, nil) +func (k Keeper) exportValidatorGenesisKeyPairs(ctx context.Context) ([]*types.ValidatorPublicKeyPair, error) { + validatorCosmosToMinaIterator, err := k.validatorCosmosToMina.Iterate(ctx, nil) if err != nil { return nil, err } - defer minaIterator.Close() + defer validatorCosmosToMinaIterator.Close() + + var validatorKeyPairs []*types.ValidatorPublicKeyPair - for minaIterator.Valid() { - minaKey, err := minaIterator.Key() + for validatorCosmosToMinaIterator.Valid() { + cosmosKey, err := validatorCosmosToMinaIterator.Key() + if err != nil { + return nil, err + } + minaKey, err := validatorCosmosToMinaIterator.Value() if err != nil { - return genesis, err + return nil, err } - cosmosKey, err := minaIterator.Value() + reverseCosmosKey, err := k.validatorMinaToCosmos.Get(ctx, minaKey) if err != nil { - return genesis, err + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator key pair missing reverse index") } - keyPair := &types.KeyPair{ + if !bytes.Equal(reverseCosmosKey, cosmosKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator key pair reverse index mismatch") + } + + keyPair := &types.ValidatorPublicKeyPair{ MinaKey: minaKey, CosmosKey: cosmosKey, } - if existenceMap[keyPair.String()] { - minaIterator.Next() - continue - } - keyPairs = append(keyPairs, keyPair) - minaIterator.Next() + + validatorKeyPairs = append(validatorKeyPairs, keyPair) + + validatorCosmosToMinaIterator.Next() } - genesis.KeyPairs = keyPairs + validatorMinaToCosmosIterator, err := k.validatorMinaToCosmos.Iterate(ctx, nil) + if err != nil { + return nil, err + } + defer validatorMinaToCosmosIterator.Close() - return genesis, nil + for validatorMinaToCosmosIterator.Valid() { + minaKey, err := validatorMinaToCosmosIterator.Key() + if err != nil { + return nil, err + } + cosmosKey, err := validatorMinaToCosmosIterator.Value() + if err != nil { + return nil, err + } + forwardMinaKey, err := k.validatorCosmosToMina.Get(ctx, cosmosKey) + if err != nil { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator reverse key pair missing forward index") + } + if !bytes.Equal(forwardMinaKey, minaKey) { + return nil, errorsmod.Wrap(types.ErrInvalidGenesisState, "validator reverse key pair forward index mismatch") + } + + validatorMinaToCosmosIterator.Next() + } + + return validatorKeyPairs, nil } diff --git a/x/keyregistry/keeper/genesis_internal_test.go b/x/keyregistry/keeper/genesis_internal_test.go new file mode 100644 index 00000000..bc804f54 --- /dev/null +++ b/x/keyregistry/keeper/genesis_internal_test.go @@ -0,0 +1,117 @@ +package keeper + +import ( + "bytes" + "context" + "testing" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func TestExportGenesisRejectsInconsistentRuntimeIndexes(t *testing.T) { + tests := []struct { + name string + corrupt func(context.Context, Keeper) error + }{ + { + name: "user forward missing reverse", + corrupt: func(ctx context.Context, k Keeper) error { + return k.userCosmosToMina.Set(ctx, testGenesisBytes(33, 'a'), testGenesisBytes(33, 'x')) + }, + }, + { + name: "user reverse missing forward", + corrupt: func(ctx context.Context, k Keeper) error { + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(33, 'a')) + }, + }, + { + name: "user forward reverse mismatch", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.userCosmosToMina.Set(ctx, testGenesisBytes(33, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(33, 'b')) + }, + }, + { + name: "validator forward missing reverse", + corrupt: func(ctx context.Context, k Keeper) error { + return k.validatorCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')) + }, + }, + { + name: "validator reverse missing forward", + corrupt: func(ctx context.Context, k Keeper) error { + return k.validatorMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'a')) + }, + }, + { + name: "validator forward reverse mismatch", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.validatorCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.validatorMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'b')) + }, + }, + { + name: "consistent indexes with invalid exported key length", + corrupt: func(ctx context.Context, k Keeper) error { + if err := k.userCosmosToMina.Set(ctx, testGenesisBytes(32, 'a'), testGenesisBytes(33, 'x')); err != nil { + return err + } + return k.userMinaToCosmos.Set(ctx, testGenesisBytes(33, 'x'), testGenesisBytes(32, 'a')) + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + ctx, k := initInternalGenesisFixture(t) + + err := tc.corrupt(ctx, k) + require.NoError(t, err) + + genesis, err := k.ExportGenesis(ctx) + require.Nil(t, genesis) + require.ErrorIs(t, err, types.ErrInvalidGenesisState) + }) + } +} + +func initInternalGenesisFixture(t *testing.T) (context.Context, Keeper) { + t.Helper() + + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + authority := authtypes.NewModuleAddress(types.GovModuleName) + cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + k := NewKeeper( + storeService, + cdc, + addressCodec, + authority, + ) + + err := k.Params.Set(ctx, types.DefaultParams()) + require.NoError(t, err) + + return ctx, k +} + +func testGenesisBytes(length int, value byte) []byte { + return bytes.Repeat([]byte{value}, length) +} diff --git a/x/keyregistry/keeper/genesis_test.go b/x/keyregistry/keeper/genesis_test.go index 26bc0bc0..d186b791 100644 --- a/x/keyregistry/keeper/genesis_test.go +++ b/x/keyregistry/keeper/genesis_test.go @@ -1,13 +1,11 @@ package keeper_test import ( - "crypto/ed25519" - "crypto/rand" "testing" + cometed25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/node101-io/pulsar-chain/x/keyregistry/types" - "github.com/stretchr/testify/require" ) @@ -26,37 +24,94 @@ func TestGenesis(t *testing.T) { require.EqualExportedValues(t, genesisState.Params, got.Params) } -// TestInitAndExportGenesis verifies that a genesis state can be initialized -// and later exported without losing the registered key pairs. +// TestInitAndExportGenesis verifies that a canonical genesis state can be +// initialized, stored in both runtime lookup maps, and exported again. func TestInitAndExportGenesis(t *testing.T) { - f := initFixture(t) - cosmosPriv := secp256k1.GenPrivKey() - - cosmosPubKey := cosmosPriv.PubKey() - - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } + userCosmosPubKey := secp256k1.GenPrivKey().PubKey() + validatorPublicKey := cometed25519.GenPrivKey().PubKey() + minaPriv := secp256k1.GenPrivKey() + minaPubKey := minaPriv.PubKey().Bytes() genesisState := types.GenesisState{ Params: types.DefaultParams(), - KeyPairs: []*types.KeyPair{ + UserKeyPairs: []*types.UserPublicKeyPair{ { MinaKey: minaPubKey, - CosmosKey: cosmosPubKey.Bytes(), + CosmosKey: userCosmosPubKey.Bytes(), + }, + }, + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + { + MinaKey: minaPubKey, + CosmosKey: validatorPublicKey.Bytes(), }, }, } - err = f.keeper.InitGenesis(f.ctx, genesisState) + err := f.keeper.InitGenesis(f.ctx, genesisState) + require.NoError(t, err) + + userMinaPubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, userCosmosPubKey.Bytes()) + require.NoError(t, err) + require.Equal(t, minaPubKey, userMinaPubKey) + + userCosmosKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, userCosmosPubKey.Bytes(), userCosmosKey) + + validatorMinaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, validatorPublicKey.Bytes()) + require.NoError(t, err) + require.Equal(t, minaPubKey, validatorMinaPubKey) + + validatorCosmosKey, err := f.keeper.ValidatorGetMinaToCosmos(f.ctx, minaPubKey) require.NoError(t, err) + require.Equal(t, validatorPublicKey.Bytes(), validatorCosmosKey) + got, err := f.keeper.ExportGenesis(f.ctx) require.NoError(t, err) require.NotNil(t, got) - require.EqualExportedValues(t, genesisState.KeyPairs, got.KeyPairs) + require.EqualExportedValues(t, genesisState.UserKeyPairs, got.UserKeyPairs) + require.EqualExportedValues(t, genesisState.ValidatorKeyPairs, got.ValidatorKeyPairs) +} + +func TestInitGenesisRejectsInvalidStateWithoutPartialWrite(t *testing.T) { + f := initFixture(t) + + userCosmosPubKey := secp256k1.GenPrivKey().PubKey() + minaPrivKey := secp256k1.GenPrivKey() + minaPubKey := minaPrivKey.PubKey().Bytes() + secondaryMinaPrivKey := secp256k1.GenPrivKey() + secondaryMinaPubKey := secondaryMinaPrivKey.PubKey().Bytes() + + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + UserKeyPairs: []*types.UserPublicKeyPair{ + { + MinaKey: minaPubKey, + CosmosKey: userCosmosPubKey.Bytes(), + }, + { + MinaKey: secondaryMinaPubKey, + CosmosKey: userCosmosPubKey.Bytes(), + }, + }, + } + + err := f.keeper.InitGenesis(f.ctx, genesisState) + require.ErrorIs(t, err, types.ErrInvalidGenesisState) + + exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, userCosmosPubKey.Bytes()) + require.NoError(t, err) + require.False(t, exists) + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaPubKey) + require.NoError(t, err) + require.False(t, exists) + + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, secondaryMinaPubKey) + require.NoError(t, err) + require.False(t, exists) } diff --git a/x/keyregistry/keeper/keeper.go b/x/keyregistry/keeper/keeper.go index 2097b0f3..52be513c 100644 --- a/x/keyregistry/keeper/keeper.go +++ b/x/keyregistry/keeper/keeper.go @@ -11,8 +11,11 @@ import ( "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) -const CosmosToMinaMapName string = "cosmos_to_mina" -const MinaToCosmosMapName string = "mina_to_cosmos" +const UserCosmosToMinaMapName string = "user_cosmos_to_mina" +const UserMinaToCosmosMapName string = "user_mina_to_cosmos" + +const ValidatorCosmosToMinaMapName string = "validator_cosmos_to_mina" +const ValidatorMinaToCosmosMapName string = "validator_mina_to_cosmos" type Keeper struct { storeService corestore.KVStoreService @@ -25,8 +28,11 @@ type Keeper struct { Schema collections.Schema Params collections.Item[types.Params] - cosmosToMina collections.Map[[]byte, []byte] // Cosmos PubKey --> Mina PubKey - minaToCosmos collections.Map[[]byte, []byte] // Mina PubKey --> Cosmos PubKey + userCosmosToMina collections.Map[[]byte, []byte] // Cosmos Public Key --> Mina Public Key + userMinaToCosmos collections.Map[[]byte, []byte] // Mina Public Key --> CosmosPublic Key + + validatorCosmosToMina collections.Map[[]byte, []byte] // Validator Cosmos Public Key --> Validator Mina Public Key + validatorMinaToCosmos collections.Map[[]byte, []byte] // Validator Mina Public Key --> Validator Cosmos Public Key } func NewKeeper( @@ -50,8 +56,11 @@ func NewKeeper( Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), - cosmosToMina: collections.NewMap(sb, types.CosmosToMinaPrefix, CosmosToMinaMapName, collections.BytesKey, collections.BytesValue), - minaToCosmos: collections.NewMap(sb, types.MinaToCosmosPrefix, MinaToCosmosMapName, collections.BytesKey, collections.BytesValue), + userCosmosToMina: collections.NewMap(sb, types.UserCosmosToMinaPrefix, UserCosmosToMinaMapName, collections.BytesKey, collections.BytesValue), + userMinaToCosmos: collections.NewMap(sb, types.UserMinaToCosmosPrefix, UserMinaToCosmosMapName, collections.BytesKey, collections.BytesValue), + + validatorCosmosToMina: collections.NewMap(sb, types.ValidatorCosmosToMinaPrefix, ValidatorCosmosToMinaMapName, collections.BytesKey, collections.BytesValue), + validatorMinaToCosmos: collections.NewMap(sb, types.ValidatorMinaToCosmosPrefix, ValidatorMinaToCosmosMapName, collections.BytesKey, collections.BytesValue), } schema, err := sb.Build() if err != nil { @@ -67,26 +76,34 @@ func (k Keeper) GetAuthority() []byte { return k.authority } -func (k Keeper) SetCosmosToMina(ctx context.Context, cosmosPublicKey, minaPublicKey []byte) error { - return k.cosmosToMina.Set(ctx, cosmosPublicKey, minaPublicKey) +func (k Keeper) UserGetCosmosToMina(ctx context.Context, cosmosPubKey []byte) ([]byte, error) { + return k.userCosmosToMina.Get(ctx, cosmosPubKey) +} + +func (k Keeper) UserGetMinaToCosmos(ctx context.Context, minaPubKey []byte) ([]byte, error) { + return k.userMinaToCosmos.Get(ctx, minaPubKey) +} + +func (k Keeper) UserCosmosToMinaHas(ctx context.Context, cosmosPubKey []byte) (bool, error) { + return k.userCosmosToMina.Has(ctx, cosmosPubKey) } -func (k Keeper) GetCosmosToMina(ctx context.Context, cosmosPublicKey []byte) ([]byte, error) { - return k.cosmosToMina.Get(ctx, cosmosPublicKey) +func (k Keeper) UserMinaToCosmosHas(ctx context.Context, minaPubKey []byte) (bool, error) { + return k.userMinaToCosmos.Has(ctx, minaPubKey) } -func (k Keeper) SetMinaToCosmos(ctx context.Context, minaPublicKey, cosmosPublicKey []byte) error { - return k.minaToCosmos.Set(ctx, minaPublicKey, cosmosPublicKey) +func (k Keeper) ValidatorGetCosmosToMina(ctx context.Context, consensusPubKey []byte) ([]byte, error) { + return k.validatorCosmosToMina.Get(ctx, consensusPubKey) } -func (k Keeper) GetMinaToCosmos(ctx context.Context, minaPublicKey []byte) ([]byte, error) { - return k.minaToCosmos.Get(ctx, minaPublicKey) +func (k Keeper) ValidatorGetMinaToCosmos(ctx context.Context, minaPubKey []byte) ([]byte, error) { + return k.validatorMinaToCosmos.Get(ctx, minaPubKey) } -func (k Keeper) CosmosToMinaHas(ctx context.Context, cosmosPublicKey []byte) (bool, error) { - return k.cosmosToMina.Has(ctx, cosmosPublicKey) +func (k Keeper) ValidatorCosmosToMinaHas(ctx context.Context, consensusPubKey []byte) (bool, error) { + return k.validatorCosmosToMina.Has(ctx, consensusPubKey) } -func (k Keeper) MinaToCosmosHas(ctx context.Context, minaPublicKey []byte) (bool, error) { - return k.minaToCosmos.Has(ctx, minaPublicKey) +func (k Keeper) ValidatorMinaToCosmosHas(ctx context.Context, minaPubKey []byte) (bool, error) { + return k.validatorMinaToCosmos.Has(ctx, minaPubKey) } diff --git a/x/keyregistry/keeper/keeper_test.go b/x/keyregistry/keeper/keeper_test.go index e00bb4a5..3d99a685 100644 --- a/x/keyregistry/keeper/keeper_test.go +++ b/x/keyregistry/keeper/keeper_test.go @@ -56,34 +56,68 @@ func initFixture(t *testing.T) *fixture { } } -// Dummy public keys used in tests. -var CosmosPubKey = []byte("cosmos") -var MinaPubKey = []byte("mina") - // TestCosmosToMina verifies that a cosmos public key can be stored in the // CosmosToMina map and correctly retrieved using the same cosmos public key. -func TestCosmosToMina(t *testing.T) { +func TestUserCosmosToMina(t *testing.T) { f := initFixture(t) - err := f.keeper.SetCosmosToMina(f.ctx, CosmosPubKey, MinaPubKey) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) - pubKey, err := f.keeper.GetCosmosToMina(f.ctx, CosmosPubKey) + pubKey, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) require.NoError(t, err) - require.Equal(t, MinaPubKey, pubKey) + require.Equal(t, minaPubKey, pubKey) } // TestMinaToCosmos verifies that a mina public key can be stored in the // MinaToCosmos map and correctly retrieved using the same mina public key. -func TestMinaToCosmos(t *testing.T) { +func TestUserMinaToCosmos(t *testing.T) { f := initFixture(t) - err := f.keeper.SetMinaToCosmos(f.ctx, MinaPubKey, CosmosPubKey) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) - pubKey, err := f.keeper.GetMinaToCosmos(f.ctx, MinaPubKey) + pubKey, err := f.keeper.UserGetMinaToCosmos(f.ctx, minaPubKey) require.NoError(t, err) - require.Equal(t, CosmosPubKey, pubKey) + require.Equal(t, cosmosPublicKey.Bytes(), pubKey) } diff --git a/x/keyregistry/keeper/msg_server_register_keys.go b/x/keyregistry/keeper/msg_server_register_keys.go index 321dfc44..b60004b9 100644 --- a/x/keyregistry/keeper/msg_server_register_keys.go +++ b/x/keyregistry/keeper/msg_server_register_keys.go @@ -3,29 +3,46 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) -// TODO: Implement Mina signature verification -func VerifyMinaSig(sig string, msg, minaPublicKey []byte) bool { +// TODO: Implement Mina signature verification for users +func VerifyUserMinaSig(sig []byte, msg, minaAddress []byte) bool { return true } -// TODO: Implement Cosmos signature verification -func VerifyCosmosSig(sig string, msg, cosmosPublicKey []byte) bool { +// TODO: Implement Cosmos signature verification for users +func VerifyUserCosmosSig(sig []byte, msg, cosmosAddress []byte) bool { return true } -// deriveAddressFromPubkey derives a bech32 cosmos address from a compressed secp256k1 public key. -func deriveAddressFromPubkey(cosmosPublicKey []byte) string { +// TODO: Implement Mina signature verification for users +func VerifyValidatorMinaSig(sig []byte, msg, minaAddress []byte) bool { + return true +} + +// TODO: Implement Cosmos signature verification for users +func VerifyValidatorCosmosSig(sig []byte, msg, cosmosAddress []byte) bool { + return true +} + +// deriveAddressFromPubkey derives the expected signer address from the provided +// key material. +func deriveAddressFromPubkey(actorType types.ActorType, cosmosPublicKey []byte) (string, error) { + + if actorType != types.ActorType_USER { + return "", types.ErrInvalidActorType + } + pubKey := secp256k1.PubKey{ Key: cosmosPublicKey, } + addr := sdk.AccAddress(pubKey.Address()) - return addr.String() + return addr.String(), nil + } // RegisterKeys registers a Mina and Cosmos public key pair on chain. @@ -38,56 +55,17 @@ func deriveAddressFromPubkey(cosmosPublicKey []byte) string { // // If all checks pass, the key pair is stored in both the CosmosToMina and MinaToCosmos maps. func (k msgServer) RegisterKeys(ctx context.Context, msg *types.MsgRegisterKeys) (*types.MsgRegisterKeysResponse, error) { - // Validate the creator address. - if _, err := k.addressCodec.StringToBytes(msg.Creator); err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") - } - - // Ensure the cosmos and mina public keys are valid. - err := types.ValidateKeyPair(types.KeyPair{ - MinaKey: msg.MinaPublicKey, - CosmosKey: msg.CosmosPublicKey, - }) - if err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidPublicKey, "pubkeys must be valid") - } - // Ensure the creator address matches the provided cosmos public key - // to prevent someone from registering a key pair on behalf of another address. - derivedAddress := deriveAddressFromPubkey(msg.CosmosPublicKey) + var err error - if derivedAddress != msg.Creator { - return nil, errorsmod.Wrap(types.ErrInvalidSigner, "creator does not match provided cosmos public key") - } - - // Check if either key is already registered to prevent duplicate registrations. - cosmosKeyExists, err := k.Keeper.cosmosToMina.Has(ctx, msg.CosmosPublicKey) - if err != nil { - return nil, err - } - minaKeyExists, err := k.Keeper.minaToCosmos.Has(ctx, msg.MinaPublicKey) - if err != nil { - return nil, err - } - if cosmosKeyExists || minaKeyExists { - return nil, errorsmod.Wrap(types.ErrSecondaryKeyExists, "") - } - - // Verify that the mina key signed the cosmos public key and vice versa. - // This proves ownership of both keys. - minaSigValidity := VerifyMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) - cosmosSigValidity := VerifyCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) - - if !minaSigValidity || !cosmosSigValidity { - return nil, errorsmod.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") - } - - // Store the key pair in both directions to allow lookups by either key. - err = k.Keeper.cosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) - if err != nil { - return nil, err + switch msg.ActorType { + case types.ActorType_USER: + err = k.handleUserRegistration(ctx, msg) + case types.ActorType_VALIDATOR: + err = k.handleValidatorRegistration(ctx, msg) + default: + return nil, types.ErrInvalidActorType } - err = k.Keeper.minaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) if err != nil { return nil, err } diff --git a/x/keyregistry/keeper/msg_server_register_user_keys.go b/x/keyregistry/keeper/msg_server_register_user_keys.go new file mode 100644 index 00000000..aec9b37a --- /dev/null +++ b/x/keyregistry/keeper/msg_server_register_user_keys.go @@ -0,0 +1,65 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func (k msgServer) handleUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + _, err := k.addressCodec.StringToBytes(msg.Creator) + if err != nil { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") + } + + err = types.UserPublicKeyPair{ + MinaKey: msg.MinaPublicKey, + CosmosKey: msg.CosmosPublicKey, + }.Validate() + if err != nil { + return err + } + + cosmosAddr, err := deriveAddressFromPubkey(msg.ActorType, msg.CosmosPublicKey) + if err != nil { + return err + } + + if msg.Creator != cosmosAddr { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address does not match the provided cosmos public key") + } + + return k.persistUserRegistration(ctx, msg) +} + +func (k msgServer) persistUserRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + cosmosKeyExists, err := k.Keeper.userCosmosToMina.Has(ctx, msg.CosmosPublicKey) + if err != nil { + return err + } + minaKeyExists, err := k.Keeper.userMinaToCosmos.Has(ctx, msg.MinaPublicKey) + if err != nil { + return err + } + if cosmosKeyExists || minaKeyExists { + return errors.Wrap(types.ErrUserSecondaryKeyExists, "provided cosmos or mina public key is already registered") + } + + minaSigValidity := VerifyUserMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) + cosmosSigValidity := VerifyUserCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) + if !minaSigValidity || !cosmosSigValidity { + return errors.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + } + + err = k.Keeper.userCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) + if err != nil { + return err + } + err = k.Keeper.userMinaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) + if err != nil { + return err + } + + return nil +} diff --git a/x/keyregistry/keeper/msg_server_register_validator_keys.go b/x/keyregistry/keeper/msg_server_register_validator_keys.go new file mode 100644 index 00000000..c6789a08 --- /dev/null +++ b/x/keyregistry/keeper/msg_server_register_validator_keys.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +// handleValidatorRegistration encapsulates the validator registration flow +// where the Cosmos-side key is the validator public key. +func (k msgServer) handleValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") + } + + err = types.ValidatorPublicKeyPair{ + MinaKey: msg.MinaPublicKey, + CosmosKey: msg.CosmosPublicKey, + }.Validate() + if err != nil { + return err + } + + return k.persistValidatorRegistration(ctx, msg) +} + +func (k msgServer) persistValidatorRegistration(ctx context.Context, msg *types.MsgRegisterKeys) error { + cosmosKeyExists, err := k.Keeper.validatorCosmosToMina.Has(ctx, msg.CosmosPublicKey) + if err != nil { + return err + } + minaKeyExists, err := k.Keeper.validatorMinaToCosmos.Has(ctx, msg.MinaPublicKey) + if err != nil { + return err + } + if cosmosKeyExists || minaKeyExists { + return errors.Wrap(types.ErrValidatorSecondaryKeyExists, "provided cosmos or mina public key is already registered") + } + + minaSigValidity := VerifyValidatorMinaSig(msg.MinaSignature, msg.CosmosPublicKey, msg.MinaPublicKey) + cosmosSigValidity := VerifyValidatorCosmosSig(msg.CosmosSignature, msg.MinaPublicKey, msg.CosmosPublicKey) + if !minaSigValidity || !cosmosSigValidity { + return errors.Wrap(types.ErrInvalidSignature, "invalid cosmos or mina signature") + } + + err = k.Keeper.validatorCosmosToMina.Set(ctx, msg.CosmosPublicKey, msg.MinaPublicKey) + if err != nil { + return err + } + err = k.Keeper.validatorMinaToCosmos.Set(ctx, msg.MinaPublicKey, msg.CosmosPublicKey) + if err != nil { + return err + } + + return nil +} diff --git a/x/keyregistry/keeper/msg_server_update_keys.go b/x/keyregistry/keeper/msg_server_update_keys.go new file mode 100644 index 00000000..163cf0a0 --- /dev/null +++ b/x/keyregistry/keeper/msg_server_update_keys.go @@ -0,0 +1,165 @@ +package keeper + +import ( + "bytes" + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func (k msgServer) UpdateKeys(ctx context.Context, msg *types.MsgUpdateKeys) (*types.MsgUpdateKeysResponse, error) { + var err error + + if len(msg.NewMinaPublicKey) != keys.PublicKeyTotalByteSize { + return nil, errors.Wrap(types.ErrInvalidPublicKey, "new mina public key must be compressed (33 bytes)") + } + + switch msg.ActorType { + case types.ActorType_USER: + err = k.updateUserKeys(ctx, msg) + case types.ActorType_VALIDATOR: + err = k.updateValidatorKeys(ctx, msg) + default: + return nil, types.ErrInvalidActorType + } + if err != nil { + return nil, err + } + + return &types.MsgUpdateKeysResponse{}, nil +} + +func (k msgServer) updateUserKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { + _, err := k.addressCodec.StringToBytes(msg.Creator) + if err != nil { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") + } + + exists, err := k.UserMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrUserNotRegistered + } + + cosmosPublicKey, err := k.UserGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + + cosmosAddr, err := deriveAddressFromPubkey(msg.ActorType, cosmosPublicKey) + if err != nil { + return err + } + + if msg.Creator != cosmosAddr { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address does not match the registered cosmos public key") + } + + exists, err = k.UserCosmosToMinaHas(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrUserNotRegistered + } + + currentMinaPublicKey, err := k.UserGetCosmosToMina(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !bytes.Equal(currentMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrUserNotRegistered + } + + exists, err = k.UserMinaToCosmosHas(ctx, msg.NewMinaPublicKey) + if err != nil { + return err + } + if exists && !bytes.Equal(msg.NewMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrUserSecondaryKeyExists + } + + if !VerifyUserCosmosSig(msg.CosmosSignature, msg.NewMinaPublicKey, cosmosPublicKey) { + return types.ErrInvalidSignature + } + if !VerifyUserMinaSig(msg.NewMinaSignature, cosmosPublicKey, msg.NewMinaPublicKey) { + return types.ErrInvalidSignature + } + + err = k.userMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + err = k.userCosmosToMina.Set(ctx, cosmosPublicKey, msg.NewMinaPublicKey) + if err != nil { + return err + } + + return k.userMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosPublicKey) +} + +func (k msgServer) updateValidatorKeys(ctx context.Context, msg *types.MsgUpdateKeys) error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errors.Wrap(types.ErrInvalidCreatorAddress, "creator address must be a valid bech32 address") + } + + exists, err := k.ValidatorMinaToCosmosHas(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrValidatorNotRegistered + } + + cosmosPublicKey, err := k.ValidatorGetMinaToCosmos(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + + exists, err = k.ValidatorCosmosToMinaHas(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !exists { + return types.ErrValidatorNotRegistered + } + + currentMinaPublicKey, err := k.ValidatorGetCosmosToMina(ctx, cosmosPublicKey) + if err != nil { + return err + } + if !bytes.Equal(currentMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrValidatorNotRegistered + } + + exists, err = k.ValidatorMinaToCosmosHas(ctx, msg.NewMinaPublicKey) + if err != nil { + return err + } + if exists && !bytes.Equal(msg.NewMinaPublicKey, msg.PrevMinaPublicKey) { + return types.ErrValidatorSecondaryKeyExists + } + + if !VerifyValidatorCosmosSig(msg.CosmosSignature, msg.NewMinaPublicKey, cosmosPublicKey) { + return types.ErrInvalidSignature + } + if !VerifyValidatorMinaSig(msg.NewMinaSignature, cosmosPublicKey, msg.NewMinaPublicKey) { + return types.ErrInvalidSignature + } + + err = k.validatorMinaToCosmos.Remove(ctx, msg.PrevMinaPublicKey) + if err != nil { + return err + } + err = k.validatorCosmosToMina.Set(ctx, cosmosPublicKey, msg.NewMinaPublicKey) + if err != nil { + return err + } + + return k.validatorMinaToCosmos.Set(ctx, msg.NewMinaPublicKey, cosmosPublicKey) +} diff --git a/x/keyregistry/keeper/msg_update_params.go b/x/keyregistry/keeper/msg_update_params.go index adb9be7d..be8957f2 100644 --- a/x/keyregistry/keeper/msg_update_params.go +++ b/x/keyregistry/keeper/msg_update_params.go @@ -4,7 +4,7 @@ import ( "bytes" "context" - errorsmod "cosmossdk.io/errors" + "cosmossdk.io/errors" "github.com/node101-io/pulsar-chain/x/keyregistry/types" ) @@ -12,12 +12,12 @@ import ( func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { authority, err := k.addressCodec.StringToBytes(req.Authority) if err != nil { - return nil, errorsmod.Wrap(types.ErrInvalidCreatorAddres, "") + return nil, errors.Wrap(types.ErrInvalidCreatorAddress, "authority address must be a valid bech32 address") } if !bytes.Equal(k.GetAuthority(), authority) { expectedAuthorityStr, _ := k.addressCodec.BytesToString(k.GetAuthority()) - return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) + return nil, errors.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) } if err := req.Params.Validate(); err != nil { diff --git a/x/keyregistry/keeper/msg_update_params_test.go b/x/keyregistry/keeper/msg_update_params_test.go index 6f90037c..a2f9145d 100644 --- a/x/keyregistry/keeper/msg_update_params_test.go +++ b/x/keyregistry/keeper/msg_update_params_test.go @@ -33,7 +33,7 @@ func TestMsgUpdateParams(t *testing.T) { Params: params, }, expErr: true, - expErrMsg: types.ErrInvalidCreatorAddres.Error(), + expErrMsg: types.ErrInvalidCreatorAddress.Error(), }, { name: "send enabled param", diff --git a/x/keyregistry/keeper/query.go b/x/keyregistry/keeper/query.go index 5b8c8317..7f90e455 100644 --- a/x/keyregistry/keeper/query.go +++ b/x/keyregistry/keeper/query.go @@ -1,8 +1,6 @@ package keeper -import ( - "github.com/node101-io/pulsar-chain/x/keyregistry/types" -) +import "github.com/node101-io/pulsar-chain/x/keyregistry/types" var _ types.QueryServer = queryServer{} diff --git a/x/keyregistry/keeper/query_get_user_cosmos_address.go b/x/keyregistry/keeper/query_get_user_cosmos_address.go new file mode 100644 index 00000000..3a280de2 --- /dev/null +++ b/x/keyregistry/keeper/query_get_user_cosmos_address.go @@ -0,0 +1,39 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetCosmosPubKey returns the user's cosmos public key associated with the given mina public key. +// Returns NotFound if no mapping exists for the provided mina public key. +func (q queryServer) GetUserCosmosPublicKey(ctx context.Context, req *types.QueryGetUserCosmosPublicKeyRequest) (*types.QueryGetUserCosmosPublicKeyResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + // Check if the mina PublicKey exists in the MinaToCosmos map. + exists, err := q.k.userMinaToCosmos.Has(sdkCtx, req.UserMinaPublicKey) + if err != nil { + return nil, status.Error(codes.Internal, "internal error") + } + + if !exists { + return nil, status.Error(codes.NotFound, "cosmos key not found for given mina key") + } + + cosmosKey, err := q.k.userMinaToCosmos.Get(sdkCtx, req.UserMinaPublicKey) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryGetUserCosmosPublicKeyResponse{ + UserCosmosPublicKey: cosmosKey, + }, nil +} diff --git a/x/keyregistry/keeper/query_get_mina_pub_key.go b/x/keyregistry/keeper/query_get_user_mina_address.go similarity index 60% rename from x/keyregistry/keeper/query_get_mina_pub_key.go rename to x/keyregistry/keeper/query_get_user_mina_address.go index 301a62c0..0cf9b7cf 100644 --- a/x/keyregistry/keeper/query_get_mina_pub_key.go +++ b/x/keyregistry/keeper/query_get_user_mina_address.go @@ -9,9 +9,9 @@ import ( "google.golang.org/grpc/status" ) -// GetMinaPubKey returns the mina public key associated with the given cosmos public key. +// GetMinaPubKey returns the user's mina public key associated with the given cosmos public key. // Returns NotFound if no mapping exists for the provided cosmos public key. -func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaPubKeyRequest) (*types.QueryGetMinaPubKeyResponse, error) { +func (q queryServer) GetUserMinaPublicKey(ctx context.Context, req *types.QueryGetUserMinaPublicKeyRequest) (*types.QueryGetUserMinaPublicKeyResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -19,7 +19,7 @@ func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaP sdkCtx := sdk.UnwrapSDKContext(ctx) // Check if the cosmos key exists in the CosmosToMina map. - exists, err := q.k.cosmosToMina.Has(sdkCtx, req.CosmosPubKey) + exists, err := q.k.userCosmosToMina.Has(sdkCtx, req.UserCosmosPublicKey) if err != nil { return nil, status.Error(codes.Internal, "internal Error") } @@ -28,12 +28,12 @@ func (q queryServer) GetMinaPubKey(ctx context.Context, req *types.QueryGetMinaP return nil, status.Error(codes.NotFound, "mina key not found for given cosmos key") } - minaKey, err := q.k.cosmosToMina.Get(sdkCtx, req.CosmosPubKey) + minaKey, err := q.k.userCosmosToMina.Get(sdkCtx, req.UserCosmosPublicKey) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetMinaPubKeyResponse{ - MinaPubKey: minaKey, + return &types.QueryGetUserMinaPublicKeyResponse{ + UserMinaPublicKey: minaKey, }, nil } diff --git a/x/keyregistry/keeper/query_get_cosmos_pub_key.go b/x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go similarity index 58% rename from x/keyregistry/keeper/query_get_cosmos_pub_key.go rename to x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go index 241233a3..69e19fa9 100644 --- a/x/keyregistry/keeper/query_get_cosmos_pub_key.go +++ b/x/keyregistry/keeper/query_get_validator_cosmos_pub_key.go @@ -9,9 +9,10 @@ import ( "google.golang.org/grpc/status" ) -// GetCosmosPubKey returns the cosmos public key associated with the given mina public key. +// GetCosmosPubKey returns the Validator's cosmos public key associated with the given mina public key. // Returns NotFound if no mapping exists for the provided mina public key. -func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCosmosPubKeyRequest) (*types.QueryGetCosmosPubKeyResponse, error) { + +func (q queryServer) GetValidatorCosmosPubKey(ctx context.Context, req *types.QueryGetValidatorCosmosPubKeyRequest) (*types.QueryGetValidatorCosmosPubKeyResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -19,7 +20,7 @@ func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCos sdkCtx := sdk.UnwrapSDKContext(ctx) // Check if the mina key exists in the MinaToCosmos map. - exists, err := q.k.minaToCosmos.Has(sdkCtx, req.MinaPubKey) + exists, err := q.k.validatorMinaToCosmos.Has(sdkCtx, req.ValidatorMinaPubKey) if err != nil { return nil, status.Error(codes.Internal, "internal error") } @@ -28,12 +29,12 @@ func (q queryServer) GetCosmosPubKey(ctx context.Context, req *types.QueryGetCos return nil, status.Error(codes.NotFound, "cosmos key not found for given mina key") } - cosmosKey, err := q.k.minaToCosmos.Get(sdkCtx, req.MinaPubKey) + cosmosKey, err := q.k.validatorMinaToCosmos.Get(sdkCtx, req.ValidatorMinaPubKey) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } - return &types.QueryGetCosmosPubKeyResponse{ - CosmosPubKey: cosmosKey, + return &types.QueryGetValidatorCosmosPubKeyResponse{ + ValidatorCosmosPubKey: cosmosKey, }, nil } diff --git a/x/keyregistry/keeper/query_get_validator_mina_pub_key.go b/x/keyregistry/keeper/query_get_validator_mina_pub_key.go new file mode 100644 index 00000000..2f0ce656 --- /dev/null +++ b/x/keyregistry/keeper/query_get_validator_mina_pub_key.go @@ -0,0 +1,39 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetMinaPubKey returns the validator's mina public key associated with the given cosmos public key. +// Returns NotFound if no mapping exists for the provided cosmos public key. +func (q queryServer) GetValidatorMinaPubKey(ctx context.Context, req *types.QueryGetValidatorMinaPubKeyRequest) (*types.QueryGetValidatorMinaPubKeyResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + // Check if the cosmos key exists in the CosmosToMina map. + exists, err := q.k.validatorCosmosToMina.Has(sdkCtx, req.ValidatorCosmosPubKey) + if err != nil { + return nil, status.Error(codes.Internal, "internal Error") + } + + if !exists { + return nil, status.Error(codes.NotFound, "mina key not found for given cosmos key") + } + + minaKey, err := q.k.validatorCosmosToMina.Get(sdkCtx, req.ValidatorCosmosPubKey) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryGetValidatorMinaPubKeyResponse{ + ValidatorMinaPubKey: minaKey, + }, nil +} diff --git a/x/keyregistry/keeper/query_keypairs_test.go b/x/keyregistry/keeper/query_keypairs_test.go deleted file mode 100644 index b29c52cb..00000000 --- a/x/keyregistry/keeper/query_keypairs_test.go +++ /dev/null @@ -1,153 +0,0 @@ -package keeper_test - -import ( - "crypto/ed25519" - "crypto/rand" - "testing" - - "github.com/cometbft/cometbft/crypto/secp256k1" - "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" - "github.com/node101-io/pulsar-chain/x/keyregistry/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// TestCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns -// an InvalidArgument error when called with a nil request. -func TestCosmosMapInvalidArgumentFail(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - _, err := qs.GetCosmosPubKey(f.ctx, nil) - require.Error(t, err) - - st, _ := status.FromError(err) - require.Equal(t, codes.InvalidArgument, st.Code()) -} - -// TestCosmosMapSuccess verifies that a mina public key can be retrieved -// by its associated cosmos public key after being stored in the CosmosToMina map. -func TestCosmosMapSuccess(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - cosmosPriv := secp256k1.GenPrivKey() - - cosmosPubKey := cosmosPriv.PubKey() - - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } - require.NoError(t, err) - - err = f.keeper.SetCosmosToMina(f.ctx, cosmosPubKey.Bytes(), minaPubKey) - require.NoError(t, err) - - resp, err := qs.GetMinaPubKey(f.ctx, &types.QueryGetMinaPubKeyRequest{ - CosmosPubKey: cosmosPubKey.Bytes(), - }) - - require.NotNil(t, resp) - require.NoError(t, err) - - require.Equal(t, resp.MinaPubKey, []byte(minaPubKey)) -} - -// TestMinaMapSuccess verifies that a cosmos public key can be retrieved -// by its associated mina public key after being stored in the MinaToCosmos map. -func TestMinaMapSuccess(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - cosmosPriv := secp256k1.GenPrivKey() - - cosmosPubKey := cosmosPriv.PubKey() - - minaPubKey, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } - require.NoError(t, err) - - err = f.keeper.SetMinaToCosmos(f.ctx, minaPubKey, cosmosPubKey.Bytes()) - require.NoError(t, err) - - resp, err := qs.GetCosmosPubKey(f.ctx, &types.QueryGetCosmosPubKeyRequest{ - MinaPubKey: minaPubKey, - }) - - require.NotNil(t, resp) - require.NoError(t, err) - - require.Equal(t, resp.CosmosPubKey, cosmosPubKey.Bytes()) -} - -// TestMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns -// an InvalidArgument error when called with a nil request. -func TestMinaMapInvalidArgumentFail(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - _, err := qs.GetMinaPubKey(f.ctx, nil) - require.Error(t, err) - - st, _ := status.FromError(err) - require.Equal(t, codes.InvalidArgument, st.Code()) -} - -// TestCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns -// a NotFound error when the provided mina public key has no associated cosmos key. -func TestCosmosMapPubkeyNotFound(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - pub, _, err := ed25519.GenerateKey(rand.Reader) - if err != nil { - panic(err) - } - - _, err = qs.GetCosmosPubKey(f.ctx, &types.QueryGetCosmosPubKeyRequest{ - MinaPubKey: pub, - }) - - st, _ := status.FromError(err) - require.Equal(t, codes.NotFound, st.Code()) -} - -// TestMinaMapPubkeyNotFound verifies that GetMinaPubKey returns -// a NotFound error when the provided cosmos public key has no associated mina key. -func TestMinaMapPubkeyNotFound(t *testing.T) { - f := initFixture(t) - - qs := keeper.NewQueryServerImpl(f.keeper) - params := types.DefaultParams() - require.NoError(t, f.keeper.Params.Set(f.ctx, params)) - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - _, err := qs.GetMinaPubKey(f.ctx, &types.QueryGetMinaPubKeyRequest{ - CosmosPubKey: pub.Bytes(), - }) - - st, _ := status.FromError(err) - require.Equal(t, codes.NotFound, st.Code()) -} diff --git a/x/keyregistry/keeper/query_user_keypairs_test.go b/x/keyregistry/keeper/query_user_keypairs_test.go new file mode 100644 index 00000000..11ac4bb1 --- /dev/null +++ b/x/keyregistry/keeper/query_user_keypairs_test.go @@ -0,0 +1,172 @@ +package keeper_test + +import ( + "crypto/ed25519" + "crypto/rand" + "testing" + + "github.com/cometbft/cometbft/crypto/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// TestUserCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns +// an InvalidArgument error when called with a nil request. +func TestUserCosmosMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetUserCosmosPublicKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestUserCosmosMapSuccess verifies that a mina public key can be retrieved +// by its associated cosmos public key after being stored in the CosmosToMina map. +func TestUserCosmosMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + queryResp, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ + UserCosmosPublicKey: cosmosPublicKey.Bytes(), + }) + + require.NotNil(t, queryResp) + require.NoError(t, err) + + require.Equal(t, minaPubKey, queryResp.UserMinaPublicKey) +} + +// TestUserMinaMapSuccess verifies that a cosmos public key can be retrieved +// by its associated mina public key after being stored in the MinaToCosmos map. +func TestUserMinaMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + queryResp, err := qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ + UserMinaPublicKey: minaPubKey, + }) + + require.NotNil(t, queryResp) + require.NoError(t, err) + + require.Equal(t, cosmosPublicKey.Bytes(), queryResp.UserCosmosPublicKey) +} + +// TestUserMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns +// an InvalidArgument error when called with a nil request. +func TestUserMinaMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetUserMinaPublicKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestUserCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns +// a NotFound error when the provided mina public key has no associated cosmos key. +func TestUserCosmosMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + pub, _, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + panic(err) + } + + _, err = qs.GetUserCosmosPublicKey(f.ctx, &types.QueryGetUserCosmosPublicKeyRequest{ + UserMinaPublicKey: pub, + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} + +// TestUserMinaMapPubkeyNotFound verifies that GetMinaPubKey returns +// a NotFound error when the provided cosmos public key has no associated mina key. +func TestUserMinaMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + priv := secp256k1.GenPrivKey() + + pub := priv.PubKey() + + _, err := qs.GetUserMinaPublicKey(f.ctx, &types.QueryGetUserMinaPublicKeyRequest{ + UserCosmosPublicKey: pub.Bytes(), + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} diff --git a/x/keyregistry/keeper/query_validator_keypairs_test.go b/x/keyregistry/keeper/query_validator_keypairs_test.go new file mode 100644 index 00000000..ae2455bc --- /dev/null +++ b/x/keyregistry/keeper/query_validator_keypairs_test.go @@ -0,0 +1,168 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// TestValidatorCosmosMapInvalidArgumentFail verifies that GetCosmosPubKey returns +// an InvalidArgument error when called with a nil request. +func TestValidatorCosmosMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetValidatorCosmosPubKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestValidatorCosmosMapSuccess verifies that a mina public key can be retrieved +// by its associated cosmos public key after being stored in the CosmosToMina map. +func TestValidatorCosmosMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + queryResp, err := qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ + ValidatorCosmosPubKey: cosmosPubKey.Bytes(), + }) + + require.NotNil(t, queryResp) + require.NoError(t, err) + + require.Equal(t, queryResp.ValidatorMinaPubKey, minaPubKey) +} + +// TestValidatorMinaMapSuccess verifies that a cosmos public key can be retrieved +// by its associated mina public key after being stored in the MinaToCosmos map. +func TestValidatorMinaMapSuccess(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + queryResp, err := qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ + ValidatorMinaPubKey: minaPubKey, + }) + require.NotNil(t, queryResp) + require.NoError(t, err) + + require.Equal(t, cosmosPubKey.Bytes(), queryResp.ValidatorCosmosPubKey) +} + +// TestValidatorMinaMapInvalidArgumentFail verifies that GetMinaPubKey returns +// an InvalidArgument error when called with a nil request. +func TestValidatorMinaMapInvalidArgumentFail(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, err := qs.GetValidatorMinaPubKey(f.ctx, nil) + require.Error(t, err) + + st, _ := status.FromError(err) + require.Equal(t, codes.InvalidArgument, st.Code()) +} + +// TestValidatorCosmosMapPubkeyNotFound verifies that GetCosmosPubKey returns +// a NotFound error when the provided mina public key has no associated cosmos key. +func TestValidatorCosmosMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + _, minaPubKey, _, err := generateValidatorPublicKeys() + require.NotNil(t, minaPubKey) + require.NoError(t, err) + + _, err = qs.GetValidatorCosmosPubKey(f.ctx, &types.QueryGetValidatorCosmosPubKeyRequest{ + ValidatorMinaPubKey: minaPubKey, + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} + +// TestValidatorMinaMapPubkeyNotFound verifies that GetMinaPubKey returns +// a NotFound error when the provided cosmos public key has no associated mina key. +func TestValidatorMinaMapPubkeyNotFound(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + require.NoError(t, err) + + _, err = qs.GetValidatorMinaPubKey(f.ctx, &types.QueryGetValidatorMinaPubKeyRequest{ + ValidatorCosmosPubKey: cosmosPubKey.Bytes(), + }) + + st, _ := status.FromError(err) + require.Equal(t, codes.NotFound, st.Code()) +} diff --git a/x/keyregistry/keeper/register_keys_test.go b/x/keyregistry/keeper/register_keys_test.go deleted file mode 100644 index 3ad930d1..00000000 --- a/x/keyregistry/keeper/register_keys_test.go +++ /dev/null @@ -1,180 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/cometbft/cometbft/crypto/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" - "github.com/node101-io/pulsar-chain/x/keyregistry/types" - "github.com/stretchr/testify/require" -) - -// Mock signatures used across msg server tests. -// These will be replaced with real signatures once VerifyMinaSig and VerifyCosmosSig are implemented. -var mockCosmosSignature = "cosmosSig" -var mockMinaSignature = "minaSig" - -// TestRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey -// when the provided cosmos public key is not a valid compressed secp256k1 key (33 bytes). -func TestRegisterKeysFail(t *testing.T) { - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - creatorAddr := sdk.AccAddress([]byte("pulsar")) - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: creatorAddr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: CosmosPubKey, - MinaPublicKey: MinaPubKey, - }) - require.ErrorIs(t, err, types.ErrInvalidPublicKey) -} - -// TestRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs -// and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. -func TestRegisterKeysSuccess(t *testing.T) { - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - require.NoError(t, err) - require.NotNil(t, resp) - - exists, err := f.keeper.CosmosToMinaHas(f.ctx, pub.Bytes()) - require.NoError(t, err) - require.Equal(t, exists, true) - - exists, err = f.keeper.MinaToCosmosHas(f.ctx, MinaPubKey) - require.NoError(t, err) - require.Equal(t, exists, true) - -} - -// TestInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres -// when the creator field is not a valid bech32 address. -func TestInvalidCreatorAddress(t *testing.T) { - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: "creator", - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - require.ErrorIs(t, err, types.ErrInvalidCreatorAddres) -} - -// TestInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner -// when the creator address does not match the address derived from the provided cosmos public key. -func TestInvalidSigner(t *testing.T) { - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - secondaryPriv := secp256k1.GenPrivKey() - - secondaryPublic := secondaryPriv.PubKey() - - addr := sdk.AccAddress(secondaryPublic.Address()) - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - - require.ErrorIs(t, err, types.ErrInvalidSigner) - -} - -// TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented -// TestInvalidSignature currently expects no error since signature verification is not yet implemented. -func TestInvalidSignature(t *testing.T) { - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) - - f := initFixture(t) - ms := keeper.NewMsgServerImpl(f.keeper) - - invalidSig := "cosmosSig" - - _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), - CosmosSignature: invalidSig, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - - require.NoError(t, err) - -} - -// TestInsertSecondaryKeysFail verifies that registering the same key pair twice -// fails with ErrSecondaryKeyExists on the second attempt. -func TestInsertSecondaryKeysFail(t *testing.T) { - f := initFixture(t) - - priv := secp256k1.GenPrivKey() - - pub := priv.PubKey() - - addr := sdk.AccAddress(pub.Address()) - - ms := keeper.NewMsgServerImpl(f.keeper) - - // First registration should succeed. - resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - require.NoError(t, err) - require.NotNil(t, resp) - - // Second registration with the same keys should fail. - resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ - Creator: addr.String(), - CosmosSignature: mockCosmosSignature, - MinaSignature: mockMinaSignature, - CosmosPublicKey: pub.Bytes(), - MinaPublicKey: MinaPubKey, - }) - - require.ErrorIs(t, err, types.ErrSecondaryKeyExists) -} diff --git a/x/keyregistry/keeper/user_register_keys_test.go b/x/keyregistry/keeper/user_register_keys_test.go new file mode 100644 index 00000000..a3896bc8 --- /dev/null +++ b/x/keyregistry/keeper/user_register_keys_test.go @@ -0,0 +1,253 @@ +package keeper_test + +import ( + "testing" + + cometed25519 "github.com/cometbft/cometbft/crypto/ed25519" + + "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +// Mock signatures used across msg server tests. +// These will be replaced with real signatures once VerifyMinaSig and VerifyCosmosSig are implemented. +var mockCosmosSignature = []byte("cosmosSig") +var mockMinaSignature = []byte("minaSig") +var CosmosPubKey = []byte("cosmos-public-key") +var MinaPubKey = []byte("mina-public-key") + +var MinaPriv = []byte("7olA5Knafb5E2hJoWFzD+oamtyXIXXUZmYG9+pBMjTGIjqZTVLNGbE7DQ3Zq5YL5NMW31UMMMGgNCeEk+gyzRA==") + +func generateUserPublicKeys() (crypto.PubKey, []byte, []byte, error) { + + cosmosPrivKey := secp256k1.GenPrivKey() + cosmosPublicKey := cosmosPrivKey.PubKey() + + minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) + + minaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + minaSecondaryPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaSecondaryPriv)) + + minaSecondaryPublicKey, err := minaSecondaryPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, nil +} + +func generateValidatorPublicKeys() (crypto.PubKey, []byte, []byte, error) { + + cosmosPrivKey := cometed25519.GenPrivKey() + cosmosPublicKey := cosmosPrivKey.PubKey() + + minaPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaPriv)) + + minaPublicKey, err := minaPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + minaSecondaryPrivKey := keys.NewPrivateKeyFromBytes([32]byte(MinaSecondaryPriv)) + + minaSecondaryPublicKey, err := minaSecondaryPrivKey.ToPublicKey().Marshal() + if err != nil { + return nil, nil, nil, err + } + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, nil +} + +// TestUserRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey +// when the provided key material does not satisfy the current user registration checks. +func TestUserRegisterKeysFail(t *testing.T) { + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress([]byte("pulsar")) + + _, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: CosmosPubKey, + MinaPublicKey: MinaPubKey, + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrInvalidPublicKey) +} + +// TestUserRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs +// and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. +func TestUserRegisterKeysSuccess(t *testing.T) { + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.UserCosmosToMinaHas(f.ctx, cosmosPublicKey.Bytes()) + require.NoError(t, err) + require.Equal(t, exists, true) + + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, exists, true) + +} + +// TestUserInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres +// when the creator field is not a valid bech32 address. +func TestUserInvalidCreatorAddress(t *testing.T) { + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + require.NoError(t, err) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: "creator", + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) +} + +// TestUserInvalidSigner verifies that RegisterKeys fails with ErrInvalidSigner +// when the creator address bytes do not match the provided Cosmos-side value. +func TestUserInvalidSigner(t *testing.T) { + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + secondaryCosmosPublicKey, _, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, secondaryCosmosPublicKey) + + creatorAddr := sdk.AccAddress(secondaryCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) + +} + +// TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented +// TestUserInvalidSignature currently expects no error since signature verification is not yet implemented. +func TestUserInvalidSignature(t *testing.T) { + + cosmosPublicKey, minaPubKey, _, err := generateUserPublicKeys() + + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + invalidSig := []byte("cosmosSig") + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: invalidSig, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + + require.NoError(t, err) + +} + +// TestUserInsertSecondaryKeysFail verifies that registering the same key pair twice +// fails with ErrSecondaryKeyExists on the second attempt. +func TestUserInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + + cosmosPublicKey, minaPubKey, minaSecondaryPublicKey, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPubKey) + require.NotNil(t, minaSecondaryPublicKey) + + ms := keeper.NewMsgServerImpl(f.keeper) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + // First registration should succeed. + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + // Second registration with the same keys should fail. + resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaSecondaryPublicKey, + ActorType: types.ActorType_USER, + }) + + require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) +} diff --git a/x/keyregistry/keeper/user_update_keys_test.go b/x/keyregistry/keeper/user_update_keys_test.go new file mode 100644 index 00000000..fd75181f --- /dev/null +++ b/x/keyregistry/keeper/user_update_keys_test.go @@ -0,0 +1,202 @@ +package keeper_test + +import ( + "testing" + + "github.com/cometbft/cometbft/crypto" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +var MinaSecondaryPriv = []byte("0GUKibsJSZwgiU7k4cXQQWb2QKEP9/iRFATJEUqf2Pc+GxciLMKRQGTIcInKsTzV09rjDsLmZiBl9Up71bvV6g==") + +func registerUserKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (crypto.PubKey, []byte, []byte) { + t.Helper() + + cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generateUserPublicKeys() + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + + require.NoError(t, err) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPublicKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey +} + +func TestUserUpdateKeysSuccess(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPublicKey, newMinaPublicKey := registerUserKeysForUpdateTest(t, f, ms) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.UserMinaToCosmosHas(f.ctx, prevMinaPublicKey) + require.NoError(t, err) + require.False(t, exists) + + exists, err = f.keeper.UserMinaToCosmosHas(f.ctx, newMinaPublicKey) + require.NoError(t, err) + require.True(t, exists) + + minaAddr, err := f.keeper.UserGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) + require.NoError(t, err) + require.Equal(t, newMinaPublicKey, minaAddr) + + storedCosmosAddr, err := f.keeper.UserGetMinaToCosmos(f.ctx, newMinaPublicKey) + require.NoError(t, err) + require.Equal(t, cosmosPublicKey.Bytes(), storedCosmosAddr) +} + +func TestUserUpdateKeysNotRegistered(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPublicKey, minaSecondaryPublicKey, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: minaSecondaryPublicKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrUserNotRegistered) +} + +func TestUserUpdateKeysInvalidCreatorAddress(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, prevMinaPublicKey, newMinaPublicKey := registerUserKeysForUpdateTest(t, f, ms) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: "creator", + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) +} + +func TestUserUpdateKeysInvalidSigner(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, prevMinaAddr, _ := registerUserKeysForUpdateTest(t, f, ms) + + secondaryAddr, newMinaAddr, _, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, secondaryAddr) + require.NotNil(t, newMinaAddr) + + creatorAddr := sdk.AccAddress(secondaryAddr.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) +} + +func TestUserUpdateKeysInvalidSignature(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaAddr, newMinaAddr := registerUserKeysForUpdateTest(t, f, ms) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaAddr, + NewMinaPublicKey: newMinaAddr, + CosmosSignature: []byte("cosmosSig"), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) +} + +func TestUserUpdateKeysInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + firstCosmosPublicKey, prevMinaPublicKey, _ := registerUserKeysForUpdateTest(t, f, ms) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generateUserPublicKeys() + require.NoError(t, err) + require.NotNil(t, secondCosmosPublicKey) + require.NotNil(t, targetMinaPublicKey) + + creatorAddr := sdk.AccAddress(secondCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: secondCosmosPublicKey.Bytes(), + MinaPublicKey: targetMinaPublicKey, + ActorType: types.ActorType_USER, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + creatorAddr = sdk.AccAddress(firstCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: targetMinaPublicKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_USER, + }) + + require.ErrorIs(t, err, types.ErrUserSecondaryKeyExists) +} diff --git a/x/keyregistry/keeper/validator_register_keys_test.go b/x/keyregistry/keeper/validator_register_keys_test.go new file mode 100644 index 00000000..1b6fd9d4 --- /dev/null +++ b/x/keyregistry/keeper/validator_register_keys_test.go @@ -0,0 +1,168 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +// TestValidatorRegisterKeysFail verifies that RegisterKeys fails with ErrInvalidPublicKey +// when the provided cosmos consensus public key is invalid. +func TestValidatorRegisterKeysFail(t *testing.T) { + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, _, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: CosmosPubKey, + MinaPublicKey: MinaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.ErrorIs(t, err, types.ErrInvalidPublicKey) +} + +// TestValidatorRegisterKeysSuccess verifies that RegisterKeys succeeds with valid inputs +// and ensures that both CosmosToMina and MinaToCosmos mappings are correctly stored. +func TestValidatorRegisterKeysSuccess(t *testing.T) { + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.ValidatorCosmosToMinaHas(f.ctx, cosmosPubKey.Bytes()) + require.NoError(t, err) + require.Equal(t, exists, true) + + exists, err = f.keeper.ValidatorMinaToCosmosHas(f.ctx, minaPubKey) + require.NoError(t, err) + require.Equal(t, exists, true) +} + +// TestValidatorInvalidCreatorAddress verifies that RegisterKeys fails with ErrInvalidCreatorAddres +// when the creator field is not a valid bech32 address. +func TestValidatorInvalidCreatorAddress(t *testing.T) { + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + + require.NoError(t, err) + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: "creator", + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) +} + +// TODO: Update require.NoError to require.ErrorIs once the VerifyCosmosSig and VerifyMinaSig is implemented +// TestValidatorInvalidSignature currently expects no error since signature verification is not yet implemented. +func TestValidatorInvalidSignature(t *testing.T) { + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + require.NotNil(t, creatorAddr) + + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + invalidSig := []byte("cosmosSig") + + _, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: invalidSig, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.NoError(t, err) + +} + +// TestValidatorInsertSecondaryKeysFail verifies that registering the same key pair twice +// fails with ErrSecondaryKeyExists on the second attempt. +func TestValidatorInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + + cosmosPubKey, minaPubKey, _, err := generateValidatorPublicKeys() + require.NoError(t, err) + + require.NotNil(t, cosmosPubKey) + require.NotNil(t, minaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPubKey.Address()) + + ms := keeper.NewMsgServerImpl(f.keeper) + + // First registration should succeed. + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.NoError(t, err) + require.NotNil(t, resp) + + // Second registration with the same keys should fail. + resp, err = ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPubKey.Bytes(), + MinaPublicKey: minaPubKey, + ActorType: types.ActorType_VALIDATOR, + }) + + require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) +} diff --git a/x/keyregistry/keeper/validator_update_keys_test.go b/x/keyregistry/keeper/validator_update_keys_test.go new file mode 100644 index 00000000..ba628e65 --- /dev/null +++ b/x/keyregistry/keeper/validator_update_keys_test.go @@ -0,0 +1,203 @@ +package keeper_test + +import ( + "testing" + + "github.com/cometbft/cometbft/crypto" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func registerValidatorKeysForUpdateTest(t *testing.T, f *fixture, ms types.MsgServer) (crypto.PubKey, []byte, []byte) { + t.Helper() + + cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey, err := generateValidatorPublicKeys() + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, minaPublicKey) + require.NotNil(t, minaSecondaryPublicKey) + + require.NoError(t, err) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: cosmosPublicKey.Bytes(), + MinaPublicKey: minaPublicKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + return cosmosPublicKey, minaPublicKey, minaSecondaryPublicKey +} + +func TestValidatorUpdateKeysSuccess(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPubKey, newMinaPubKey := registerValidatorKeysForUpdateTest(t, f, ms) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + exists, err := f.keeper.ValidatorMinaToCosmosHas(f.ctx, prevMinaPubKey) + require.NoError(t, err) + require.False(t, exists) + + exists, err = f.keeper.ValidatorMinaToCosmosHas(f.ctx, newMinaPubKey) + require.NoError(t, err) + require.True(t, exists) + + minaPubKey, err := f.keeper.ValidatorGetCosmosToMina(f.ctx, cosmosPublicKey.Bytes()) + require.NoError(t, err) + require.Equal(t, newMinaPubKey, minaPubKey) + + storedCosmosPubKey, err := f.keeper.ValidatorGetMinaToCosmos(f.ctx, newMinaPubKey) + require.NoError(t, err) + require.Equal(t, cosmosPublicKey.Bytes(), storedCosmosPubKey) +} + +func TestValidatorUpdateKeysNotRegistered(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrValidatorNotRegistered) +} + +func TestValidatorUpdateKeysMissingCosmosToMinaMapping(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, cosmosPublicKey) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrValidatorNotRegistered) +} + +func TestValidatorUpdateKeysInvalidCreatorAddress(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + _, prevMinaPubKey, newMinaPubKey, err := generateValidatorPublicKeys() + + require.NoError(t, err) + require.NotNil(t, prevMinaPubKey) + require.NotNil(t, newMinaPubKey) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: "creator", + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPubKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.ErrorIs(t, err, types.ErrInvalidCreatorAddress) +} + +func TestValidatorUpdateKeysInvalidSignature(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + cosmosPublicKey, prevMinaPubKey, newMinaPublicKey := registerValidatorKeysForUpdateTest(t, f, ms) + + creatorAddr := sdk.AccAddress(cosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err := ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPubKey, + NewMinaPublicKey: newMinaPublicKey, + CosmosSignature: []byte("cosmosSig"), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) +} + +func TestValidatorUpdateKeysInsertSecondaryKeysFail(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + firstCosmosPublicKey, prevMinaPublicKey, _ := registerValidatorKeysForUpdateTest(t, f, ms) + secondCosmosPublicKey, _, targetMinaPublicKey, err := generateValidatorPublicKeys() + require.NoError(t, err) + require.NotNil(t, secondCosmosPublicKey) + require.NotNil(t, targetMinaPublicKey) + + creatorAddr := sdk.AccAddress(secondCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + resp, err := ms.RegisterKeys(f.ctx, &types.MsgRegisterKeys{ + Creator: creatorAddr.String(), + CosmosSignature: mockCosmosSignature, + MinaSignature: mockMinaSignature, + CosmosPublicKey: secondCosmosPublicKey.Bytes(), + MinaPublicKey: targetMinaPublicKey, + ActorType: types.ActorType_VALIDATOR, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + creatorAddr = sdk.AccAddress(firstCosmosPublicKey.Address()) + require.NotNil(t, creatorAddr) + + _, err = ms.UpdateKeys(f.ctx, &types.MsgUpdateKeys{ + Creator: creatorAddr.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: targetMinaPublicKey, + CosmosSignature: []byte(mockCosmosSignature), + NewMinaSignature: []byte(mockMinaSignature), + ActorType: types.ActorType_VALIDATOR, + }) + + require.ErrorIs(t, err, types.ErrValidatorSecondaryKeyExists) +} diff --git a/x/keyregistry/module/autocli.go b/x/keyregistry/module/autocli.go index 70bfd25b..f52a38bb 100644 --- a/x/keyregistry/module/autocli.go +++ b/x/keyregistry/module/autocli.go @@ -18,17 +18,31 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Shows the parameters of the module", }, { - RpcMethod: "GetMinaPubKey", - Use: "get-mina-pub-key [cosmos-pub-key]", - Short: "Query GetMinaPubKey", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_pub_key", Varargs: true}}, + RpcMethod: "GetUserMinaPublicKey", + Use: "get-user-mina-public-key [user-cosmos-public-key]", + Short: "Query GetUserMinaPublicKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_cosmos_public_key", Varargs: true}}, }, { - RpcMethod: "GetCosmosPubKey", - Use: "get-cosmos-pub-key [mina-pub-key]", - Short: "Query GetCosmosPubKey", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "mina_pub_key", Varargs: true}}, + RpcMethod: "GetUserCosmosPublicKey", + Use: "get-user-cosmos-public-key [user-mina-public-key]", + Short: "Query GetUserCosmosPublicKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "user_mina_public_key", Varargs: true}}, + }, + + { + RpcMethod: "GetValidatorMinaPubKey", + Use: "get-validator-mina-pub-key [validator-cosmos-pub-key]", + Short: "Query GetValidatorMinaPubKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_cosmos_pub_key", Varargs: true}}, + }, + + { + RpcMethod: "GetValidatorCosmosPubKey", + Use: "get-validator-cosmos-pub-key [validator-mina-pub-key]", + Short: "Query GetValidatorCosmosPubKey", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "validator_mina_pub_key", Varargs: true}}, }, // this line is used by ignite scaffolding # autocli/query @@ -43,12 +57,29 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Skip: true, // skipped because authority gated }, { - RpcMethod: "RegisterKeys", - Use: "register-keys [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", - Short: "Send a registerKeys tx", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "cosmos_signature"}, {ProtoField: "mina_signature"}, {ProtoField: "cosmos_public_key"}, {ProtoField: "mina_public_key", Varargs: true}}, + RpcMethod: "RegisterKeys", + Use: "register-keys [actor-type] [cosmos-signature] [mina-signature] [cosmos-public-key] [mina-public-key]", + Short: "Send a RegisterKeys tx", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "actor_type"}, + {ProtoField: "cosmos_signature"}, + {ProtoField: "mina_signature"}, + {ProtoField: "cosmos_public_key"}, + {ProtoField: "mina_public_key"}, + }, + }, + { + RpcMethod: "UpdateKeys", + Use: "update-keys [actor-type] [prev-mina-public-key] [new-mina-public-key] [cosmos-signature] [new-mina-signature]", + Short: "Send an UpdateKeys tx", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "actor_type"}, + {ProtoField: "prev_mina_public_key"}, + {ProtoField: "new_mina_public_key"}, + {ProtoField: "cosmos_signature"}, + {ProtoField: "new_mina_signature"}, + }, }, - // this line is used by ignite scaffolding # autocli/tx }, }, } diff --git a/x/keyregistry/module/simulation.go b/x/keyregistry/module/simulation.go index e867e489..2748287d 100644 --- a/x/keyregistry/module/simulation.go +++ b/x/keyregistry/module/simulation.go @@ -30,7 +30,7 @@ func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { operations := make([]simtypes.WeightedOperation, 0) const ( - opWeightMsgRegisterKeys = "op_weight_msg_keyregistry" + opWeightMsgRegisterKeys = "op_weight_msg_keyregistry_register_keys" defaultWeightMsgRegisterKeys int = 100 ) @@ -44,6 +44,21 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp weightMsgRegisterKeys, keyregistrysimulation.SimulateMsgRegisterKeys(am.authKeeper, am.bankKeeper, am.keeper, simState.TxConfig), )) + const ( + opWeightMsgUpdateKeys = "op_weight_msg_keyregistry_update_keys" + defaultWeightMsgUpdateKeys int = 100 + ) + + var weightMsgUpdateKeys int + simState.AppParams.GetOrGenerate(opWeightMsgUpdateKeys, &weightMsgUpdateKeys, nil, + func(_ *rand.Rand) { + weightMsgUpdateKeys = defaultWeightMsgUpdateKeys + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgUpdateKeys, + keyregistrysimulation.SimulateMsgUpdateKeys(am.authKeeper, am.bankKeeper, am.keeper, simState.TxConfig), + )) return operations } diff --git a/x/keyregistry/simulation/helpers.go b/x/keyregistry/simulation/helpers.go new file mode 100644 index 00000000..a6589466 --- /dev/null +++ b/x/keyregistry/simulation/helpers.go @@ -0,0 +1,298 @@ +package simulation + +import ( + "context" + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + simutil "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +const maxUniqueMinaKeyRetries = 20 + +type registeredUserPair struct { + pair *types.UserPublicKeyPair + account simtypes.Account +} + +func randomActorType(r *rand.Rand) types.ActorType { + if r.Intn(2) == 0 { + return types.ActorType_USER + } + + return types.ActorType_VALIDATOR +} + +func randomBytes(r *rand.Rand, size int) []byte { + bytes := make([]byte, size) + if _, err := r.Read(bytes); err != nil { + panic(err) + } + + return bytes +} + +func randomMinaPublicKey(r *rand.Rand) []byte { + // TODO: Generate a real Mina public key once the crypto library is integrated. + return randomBytes(r, keys.PublicKeyTotalByteSize) +} + +func mockSimulationSignature() []byte { + // TODO: Generate deterministic valid signatures once real crypto verification is integrated. + return []byte("mock-keyregistry-signature") +} + +func randomUniqueMinaPublicKey( + r *rand.Rand, + ctx context.Context, + hasMinaKey func(context.Context, []byte) (bool, error), +) ([]byte, bool, error) { + for i := 0; i < maxUniqueMinaKeyRetries; i++ { + minaPublicKey := randomMinaPublicKey(r) + exists, err := hasMinaKey(ctx, minaPublicKey) + if err != nil { + return nil, false, err + } + if !exists { + return minaPublicKey, true, nil + } + } + + return nil, false, nil +} + +func deliverKeyregistryTx( + r *rand.Rand, + app *baseapp.BaseApp, + txGen client.TxConfig, + ak types.AuthKeeper, + bk types.BankKeeper, + msg sdk.Msg, + ctx sdk.Context, + simAccount simtypes.Account, +) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + if ak.GetAccount(ctx, simAccount.Address) == nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "account not found"), nil, nil + } + + return simutil.GenAndDeliverTxWithRandFees(simutil.OperationInput{ + R: r, + App: app, + TxGen: txGen, + Msg: msg, + CoinsSpentInMsg: sdk.Coins{}, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + }) +} + +func buildRegisterKeysMsg( + r *rand.Rand, + ctx context.Context, + k keeper.Keeper, + actorType types.ActorType, + simAccount simtypes.Account, +) (*types.MsgRegisterKeys, string, error) { + cosmosPublicKey, noOpReason := cosmosPublicKeyForActor(actorType, simAccount) + if noOpReason != "" { + return nil, noOpReason, nil + } + + cosmosKeyExists, err := actorCosmosKeyExists(ctx, k, actorType, cosmosPublicKey) + if err != nil { + return nil, "", err + } + if cosmosKeyExists { + return nil, "cosmos public key already registered", nil + } + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, ctx, actorMinaKeyExistsFunc(k, actorType)) + if err != nil { + return nil, "", err + } + if !ok { + return nil, "unable to generate unique mina public key", nil + } + + return &types.MsgRegisterKeys{ + Creator: simAccount.Address.String(), + CosmosPublicKey: cosmosPublicKey, + MinaPublicKey: minaPublicKey, + CosmosSignature: mockSimulationSignature(), + MinaSignature: mockSimulationSignature(), + ActorType: actorType, + }, "", nil +} + +func buildUpdateKeysMsg( + r *rand.Rand, + ctx context.Context, + k keeper.Keeper, + actorType types.ActorType, + genesis *types.GenesisState, + accs []simtypes.Account, +) (*types.MsgUpdateKeys, simtypes.Account, string, error) { + var ( + simAccount simtypes.Account + prevMinaPublicKey []byte + noOpReason string + ) + + switch actorType { + case types.ActorType_USER: + userPair, ok := selectRegisteredUserPairWithSigner(r, genesis.UserKeyPairs, accs) + if !ok { + return nil, simtypes.Account{}, "no registered user key pair with simulation signer", nil + } + simAccount = userPair.account + prevMinaPublicKey = userPair.pair.MinaKey + case types.ActorType_VALIDATOR: + validatorPair, ok := selectRegisteredValidatorPair(r, genesis.ValidatorKeyPairs) + if !ok { + return nil, simtypes.Account{}, "no registered validator key pair", nil + } + simAccount, noOpReason = randomSimulationAccount(r, accs) + if noOpReason != "" { + return nil, simtypes.Account{}, noOpReason, nil + } + prevMinaPublicKey = validatorPair.MinaKey + default: + return nil, simtypes.Account{}, "invalid actor type", nil + } + + newMinaPublicKey, ok, err := randomUniqueMinaPublicKey(r, ctx, actorMinaKeyExistsFunc(k, actorType)) + if err != nil { + return nil, simtypes.Account{}, "", err + } + if !ok { + return nil, simtypes.Account{}, "unable to generate unique mina public key", nil + } + + return &types.MsgUpdateKeys{ + Creator: simAccount.Address.String(), + PrevMinaPublicKey: prevMinaPublicKey, + NewMinaPublicKey: newMinaPublicKey, + CosmosSignature: mockSimulationSignature(), + NewMinaSignature: mockSimulationSignature(), + ActorType: actorType, + }, simAccount, "", nil +} + +func cosmosPublicKeyForActor(actorType types.ActorType, simAccount simtypes.Account) ([]byte, string) { + switch actorType { + case types.ActorType_USER: + if simAccount.PubKey == nil { + return nil, "simulation account has no user public key" + } + + return simAccount.PubKey.Bytes(), "" + case types.ActorType_VALIDATOR: + if simAccount.ConsKey == nil { + return nil, "simulation account has no validator consensus key" + } + + return simAccount.ConsKey.PubKey().Bytes(), "" + default: + return nil, "invalid actor type" + } +} + +func actorCosmosKeyExists(ctx context.Context, k keeper.Keeper, actorType types.ActorType, cosmosPublicKey []byte) (bool, error) { + switch actorType { + case types.ActorType_USER: + return k.UserCosmosToMinaHas(ctx, cosmosPublicKey) + case types.ActorType_VALIDATOR: + return k.ValidatorCosmosToMinaHas(ctx, cosmosPublicKey) + default: + return false, types.ErrInvalidActorType + } +} + +func actorMinaKeyExistsFunc( + k keeper.Keeper, + actorType types.ActorType, +) func(context.Context, []byte) (bool, error) { + switch actorType { + case types.ActorType_USER: + return k.UserMinaToCosmosHas + case types.ActorType_VALIDATOR: + return k.ValidatorMinaToCosmosHas + default: + return func(context.Context, []byte) (bool, error) { + return false, types.ErrInvalidActorType + } + } +} + +func randomSimulationAccount(r *rand.Rand, accs []simtypes.Account) (simtypes.Account, string) { + if len(accs) == 0 { + return simtypes.Account{}, "no simulation accounts" + } + + simAccount, _ := simtypes.RandomAcc(r, accs) + return simAccount, "" +} + +func selectRegisteredUserPairWithSigner( + r *rand.Rand, + userKeyPairs []*types.UserPublicKeyPair, + accs []simtypes.Account, +) (registeredUserPair, bool) { + accountByPublicKey := make(map[string]simtypes.Account, len(accs)) + for _, account := range accs { + if account.PubKey == nil { + continue + } + accountByPublicKey[string(account.PubKey.Bytes())] = account + } + + var candidates []registeredUserPair + for _, keyPair := range userKeyPairs { + if keyPair == nil { + continue + } + account, ok := accountByPublicKey[string(keyPair.CosmosKey)] + if !ok { + continue + } + + candidates = append(candidates, registeredUserPair{ + pair: keyPair, + account: account, + }) + } + + if len(candidates) == 0 { + return registeredUserPair{}, false + } + + return candidates[r.Intn(len(candidates))], true +} + +func selectRegisteredValidatorPair( + r *rand.Rand, + validatorKeyPairs []*types.ValidatorPublicKeyPair, +) (*types.ValidatorPublicKeyPair, bool) { + var candidates []*types.ValidatorPublicKeyPair + for _, keyPair := range validatorKeyPairs { + if keyPair == nil { + continue + } + candidates = append(candidates, keyPair) + } + + if len(candidates) == 0 { + return nil, false + } + + return candidates[r.Intn(len(candidates))], true +} diff --git a/x/keyregistry/simulation/operations_test.go b/x/keyregistry/simulation/operations_test.go new file mode 100644 index 00000000..aa84c551 --- /dev/null +++ b/x/keyregistry/simulation/operations_test.go @@ -0,0 +1,139 @@ +package simulation + +import ( + "context" + "math/rand" + "testing" + + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" + "github.com/stretchr/testify/require" +) + +func TestRandomMinaPublicKeyLength(t *testing.T) { + r := rand.New(rand.NewSource(1)) + + minaPublicKey := randomMinaPublicKey(r) + + require.Len(t, minaPublicKey, keys.PublicKeyTotalByteSize) +} + +func TestBuildRegisterKeysMsgUsesUserSimulationAccountPublicKey(t *testing.T) { + r := rand.New(rand.NewSource(1)) + ctx, k := initSimulationKeeperFixture(t) + simAccount := simtypes.RandomAccounts(r, 1)[0] + + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, types.ActorType_USER, simAccount) + + require.NoError(t, err) + require.Empty(t, noOpReason) + require.Equal(t, simAccount.Address.String(), msg.Creator) + require.Equal(t, types.ActorType_USER, msg.ActorType) + require.Equal(t, simAccount.PubKey.Bytes(), msg.CosmosPublicKey) + require.Len(t, msg.MinaPublicKey, keys.PublicKeyTotalByteSize) + require.NotEmpty(t, msg.CosmosSignature) + require.NotEmpty(t, msg.MinaSignature) +} + +func TestBuildRegisterKeysMsgUsesValidatorConsensusPublicKey(t *testing.T) { + r := rand.New(rand.NewSource(1)) + ctx, k := initSimulationKeeperFixture(t) + simAccount := simtypes.RandomAccounts(r, 1)[0] + + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, types.ActorType_VALIDATOR, simAccount) + + require.NoError(t, err) + require.Empty(t, noOpReason) + require.Equal(t, simAccount.Address.String(), msg.Creator) + require.Equal(t, types.ActorType_VALIDATOR, msg.ActorType) + require.Equal(t, simAccount.ConsKey.PubKey().Bytes(), msg.CosmosPublicKey) + require.Len(t, msg.CosmosPublicKey, 32) + require.Len(t, msg.MinaPublicKey, keys.PublicKeyTotalByteSize) + require.NotEmpty(t, msg.CosmosSignature) + require.NotEmpty(t, msg.MinaSignature) +} + +func TestSelectRegisteredUserPairWithSigner(t *testing.T) { + r := rand.New(rand.NewSource(1)) + accs := simtypes.RandomAccounts(r, 2) + matchingPair := &types.UserPublicKeyPair{ + CosmosKey: accs[0].PubKey.Bytes(), + MinaKey: randomMinaPublicKey(r), + } + unmatchedPair := &types.UserPublicKeyPair{ + CosmosKey: randomBytes(r, 33), + MinaKey: randomMinaPublicKey(r), + } + + selected, ok := selectRegisteredUserPairWithSigner(r, []*types.UserPublicKeyPair{ + unmatchedPair, + matchingPair, + }, accs) + + require.True(t, ok) + require.Equal(t, matchingPair, selected.pair) + require.True(t, selected.account.Address.Equals(accs[0].Address)) +} + +func TestRandomUniqueMinaPublicKeyRetriesDuplicate(t *testing.T) { + r := rand.New(rand.NewSource(1)) + calls := 0 + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, context.Background(), func(context.Context, []byte) (bool, error) { + calls++ + return calls == 1, nil + }) + + require.NoError(t, err) + require.True(t, ok) + require.Equal(t, 2, calls) + require.Len(t, minaPublicKey, keys.PublicKeyTotalByteSize) +} + +func TestRandomUniqueMinaPublicKeyStopsAfterRetries(t *testing.T) { + r := rand.New(rand.NewSource(1)) + calls := 0 + + minaPublicKey, ok, err := randomUniqueMinaPublicKey(r, context.Background(), func(context.Context, []byte) (bool, error) { + calls++ + return true, nil + }) + + require.NoError(t, err) + require.False(t, ok) + require.Nil(t, minaPublicKey) + require.Equal(t, maxUniqueMinaKeyRetries, calls) +} + +func initSimulationKeeperFixture(t *testing.T) (context.Context, keeper.Keeper) { + t.Helper() + + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + authority := authtypes.NewModuleAddress(types.GovModuleName) + cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + k := keeper.NewKeeper( + storeService, + cdc, + addressCodec, + authority, + ) + + err := k.Params.Set(ctx, types.DefaultParams()) + require.NoError(t, err) + + return ctx, k +} diff --git a/x/keyregistry/simulation/register_keys.go b/x/keyregistry/simulation/register_keys.go index 49593095..764bde1a 100644 --- a/x/keyregistry/simulation/register_keys.go +++ b/x/keyregistry/simulation/register_keys.go @@ -20,13 +20,20 @@ func SimulateMsgRegisterKeys( ) simtypes.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - msg := &types.MsgRegisterKeys{ - Creator: simAccount.Address.String(), + msgType := sdk.MsgTypeURL(&types.MsgRegisterKeys{}) + simAccount, noOpReason := randomSimulationAccount(r, accs) + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil } - // TODO: Handle the RegisterKeys simulation + msg, noOpReason, err := buildRegisterKeysMsg(r, ctx, k, randomActorType(r), simAccount) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to build RegisterKeys msg"), nil, err + } + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil + } - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "RegisterKeys simulation not implemented"), nil, nil + return deliverKeyregistryTx(r, app, txGen, ak, bk, msg, ctx, simAccount) } } diff --git a/x/keyregistry/simulation/update_keys.go b/x/keyregistry/simulation/update_keys.go new file mode 100644 index 00000000..8804e087 --- /dev/null +++ b/x/keyregistry/simulation/update_keys.go @@ -0,0 +1,39 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + "github.com/node101-io/pulsar-chain/x/keyregistry/types" +) + +func SimulateMsgUpdateKeys( + ak types.AuthKeeper, + bk types.BankKeeper, + k keeper.Keeper, + txGen client.TxConfig, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgUpdateKeys{}) + genesis, err := k.ExportGenesis(ctx) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to export keyregistry genesis"), nil, err + } + + msg, simAccount, noOpReason, err := buildUpdateKeysMsg(r, ctx, k, randomActorType(r), genesis, accs) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to build UpdateKeys msg"), nil, err + } + if noOpReason != "" { + return simtypes.NoOpMsg(types.ModuleName, msgType, noOpReason), nil, nil + } + + return deliverKeyregistryTx(r, app, txGen, ak, bk, msg, ctx, simAccount) + } +} diff --git a/x/keyregistry/types/address_pair.pb.go b/x/keyregistry/types/address_pair.pb.go new file mode 100644 index 00000000..3f5b82ab --- /dev/null +++ b/x/keyregistry/types/address_pair.pb.go @@ -0,0 +1,374 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/address_pair.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type AddressPair struct { + MinaAddr []byte `protobuf:"bytes,1,opt,name=mina_addr,json=minaAddr,proto3" json:"mina_addr,omitempty"` + CosmosAddr []byte `protobuf:"bytes,2,opt,name=cosmos_addr,json=cosmosAddr,proto3" json:"cosmos_addr,omitempty"` +} + +func (m *AddressPair) Reset() { *m = AddressPair{} } +func (m *AddressPair) String() string { return proto.CompactTextString(m) } +func (*AddressPair) ProtoMessage() {} +func (*AddressPair) Descriptor() ([]byte, []int) { + return fileDescriptor_eb9cea5d1b988cd3, []int{0} +} +func (m *AddressPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AddressPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AddressPair.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AddressPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddressPair.Merge(m, src) +} +func (m *AddressPair) XXX_Size() int { + return m.Size() +} +func (m *AddressPair) XXX_DiscardUnknown() { + xxx_messageInfo_AddressPair.DiscardUnknown(m) +} + +var xxx_messageInfo_AddressPair proto.InternalMessageInfo + +func (m *AddressPair) GetMinaAddr() []byte { + if m != nil { + return m.MinaAddr + } + return nil +} + +func (m *AddressPair) GetCosmosAddr() []byte { + if m != nil { + return m.CosmosAddr + } + return nil +} + +func init() { + proto.RegisterType((*AddressPair)(nil), "pulsarchain.keyregistry.v1.AddressPair") +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/address_pair.proto", fileDescriptor_eb9cea5d1b988cd3) +} + +var fileDescriptor_eb9cea5d1b988cd3 = []byte{ + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2d, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0x8e, 0x2f, + 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xae, 0x87, 0xa4, + 0x5c, 0xaf, 0xcc, 0x50, 0xc9, 0x9b, 0x8b, 0xdb, 0x11, 0xa2, 0x23, 0x20, 0x31, 0xb3, 0x48, 0x48, + 0x9a, 0x8b, 0x33, 0x37, 0x33, 0x2f, 0x31, 0x1e, 0x64, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, + 0x10, 0x07, 0x48, 0x00, 0xa4, 0x46, 0x48, 0x9e, 0x8b, 0x3b, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, + 0x22, 0xcd, 0x04, 0x96, 0xe6, 0x82, 0x08, 0x81, 0x14, 0x38, 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, + 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, + 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, + 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x61, 0xba, + 0x10, 0x8f, 0x54, 0xa0, 0x78, 0xa5, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x03, 0x63, + 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x32, 0x26, 0x7c, 0xb2, 0xf2, 0x00, 0x00, 0x00, +} + +func (m *AddressPair) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AddressPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddressPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosAddr) > 0 { + i -= len(m.CosmosAddr) + copy(dAtA[i:], m.CosmosAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.CosmosAddr))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaAddr) > 0 { + i -= len(m.MinaAddr) + copy(dAtA[i:], m.MinaAddr) + i = encodeVarintAddressPair(dAtA, i, uint64(len(m.MinaAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAddressPair(dAtA []byte, offset int, v uint64) int { + offset -= sovAddressPair(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AddressPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + l = len(m.CosmosAddr) + if l > 0 { + n += 1 + l + sovAddressPair(uint64(l)) + } + return n +} + +func sovAddressPair(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAddressPair(x uint64) (n int) { + return sovAddressPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AddressPair) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AddressPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AddressPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaAddr = append(m.MinaAddr[:0], dAtA[iNdEx:postIndex]...) + if m.MinaAddr == nil { + m.MinaAddr = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddressPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthAddressPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthAddressPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddr = append(m.CosmosAddr[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosAddr == nil { + m.CosmosAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAddressPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAddressPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAddressPair(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddressPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAddressPair + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAddressPair + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAddressPair + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAddressPair = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAddressPair = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAddressPair = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyregistry/types/codec.go b/x/keyregistry/types/codec.go index 7e1f4224..ee459eb8 100644 --- a/x/keyregistry/types/codec.go +++ b/x/keyregistry/types/codec.go @@ -7,6 +7,10 @@ import ( ) func RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + registrar.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateKeys{}, + ) + registrar.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterKeys{}, ) diff --git a/x/keyregistry/types/errors.go b/x/keyregistry/types/errors.go index 202d20f0..3bc341ca 100644 --- a/x/keyregistry/types/errors.go +++ b/x/keyregistry/types/errors.go @@ -8,9 +8,15 @@ import ( // x/keyregistry module sentinel errors var ( - ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") - ErrInvalidSignature = errors.Register(ModuleName, 1101, "invalid signature") - ErrSecondaryKeyExists = errors.Register(ModuleName, 1102, "secondary key already exists") - ErrInvalidCreatorAddres = errors.Register(ModuleName, 1103, "invalid creator address") - ErrInvalidPublicKey = errors.Register(ModuleName, 1104, "invalid public key") + ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrInvalidSignature = errors.Register(ModuleName, 1101, "invalid signature") + ErrUserSecondaryKeyExists = errors.Register(ModuleName, 1102, "user's secondary key already exists") + ErrValidatorSecondaryKeyExists = errors.Register(ModuleName, 1103, "validator's secondary key already exists") + ErrInvalidCreatorAddress = errors.Register(ModuleName, 1104, "invalid creator address") + ErrInvalidPublicKey = errors.Register(ModuleName, 1105, "invalid public key") + ErrUserNotRegistered = errors.Register(ModuleName, 1106, "user has not been registered") + ErrValidatorNotRegistered = errors.Register(ModuleName, 1107, "validator has not been registered") + ErrInvalidActorType = errors.Register(ModuleName, 1108, "invalid actor type") + ErrNilKeyPair = errors.Register(ModuleName, 1109, "nil keypair") + ErrInvalidGenesisState = errors.Register(ModuleName, 1110, "invalid genesis state") ) diff --git a/x/keyregistry/types/genesis.go b/x/keyregistry/types/genesis.go index b2e8fb0f..654840ba 100644 --- a/x/keyregistry/types/genesis.go +++ b/x/keyregistry/types/genesis.go @@ -1,23 +1,84 @@ package types +import errorsmod "cosmossdk.io/errors" + // DefaultGenesis returns the default genesis state func DefaultGenesis() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - KeyPairs: DefaultKeyPairs(), + Params: DefaultParams(), + UserKeyPairs: DefaultUserPublicKeyPair(), + ValidatorKeyPairs: DefaultValidatorPublicKeyPair(), } } // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { + if err := validateUserGenesisKeyPairs(gs.UserKeyPairs); err != nil { + return err + } + + if err := validateValidatorGenesisKeyPairs(gs.ValidatorKeyPairs); err != nil { + return err + } + + return gs.Params.Validate() +} + +func validateUserGenesisKeyPairs(keyPairs []*UserPublicKeyPair) error { + seenCosmosKeys := make(map[string]struct{}, len(keyPairs)) + seenMinaKeys := make(map[string]struct{}, len(keyPairs)) + + for _, keyPair := range keyPairs { + if keyPair == nil { + return ErrNilKeyPair + } + + if err := keyPair.Validate(); err != nil { + return err + } + + cosmosKey := string(keyPair.CosmosKey) + if _, exists := seenCosmosKeys[cosmosKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate user cosmos key") + } + seenCosmosKeys[cosmosKey] = struct{}{} + + minaKey := string(keyPair.MinaKey) + if _, exists := seenMinaKeys[minaKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate user mina key") + } + seenMinaKeys[minaKey] = struct{}{} + } + + return nil +} + +func validateValidatorGenesisKeyPairs(keyPairs []*ValidatorPublicKeyPair) error { + seenConsensusKeys := make(map[string]struct{}, len(keyPairs)) + seenMinaKeys := make(map[string]struct{}, len(keyPairs)) - for _, keyPair := range gs.KeyPairs { - err := ValidateKeyPair(*keyPair) - if err != nil { + for _, keyPair := range keyPairs { + if keyPair == nil { + return ErrNilKeyPair + } + + if err := keyPair.Validate(); err != nil { return err } + + consensusKey := string(keyPair.CosmosKey) + if _, exists := seenConsensusKeys[consensusKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate validator consensus key") + } + seenConsensusKeys[consensusKey] = struct{}{} + + minaKey := string(keyPair.MinaKey) + if _, exists := seenMinaKeys[minaKey]; exists { + return errorsmod.Wrap(ErrInvalidGenesisState, "duplicate validator mina key") + } + seenMinaKeys[minaKey] = struct{}{} } - return gs.Params.Validate() + return nil } diff --git a/x/keyregistry/types/genesis.pb.go b/x/keyregistry/types/genesis.pb.go index 86964336..38980463 100644 --- a/x/keyregistry/types/genesis.pb.go +++ b/x/keyregistry/types/genesis.pb.go @@ -27,8 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the keyregistry module's genesis state. type GenesisState struct { // params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - KeyPairs []*KeyPair `protobuf:"bytes,2,rep,name=key_pairs,json=keyPairs,proto3" json:"key_pairs,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + UserKeyPairs []*UserPublicKeyPair `protobuf:"bytes,2,rep,name=user_key_pairs,json=userKeyPairs,proto3" json:"user_key_pairs,omitempty"` + ValidatorKeyPairs []*ValidatorPublicKeyPair `protobuf:"bytes,3,rep,name=validator_key_pairs,json=validatorKeyPairs,proto3" json:"validator_key_pairs,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -71,9 +72,16 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetKeyPairs() []*KeyPair { +func (m *GenesisState) GetUserKeyPairs() []*UserPublicKeyPair { if m != nil { - return m.KeyPairs + return m.UserKeyPairs + } + return nil +} + +func (m *GenesisState) GetValidatorKeyPairs() []*ValidatorPublicKeyPair { + if m != nil { + return m.ValidatorKeyPairs } return nil } @@ -87,25 +95,28 @@ func init() { } var fileDescriptor_dbaeb2ea35536f14 = []byte{ - // 275 bytes of a gzipped FileDescriptorProto + // 325 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x28, 0xcd, 0x29, 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0x52, 0xa9, 0x87, 0xa4, 0x52, 0xaf, 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0x94, 0x4b, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x1d, 0x8f, 0x75, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x50, - 0xdb, 0xa4, 0x34, 0xf1, 0x28, 0xcc, 0x4e, 0xad, 0x8c, 0x2f, 0x48, 0xcc, 0x2c, 0x82, 0x28, 0x55, - 0x9a, 0xce, 0xc8, 0xc5, 0xe3, 0x0e, 0x71, 0x6a, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x2b, 0x17, - 0x1b, 0xc4, 0x2c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x25, 0x3d, 0xdc, 0x4e, 0xd7, 0x0b, - 0x00, 0xab, 0x74, 0xe2, 0x3c, 0x71, 0x4f, 0x9e, 0x61, 0xc5, 0xf3, 0x0d, 0x5a, 0x8c, 0x41, 0x50, - 0xcd, 0x42, 0x0e, 0x5c, 0x9c, 0x30, 0x9b, 0x8a, 0x25, 0x98, 0x14, 0x98, 0x35, 0xb8, 0x8d, 0x94, - 0xf1, 0x99, 0xe4, 0x9d, 0x5a, 0x19, 0x90, 0x98, 0x59, 0x14, 0xc4, 0x91, 0x0d, 0x61, 0x14, 0x3b, - 0x05, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, - 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x59, 0x7a, 0x66, 0x49, - 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x5e, 0x7e, 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, - 0x66, 0xbe, 0x3e, 0xc4, 0x74, 0x5d, 0x88, 0xaf, 0x2b, 0x50, 0xfc, 0x5d, 0x52, 0x59, 0x90, 0x5a, - 0x9c, 0xc4, 0x06, 0xf6, 0xb2, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xa5, 0xaa, 0xf8, 0xf1, 0xb7, - 0x01, 0x00, 0x00, + 0xdb, 0xa4, 0x0c, 0xf0, 0x29, 0x2c, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, 0xad, 0x8c, 0x2f, + 0x48, 0xcc, 0x2c, 0x82, 0xe8, 0x50, 0xea, 0x63, 0xe2, 0xe2, 0x71, 0x87, 0xb8, 0x38, 0xb8, 0x24, + 0xb1, 0x24, 0x55, 0xc8, 0x95, 0x8b, 0x0d, 0x62, 0xa4, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, + 0x92, 0x1e, 0x6e, 0x1f, 0xe8, 0x05, 0x80, 0x55, 0x3a, 0x71, 0x9e, 0xb8, 0x27, 0xcf, 0xb0, 0xe2, + 0xf9, 0x06, 0x2d, 0xc6, 0x20, 0xa8, 0x66, 0xa1, 0x60, 0x2e, 0xbe, 0xd2, 0xe2, 0xd4, 0x22, 0xb8, + 0x75, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xba, 0xf8, 0x8c, 0x0b, 0x2d, 0x4e, 0x2d, + 0x0a, 0x00, 0x3b, 0xd3, 0x3b, 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x28, 0x88, 0x07, 0x64, 0x08, 0x94, + 0x53, 0x2c, 0x94, 0xc4, 0x25, 0x5c, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x8f, 0x6c, 0x32, + 0x33, 0xd8, 0x64, 0x23, 0x7c, 0x26, 0x87, 0xc1, 0xb4, 0xa1, 0x1a, 0x2f, 0x08, 0x37, 0x0e, 0x66, + 0x87, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, + 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, 0xa5, 0x67, + 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, 0xa7, 0xa4, 0x1a, 0x1a, 0x18, + 0xea, 0x66, 0xe6, 0xeb, 0x43, 0x6c, 0xd5, 0x85, 0x84, 0x79, 0x05, 0x4a, 0xa8, 0x97, 0x54, 0x16, + 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x43, 0xda, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x8a, 0xf3, 0xc3, + 0xbd, 0x35, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -128,10 +139,24 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.KeyPairs) > 0 { - for iNdEx := len(m.KeyPairs) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ValidatorKeyPairs) > 0 { + for iNdEx := len(m.ValidatorKeyPairs) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.KeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ValidatorKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.UserKeyPairs) > 0 { + for iNdEx := len(m.UserKeyPairs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.UserKeyPairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -174,8 +199,14 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.KeyPairs) > 0 { - for _, e := range m.KeyPairs { + if len(m.UserKeyPairs) > 0 { + for _, e := range m.UserKeyPairs { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorKeyPairs) > 0 { + for _, e := range m.ValidatorKeyPairs { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -253,7 +284,41 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field KeyPairs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field UserKeyPairs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserKeyPairs = append(m.UserKeyPairs, &UserPublicKeyPair{}) + if err := m.UserKeyPairs[len(m.UserKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorKeyPairs", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -280,8 +345,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.KeyPairs = append(m.KeyPairs, &KeyPair{}) - if err := m.KeyPairs[len(m.KeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ValidatorKeyPairs = append(m.ValidatorKeyPairs, &ValidatorPublicKeyPair{}) + if err := m.ValidatorKeyPairs[len(m.ValidatorKeyPairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/keyregistry/types/genesis_test.go b/x/keyregistry/types/genesis_test.go index f963da22..14ec6918 100644 --- a/x/keyregistry/types/genesis_test.go +++ b/x/keyregistry/types/genesis_test.go @@ -1,6 +1,7 @@ package types_test import ( + "bytes" "testing" "github.com/node101-io/pulsar-chain/x/keyregistry/types" @@ -8,30 +9,148 @@ import ( ) func TestGenesisState_Validate(t *testing.T) { + userCosmosA := testBytes(33, 'a') + userCosmosB := testBytes(33, 'b') + userMinaX := testBytes(33, 'x') + userMinaY := testBytes(33, 'y') + validatorConsensusA := testBytes(32, 'a') + validatorConsensusB := testBytes(32, 'b') + validatorMinaX := testBytes(33, 'x') + validatorMinaY := testBytes(33, 'y') + tests := []struct { - desc string - genState *types.GenesisState - valid bool + desc string + genState *types.GenesisState + expectedErr error }{ { - desc: "default is valid", - genState: types.DefaultGenesis(), - valid: true, + desc: "default genesis is valid", + genState: withDefaultParams(types.DefaultGenesis()), + }, + { + desc: "empty genesis is valid", + genState: withDefaultParams(&types.GenesisState{}), + }, + { + desc: "valid user key pairs are valid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + }, + }), + }, + { + desc: "valid validator key pairs are valid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + }, + }), + }, + { + desc: "nil user key pair is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{nil}, + }), + expectedErr: types.ErrNilKeyPair, + }, + { + desc: "nil validator key pair is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{nil}, + }), + expectedErr: types.ErrNilKeyPair, + }, + { + desc: "invalid user key length is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(testBytes(32, 'a'), userMinaX), + }, + }), + expectedErr: types.ErrInvalidPublicKey, + }, + { + desc: "invalid validator key length is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(testBytes(33, 'a'), validatorMinaX), + }, + }), + expectedErr: types.ErrInvalidPublicKey, }, { - desc: "valid genesis state", - genState: &types.GenesisState{}, - valid: true, + desc: "duplicate user cosmos key is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + userPair(userCosmosA, userMinaY), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate user mina key is invalid", + genState: withDefaultParams(&types.GenesisState{ + UserKeyPairs: []*types.UserPublicKeyPair{ + userPair(userCosmosA, userMinaX), + userPair(userCosmosB, userMinaX), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate validator consensus key is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + validatorPair(validatorConsensusA, validatorMinaY), + }, + }), + expectedErr: types.ErrInvalidGenesisState, + }, + { + desc: "duplicate validator mina key is invalid", + genState: withDefaultParams(&types.GenesisState{ + ValidatorKeyPairs: []*types.ValidatorPublicKeyPair{ + validatorPair(validatorConsensusA, validatorMinaX), + validatorPair(validatorConsensusB, validatorMinaX), + }, + }), + expectedErr: types.ErrInvalidGenesisState, }, } for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() - if tc.valid { + if tc.expectedErr == nil { require.NoError(t, err) } else { - require.Error(t, err) + require.ErrorIs(t, err, tc.expectedErr) } }) } } + +func testBytes(length int, value byte) []byte { + return bytes.Repeat([]byte{value}, length) +} + +func withDefaultParams(genState *types.GenesisState) *types.GenesisState { + genState.Params = types.DefaultParams() + return genState +} + +func userPair(cosmosKey, minaKey []byte) *types.UserPublicKeyPair { + return &types.UserPublicKeyPair{ + CosmosKey: cosmosKey, + MinaKey: minaKey, + } +} + +func validatorPair(consensusKey, minaKey []byte) *types.ValidatorPublicKeyPair { + return &types.ValidatorPublicKeyPair{ + CosmosKey: consensusKey, + MinaKey: minaKey, + } +} diff --git a/x/keyregistry/types/key_pair.pb.go b/x/keyregistry/types/key_pair.pb.go deleted file mode 100644 index 94a30630..00000000 --- a/x/keyregistry/types/key_pair.pb.go +++ /dev/null @@ -1,375 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: pulsarchain/keyregistry/v1/key_pair.proto - -package types - -import ( - fmt "fmt" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// KeyPair defines the KeyPair message. -type KeyPair struct { - MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` - CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` -} - -func (m *KeyPair) Reset() { *m = KeyPair{} } -func (m *KeyPair) String() string { return proto.CompactTextString(m) } -func (*KeyPair) ProtoMessage() {} -func (*KeyPair) Descriptor() ([]byte, []int) { - return fileDescriptor_7125759d37e49a74, []int{0} -} -func (m *KeyPair) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *KeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_KeyPair.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *KeyPair) XXX_Merge(src proto.Message) { - xxx_messageInfo_KeyPair.Merge(m, src) -} -func (m *KeyPair) XXX_Size() int { - return m.Size() -} -func (m *KeyPair) XXX_DiscardUnknown() { - xxx_messageInfo_KeyPair.DiscardUnknown(m) -} - -var xxx_messageInfo_KeyPair proto.InternalMessageInfo - -func (m *KeyPair) GetMinaKey() []byte { - if m != nil { - return m.MinaKey - } - return nil -} - -func (m *KeyPair) GetCosmosKey() []byte { - if m != nil { - return m.CosmosKey - } - return nil -} - -func init() { - proto.RegisterType((*KeyPair)(nil), "pulsarchain.keyregistry.v1.KeyPair") -} - -func init() { - proto.RegisterFile("pulsarchain/keyregistry/v1/key_pair.proto", fileDescriptor_7125759d37e49a74) -} - -var fileDescriptor_7125759d37e49a74 = []byte{ - // 202 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x28, 0xcd, 0x29, - 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, - 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x0b, 0x12, 0x33, 0x8b, 0xf4, 0x0a, 0x8a, - 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x94, 0xea, 0x21, 0x29, 0xd5, 0x2b, 0x33, 0x54, 0x72, 0xe6, - 0x62, 0xf7, 0x4e, 0xad, 0x0c, 0x48, 0xcc, 0x2c, 0x12, 0x92, 0xe4, 0xe2, 0xc8, 0xcd, 0xcc, 0x4b, - 0x8c, 0xcf, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x62, 0x07, 0xf1, 0xbd, 0x53, - 0x2b, 0x85, 0x64, 0xb9, 0xb8, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xc1, 0x92, 0x4c, 0x60, 0x49, - 0x4e, 0x88, 0x88, 0x77, 0x6a, 0xa5, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, - 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, - 0x31, 0x44, 0x99, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, - 0xa7, 0xa4, 0x1a, 0x1a, 0x18, 0xea, 0x66, 0xe6, 0xeb, 0x43, 0x1c, 0xa4, 0x0b, 0x71, 0x7c, 0x05, - 0x8a, 0xf3, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x2e, 0x37, 0x06, 0x04, 0x00, 0x00, - 0xff, 0xff, 0x61, 0x07, 0x29, 0xd9, 0xe6, 0x00, 0x00, 0x00, -} - -func (m *KeyPair) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyPair) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *KeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CosmosKey) > 0 { - i -= len(m.CosmosKey) - copy(dAtA[i:], m.CosmosKey) - i = encodeVarintKeyPair(dAtA, i, uint64(len(m.CosmosKey))) - i-- - dAtA[i] = 0x12 - } - if len(m.MinaKey) > 0 { - i -= len(m.MinaKey) - copy(dAtA[i:], m.MinaKey) - i = encodeVarintKeyPair(dAtA, i, uint64(len(m.MinaKey))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintKeyPair(dAtA []byte, offset int, v uint64) int { - offset -= sovKeyPair(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *KeyPair) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.MinaKey) - if l > 0 { - n += 1 + l + sovKeyPair(uint64(l)) - } - l = len(m.CosmosKey) - if l > 0 { - n += 1 + l + sovKeyPair(uint64(l)) - } - return n -} - -func sovKeyPair(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozKeyPair(x uint64) (n int) { - return sovKeyPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *KeyPair) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKeyPair - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyPair: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyPair: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKeyPair - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKeyPair - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthKeyPair - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MinaKey = append(m.MinaKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaKey == nil { - m.MinaKey = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKeyPair - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKeyPair - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthKeyPair - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CosmosKey = append(m.CosmosKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosKey == nil { - m.CosmosKey = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKeyPair(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthKeyPair - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipKeyPair(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKeyPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKeyPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKeyPair - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthKeyPair - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupKeyPair - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthKeyPair - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthKeyPair = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKeyPair = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupKeyPair = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/keyregistry/types/key_update_type.pb.go b/x/keyregistry/types/key_update_type.pb.go new file mode 100644 index 00000000..083028ac --- /dev/null +++ b/x/keyregistry/types/key_update_type.pb.go @@ -0,0 +1,74 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/key_update_type.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ActorType int32 + +const ( + ActorType_UNSPECIFIED ActorType = 0 + ActorType_USER ActorType = 1 + ActorType_VALIDATOR ActorType = 2 +) + +var ActorType_name = map[int32]string{ + 0: "UNSPECIFIED", + 1: "USER", + 2: "VALIDATOR", +} + +var ActorType_value = map[string]int32{ + "UNSPECIFIED": 0, + "USER": 1, + "VALIDATOR": 2, +} + +func (x ActorType) String() string { + return proto.EnumName(ActorType_name, int32(x)) +} + +func (ActorType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_ba25ac2a902d16f7, []int{0} +} + +func init() { + proto.RegisterEnum("pulsarchain.keyregistry.v1.ActorType", ActorType_name, ActorType_value) +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/key_update_type.proto", fileDescriptor_ba25ac2a902d16f7) +} + +var fileDescriptor_ba25ac2a902d16f7 = []byte{ + // 206 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0x04, 0x71, 0xe3, 0x4b, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0xe3, + 0x4b, 0x2a, 0x0b, 0x52, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xa4, 0x90, 0x74, 0xe8, 0x21, + 0xe9, 0xd0, 0x2b, 0x33, 0xd4, 0x32, 0xe5, 0xe2, 0x74, 0x4c, 0x2e, 0xc9, 0x2f, 0x0a, 0xa9, 0x2c, + 0x48, 0x15, 0xe2, 0xe7, 0xe2, 0x0e, 0xf5, 0x0b, 0x0e, 0x70, 0x75, 0xf6, 0x74, 0xf3, 0x74, 0x75, + 0x11, 0x60, 0x10, 0xe2, 0xe0, 0x62, 0x09, 0x0d, 0x76, 0x0d, 0x12, 0x60, 0x14, 0xe2, 0xe5, 0xe2, + 0x0c, 0x73, 0xf4, 0xf1, 0x74, 0x71, 0x0c, 0xf1, 0x0f, 0x12, 0x60, 0x72, 0x0a, 0x38, 0xf1, 0x48, + 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, + 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xb3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, + 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, 0xcc, 0x7c, 0x7d, 0x88, + 0x13, 0x74, 0x21, 0xae, 0xae, 0x40, 0x71, 0x37, 0xc8, 0xa5, 0xc5, 0x49, 0x6c, 0x60, 0xb7, 0x1a, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xba, 0xc7, 0x23, 0x30, 0xdf, 0x00, 0x00, 0x00, +} diff --git a/x/keyregistry/types/keys.go b/x/keyregistry/types/keys.go index 5dcbbf70..9e6fb4e6 100644 --- a/x/keyregistry/types/keys.go +++ b/x/keyregistry/types/keys.go @@ -17,5 +17,8 @@ const ( // ParamsKey is the prefix to retrieve all Params var ParamsKey = collections.NewPrefix("p_keyregistry") -var CosmosToMinaPrefix = collections.NewPrefix("cosmos_map") -var MinaToCosmosPrefix = collections.NewPrefix("mina_map") +var UserCosmosToMinaPrefix = collections.NewPrefix("user_cosmos_map") +var UserMinaToCosmosPrefix = collections.NewPrefix("user_mina_map") + +var ValidatorCosmosToMinaPrefix = collections.NewPrefix("validator_cosmos_map") +var ValidatorMinaToCosmosPrefix = collections.NewPrefix("validator_mina_map") diff --git a/x/keyregistry/types/public_key_pair.pb.go b/x/keyregistry/types/public_key_pair.pb.go new file mode 100644 index 00000000..db1d3fc2 --- /dev/null +++ b/x/keyregistry/types/public_key_pair.pb.go @@ -0,0 +1,602 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/keyregistry/v1/public_key_pair.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// KeyPair defines the KeyPair message. +type UserPublicKeyPair struct { + MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` + CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` +} + +func (m *UserPublicKeyPair) Reset() { *m = UserPublicKeyPair{} } +func (m *UserPublicKeyPair) String() string { return proto.CompactTextString(m) } +func (*UserPublicKeyPair) ProtoMessage() {} +func (*UserPublicKeyPair) Descriptor() ([]byte, []int) { + return fileDescriptor_e897d11daaf50b90, []int{0} +} +func (m *UserPublicKeyPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UserPublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UserPublicKeyPair.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UserPublicKeyPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_UserPublicKeyPair.Merge(m, src) +} +func (m *UserPublicKeyPair) XXX_Size() int { + return m.Size() +} +func (m *UserPublicKeyPair) XXX_DiscardUnknown() { + xxx_messageInfo_UserPublicKeyPair.DiscardUnknown(m) +} + +var xxx_messageInfo_UserPublicKeyPair proto.InternalMessageInfo + +func (m *UserPublicKeyPair) GetMinaKey() []byte { + if m != nil { + return m.MinaKey + } + return nil +} + +func (m *UserPublicKeyPair) GetCosmosKey() []byte { + if m != nil { + return m.CosmosKey + } + return nil +} + +type ValidatorPublicKeyPair struct { + MinaKey []byte `protobuf:"bytes,1,opt,name=mina_key,json=minaKey,proto3" json:"mina_key,omitempty"` + CosmosKey []byte `protobuf:"bytes,2,opt,name=cosmos_key,json=cosmosKey,proto3" json:"cosmos_key,omitempty"` +} + +func (m *ValidatorPublicKeyPair) Reset() { *m = ValidatorPublicKeyPair{} } +func (m *ValidatorPublicKeyPair) String() string { return proto.CompactTextString(m) } +func (*ValidatorPublicKeyPair) ProtoMessage() {} +func (*ValidatorPublicKeyPair) Descriptor() ([]byte, []int) { + return fileDescriptor_e897d11daaf50b90, []int{1} +} +func (m *ValidatorPublicKeyPair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorPublicKeyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorPublicKeyPair.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorPublicKeyPair) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorPublicKeyPair.Merge(m, src) +} +func (m *ValidatorPublicKeyPair) XXX_Size() int { + return m.Size() +} +func (m *ValidatorPublicKeyPair) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorPublicKeyPair.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorPublicKeyPair proto.InternalMessageInfo + +func (m *ValidatorPublicKeyPair) GetMinaKey() []byte { + if m != nil { + return m.MinaKey + } + return nil +} + +func (m *ValidatorPublicKeyPair) GetCosmosKey() []byte { + if m != nil { + return m.CosmosKey + } + return nil +} + +func init() { + proto.RegisterType((*UserPublicKeyPair)(nil), "pulsarchain.keyregistry.v1.UserPublicKeyPair") + proto.RegisterType((*ValidatorPublicKeyPair)(nil), "pulsarchain.keyregistry.v1.ValidatorPublicKeyPair") +} + +func init() { + proto.RegisterFile("pulsarchain/keyregistry/v1/public_key_pair.proto", fileDescriptor_e897d11daaf50b90) +} + +var fileDescriptor_e897d11daaf50b90 = []byte{ + // 231 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x28, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0x4a, 0x4d, 0xcf, 0x2c, + 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0x33, 0xd4, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x8e, 0xcf, 0x4e, + 0xad, 0x8c, 0x2f, 0x48, 0xcc, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x42, 0xd2, + 0xa1, 0x87, 0xa4, 0x43, 0xaf, 0xcc, 0x50, 0xc9, 0x97, 0x4b, 0x30, 0xb4, 0x38, 0xb5, 0x28, 0x00, + 0xac, 0xd1, 0x3b, 0xb5, 0x32, 0x20, 0x31, 0xb3, 0x48, 0x48, 0x92, 0x8b, 0x23, 0x37, 0x33, 0x2f, + 0x11, 0x64, 0x8e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x3b, 0x88, 0xef, 0x9d, 0x5a, 0x29, + 0x24, 0xcb, 0xc5, 0x95, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x0c, 0x96, 0x64, 0x02, 0x4b, 0x72, 0x42, + 0x44, 0xbc, 0x53, 0x2b, 0x95, 0x82, 0xb8, 0xc4, 0xc2, 0x12, 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, + 0xa9, 0x65, 0xa6, 0x53, 0xc0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, + 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x99, + 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe5, 0xa7, 0xa4, 0x1a, + 0x1a, 0x18, 0xea, 0x66, 0xe6, 0xeb, 0x43, 0xbc, 0xab, 0x0b, 0x09, 0xa1, 0x0a, 0x94, 0x30, 0x2a, + 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x87, 0x8b, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xbf, + 0x3d, 0x3b, 0xff, 0x4b, 0x01, 0x00, 0x00, +} + +func (m *UserPublicKeyPair) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UserPublicKeyPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UserPublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosKey) > 0 { + i -= len(m.CosmosKey) + copy(dAtA[i:], m.CosmosKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.CosmosKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaKey) > 0 { + i -= len(m.MinaKey) + copy(dAtA[i:], m.MinaKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.MinaKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorPublicKeyPair) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorPublicKeyPair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorPublicKeyPair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosKey) > 0 { + i -= len(m.CosmosKey) + copy(dAtA[i:], m.CosmosKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.CosmosKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.MinaKey) > 0 { + i -= len(m.MinaKey) + copy(dAtA[i:], m.MinaKey) + i = encodeVarintPublicKeyPair(dAtA, i, uint64(len(m.MinaKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPublicKeyPair(dAtA []byte, offset int, v uint64) int { + offset -= sovPublicKeyPair(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *UserPublicKeyPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + l = len(m.CosmosKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + return n +} + +func (m *ValidatorPublicKeyPair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MinaKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + l = len(m.CosmosKey) + if l > 0 { + n += 1 + l + sovPublicKeyPair(uint64(l)) + } + return n +} + +func sovPublicKeyPair(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPublicKeyPair(x uint64) (n int) { + return sovPublicKeyPair(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *UserPublicKeyPair) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UserPublicKeyPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UserPublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaKey = append(m.MinaKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaKey == nil { + m.MinaKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosKey = append(m.CosmosKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosKey == nil { + m.CosmosKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPublicKeyPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPublicKeyPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorPublicKeyPair) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorPublicKeyPair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorPublicKeyPair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaKey = append(m.MinaKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaKey == nil { + m.MinaKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthPublicKeyPair + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthPublicKeyPair + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosKey = append(m.CosmosKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosKey == nil { + m.CosmosKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPublicKeyPair(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPublicKeyPair + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPublicKeyPair(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPublicKeyPair + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPublicKeyPair + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPublicKeyPair + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPublicKeyPair + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPublicKeyPair = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPublicKeyPair = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPublicKeyPair = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyregistry/types/query.pb.go b/x/keyregistry/types/query.pb.go index 09839626..e529ad88 100644 --- a/x/keyregistry/types/query.pb.go +++ b/x/keyregistry/types/query.pb.go @@ -114,23 +114,23 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } -// QueryGetMinaPubKeyRequest defines the QueryGetMinaPubKeyRequest message. -type QueryGetMinaPubKeyRequest struct { - CosmosPubKey []byte `protobuf:"bytes,1,opt,name=cosmos_pub_key,json=cosmosPubKey,proto3" json:"cosmos_pub_key,omitempty"` +// QueryGetUserMinaPublicKeyRequest defines the QueryGetUserMinaPublicKeyRequest message. +type QueryGetUserMinaPublicKeyRequest struct { + UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } -func (m *QueryGetMinaPubKeyRequest) Reset() { *m = QueryGetMinaPubKeyRequest{} } -func (m *QueryGetMinaPubKeyRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetMinaPubKeyRequest) ProtoMessage() {} -func (*QueryGetMinaPubKeyRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaPublicKeyRequest) Reset() { *m = QueryGetUserMinaPublicKeyRequest{} } +func (m *QueryGetUserMinaPublicKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaPublicKeyRequest) ProtoMessage() {} +func (*QueryGetUserMinaPublicKeyRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{2} } -func (m *QueryGetMinaPubKeyRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetMinaPubKeyRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -140,42 +140,42 @@ func (m *QueryGetMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *QueryGetMinaPubKeyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetMinaPubKeyRequest.Merge(m, src) +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.Merge(m, src) } -func (m *QueryGetMinaPubKeyRequest) XXX_Size() int { +func (m *QueryGetUserMinaPublicKeyRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetMinaPubKeyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetMinaPubKeyRequest.DiscardUnknown(m) +func (m *QueryGetUserMinaPublicKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaPublicKeyRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetMinaPubKeyRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaPublicKeyRequest proto.InternalMessageInfo -func (m *QueryGetMinaPubKeyRequest) GetCosmosPubKey() []byte { +func (m *QueryGetUserMinaPublicKeyRequest) GetUserCosmosPublicKey() []byte { if m != nil { - return m.CosmosPubKey + return m.UserCosmosPublicKey } return nil } -// QueryGetMinaPubKeyResponse defines the QueryGetMinaPubKeyResponse message. -type QueryGetMinaPubKeyResponse struct { - MinaPubKey []byte `protobuf:"bytes,1,opt,name=mina_pub_key,json=minaPubKey,proto3" json:"mina_pub_key,omitempty"` +// QueryGetUserMinaPublicKeyResponse defines the QueryGetUserMinaPublicKeyResponse message. +type QueryGetUserMinaPublicKeyResponse struct { + UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } -func (m *QueryGetMinaPubKeyResponse) Reset() { *m = QueryGetMinaPubKeyResponse{} } -func (m *QueryGetMinaPubKeyResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetMinaPubKeyResponse) ProtoMessage() {} -func (*QueryGetMinaPubKeyResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserMinaPublicKeyResponse) Reset() { *m = QueryGetUserMinaPublicKeyResponse{} } +func (m *QueryGetUserMinaPublicKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserMinaPublicKeyResponse) ProtoMessage() {} +func (*QueryGetUserMinaPublicKeyResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{3} } -func (m *QueryGetMinaPubKeyResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetMinaPubKeyResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -185,42 +185,42 @@ func (m *QueryGetMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *QueryGetMinaPubKeyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetMinaPubKeyResponse.Merge(m, src) +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.Merge(m, src) } -func (m *QueryGetMinaPubKeyResponse) XXX_Size() int { +func (m *QueryGetUserMinaPublicKeyResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetMinaPubKeyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetMinaPubKeyResponse.DiscardUnknown(m) +func (m *QueryGetUserMinaPublicKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserMinaPublicKeyResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetMinaPubKeyResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserMinaPublicKeyResponse proto.InternalMessageInfo -func (m *QueryGetMinaPubKeyResponse) GetMinaPubKey() []byte { +func (m *QueryGetUserMinaPublicKeyResponse) GetUserMinaPublicKey() []byte { if m != nil { - return m.MinaPubKey + return m.UserMinaPublicKey } return nil } -// QueryGetCosmosPubKeyRequest defines the QueryGetCosmosPubKeyRequest message. -type QueryGetCosmosPubKeyRequest struct { - MinaPubKey []byte `protobuf:"bytes,1,opt,name=mina_pub_key,json=minaPubKey,proto3" json:"mina_pub_key,omitempty"` +// QueryGetUserCosmosPublicKeyRequest defines the QueryGetUserCosmosPublicKeyRequest message. +type QueryGetUserCosmosPublicKeyRequest struct { + UserMinaPublicKey []byte `protobuf:"bytes,1,opt,name=user_mina_public_key,json=userMinaPublicKey,proto3" json:"user_mina_public_key,omitempty"` } -func (m *QueryGetCosmosPubKeyRequest) Reset() { *m = QueryGetCosmosPubKeyRequest{} } -func (m *QueryGetCosmosPubKeyRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetCosmosPubKeyRequest) ProtoMessage() {} -func (*QueryGetCosmosPubKeyRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosPublicKeyRequest) Reset() { *m = QueryGetUserCosmosPublicKeyRequest{} } +func (m *QueryGetUserCosmosPublicKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosPublicKeyRequest) ProtoMessage() {} +func (*QueryGetUserCosmosPublicKeyRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{4} } -func (m *QueryGetCosmosPubKeyRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetCosmosPubKeyRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -230,42 +230,42 @@ func (m *QueryGetCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *QueryGetCosmosPubKeyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetCosmosPubKeyRequest.Merge(m, src) +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.Merge(m, src) } -func (m *QueryGetCosmosPubKeyRequest) XXX_Size() int { +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetCosmosPubKeyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetCosmosPubKeyRequest.DiscardUnknown(m) +func (m *QueryGetUserCosmosPublicKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetCosmosPubKeyRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosPublicKeyRequest proto.InternalMessageInfo -func (m *QueryGetCosmosPubKeyRequest) GetMinaPubKey() []byte { +func (m *QueryGetUserCosmosPublicKeyRequest) GetUserMinaPublicKey() []byte { if m != nil { - return m.MinaPubKey + return m.UserMinaPublicKey } return nil } -// QueryGetCosmosPubKeyResponse defines the QueryGetCosmosPubKeyResponse message. -type QueryGetCosmosPubKeyResponse struct { - CosmosPubKey []byte `protobuf:"bytes,1,opt,name=cosmos_pub_key,json=cosmosPubKey,proto3" json:"cosmos_pub_key,omitempty"` +// QueryGetUserCosmosPublicKeyResponse defines the QueryGetUserCosmosPublicKeyResponse message. +type QueryGetUserCosmosPublicKeyResponse struct { + UserCosmosPublicKey []byte `protobuf:"bytes,1,opt,name=user_cosmos_public_key,json=userCosmosPublicKey,proto3" json:"user_cosmos_public_key,omitempty"` } -func (m *QueryGetCosmosPubKeyResponse) Reset() { *m = QueryGetCosmosPubKeyResponse{} } -func (m *QueryGetCosmosPubKeyResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetCosmosPubKeyResponse) ProtoMessage() {} -func (*QueryGetCosmosPubKeyResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetUserCosmosPublicKeyResponse) Reset() { *m = QueryGetUserCosmosPublicKeyResponse{} } +func (m *QueryGetUserCosmosPublicKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetUserCosmosPublicKeyResponse) ProtoMessage() {} +func (*QueryGetUserCosmosPublicKeyResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d580bfce910e0ca3, []int{5} } -func (m *QueryGetCosmosPubKeyResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetCosmosPubKeyResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -275,21 +275,201 @@ func (m *QueryGetCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *QueryGetCosmosPubKeyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetCosmosPubKeyResponse.Merge(m, src) +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.Merge(m, src) } -func (m *QueryGetCosmosPubKeyResponse) XXX_Size() int { +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetCosmosPubKeyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetCosmosPubKeyResponse.DiscardUnknown(m) +func (m *QueryGetUserCosmosPublicKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetCosmosPubKeyResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetUserCosmosPublicKeyResponse proto.InternalMessageInfo -func (m *QueryGetCosmosPubKeyResponse) GetCosmosPubKey() []byte { +func (m *QueryGetUserCosmosPublicKeyResponse) GetUserCosmosPublicKey() []byte { if m != nil { - return m.CosmosPubKey + return m.UserCosmosPublicKey + } + return nil +} + +// QueryGetValidatorMinaPubKeyRequest defines the QueryGetValidatorMinaPubKeyRequest message. +type QueryGetValidatorMinaPubKeyRequest struct { + ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` +} + +func (m *QueryGetValidatorMinaPubKeyRequest) Reset() { *m = QueryGetValidatorMinaPubKeyRequest{} } +func (m *QueryGetValidatorMinaPubKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorMinaPubKeyRequest) ProtoMessage() {} +func (*QueryGetValidatorMinaPubKeyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{6} +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.Merge(m, src) +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorMinaPubKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorMinaPubKeyRequest proto.InternalMessageInfo + +func (m *QueryGetValidatorMinaPubKeyRequest) GetValidatorCosmosPubKey() []byte { + if m != nil { + return m.ValidatorCosmosPubKey + } + return nil +} + +// QueryGetValidatorMinaPubKeyResponse defines the QueryGetValidatorMinaPubKeyResponse message. +type QueryGetValidatorMinaPubKeyResponse struct { + ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` +} + +func (m *QueryGetValidatorMinaPubKeyResponse) Reset() { *m = QueryGetValidatorMinaPubKeyResponse{} } +func (m *QueryGetValidatorMinaPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorMinaPubKeyResponse) ProtoMessage() {} +func (*QueryGetValidatorMinaPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{7} +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.Merge(m, src) +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorMinaPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorMinaPubKeyResponse proto.InternalMessageInfo + +func (m *QueryGetValidatorMinaPubKeyResponse) GetValidatorMinaPubKey() []byte { + if m != nil { + return m.ValidatorMinaPubKey + } + return nil +} + +// QueryGetValidatorCosmosPubKeyRequest defines the QueryGetValidatorCosmosPubKeyRequest message. +type QueryGetValidatorCosmosPubKeyRequest struct { + ValidatorMinaPubKey []byte `protobuf:"bytes,1,opt,name=validator_mina_pub_key,json=validatorMinaPubKey,proto3" json:"validator_mina_pub_key,omitempty"` +} + +func (m *QueryGetValidatorCosmosPubKeyRequest) Reset() { *m = QueryGetValidatorCosmosPubKeyRequest{} } +func (m *QueryGetValidatorCosmosPubKeyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorCosmosPubKeyRequest) ProtoMessage() {} +func (*QueryGetValidatorCosmosPubKeyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{8} +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.Merge(m, src) +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorCosmosPubKeyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorCosmosPubKeyRequest proto.InternalMessageInfo + +func (m *QueryGetValidatorCosmosPubKeyRequest) GetValidatorMinaPubKey() []byte { + if m != nil { + return m.ValidatorMinaPubKey + } + return nil +} + +// QueryGetValidatorCosmosPubKeyResponse defines the QueryGetValidatorCosmosPubKeyResponse message. +type QueryGetValidatorCosmosPubKeyResponse struct { + ValidatorCosmosPubKey []byte `protobuf:"bytes,1,opt,name=validator_cosmos_pub_key,json=validatorCosmosPubKey,proto3" json:"validator_cosmos_pub_key,omitempty"` +} + +func (m *QueryGetValidatorCosmosPubKeyResponse) Reset() { *m = QueryGetValidatorCosmosPubKeyResponse{} } +func (m *QueryGetValidatorCosmosPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetValidatorCosmosPubKeyResponse) ProtoMessage() {} +func (*QueryGetValidatorCosmosPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d580bfce910e0ca3, []int{9} +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.Merge(m, src) +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetValidatorCosmosPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetValidatorCosmosPubKeyResponse proto.InternalMessageInfo + +func (m *QueryGetValidatorCosmosPubKeyResponse) GetValidatorCosmosPubKey() []byte { + if m != nil { + return m.ValidatorCosmosPubKey } return nil } @@ -297,10 +477,14 @@ func (m *QueryGetCosmosPubKeyResponse) GetCosmosPubKey() []byte { func init() { proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.keyregistry.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.keyregistry.v1.QueryParamsResponse") - proto.RegisterType((*QueryGetMinaPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetMinaPubKeyRequest") - proto.RegisterType((*QueryGetMinaPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetMinaPubKeyResponse") - proto.RegisterType((*QueryGetCosmosPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyRequest") - proto.RegisterType((*QueryGetCosmosPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetCosmosPubKeyResponse") + proto.RegisterType((*QueryGetUserMinaPublicKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyRequest") + proto.RegisterType((*QueryGetUserMinaPublicKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserMinaPublicKeyResponse") + proto.RegisterType((*QueryGetUserCosmosPublicKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyRequest") + proto.RegisterType((*QueryGetUserCosmosPublicKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetUserCosmosPublicKeyResponse") + proto.RegisterType((*QueryGetValidatorMinaPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyRequest") + proto.RegisterType((*QueryGetValidatorMinaPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorMinaPubKeyResponse") + proto.RegisterType((*QueryGetValidatorCosmosPubKeyRequest)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyRequest") + proto.RegisterType((*QueryGetValidatorCosmosPubKeyResponse)(nil), "pulsarchain.keyregistry.v1.QueryGetValidatorCosmosPubKeyResponse") } func init() { @@ -308,38 +492,48 @@ func init() { } var fileDescriptor_d580bfce910e0ca3 = []byte{ - // 495 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcf, 0x6a, 0x14, 0x31, - 0x18, 0xdf, 0x88, 0x2e, 0x18, 0x57, 0xc5, 0xd8, 0x83, 0x8e, 0x65, 0x2c, 0x83, 0xa8, 0x14, 0x3a, - 0xe9, 0x54, 0x5c, 0x3d, 0x29, 0x56, 0x45, 0xa4, 0x08, 0xdb, 0x3d, 0x8a, 0xb0, 0x64, 0xd6, 0x90, - 0x86, 0x76, 0x92, 0x74, 0x92, 0x59, 0x1c, 0x4a, 0x2f, 0x3e, 0x81, 0xe0, 0x13, 0x78, 0xf3, 0xe8, - 0x63, 0xf4, 0x58, 0xf1, 0xa0, 0x5e, 0x44, 0x76, 0x05, 0x5f, 0x43, 0x9a, 0xa4, 0x32, 0x53, 0xb7, - 0xdb, 0x5d, 0xbc, 0x0c, 0xe1, 0x9b, 0xdf, 0xbf, 0xef, 0xfb, 0x42, 0xe0, 0x4d, 0x55, 0x6c, 0x69, - 0x92, 0xf7, 0x37, 0x08, 0x17, 0x78, 0x93, 0x96, 0x39, 0x65, 0x5c, 0x9b, 0xbc, 0xc4, 0x83, 0x04, - 0x6f, 0x17, 0x34, 0x2f, 0x63, 0x95, 0x4b, 0x23, 0x51, 0x50, 0xc1, 0xc5, 0x15, 0x5c, 0x3c, 0x48, - 0x82, 0x4b, 0x24, 0xe3, 0x42, 0x62, 0xfb, 0x75, 0xf0, 0x60, 0xb1, 0x2f, 0x75, 0x26, 0x35, 0x4e, - 0x89, 0xa6, 0x4e, 0x07, 0x0f, 0x92, 0x94, 0x1a, 0x92, 0x60, 0x45, 0x18, 0x17, 0xc4, 0x70, 0x29, - 0x3c, 0x76, 0x8e, 0x49, 0x26, 0xed, 0x11, 0x1f, 0x9c, 0x7c, 0x75, 0x9e, 0x49, 0xc9, 0xb6, 0x28, - 0x26, 0x8a, 0x63, 0x22, 0x84, 0x34, 0x96, 0xa2, 0xfd, 0xdf, 0x5b, 0x13, 0x62, 0x2b, 0x92, 0x93, - 0xcc, 0x03, 0xa3, 0x39, 0x88, 0xd6, 0x0f, 0xec, 0x3b, 0xb6, 0xd8, 0xa5, 0xdb, 0x05, 0xd5, 0x26, - 0x7a, 0x05, 0x2f, 0xd7, 0xaa, 0x5a, 0x49, 0xa1, 0x29, 0x7a, 0x0a, 0x9b, 0x8e, 0x7c, 0x05, 0x2c, - 0x80, 0xdb, 0xe7, 0x56, 0xa2, 0xf8, 0xf8, 0xae, 0x63, 0xc7, 0x5d, 0x3d, 0xbb, 0xf7, 0xe3, 0x7a, - 0xe3, 0xe3, 0xef, 0x4f, 0x8b, 0xa0, 0xeb, 0xc9, 0xd1, 0x23, 0x78, 0xd5, 0xaa, 0x3f, 0xa3, 0xe6, - 0x05, 0x17, 0xa4, 0x53, 0xa4, 0x6b, 0xb4, 0xf4, 0xd6, 0xe8, 0x06, 0xbc, 0xe0, 0x66, 0xd3, 0x53, - 0x45, 0xda, 0xdb, 0xa4, 0xa5, 0xf5, 0x6a, 0x75, 0x5b, 0xae, 0xea, 0xc0, 0xd1, 0x03, 0x18, 0x8c, - 0x93, 0xf0, 0x39, 0x17, 0x60, 0x2b, 0xe3, 0x82, 0x1c, 0x51, 0x80, 0xd9, 0x5f, 0x64, 0xf4, 0x10, - 0x5e, 0x3b, 0xe4, 0x3f, 0xae, 0xe8, 0x1e, 0x86, 0x38, 0x59, 0xe0, 0x09, 0x9c, 0x1f, 0x2f, 0xe0, - 0x23, 0x4c, 0xd5, 0xc6, 0xca, 0xf7, 0xd3, 0xf0, 0x8c, 0x95, 0x41, 0x1f, 0x00, 0x6c, 0xba, 0x89, - 0xa1, 0x78, 0xd2, 0x54, 0xff, 0x5d, 0x56, 0x80, 0xa7, 0xc6, 0xbb, 0x6c, 0x51, 0xfb, 0xed, 0x97, - 0x5f, 0xef, 0x4f, 0x2d, 0xa3, 0x18, 0x0b, 0xf9, 0x9a, 0x26, 0xcb, 0xc9, 0x12, 0x97, 0xd8, 0x69, - 0x2c, 0x4d, 0xb8, 0x31, 0xe8, 0x33, 0x80, 0xe7, 0x6b, 0x03, 0x47, 0x77, 0x4f, 0xb4, 0x1e, 0xb7, - 0xe3, 0xa0, 0x3d, 0x2b, 0xcd, 0x07, 0x5f, 0xb7, 0xc1, 0xd7, 0xd0, 0xf3, 0x69, 0x83, 0x33, 0x6a, - 0x7a, 0xd5, 0x45, 0xe2, 0x9d, 0xfa, 0x52, 0x76, 0xd1, 0x57, 0x00, 0x2f, 0x1e, 0xd9, 0x21, 0xba, - 0x37, 0x4d, 0xbc, 0x31, 0xd7, 0x26, 0xb8, 0x3f, 0x3b, 0xf1, 0x7f, 0x3a, 0xab, 0xf7, 0x82, 0x77, - 0xaa, 0x9d, 0xee, 0xae, 0x76, 0xf6, 0x86, 0x21, 0xd8, 0x1f, 0x86, 0xe0, 0xe7, 0x30, 0x04, 0xef, - 0x46, 0x61, 0x63, 0x7f, 0x14, 0x36, 0xbe, 0x8d, 0xc2, 0xc6, 0xcb, 0x36, 0xe3, 0x66, 0xa3, 0x48, - 0xe3, 0xbe, 0xcc, 0x8e, 0xb5, 0x7b, 0x53, 0x33, 0x34, 0xa5, 0xa2, 0x3a, 0x6d, 0xda, 0x27, 0xe3, - 0xce, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd9, 0x53, 0x57, 0x8b, 0x14, 0x05, 0x00, 0x00, + // 647 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcf, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0x16, 0x0c, 0x74, 0xf4, 0xd2, 0x69, 0x2c, 0x61, 0x91, 0xb5, 0xae, 0x3f, 0x29, 0x74, + 0xa7, 0xdb, 0x42, 0xbd, 0xf8, 0xb3, 0x22, 0x1e, 0x44, 0x88, 0xc1, 0x2a, 0xb6, 0x96, 0x38, 0x49, + 0x87, 0xed, 0xd0, 0x64, 0x67, 0xbb, 0xb3, 0x1b, 0x5c, 0x4a, 0x40, 0x3c, 0x78, 0x16, 0xfc, 0x0b, + 0xbc, 0x79, 0xd3, 0x3f, 0xa3, 0xc7, 0x82, 0x17, 0x4f, 0x22, 0x89, 0xe0, 0x7f, 0xe0, 0xc9, 0x83, + 0x64, 0x76, 0x92, 0x4c, 0x92, 0xcd, 0x36, 0x49, 0xbd, 0x94, 0x65, 0xde, 0x7b, 0xdf, 0xfb, 0xbe, + 0x8f, 0x7e, 0x8f, 0x80, 0x6b, 0x5e, 0x58, 0xe5, 0xd8, 0xaf, 0xec, 0x61, 0xea, 0xa2, 0x7d, 0x12, + 0xf9, 0xc4, 0xa1, 0x3c, 0xf0, 0x23, 0x54, 0xb7, 0xd1, 0x41, 0x48, 0xfc, 0xc8, 0xf2, 0x7c, 0x16, + 0x30, 0xa8, 0x2b, 0x7d, 0x96, 0xd2, 0x67, 0xd5, 0x6d, 0x7d, 0x0e, 0xd7, 0xa8, 0xcb, 0x90, 0xf8, + 0x1b, 0xb7, 0xeb, 0x4b, 0x15, 0xc6, 0x6b, 0x8c, 0xa3, 0x32, 0xe6, 0x24, 0xc6, 0x41, 0x75, 0xbb, + 0x4c, 0x02, 0x6c, 0x23, 0x0f, 0x3b, 0xd4, 0xc5, 0x01, 0x65, 0xae, 0xec, 0xcd, 0x39, 0xcc, 0x61, + 0xe2, 0x13, 0xb5, 0xbf, 0xe4, 0xeb, 0x05, 0x87, 0x31, 0xa7, 0x4a, 0x10, 0xf6, 0x28, 0xc2, 0xae, + 0xcb, 0x02, 0x31, 0xc2, 0x65, 0xf5, 0x7a, 0x0a, 0x6d, 0x0f, 0xfb, 0xb8, 0x26, 0x1b, 0xcd, 0x1c, + 0x80, 0x4f, 0xdb, 0xeb, 0x0b, 0xe2, 0xb1, 0x48, 0x0e, 0x42, 0xc2, 0x03, 0xf3, 0x15, 0x98, 0xef, + 0x7b, 0xe5, 0x1e, 0x73, 0x39, 0x81, 0x0f, 0x41, 0x36, 0x1e, 0xce, 0x6b, 0x8b, 0xda, 0x8d, 0xb3, + 0xab, 0xa6, 0x35, 0x5a, 0xb5, 0x15, 0xcf, 0x6e, 0xcc, 0x1e, 0xfd, 0xb8, 0x98, 0xf9, 0xfc, 0xfb, + 0xeb, 0x92, 0x56, 0x94, 0xc3, 0xe6, 0x0b, 0xb0, 0x28, 0xd0, 0x1f, 0x91, 0x60, 0x93, 0x13, 0xff, + 0x09, 0x75, 0x71, 0x21, 0x2c, 0x57, 0x69, 0xe5, 0x31, 0x89, 0x24, 0x03, 0xb8, 0x06, 0x16, 0x42, + 0x4e, 0xfc, 0x52, 0xec, 0x53, 0xc9, 0x13, 0xf5, 0xd2, 0x3e, 0x89, 0xc4, 0xea, 0x73, 0xc5, 0xf9, + 0x76, 0xf5, 0x81, 0x28, 0x76, 0x67, 0xcd, 0x67, 0xe0, 0x52, 0x0a, 0xb0, 0x14, 0x81, 0x40, 0x4e, + 0x20, 0xd7, 0xa8, 0x8b, 0x87, 0x71, 0xe7, 0xc2, 0xc1, 0x41, 0x73, 0x13, 0x98, 0x2a, 0xea, 0xc0, + 0xd2, 0x0e, 0xe1, 0x89, 0x61, 0xb7, 0xc0, 0xe5, 0x54, 0x58, 0x49, 0x77, 0x2a, 0x23, 0x76, 0x7a, + 0x94, 0x9f, 0xe3, 0x2a, 0xdd, 0xc5, 0x01, 0xeb, 0x6c, 0x57, 0x28, 0xdf, 0x04, 0xf9, 0x7a, 0xa7, + 0xaa, 0xe0, 0x2b, 0xe0, 0xe7, 0xbb, 0xf5, 0xee, 0x86, 0x01, 0xea, 0x89, 0xf0, 0x3d, 0xea, 0x3d, + 0xfc, 0x8e, 0x2f, 0x2a, 0xf5, 0xfa, 0xf0, 0xb0, 0xb9, 0x0d, 0xae, 0x0c, 0x61, 0xab, 0xcb, 0x95, + 0x7f, 0x90, 0xc9, 0xc1, 0x5f, 0x83, 0xab, 0x27, 0x80, 0x4b, 0xea, 0xd3, 0x5a, 0xb3, 0xfa, 0x65, + 0x16, 0x9c, 0x11, 0x2b, 0xe0, 0x27, 0x0d, 0x64, 0xe3, 0x0c, 0x40, 0x2b, 0x2d, 0x27, 0xc3, 0xf1, + 0xd3, 0xd1, 0xd8, 0xfd, 0x31, 0x5d, 0x73, 0xfd, 0xdd, 0xb7, 0x5f, 0x1f, 0x67, 0x56, 0xa0, 0x85, + 0x5c, 0xb6, 0x4b, 0xec, 0x15, 0x7b, 0x99, 0x32, 0x14, 0x63, 0x2c, 0xa7, 0xdc, 0x00, 0xf8, 0x47, + 0x03, 0xb9, 0xa4, 0xb0, 0xc0, 0x5b, 0x27, 0x32, 0x48, 0x09, 0xaf, 0x7e, 0x7b, 0xca, 0x69, 0xa9, + 0x06, 0x0b, 0x35, 0xdb, 0xf0, 0xe5, 0xb8, 0x6a, 0x1c, 0x12, 0x94, 0x92, 0xc2, 0x87, 0x0e, 0x93, + 0xa3, 0xd3, 0x80, 0x7f, 0x35, 0xb0, 0x90, 0x1c, 0x3c, 0x78, 0x67, 0x5c, 0xf2, 0xc9, 0x87, 0x40, + 0xbf, 0x3b, 0xf5, 0xfc, 0xa9, 0xe5, 0x0f, 0x09, 0x95, 0x06, 0x0c, 0xd8, 0xd2, 0x80, 0x6f, 0x67, + 0x84, 0xfc, 0x84, 0xf0, 0x8e, 0x27, 0x7f, 0xf4, 0x51, 0x19, 0x4f, 0x7e, 0xca, 0xd5, 0x30, 0x89, + 0x90, 0x5f, 0x82, 0x3b, 0x93, 0xc8, 0x4f, 0x3e, 0x05, 0xe8, 0x70, 0x54, 0x88, 0x1b, 0xf0, 0xfd, + 0x0c, 0xc8, 0x8f, 0x3a, 0x03, 0xf0, 0xde, 0x44, 0x22, 0x12, 0xce, 0x93, 0x7e, 0xff, 0x14, 0x08, + 0xff, 0xc7, 0x88, 0x7e, 0xc1, 0xaa, 0x15, 0xaa, 0x45, 0x8d, 0x8d, 0xc2, 0x51, 0xd3, 0xd0, 0x8e, + 0x9b, 0x86, 0xf6, 0xb3, 0x69, 0x68, 0x1f, 0x5a, 0x46, 0xe6, 0xb8, 0x65, 0x64, 0xbe, 0xb7, 0x8c, + 0xcc, 0xd6, 0xba, 0x43, 0x83, 0xbd, 0xb0, 0x6c, 0x55, 0x58, 0x6d, 0x24, 0x85, 0x37, 0x7d, 0x24, + 0x82, 0xc8, 0x23, 0xbc, 0x9c, 0x15, 0x3f, 0x2d, 0xd6, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0xd2, + 0xf4, 0x46, 0xb1, 0x3c, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -356,10 +550,14 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // GetMinaPubKey Queries a list of GetMinaPubKey items. - GetMinaPubKey(ctx context.Context, in *QueryGetMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetMinaPubKeyResponse, error) - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetCosmosPubKeyResponse, error) + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. + GetUserMinaPublicKey(ctx context.Context, in *QueryGetUserMinaPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserMinaPublicKeyResponse, error) + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. + GetUserCosmosPublicKey(ctx context.Context, in *QueryGetUserCosmosPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosPublicKeyResponse, error) + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. + GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. + GetValidatorCosmosPubKey(ctx context.Context, in *QueryGetValidatorCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorCosmosPubKeyResponse, error) } type queryClient struct { @@ -379,18 +577,36 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } -func (c *queryClient) GetMinaPubKey(ctx context.Context, in *QueryGetMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetMinaPubKeyResponse, error) { - out := new(QueryGetMinaPubKeyResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetMinaPubKey", in, out, opts...) +func (c *queryClient) GetUserMinaPublicKey(ctx context.Context, in *QueryGetUserMinaPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserMinaPublicKeyResponse, error) { + out := new(QueryGetUserMinaPublicKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserMinaPublicKey", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetUserCosmosPublicKey(ctx context.Context, in *QueryGetUserCosmosPublicKeyRequest, opts ...grpc.CallOption) (*QueryGetUserCosmosPublicKeyResponse, error) { + out := new(QueryGetUserCosmosPublicKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetUserCosmosPublicKey", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetValidatorMinaPubKey(ctx context.Context, in *QueryGetValidatorMinaPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorMinaPubKeyResponse, error) { + out := new(QueryGetValidatorMinaPubKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetValidatorMinaPubKey", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetCosmosPubKeyResponse, error) { - out := new(QueryGetCosmosPubKeyResponse) - err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetCosmosPubKey", in, out, opts...) +func (c *queryClient) GetValidatorCosmosPubKey(ctx context.Context, in *QueryGetValidatorCosmosPubKeyRequest, opts ...grpc.CallOption) (*QueryGetValidatorCosmosPubKeyResponse, error) { + out := new(QueryGetValidatorCosmosPubKeyResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Query/GetValidatorCosmosPubKey", in, out, opts...) if err != nil { return nil, err } @@ -401,10 +617,14 @@ func (c *queryClient) GetCosmosPubKey(ctx context.Context, in *QueryGetCosmosPub type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // GetMinaPubKey Queries a list of GetMinaPubKey items. - GetMinaPubKey(context.Context, *QueryGetMinaPubKeyRequest) (*QueryGetMinaPubKeyResponse, error) - // GetCosmosPubKey Queries a list of GetCosmosPubKey items. - GetCosmosPubKey(context.Context, *QueryGetCosmosPubKeyRequest) (*QueryGetCosmosPubKeyResponse, error) + // GetUserMinaPublicKey Queries a list of GetUserMinaPublicKey items. + GetUserMinaPublicKey(context.Context, *QueryGetUserMinaPublicKeyRequest) (*QueryGetUserMinaPublicKeyResponse, error) + // GetUserCosmosPublicKey Queries a list of GetUserCosmosPublicKey items. + GetUserCosmosPublicKey(context.Context, *QueryGetUserCosmosPublicKeyRequest) (*QueryGetUserCosmosPublicKeyResponse, error) + // GetValidatorMinaPubKey Queries a list of GetValidatorMinaPubKey items. + GetValidatorMinaPubKey(context.Context, *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) + // GetValidatorCosmosPubKey Queries a list of GetValidatorCosmosPubKey items. + GetValidatorCosmosPubKey(context.Context, *QueryGetValidatorCosmosPubKeyRequest) (*QueryGetValidatorCosmosPubKeyResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -414,11 +634,17 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) GetMinaPubKey(ctx context.Context, req *QueryGetMinaPubKeyRequest) (*QueryGetMinaPubKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetMinaPubKey not implemented") +func (*UnimplementedQueryServer) GetUserMinaPublicKey(ctx context.Context, req *QueryGetUserMinaPublicKeyRequest) (*QueryGetUserMinaPublicKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserMinaPublicKey not implemented") } -func (*UnimplementedQueryServer) GetCosmosPubKey(ctx context.Context, req *QueryGetCosmosPubKeyRequest) (*QueryGetCosmosPubKeyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetCosmosPubKey not implemented") +func (*UnimplementedQueryServer) GetUserCosmosPublicKey(ctx context.Context, req *QueryGetUserCosmosPublicKeyRequest) (*QueryGetUserCosmosPublicKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserCosmosPublicKey not implemented") +} +func (*UnimplementedQueryServer) GetValidatorMinaPubKey(ctx context.Context, req *QueryGetValidatorMinaPubKeyRequest) (*QueryGetValidatorMinaPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetValidatorMinaPubKey not implemented") +} +func (*UnimplementedQueryServer) GetValidatorCosmosPubKey(ctx context.Context, req *QueryGetValidatorCosmosPubKeyRequest) (*QueryGetValidatorCosmosPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetValidatorCosmosPubKey not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -443,38 +669,74 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_GetMinaPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetMinaPubKeyRequest) +func _Query_GetUserMinaPublicKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserMinaPublicKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetUserMinaPublicKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserMinaPublicKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetUserMinaPublicKey(ctx, req.(*QueryGetUserMinaPublicKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetUserCosmosPublicKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetUserCosmosPublicKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetUserCosmosPublicKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetUserCosmosPublicKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetUserCosmosPublicKey(ctx, req.(*QueryGetUserCosmosPublicKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetValidatorMinaPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetValidatorMinaPubKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetMinaPubKey(ctx, in) + return srv.(QueryServer).GetValidatorMinaPubKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetMinaPubKey", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetValidatorMinaPubKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetMinaPubKey(ctx, req.(*QueryGetMinaPubKeyRequest)) + return srv.(QueryServer).GetValidatorMinaPubKey(ctx, req.(*QueryGetValidatorMinaPubKeyRequest)) } return interceptor(ctx, in, info, handler) } -func _Query_GetCosmosPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetCosmosPubKeyRequest) +func _Query_GetValidatorCosmosPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetValidatorCosmosPubKeyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetCosmosPubKey(ctx, in) + return srv.(QueryServer).GetValidatorCosmosPubKey(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pulsarchain.keyregistry.v1.Query/GetCosmosPubKey", + FullMethod: "/pulsarchain.keyregistry.v1.Query/GetValidatorCosmosPubKey", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetCosmosPubKey(ctx, req.(*QueryGetCosmosPubKeyRequest)) + return srv.(QueryServer).GetValidatorCosmosPubKey(ctx, req.(*QueryGetValidatorCosmosPubKeyRequest)) } return interceptor(ctx, in, info, handler) } @@ -489,12 +751,20 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "GetMinaPubKey", - Handler: _Query_GetMinaPubKey_Handler, + MethodName: "GetUserMinaPublicKey", + Handler: _Query_GetUserMinaPublicKey_Handler, }, { - MethodName: "GetCosmosPubKey", - Handler: _Query_GetCosmosPubKey_Handler, + MethodName: "GetUserCosmosPublicKey", + Handler: _Query_GetUserCosmosPublicKey_Handler, + }, + { + MethodName: "GetValidatorMinaPubKey", + Handler: _Query_GetValidatorMinaPubKey_Handler, + }, + { + MethodName: "GetValidatorCosmosPubKey", + Handler: _Query_GetValidatorCosmosPubKey_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -557,7 +827,127 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryGetMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetUserMinaPublicKeyRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetUserMinaPublicKeyRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserMinaPublicKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserCosmosPublicKey) > 0 { + i -= len(m.UserCosmosPublicKey) + copy(dAtA[i:], m.UserCosmosPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserMinaPublicKeyResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetUserMinaPublicKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserMinaPublicKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserMinaPublicKey) > 0 { + i -= len(m.UserMinaPublicKey) + copy(dAtA[i:], m.UserMinaPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserCosmosPublicKeyRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetUserCosmosPublicKeyRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserCosmosPublicKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserMinaPublicKey) > 0 { + i -= len(m.UserMinaPublicKey) + copy(dAtA[i:], m.UserMinaPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserMinaPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetUserCosmosPublicKeyResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGetUserCosmosPublicKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetUserCosmosPublicKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.UserCosmosPublicKey) > 0 { + i -= len(m.UserCosmosPublicKey) + copy(dAtA[i:], m.UserCosmosPublicKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.UserCosmosPublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryGetValidatorMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -567,27 +957,27 @@ func (m *QueryGetMinaPubKeyRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetMinaPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetMinaPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.CosmosPubKey) > 0 { - i -= len(m.CosmosPubKey) - copy(dAtA[i:], m.CosmosPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosPubKey))) + if len(m.ValidatorCosmosPubKey) > 0 { + i -= len(m.ValidatorCosmosPubKey) + copy(dAtA[i:], m.ValidatorCosmosPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorCosmosPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -597,27 +987,27 @@ func (m *QueryGetMinaPubKeyResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetMinaPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetMinaPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorMinaPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.MinaPubKey) > 0 { - i -= len(m.MinaPubKey) - copy(dAtA[i:], m.MinaPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.MinaPubKey))) + if len(m.ValidatorMinaPubKey) > 0 { + i -= len(m.ValidatorMinaPubKey) + copy(dAtA[i:], m.ValidatorMinaPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorMinaPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -627,27 +1017,27 @@ func (m *QueryGetCosmosPubKeyRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetCosmosPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetCosmosPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.MinaPubKey) > 0 { - i -= len(m.MinaPubKey) - copy(dAtA[i:], m.MinaPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.MinaPubKey))) + if len(m.ValidatorMinaPubKey) > 0 { + i -= len(m.ValidatorMinaPubKey) + copy(dAtA[i:], m.ValidatorMinaPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorMinaPubKey))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryGetCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -657,20 +1047,20 @@ func (m *QueryGetCosmosPubKeyResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetCosmosPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetCosmosPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetValidatorCosmosPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.CosmosPubKey) > 0 { - i -= len(m.CosmosPubKey) - copy(dAtA[i:], m.CosmosPubKey) - i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosPubKey))) + if len(m.ValidatorCosmosPubKey) > 0 { + i -= len(m.ValidatorCosmosPubKey) + copy(dAtA[i:], m.ValidatorCosmosPubKey) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ValidatorCosmosPubKey))) i-- dAtA[i] = 0xa } @@ -708,66 +1098,118 @@ func (m *QueryParamsResponse) Size() (n int) { return n } -func (m *QueryGetMinaPubKeyRequest) Size() (n int) { +func (m *QueryGetUserMinaPublicKeyRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.CosmosPubKey) + l = len(m.UserCosmosPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetMinaPubKeyResponse) Size() (n int) { +func (m *QueryGetUserMinaPublicKeyResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.MinaPubKey) + l = len(m.UserMinaPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetCosmosPubKeyRequest) Size() (n int) { +func (m *QueryGetUserCosmosPublicKeyRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.MinaPubKey) + l = len(m.UserMinaPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func (m *QueryGetCosmosPubKeyResponse) Size() (n int) { +func (m *QueryGetUserCosmosPublicKeyResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.CosmosPubKey) + l = len(m.UserCosmosPublicKey) if l > 0 { n += 1 + l + sovQuery(uint64(l)) } return n } -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func (m *QueryGetValidatorMinaPubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorCosmosPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n } -func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) + +func (m *QueryGetValidatorMinaPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorMinaPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetValidatorCosmosPubKeyRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorMinaPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryGetValidatorCosmosPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorCosmosPubKey) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) iNdEx := 0 for iNdEx < l { preIndex := iNdEx @@ -899,7 +1341,343 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetUserMinaPublicKeyRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserCosmosPublicKey = append(m.UserCosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosPublicKey == nil { + m.UserCosmosPublicKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetUserMinaPublicKeyResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserMinaPublicKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserMinaPublicKey = append(m.UserMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaPublicKey == nil { + m.UserMinaPublicKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetUserCosmosPublicKeyRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserMinaPublicKey = append(m.UserMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserMinaPublicKey == nil { + m.UserMinaPublicKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetUserCosmosPublicKeyResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetUserCosmosPublicKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UserCosmosPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UserCosmosPublicKey = append(m.UserCosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.UserCosmosPublicKey == nil { + m.UserCosmosPublicKey = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGetValidatorMinaPubKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -922,15 +1700,15 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetMinaPubKeyRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetMinaPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -957,9 +1735,9 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPubKey = append(m.CosmosPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPubKey == nil { - m.CosmosPubKey = []byte{} + m.ValidatorCosmosPubKey = append(m.ValidatorCosmosPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorCosmosPubKey == nil { + m.ValidatorCosmosPubKey = []byte{} } iNdEx = postIndex default: @@ -983,7 +1761,7 @@ func (m *QueryGetMinaPubKeyRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorMinaPubKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1006,15 +1784,15 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetMinaPubKeyResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetMinaPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorMinaPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1041,9 +1819,9 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPubKey = append(m.MinaPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPubKey == nil { - m.MinaPubKey = []byte{} + m.ValidatorMinaPubKey = append(m.ValidatorMinaPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorMinaPubKey == nil { + m.ValidatorMinaPubKey = []byte{} } iNdEx = postIndex default: @@ -1067,7 +1845,7 @@ func (m *QueryGetMinaPubKeyResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1090,15 +1868,15 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorMinaPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1125,9 +1903,9 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPubKey = append(m.MinaPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPubKey == nil { - m.MinaPubKey = []byte{} + m.ValidatorMinaPubKey = append(m.ValidatorMinaPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorMinaPubKey == nil { + m.ValidatorMinaPubKey = []byte{} } iNdEx = postIndex default: @@ -1151,7 +1929,7 @@ func (m *QueryGetCosmosPubKeyRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetValidatorCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1174,15 +1952,15 @@ func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetCosmosPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetValidatorCosmosPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPubKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCosmosPubKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1209,9 +1987,9 @@ func (m *QueryGetCosmosPubKeyResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPubKey = append(m.CosmosPubKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPubKey == nil { - m.CosmosPubKey = []byte{} + m.ValidatorCosmosPubKey = append(m.ValidatorCosmosPubKey[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorCosmosPubKey == nil { + m.ValidatorCosmosPubKey = []byte{} } iNdEx = postIndex default: diff --git a/x/keyregistry/types/query.pb.gw.go b/x/keyregistry/types/query.pb.gw.go index 0ec64544..cfa29756 100644 --- a/x/keyregistry/types/query.pb.gw.go +++ b/x/keyregistry/types/query.pb.gw.go @@ -51,8 +51,8 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } -func request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetMinaPubKeyRequest +func request_Query_GetUserMinaPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -62,24 +62,24 @@ func request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marsha _ = err ) - val, ok = pathParams["cosmos_pub_key"] + val, ok = pathParams["user_cosmos_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_public_key") } - protoReq.CosmosPubKey, err = runtime.Bytes(val) + protoReq.UserCosmosPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_public_key", err) } - msg, err := client.GetMinaPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserMinaPublicKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetMinaPubKeyRequest +func local_request_Query_GetUserMinaPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserMinaPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -89,24 +89,24 @@ func local_request_Query_GetMinaPubKey_0(ctx context.Context, marshaler runtime. _ = err ) - val, ok = pathParams["cosmos_pub_key"] + val, ok = pathParams["user_cosmos_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_cosmos_public_key") } - protoReq.CosmosPubKey, err = runtime.Bytes(val) + protoReq.UserCosmosPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_cosmos_public_key", err) } - msg, err := server.GetMinaPubKey(ctx, &protoReq) + msg, err := server.GetUserMinaPublicKey(ctx, &protoReq) return msg, metadata, err } -func request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetCosmosPubKeyRequest +func request_Query_GetUserCosmosPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -116,24 +116,24 @@ func request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Mars _ = err ) - val, ok = pathParams["mina_pub_key"] + val, ok = pathParams["user_mina_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "mina_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_public_key") } - protoReq.MinaPubKey, err = runtime.Bytes(val) + protoReq.UserMinaPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "mina_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_public_key", err) } - msg, err := client.GetCosmosPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetUserCosmosPublicKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetCosmosPubKeyRequest +func local_request_Query_GetUserCosmosPublicKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetUserCosmosPublicKeyRequest var metadata runtime.ServerMetadata var ( @@ -143,18 +143,126 @@ func local_request_Query_GetCosmosPubKey_0(ctx context.Context, marshaler runtim _ = err ) - val, ok = pathParams["mina_pub_key"] + val, ok = pathParams["user_mina_public_key"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "mina_pub_key") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "user_mina_public_key") } - protoReq.MinaPubKey, err = runtime.Bytes(val) + protoReq.UserMinaPublicKey, err = runtime.Bytes(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "mina_pub_key", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "user_mina_public_key", err) } - msg, err := server.GetCosmosPubKey(ctx, &protoReq) + msg, err := server.GetUserCosmosPublicKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetValidatorMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorMinaPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_cosmos_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_cosmos_pub_key") + } + + protoReq.ValidatorCosmosPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_cosmos_pub_key", err) + } + + msg, err := client.GetValidatorMinaPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetValidatorMinaPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorMinaPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_cosmos_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_cosmos_pub_key") + } + + protoReq.ValidatorCosmosPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_cosmos_pub_key", err) + } + + msg, err := server.GetValidatorMinaPubKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetValidatorCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorCosmosPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_mina_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_mina_pub_key") + } + + protoReq.ValidatorMinaPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_mina_pub_key", err) + } + + msg, err := client.GetValidatorCosmosPubKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetValidatorCosmosPubKey_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetValidatorCosmosPubKeyRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["validator_mina_pub_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "validator_mina_pub_key") + } + + protoReq.ValidatorMinaPubKey, err = runtime.Bytes(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "validator_mina_pub_key", err) + } + + msg, err := server.GetValidatorCosmosPubKey(ctx, &protoReq) return msg, metadata, err } @@ -188,7 +296,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetUserMinaPublicKey_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetUserMinaPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetUserCosmosPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -199,7 +330,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetMinaPubKey_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetUserCosmosPublicKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -207,11 +338,11 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetValidatorMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -222,7 +353,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetCosmosPubKey_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetValidatorMinaPubKey_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -230,7 +361,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetValidatorMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetValidatorCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetValidatorCosmosPubKey_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetValidatorCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -295,7 +449,27 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetUserMinaPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetUserMinaPublicKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetUserMinaPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetUserCosmosPublicKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -304,18 +478,18 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetMinaPubKey_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetUserCosmosPublicKey_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetUserCosmosPublicKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("GET", pattern_Query_GetCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetValidatorMinaPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -324,14 +498,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetCosmosPubKey_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetValidatorMinaPubKey_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_GetCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetValidatorMinaPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetValidatorCosmosPubKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetValidatorCosmosPubKey_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetValidatorCosmosPubKey_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -341,15 +535,23 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetMinaPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_mina_pub_key", "cosmos_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserMinaPublicKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_mina_public_key", "user_cosmos_public_key"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_GetCosmosPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_cosmos_pub_key", "mina_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_GetUserCosmosPublicKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_user_cosmos_public_key", "user_mina_public_key"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetValidatorMinaPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_validator_mina_pub_key", "validator_cosmos_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GetValidatorCosmosPubKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "keyregistry", "v1", "get_validator_cosmos_pub_key", "validator_mina_pub_key"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_GetMinaPubKey_0 = runtime.ForwardResponseMessage + forward_Query_GetUserMinaPublicKey_0 = runtime.ForwardResponseMessage + + forward_Query_GetUserCosmosPublicKey_0 = runtime.ForwardResponseMessage + + forward_Query_GetValidatorMinaPubKey_0 = runtime.ForwardResponseMessage - forward_Query_GetCosmosPubKey_0 = runtime.ForwardResponseMessage + forward_Query_GetValidatorCosmosPubKey_0 = runtime.ForwardResponseMessage ) diff --git a/x/keyregistry/types/tx.pb.go b/x/keyregistry/types/tx.pb.go index 42552c4c..b0b00dec 100644 --- a/x/keyregistry/types/tx.pb.go +++ b/x/keyregistry/types/tx.pb.go @@ -126,11 +126,12 @@ var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo // MsgRegisterKeys defines the MsgRegisterKeys message. type MsgRegisterKeys struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - CosmosSignature string `protobuf:"bytes,2,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` - MinaSignature string `protobuf:"bytes,3,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` - CosmosPublicKey []byte `protobuf:"bytes,4,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` - MinaPublicKey []byte `protobuf:"bytes,5,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + CosmosPublicKey []byte `protobuf:"bytes,2,opt,name=cosmos_public_key,json=cosmosPublicKey,proto3" json:"cosmos_public_key,omitempty"` + MinaPublicKey []byte `protobuf:"bytes,3,opt,name=mina_public_key,json=minaPublicKey,proto3" json:"mina_public_key,omitempty"` + CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + MinaSignature []byte `protobuf:"bytes,5,opt,name=mina_signature,json=minaSignature,proto3" json:"mina_signature,omitempty"` + ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` } func (m *MsgRegisterKeys) Reset() { *m = MsgRegisterKeys{} } @@ -173,34 +174,41 @@ func (m *MsgRegisterKeys) GetCreator() string { return "" } -func (m *MsgRegisterKeys) GetCosmosSignature() string { +func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { if m != nil { - return m.CosmosSignature + return m.CosmosPublicKey } - return "" + return nil } -func (m *MsgRegisterKeys) GetMinaSignature() string { +func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { if m != nil { - return m.MinaSignature + return m.MinaPublicKey } - return "" + return nil } -func (m *MsgRegisterKeys) GetCosmosPublicKey() []byte { +func (m *MsgRegisterKeys) GetCosmosSignature() []byte { if m != nil { - return m.CosmosPublicKey + return m.CosmosSignature } return nil } -func (m *MsgRegisterKeys) GetMinaPublicKey() []byte { +func (m *MsgRegisterKeys) GetMinaSignature() []byte { if m != nil { - return m.MinaPublicKey + return m.MinaSignature } return nil } +func (m *MsgRegisterKeys) GetActorType() ActorType { + if m != nil { + return m.ActorType + } + return ActorType_UNSPECIFIED +} + // MsgRegisterKeysResponse defines the MsgRegisterKeysResponse message. type MsgRegisterKeysResponse struct { } @@ -238,11 +246,135 @@ func (m *MsgRegisterKeysResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterKeysResponse proto.InternalMessageInfo +// MsgUpdateKeys defines the MsgUpdateKeys message. +type MsgUpdateKeys struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + PrevMinaPublicKey []byte `protobuf:"bytes,2,opt,name=prev_mina_public_key,json=prevMinaPublicKey,proto3" json:"prev_mina_public_key,omitempty"` + NewMinaPublicKey []byte `protobuf:"bytes,3,opt,name=new_mina_public_key,json=newMinaPublicKey,proto3" json:"new_mina_public_key,omitempty"` + CosmosSignature []byte `protobuf:"bytes,4,opt,name=cosmos_signature,json=cosmosSignature,proto3" json:"cosmos_signature,omitempty"` + NewMinaSignature []byte `protobuf:"bytes,5,opt,name=new_mina_signature,json=newMinaSignature,proto3" json:"new_mina_signature,omitempty"` + ActorType ActorType `protobuf:"varint,6,opt,name=actor_type,json=actorType,proto3,enum=pulsarchain.keyregistry.v1.ActorType" json:"actor_type,omitempty"` +} + +func (m *MsgUpdateKeys) Reset() { *m = MsgUpdateKeys{} } +func (m *MsgUpdateKeys) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateKeys) ProtoMessage() {} +func (*MsgUpdateKeys) Descriptor() ([]byte, []int) { + return fileDescriptor_235f5fb22cc1f8d8, []int{4} +} +func (m *MsgUpdateKeys) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateKeys) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateKeys.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateKeys) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateKeys.Merge(m, src) +} +func (m *MsgUpdateKeys) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateKeys) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateKeys.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateKeys proto.InternalMessageInfo + +func (m *MsgUpdateKeys) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateKeys) GetPrevMinaPublicKey() []byte { + if m != nil { + return m.PrevMinaPublicKey + } + return nil +} + +func (m *MsgUpdateKeys) GetNewMinaPublicKey() []byte { + if m != nil { + return m.NewMinaPublicKey + } + return nil +} + +func (m *MsgUpdateKeys) GetCosmosSignature() []byte { + if m != nil { + return m.CosmosSignature + } + return nil +} + +func (m *MsgUpdateKeys) GetNewMinaSignature() []byte { + if m != nil { + return m.NewMinaSignature + } + return nil +} + +func (m *MsgUpdateKeys) GetActorType() ActorType { + if m != nil { + return m.ActorType + } + return ActorType_UNSPECIFIED +} + +// MsgUpdateKeysResponse defines the MsgUpdateKeysResponse message. +type MsgUpdateKeysResponse struct { +} + +func (m *MsgUpdateKeysResponse) Reset() { *m = MsgUpdateKeysResponse{} } +func (m *MsgUpdateKeysResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateKeysResponse) ProtoMessage() {} +func (*MsgUpdateKeysResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_235f5fb22cc1f8d8, []int{5} +} +func (m *MsgUpdateKeysResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateKeysResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateKeysResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateKeysResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateKeysResponse.Merge(m, src) +} +func (m *MsgUpdateKeysResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateKeysResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateKeysResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateKeysResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgUpdateParams)(nil), "pulsarchain.keyregistry.v1.MsgUpdateParams") proto.RegisterType((*MsgUpdateParamsResponse)(nil), "pulsarchain.keyregistry.v1.MsgUpdateParamsResponse") proto.RegisterType((*MsgRegisterKeys)(nil), "pulsarchain.keyregistry.v1.MsgRegisterKeys") proto.RegisterType((*MsgRegisterKeysResponse)(nil), "pulsarchain.keyregistry.v1.MsgRegisterKeysResponse") + proto.RegisterType((*MsgUpdateKeys)(nil), "pulsarchain.keyregistry.v1.MsgUpdateKeys") + proto.RegisterType((*MsgUpdateKeysResponse)(nil), "pulsarchain.keyregistry.v1.MsgUpdateKeysResponse") } func init() { @@ -250,39 +382,46 @@ func init() { } var fileDescriptor_235f5fb22cc1f8d8 = []byte{ - // 503 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xb1, 0x6f, 0x13, 0x31, - 0x14, 0xc6, 0x63, 0x4a, 0x8b, 0x62, 0x02, 0xa1, 0xa7, 0x4a, 0x4d, 0x6f, 0x38, 0xa2, 0x20, 0x20, - 0x0d, 0xca, 0x1d, 0x49, 0xa5, 0x0e, 0x15, 0x0b, 0x91, 0x98, 0xaa, 0x4a, 0xd1, 0x55, 0x2c, 0x2c, - 0x95, 0x73, 0xb1, 0x1c, 0xab, 0xbd, 0xf3, 0xc9, 0xf6, 0x55, 0xbd, 0x0d, 0x31, 0x32, 0xf1, 0x67, - 0x30, 0x66, 0xe0, 0x8f, 0xe8, 0x84, 0x2a, 0x26, 0x26, 0x84, 0x92, 0x21, 0x2b, 0x2b, 0x1b, 0x3a, - 0xdb, 0x47, 0x2e, 0x51, 0x49, 0xc4, 0x12, 0xc5, 0x9f, 0x7f, 0x7e, 0x9f, 0xbf, 0xf7, 0x7c, 0xf0, - 0x49, 0x9c, 0x5c, 0x08, 0xc4, 0x83, 0x11, 0xa2, 0x91, 0x77, 0x8e, 0x53, 0x8e, 0x09, 0x15, 0x92, - 0xa7, 0xde, 0x65, 0xc7, 0x93, 0x57, 0x6e, 0xcc, 0x99, 0x64, 0x96, 0x5d, 0x80, 0xdc, 0x02, 0xe4, - 0x5e, 0x76, 0xec, 0x6d, 0x14, 0xd2, 0x88, 0x79, 0xea, 0x57, 0xe3, 0xf6, 0x6e, 0xc0, 0x44, 0xc8, - 0x84, 0x17, 0x0a, 0x92, 0x95, 0x09, 0x05, 0x31, 0x1b, 0x7b, 0x7a, 0xe3, 0x4c, 0xad, 0x3c, 0xbd, - 0x30, 0x5b, 0x3b, 0x84, 0x11, 0xa6, 0xf5, 0xec, 0x9f, 0x51, 0x9f, 0xaf, 0xb8, 0x5d, 0x8c, 0x38, - 0x0a, 0xcd, 0xf1, 0xc6, 0x57, 0x00, 0xab, 0x27, 0x82, 0xbc, 0x8d, 0x87, 0x48, 0xe2, 0xbe, 0xda, - 0xb1, 0x0e, 0x61, 0x19, 0x25, 0x72, 0xc4, 0x38, 0x95, 0x69, 0x0d, 0xd4, 0x41, 0xb3, 0xdc, 0xab, - 0x7d, 0xfb, 0xd2, 0xde, 0x31, 0xbe, 0xaf, 0x87, 0x43, 0x8e, 0x85, 0x38, 0x95, 0x9c, 0x46, 0xc4, - 0x9f, 0xa3, 0xd6, 0x1b, 0xb8, 0xa5, 0x6b, 0xd7, 0xee, 0xd4, 0x41, 0xf3, 0x7e, 0xb7, 0xe1, 0xfe, - 0x3b, 0xbe, 0xab, 0xbd, 0x7a, 0xe5, 0xeb, 0x1f, 0x8f, 0x4b, 0x9f, 0x67, 0xe3, 0x16, 0xf0, 0xcd, - 0xe1, 0xa3, 0x57, 0x1f, 0x66, 0xe3, 0xd6, 0xbc, 0xec, 0xc7, 0xd9, 0xb8, 0xb5, 0x5f, 0x8c, 0x73, - 0xb5, 0x10, 0x68, 0xe9, 0xf2, 0x8d, 0x3d, 0xb8, 0xbb, 0x24, 0xf9, 0x58, 0xc4, 0x2c, 0x12, 0xb8, - 0xf1, 0x5b, 0x67, 0xf5, 0xd5, 0x51, 0xcc, 0x8f, 0x71, 0x2a, 0xac, 0x2e, 0xbc, 0x17, 0x70, 0x8c, - 0x24, 0xe3, 0x6b, 0x93, 0xe6, 0xa0, 0xb5, 0x0f, 0x1f, 0x99, 0x79, 0x08, 0x4a, 0x22, 0x24, 0x13, - 0x8e, 0x55, 0xe2, 0xb2, 0x5f, 0xd5, 0xfa, 0x69, 0x2e, 0x5b, 0x4f, 0xe1, 0xc3, 0x90, 0x46, 0xa8, - 0x00, 0x6e, 0x28, 0xf0, 0x41, 0xa6, 0xce, 0xb1, 0x16, 0xdc, 0xce, 0x27, 0x9c, 0x0c, 0x2e, 0x68, - 0x70, 0x76, 0x8e, 0xd3, 0xda, 0xdd, 0x3a, 0x68, 0x56, 0xf2, 0x92, 0x7d, 0xa5, 0x1f, 0xe3, 0xd4, - 0x7a, 0x06, 0xab, 0xaa, 0x64, 0x81, 0xdc, 0x54, 0xa4, 0xaa, 0xf9, 0x97, 0x3b, 0xaa, 0x64, 0x6d, - 0xcc, 0xef, 0x6c, 0xda, 0x52, 0x8c, 0x9e, 0xb7, 0xa5, 0xfb, 0x0b, 0xc0, 0x8d, 0x13, 0x41, 0xac, - 0x18, 0x56, 0x16, 0x9e, 0xc1, 0x8b, 0x55, 0xe3, 0x5b, 0xea, 0xb1, 0x7d, 0xf0, 0x1f, 0x70, 0xee, - 0x9c, 0x39, 0x2e, 0x0c, 0x63, 0x9d, 0x63, 0x11, 0x5e, 0xeb, 0x78, 0x5b, 0x56, 0x7b, 0xf3, 0x7d, - 0xf6, 0xd4, 0x7a, 0xfd, 0xeb, 0x89, 0x03, 0x6e, 0x26, 0x0e, 0xf8, 0x39, 0x71, 0xc0, 0xa7, 0xa9, - 0x53, 0xba, 0x99, 0x3a, 0xa5, 0xef, 0x53, 0xa7, 0xf4, 0xee, 0x90, 0x50, 0x39, 0x4a, 0x06, 0x6e, - 0xc0, 0x42, 0x2f, 0x62, 0x43, 0xdc, 0x79, 0xd9, 0x69, 0x53, 0xe6, 0x69, 0xab, 0xf6, 0x6d, 0x0f, - 0x50, 0xa6, 0x31, 0x16, 0x83, 0x2d, 0xf5, 0x39, 0x1d, 0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0xfb, - 0xf4, 0xf0, 0x15, 0x17, 0x04, 0x00, 0x00, + // 620 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0x8e, 0xd3, 0x5f, 0xfb, 0x53, 0x8e, 0xfe, 0x35, 0x45, 0x49, 0x33, 0x98, 0x28, 0xa8, 0x90, + 0x04, 0x62, 0x37, 0xa9, 0xd4, 0xa1, 0x62, 0x69, 0x04, 0x53, 0x15, 0x29, 0x72, 0x61, 0x61, 0xb1, + 0x2e, 0xce, 0xc9, 0x31, 0xa9, 0x7d, 0xd6, 0xdd, 0x39, 0xad, 0x37, 0xc4, 0xc8, 0xc4, 0xc7, 0x60, + 0xcc, 0xc0, 0xce, 0xda, 0x09, 0x45, 0x4c, 0x0c, 0x08, 0xa1, 0x64, 0xc8, 0xd7, 0x40, 0x3e, 0xdb, + 0xb1, 0x13, 0x85, 0xa4, 0x54, 0x62, 0xb1, 0x7c, 0xef, 0xfb, 0xdc, 0xf3, 0xbc, 0xef, 0xf3, 0xde, + 0x1d, 0x78, 0xe4, 0xb8, 0x97, 0x14, 0x12, 0xbd, 0x0b, 0x4d, 0x5b, 0xe9, 0x21, 0x8f, 0x20, 0xc3, + 0xa4, 0x8c, 0x78, 0x4a, 0xbf, 0xa6, 0xb0, 0x6b, 0xd9, 0x21, 0x98, 0x61, 0x31, 0x9f, 0x00, 0xc9, + 0x09, 0x90, 0xdc, 0xaf, 0xe5, 0xf7, 0xa0, 0x65, 0xda, 0x58, 0xe1, 0xdf, 0x00, 0x9e, 0xcf, 0xea, + 0x98, 0x5a, 0x98, 0x2a, 0x16, 0x35, 0x7c, 0x1a, 0x8b, 0x1a, 0x61, 0xe2, 0x20, 0x48, 0x68, 0x7c, + 0xa5, 0x04, 0x8b, 0x30, 0xb5, 0x6f, 0x60, 0x03, 0x07, 0x71, 0xff, 0x2f, 0x8c, 0x3e, 0x59, 0x52, + 0x9d, 0x03, 0x09, 0xb4, 0xa2, 0xed, 0x47, 0x4b, 0x80, 0x3d, 0xe4, 0x69, 0xae, 0xd3, 0x81, 0x0c, + 0x69, 0xcc, 0x73, 0x50, 0xb0, 0xa3, 0xf8, 0x55, 0x00, 0x3b, 0x4d, 0x6a, 0xbc, 0xe6, 0x89, 0x16, + 0xe7, 0x12, 0x4f, 0x40, 0x06, 0xba, 0xac, 0x8b, 0x89, 0xc9, 0xbc, 0x9c, 0x50, 0x10, 0x4a, 0x99, + 0x46, 0xee, 0xdb, 0xe7, 0xea, 0x7e, 0x58, 0xe9, 0x59, 0xa7, 0x43, 0x10, 0xa5, 0x17, 0x8c, 0x98, + 0xb6, 0xa1, 0xc6, 0x50, 0xf1, 0x25, 0xd8, 0x08, 0xaa, 0xc9, 0xa5, 0x0b, 0x42, 0xe9, 0x5e, 0xbd, + 0x28, 0xff, 0xd9, 0x30, 0x39, 0xd0, 0x6a, 0x64, 0x6e, 0x7e, 0x3e, 0x4c, 0x7d, 0x9a, 0x0c, 0x2a, + 0x82, 0x1a, 0x6e, 0x3e, 0x7d, 0xfe, 0x7e, 0x32, 0xa8, 0xc4, 0xb4, 0x1f, 0x26, 0x83, 0x4a, 0x39, + 0xd9, 0xd7, 0xf5, 0x4c, 0x67, 0x73, 0xc5, 0x17, 0x0f, 0x40, 0x76, 0x2e, 0xa4, 0x22, 0xea, 0x60, + 0x9b, 0xa2, 0xe2, 0x97, 0x34, 0xef, 0x55, 0xe5, 0x5b, 0x11, 0x39, 0x47, 0x1e, 0x15, 0xeb, 0xe0, + 0x7f, 0x9d, 0x20, 0xc8, 0x30, 0x59, 0xd9, 0x69, 0x04, 0x14, 0x2b, 0x60, 0x2f, 0x9a, 0xa0, 0xdb, + 0xbe, 0x34, 0x75, 0xad, 0x87, 0x3c, 0xde, 0xf2, 0xa6, 0xba, 0x13, 0x24, 0x5a, 0x3c, 0x7e, 0x8e, + 0x3c, 0xf1, 0x31, 0xd8, 0xb1, 0x4c, 0x1b, 0x26, 0x91, 0x6b, 0x1c, 0xb9, 0xe5, 0x87, 0x63, 0x5c, + 0x19, 0xec, 0x86, 0x9c, 0xd4, 0x34, 0x6c, 0xc8, 0x5c, 0x82, 0x72, 0xff, 0x25, 0x29, 0x2f, 0xa2, + 0xb0, 0x78, 0x08, 0xb6, 0x39, 0x65, 0x0c, 0x5c, 0x8f, 0x19, 0x63, 0xd8, 0x0b, 0x00, 0xa0, 0xce, + 0x30, 0xe1, 0xd3, 0xce, 0x6d, 0x14, 0x84, 0xd2, 0x76, 0xfd, 0x70, 0xd9, 0x44, 0xce, 0x7c, 0xf4, + 0x2b, 0xcf, 0x41, 0x6a, 0x06, 0x46, 0xbf, 0xa7, 0x9b, 0xfe, 0x30, 0xa2, 0xce, 0x43, 0x73, 0x93, + 0x06, 0x4e, 0xcd, 0x1d, 0xa6, 0xc1, 0xd6, 0xd4, 0xf8, 0x3b, 0x5b, 0xab, 0x80, 0x7d, 0x87, 0xa0, + 0xbe, 0x36, 0xef, 0x59, 0xe0, 0xee, 0x9e, 0x9f, 0x6b, 0xce, 0xf8, 0x56, 0x05, 0xf7, 0x6d, 0x74, + 0xa5, 0x2d, 0xf6, 0x78, 0xd7, 0x46, 0x57, 0xcd, 0xbb, 0xda, 0xfc, 0x0c, 0x88, 0x53, 0xe6, 0x79, + 0xab, 0x23, 0xe2, 0x7f, 0xeb, 0x76, 0x16, 0x3c, 0x98, 0x71, 0x34, 0xf2, 0xba, 0xfe, 0x23, 0x0d, + 0xd6, 0x9a, 0xd4, 0x10, 0x1d, 0xb0, 0x39, 0x73, 0x71, 0x9f, 0x2e, 0x13, 0x9c, 0xbb, 0x15, 0xf9, + 0xe3, 0xbf, 0x00, 0x47, 0xca, 0xbe, 0xe2, 0xcc, 0xf5, 0x59, 0xa5, 0x98, 0x04, 0xaf, 0x54, 0x5c, + 0x74, 0xae, 0xc4, 0xb7, 0x00, 0x24, 0xce, 0x54, 0xf9, 0x56, 0x45, 0x73, 0xb5, 0xda, 0xad, 0xa1, + 0x91, 0x56, 0x7e, 0xfd, 0x9d, 0xff, 0x10, 0x35, 0x5a, 0x37, 0x23, 0x49, 0x18, 0x8e, 0x24, 0xe1, + 0xd7, 0x48, 0x12, 0x3e, 0x8e, 0xa5, 0xd4, 0x70, 0x2c, 0xa5, 0xbe, 0x8f, 0xa5, 0xd4, 0x9b, 0x13, + 0xc3, 0x64, 0x5d, 0xb7, 0x2d, 0xeb, 0xd8, 0x52, 0x6c, 0xdc, 0x41, 0xb5, 0xa3, 0x5a, 0xd5, 0xc4, + 0x4a, 0x20, 0x54, 0x5d, 0xf4, 0x3c, 0xf9, 0xc7, 0x81, 0xb6, 0x37, 0xf8, 0x63, 0x7b, 0xfc, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0x12, 0x10, 0x94, 0x52, 0x67, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -302,6 +441,8 @@ type MsgClient interface { UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) // RegisterKeys defines the RegisterKeys RPC. RegisterKeys(ctx context.Context, in *MsgRegisterKeys, opts ...grpc.CallOption) (*MsgRegisterKeysResponse, error) + // UpdateKeys defines the UpdateKeys RPC. + UpdateKeys(ctx context.Context, in *MsgUpdateKeys, opts ...grpc.CallOption) (*MsgUpdateKeysResponse, error) } type msgClient struct { @@ -330,6 +471,15 @@ func (c *msgClient) RegisterKeys(ctx context.Context, in *MsgRegisterKeys, opts return out, nil } +func (c *msgClient) UpdateKeys(ctx context.Context, in *MsgUpdateKeys, opts ...grpc.CallOption) (*MsgUpdateKeysResponse, error) { + out := new(MsgUpdateKeysResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.keyregistry.v1.Msg/UpdateKeys", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // UpdateParams defines a (governance) operation for updating the module @@ -337,6 +487,8 @@ type MsgServer interface { UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) // RegisterKeys defines the RegisterKeys RPC. RegisterKeys(context.Context, *MsgRegisterKeys) (*MsgRegisterKeysResponse, error) + // UpdateKeys defines the UpdateKeys RPC. + UpdateKeys(context.Context, *MsgUpdateKeys) (*MsgUpdateKeysResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -349,6 +501,9 @@ func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateP func (*UnimplementedMsgServer) RegisterKeys(ctx context.Context, req *MsgRegisterKeys) (*MsgRegisterKeysResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RegisterKeys not implemented") } +func (*UnimplementedMsgServer) UpdateKeys(ctx context.Context, req *MsgUpdateKeys) (*MsgUpdateKeysResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateKeys not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -390,6 +545,24 @@ func _Msg_RegisterKeys_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_UpdateKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateKeys) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateKeys(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.keyregistry.v1.Msg/UpdateKeys", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateKeys(ctx, req.(*MsgUpdateKeys)) + } + return interceptor(ctx, in, info, handler) +} + var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "pulsarchain.keyregistry.v1.Msg", @@ -403,6 +576,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "RegisterKeys", Handler: _Msg_RegisterKeys_Handler, }, + { + MethodName: "UpdateKeys", + Handler: _Msg_UpdateKeys_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "pulsarchain/keyregistry/v1/tx.proto", @@ -491,32 +668,123 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ActorType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ActorType)) + i-- + dAtA[i] = 0x30 + } + if len(m.MinaSignature) > 0 { + i -= len(m.MinaSignature) + copy(dAtA[i:], m.MinaSignature) + i = encodeVarintTx(dAtA, i, uint64(len(m.MinaSignature))) + i-- + dAtA[i] = 0x2a + } + if len(m.CosmosSignature) > 0 { + i -= len(m.CosmosSignature) + copy(dAtA[i:], m.CosmosSignature) + i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosSignature))) + i-- + dAtA[i] = 0x22 + } if len(m.MinaPublicKey) > 0 { i -= len(m.MinaPublicKey) copy(dAtA[i:], m.MinaPublicKey) i = encodeVarintTx(dAtA, i, uint64(len(m.MinaPublicKey))) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x1a } if len(m.CosmosPublicKey) > 0 { i -= len(m.CosmosPublicKey) copy(dAtA[i:], m.CosmosPublicKey) i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosPublicKey))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x12 } - if len(m.MinaSignature) > 0 { - i -= len(m.MinaSignature) - copy(dAtA[i:], m.MinaSignature) - i = encodeVarintTx(dAtA, i, uint64(len(m.MinaSignature))) + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterKeysResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRegisterKeysResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterKeysResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateKeys) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateKeys) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ActorType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ActorType)) + i-- + dAtA[i] = 0x30 + } + if len(m.NewMinaSignature) > 0 { + i -= len(m.NewMinaSignature) + copy(dAtA[i:], m.NewMinaSignature) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewMinaSignature))) + i-- + dAtA[i] = 0x2a } if len(m.CosmosSignature) > 0 { i -= len(m.CosmosSignature) copy(dAtA[i:], m.CosmosSignature) i = encodeVarintTx(dAtA, i, uint64(len(m.CosmosSignature))) i-- + dAtA[i] = 0x22 + } + if len(m.NewMinaPublicKey) > 0 { + i -= len(m.NewMinaPublicKey) + copy(dAtA[i:], m.NewMinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.NewMinaPublicKey))) + i-- + dAtA[i] = 0x1a + } + if len(m.PrevMinaPublicKey) > 0 { + i -= len(m.PrevMinaPublicKey) + copy(dAtA[i:], m.PrevMinaPublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PrevMinaPublicKey))) + i-- dAtA[i] = 0x12 } if len(m.Creator) > 0 { @@ -529,7 +797,7 @@ func (m *MsgRegisterKeys) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgRegisterKeysResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdateKeysResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -539,12 +807,12 @@ func (m *MsgRegisterKeysResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRegisterKeysResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdateKeysResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRegisterKeysResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdateKeysResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -597,6 +865,14 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.CosmosPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MinaPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } l = len(m.CosmosSignature) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -605,18 +881,54 @@ func (m *MsgRegisterKeys) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.CosmosPublicKey) + if m.ActorType != 0 { + n += 1 + sovTx(uint64(m.ActorType)) + } + return n +} + +func (m *MsgRegisterKeysResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateKeys) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.MinaPublicKey) + l = len(m.PrevMinaPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NewMinaPublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CosmosSignature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.NewMinaSignature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.ActorType != 0 { + n += 1 + sovTx(uint64(m.ActorType)) + } return n } -func (m *MsgRegisterKeysResponse) Size() (n int) { +func (m *MsgUpdateKeysResponse) Size() (n int) { if m == nil { return 0 } @@ -859,9 +1171,9 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -871,28 +1183,251 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosSignature = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: + m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosPublicKey == nil { + m.CosmosPublicKey = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.MinaPublicKey == nil { + m.MinaPublicKey = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosSignature = append(m.CosmosSignature[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosSignature == nil { + m.CosmosSignature = []byte{} + } + iNdEx = postIndex + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MinaSignature", wireType) } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinaSignature = append(m.MinaSignature[:0], dAtA[iNdEx:postIndex]...) + if m.MinaSignature == nil { + m.MinaSignature = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ActorType", wireType) + } + m.ActorType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ActorType |= ActorType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterKeysResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRegisterKeysResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterKeysResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateKeys) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateKeys: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateKeys: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { @@ -919,11 +1454,79 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaSignature = string(dAtA[iNdEx:postIndex]) + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PrevMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PrevMinaPublicKey = append(m.PrevMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PrevMinaPublicKey == nil { + m.PrevMinaPublicKey = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewMinaPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NewMinaPublicKey = append(m.NewMinaPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.NewMinaPublicKey == nil { + m.NewMinaPublicKey = []byte{} + } iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CosmosPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CosmosSignature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -950,14 +1553,14 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CosmosPublicKey = append(m.CosmosPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.CosmosPublicKey == nil { - m.CosmosPublicKey = []byte{} + m.CosmosSignature = append(m.CosmosSignature[:0], dAtA[iNdEx:postIndex]...) + if m.CosmosSignature == nil { + m.CosmosSignature = []byte{} } iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinaPublicKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NewMinaSignature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -984,11 +1587,30 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinaPublicKey = append(m.MinaPublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.MinaPublicKey == nil { - m.MinaPublicKey = []byte{} + m.NewMinaSignature = append(m.NewMinaSignature[:0], dAtA[iNdEx:postIndex]...) + if m.NewMinaSignature == nil { + m.NewMinaSignature = []byte{} } iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ActorType", wireType) + } + m.ActorType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ActorType |= ActorType(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1010,7 +1632,7 @@ func (m *MsgRegisterKeys) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgRegisterKeysResponse) Unmarshal(dAtA []byte) error { +func (m *MsgUpdateKeysResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1033,10 +1655,10 @@ func (m *MsgRegisterKeysResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgRegisterKeysResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgUpdateKeysResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgRegisterKeysResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgUpdateKeysResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/x/keyregistry/types/keypairs.go b/x/keyregistry/types/user_public_key_pairs.go similarity index 54% rename from x/keyregistry/types/keypairs.go rename to x/keyregistry/types/user_public_key_pairs.go index f3c372dd..25ffea70 100644 --- a/x/keyregistry/types/keypairs.go +++ b/x/keyregistry/types/user_public_key_pairs.go @@ -2,20 +2,23 @@ package types import ( "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/node101-io/mina-signer-go/keys" ) -func NewKeyPairs() []*KeyPair { - return []*KeyPair{} +func NewUserPublicKeyPairs() []*UserPublicKeyPair { + return []*UserPublicKeyPair{} } -func DefaultKeyPairs() []*KeyPair { - return NewKeyPairs() + +func DefaultUserPublicKeyPair() []*UserPublicKeyPair { + return NewUserPublicKeyPairs() } -func ValidateKeyPair(k KeyPair) error { +// Validate validates the set of params. +// TODO: make strict validate once mina-signer-go is complete +func (k UserPublicKeyPair) Validate() error { if len(k.CosmosKey) != secp256k1.PubKeySize { - return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be compressed (33 bytes)") + return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be secp256k1 (33 bytes)") } if len(k.MinaKey) != keys.PublicKeyTotalByteSize { @@ -23,8 +26,3 @@ func ValidateKeyPair(k KeyPair) error { } return nil } - -// Validate validates the set of params. -func (k KeyPair) Validate() error { - return ValidateKeyPair(k) -} diff --git a/x/keyregistry/types/validator_public_key_pairs.go b/x/keyregistry/types/validator_public_key_pairs.go new file mode 100644 index 00000000..b4c8b768 --- /dev/null +++ b/x/keyregistry/types/validator_public_key_pairs.go @@ -0,0 +1,29 @@ +package types + +import ( + "crypto/ed25519" + + "cosmossdk.io/errors" + "github.com/node101-io/mina-signer-go/keys" +) + +func NewValidatorPublicKeyPairs() []*ValidatorPublicKeyPair { + return []*ValidatorPublicKeyPair{} +} + +func DefaultValidatorPublicKeyPair() []*ValidatorPublicKeyPair { + return NewValidatorPublicKeyPairs() +} + +// Validate validates the set of params. +// TODO: make strict validate once mina-signer-go is complete +func (k ValidatorPublicKeyPair) Validate() error { + if len(k.CosmosKey) != ed25519.PublicKeySize { + return errors.Wrap(ErrInvalidPublicKey, "cosmos public key must be ed25519 (32 bytes)") + } + + if len(k.MinaKey) != keys.PublicKeyTotalByteSize { + return errors.Wrap(ErrInvalidPublicKey, "mina public key must be compressed (33 bytes)") + } + return nil +} diff --git a/x/votepersistence/keeper/genesis.go b/x/votepersistence/keeper/genesis.go new file mode 100644 index 00000000..5b53e605 --- /dev/null +++ b/x/votepersistence/keeper/genesis.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error { + return k.Params.Set(ctx, genState.Params) +} + +// ExportGenesis returns the module's exported genesis. +func (k Keeper) ExportGenesis(ctx context.Context) (*types.GenesisState, error) { + var err error + + genesis := types.DefaultGenesis() + genesis.Params, err = k.Params.Get(ctx) + if err != nil { + return nil, err + } + + return genesis, nil +} diff --git a/x/votepersistence/keeper/genesis_test.go b/x/votepersistence/keeper/genesis_test.go new file mode 100644 index 00000000..ecfbbac5 --- /dev/null +++ b/x/votepersistence/keeper/genesis_test.go @@ -0,0 +1,24 @@ +package keeper_test + +import ( + "testing" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + + "github.com/stretchr/testify/require" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + } + + f := initFixture(t) + err := f.keeper.InitGenesis(f.ctx, genesisState) + require.NoError(t, err) + got, err := f.keeper.ExportGenesis(f.ctx) + require.NoError(t, err) + require.NotNil(t, got) + + require.EqualExportedValues(t, genesisState.Params, got.Params) +} diff --git a/x/votepersistence/keeper/keeper.go b/x/votepersistence/keeper/keeper.go new file mode 100644 index 00000000..3cf7666b --- /dev/null +++ b/x/votepersistence/keeper/keeper.go @@ -0,0 +1,98 @@ +package keeper + +import ( + "context" + "fmt" + + "cosmossdk.io/collections" + "cosmossdk.io/core/address" + corestore "cosmossdk.io/core/store" + "github.com/cosmos/cosmos-sdk/codec" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +const VoteStorageMapName string = "vote_storage" + +type Keeper struct { + storeService corestore.KVStoreService + cdc codec.Codec + addressCodec address.Codec + stakingKeeper types.StakingKeeper + keyregistryKeeper types.KeyregistryKeeper + // Address capable of executing a MsgUpdateParams message. + // Typically, this should be the x/gov module account. + authority []byte + + voteStorage collections.Map[collections.Pair[int64, []byte], []byte] + + Schema collections.Schema + Params collections.Item[types.Params] +} + +func NewKeeper( + storeService corestore.KVStoreService, + cdc codec.Codec, + addressCodec address.Codec, + stakingKeeper types.StakingKeeper, + keyregistryKeeper types.KeyregistryKeeper, + authority []byte, + +) Keeper { + if _, err := addressCodec.BytesToString(authority); err != nil { + panic(fmt.Sprintf("invalid authority address %s: %s", authority, err)) + } + + sb := collections.NewSchemaBuilder(storeService) + + k := Keeper{ + storeService: storeService, + cdc: cdc, + addressCodec: addressCodec, + stakingKeeper: stakingKeeper, + keyregistryKeeper: keyregistryKeeper, + authority: authority, + + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + + voteStorage: collections.NewMap(sb, + types.VoteStorageMapPrefix, + VoteStorageMapName, + collections.PairKeyCodec(collections.Int64Key, collections.BytesKey), + collections.BytesValue), + } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + + return k +} + +// GetAuthority returns the module's authority. +func (k Keeper) GetAuthority() []byte { + return k.authority +} + +func (k Keeper) SetVote(ctx context.Context, blockHeight int64, minaAddress, voteExtensions []byte) error { + return k.voteStorage.Set(ctx, collections.Join(blockHeight, minaAddress), voteExtensions) +} +func (k Keeper) GetVote(ctx context.Context, blockHeight int64, minaAddress []byte) ([]byte, error) { + return k.voteStorage.Get(ctx, collections.Join(blockHeight, minaAddress)) +} +func (k Keeper) RemoveVote(ctx context.Context, blockHeight int64, minaAddress []byte) error { + return k.voteStorage.Remove(ctx, collections.Join(blockHeight, minaAddress)) +} + +func (k Keeper) Clear(ctx context.Context) error { + return k.voteStorage.Clear(ctx, nil) +} + +func (k Keeper) VoteExists(ctx context.Context, blockHeight int64, minaAddress []byte) (bool, error) { + return k.voteStorage.Has(ctx, collections.Join(blockHeight, minaAddress)) +} +func (k Keeper) IterateVotes(ctx context.Context) (collections.Iterator[collections.Pair[int64, []byte], []byte], error) { + return k.voteStorage.Iterate(ctx, nil) +} diff --git a/x/votepersistence/keeper/keeper_test.go b/x/votepersistence/keeper/keeper_test.go new file mode 100644 index 00000000..d892a036 --- /dev/null +++ b/x/votepersistence/keeper/keeper_test.go @@ -0,0 +1,58 @@ +package keeper_test + +import ( + "context" + "testing" + + "cosmossdk.io/core/address" + storetypes "cosmossdk.io/store/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + module "github.com/node101-io/pulsar-chain/x/votepersistence/module" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +type fixture struct { + ctx context.Context + keeper keeper.Keeper + addressCodec address.Codec +} + +func initFixture(t *testing.T) *fixture { + t.Helper() + + encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModule{}) + addressCodec := addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) + + storeService := runtime.NewKVStoreService(storeKey) + ctx := testutil.DefaultContextWithDB(t, storeKey, storetypes.NewTransientStoreKey("transient_test")).Ctx + + authority := authtypes.NewModuleAddress(types.GovModuleName) + + k := keeper.NewKeeper( + storeService, + encCfg.Codec, + addressCodec, + nil, + nil, + authority, + ) + + // Initialize params + if err := k.Params.Set(ctx, types.DefaultParams()); err != nil { + t.Fatalf("failed to set params: %v", err) + } + + return &fixture{ + ctx: ctx, + keeper: k, + addressCodec: addressCodec, + } +} diff --git a/x/votepersistence/keeper/msg_server.go b/x/votepersistence/keeper/msg_server.go new file mode 100644 index 00000000..5e538c2f --- /dev/null +++ b/x/votepersistence/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/votepersistence/keeper/msg_update_params.go b/x/votepersistence/keeper/msg_update_params.go new file mode 100644 index 00000000..aef1db35 --- /dev/null +++ b/x/votepersistence/keeper/msg_update_params.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "bytes" + "context" + + errorsmod "cosmossdk.io/errors" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + authority, err := k.addressCodec.StringToBytes(req.Authority) + if err != nil { + return nil, errorsmod.Wrap(err, "invalid authority address") + } + + if !bytes.Equal(k.GetAuthority(), authority) { + expectedAuthorityStr, _ := k.addressCodec.BytesToString(k.GetAuthority()) + return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", expectedAuthorityStr, req.Authority) + } + + if err := req.Params.Validate(); err != nil { + return nil, err + } + + if err := k.Params.Set(ctx, req.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/votepersistence/keeper/msg_update_params_test.go b/x/votepersistence/keeper/msg_update_params_test.go new file mode 100644 index 00000000..c9818916 --- /dev/null +++ b/x/votepersistence/keeper/msg_update_params_test.go @@ -0,0 +1,68 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func TestMsgUpdateParams(t *testing.T) { + f := initFixture(t) + ms := keeper.NewMsgServerImpl(f.keeper) + + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + authorityStr, err := f.addressCodec.BytesToString(f.keeper.GetAuthority()) + require.NoError(t, err) + + // default params + testCases := []struct { + name string + input *types.MsgUpdateParams + expErr bool + expErrMsg string + }{ + { + name: "invalid authority", + input: &types.MsgUpdateParams{ + Authority: "invalid", + Params: params, + }, + expErr: true, + expErrMsg: "invalid authority", + }, + { + name: "send enabled param", + input: &types.MsgUpdateParams{ + Authority: authorityStr, + Params: types.Params{}, + }, + expErr: false, + }, + { + name: "all good", + input: &types.MsgUpdateParams{ + Authority: authorityStr, + Params: params, + }, + expErr: false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + _, err := ms.UpdateParams(f.ctx, tc.input) + + if tc.expErr { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expErrMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/votepersistence/keeper/query.go b/x/votepersistence/keeper/query.go new file mode 100644 index 00000000..58ad2a9e --- /dev/null +++ b/x/votepersistence/keeper/query.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var _ types.QueryServer = queryServer{} + +// NewQueryServerImpl returns an implementation of the QueryServer interface +// for the provided Keeper. +func NewQueryServerImpl(k Keeper) types.QueryServer { + return queryServer{k} +} + +type queryServer struct { + k Keeper +} diff --git a/x/votepersistence/keeper/query_params.go b/x/votepersistence/keeper/query_params.go new file mode 100644 index 00000000..3c86597c --- /dev/null +++ b/x/votepersistence/keeper/query_params.go @@ -0,0 +1,26 @@ +package keeper + +import ( + "context" + "errors" + + "cosmossdk.io/collections" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func (q queryServer) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + params, err := q.k.Params.Get(ctx) + if err != nil && !errors.Is(err, collections.ErrNotFound) { + return nil, status.Error(codes.Internal, "internal error") + } + + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/votepersistence/keeper/query_params_test.go b/x/votepersistence/keeper/query_params_test.go new file mode 100644 index 00000000..0df3eb53 --- /dev/null +++ b/x/votepersistence/keeper/query_params_test.go @@ -0,0 +1,22 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +func TestParamsQuery(t *testing.T) { + f := initFixture(t) + + qs := keeper.NewQueryServerImpl(f.keeper) + params := types.DefaultParams() + require.NoError(t, f.keeper.Params.Set(f.ctx, params)) + + response, err := qs.Params(f.ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) +} diff --git a/x/votepersistence/keeper/query_vote_ext_body_by_height.go b/x/votepersistence/keeper/query_vote_ext_body_by_height.go new file mode 100644 index 00000000..b8aea73d --- /dev/null +++ b/x/votepersistence/keeper/query_vote_ext_body_by_height.go @@ -0,0 +1,113 @@ +package keeper + +import ( + "context" + "math/big" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/node101-io/mina-signer-go/constants" + "github.com/node101-io/mina-signer-go/field" + "github.com/node101-io/mina-signer-go/keys" + "github.com/node101-io/mina-signer-go/poseidon" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +const ActionsReducedRoot string = "pulsar" + +func (q queryServer) VoteExtBodyByHeight(ctx context.Context, req *types.QueryVoteExtBodyByHeightRequest) (*types.VoteExtBody, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + if req.BlockHeight < 4 { + return nil, status.Error(codes.InvalidArgument, "there is no vote extension in blocks smaller than 4") + } + + sdkCtx := sdk.UnwrapSDKContext(ctx) + + if req.BlockHeight >= sdkCtx.BlockHeight() { + return nil, status.Error(codes.InvalidArgument, "no vote extensions in the requested block yet") + } + + if q.k.stakingKeeper == nil || q.k.keyregistryKeeper == nil { + return nil, status.Error(codes.Internal, "vote extension query dependencies are not configured") + } + + return q.constructVoteExtBodyByHeight(ctx, req.BlockHeight) +} + +func (q queryServer) constructVoteExtBodyByHeight(ctx context.Context, blockHeight int64) (*types.VoteExtBody, error) { + currentBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-2) + if err != nil { + return nil, err + } + + nextBlockInfo, err := q.k.stakingKeeper.GetHistoricalInfo(ctx, blockHeight-1) + if err != nil { + return nil, err + } + + nextValidatorSetHash, err := q.calculateValidatorSetRoot(ctx, nextBlockInfo.Valset) + if err != nil { + return nil, err + } + + return &types.VoteExtBody{ + NextValidatorSetHash: nextValidatorSetHash, + CurrentStateRoot: currentBlockInfo.Header.AppHash, + CurrentBlockHeight: blockHeight - 1, + ActionsReducedRoot: ActionsReducedRoot, + }, nil +} + +func (q queryServer) calculateValidatorSetRoot(ctx context.Context, validatorSet []stakingtypes.Validator) ([]byte, error) { + + poseidonHash := poseidon.CreatePoseidon(*field.Fp, constants.PoseidonParamsKimchiFp) + merkleRoot := poseidonHash.Hash([]*big.Int{big.NewInt(0)}) + + for _, validator := range validatorSet { + cosmosValidatorPubKey, err := validator.ConsPubKey() + if err != nil { + return nil, status.Error(codes.Internal, "failed to read validator consensus public key") + } + + exists, err := q.k.keyregistryKeeper.ValidatorCosmosToMinaHas(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, status.Error(codes.Internal, "failed to check validator Mina key") + } + if !exists { + return nil, status.Errorf(codes.NotFound, "validator Mina key not found for consensus public key %X", cosmosValidatorPubKey.Bytes()) + } + + minaPubKey, err := q.k.keyregistryKeeper.ValidatorGetCosmosToMina(ctx, cosmosValidatorPubKey.Bytes()) + if err != nil { + return nil, status.Error(codes.Internal, "failed to load validator Mina key") + } + + var minaPublicKey keys.PublicKey + err = minaPublicKey.Unmarshal(minaPubKey) + if err != nil { + return nil, status.Error(codes.Internal, "failed to decode validator Mina public key") + } + + input := []*big.Int{minaPublicKey.X} + if minaPublicKey.IsOdd { + input = append(input, big.NewInt(1)) + } else { + input = append(input, big.NewInt(0)) + } + input = append(input, big.NewInt(validator.ConsensusPower(sdk.DefaultPowerReduction))) + + hashOfValidator := poseidonHash.Hash(input) + merkleRoot = poseidonHash.Hash([]*big.Int{merkleRoot, hashOfValidator}) + } + + if merkleRoot == nil { + return nil, status.Error(codes.Internal, "failed to calculate next validator set hash") + } + + return merkleRoot.Bytes(), nil +} diff --git a/x/votepersistence/keeper/vote_storage_test.go b/x/votepersistence/keeper/vote_storage_test.go new file mode 100644 index 00000000..84e2f8ff --- /dev/null +++ b/x/votepersistence/keeper/vote_storage_test.go @@ -0,0 +1,144 @@ +package keeper_test + +import ( + "bytes" + "testing" + + "cosmossdk.io/collections" + "github.com/stretchr/testify/require" +) + +type voteEntry struct { + blockHeight int64 + minaAddress []byte + voteExtensions []byte +} + +func TestVoteStorageSetGetHas(t *testing.T) { + f := initFixture(t) + + blockHeight := int64(42) + minaAddress := []byte("mina-address-1") + voteExtensions := []byte("vote-extension-1") + + exists, err := f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.False(t, exists) + + err = f.keeper.SetVote(f.ctx, blockHeight, minaAddress, voteExtensions) + require.NoError(t, err) + + got, err := f.keeper.GetVote(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.Equal(t, voteExtensions, got) + + exists, err = f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.True(t, exists) +} + +func TestVoteStorageGetFailsWhenVoteMissing(t *testing.T) { + f := initFixture(t) + + _, err := f.keeper.GetVote(f.ctx, 42, []byte("missing-mina-address")) + require.ErrorIs(t, err, collections.ErrNotFound) +} + +func TestVoteStorageRemove(t *testing.T) { + f := initFixture(t) + + blockHeight := int64(42) + minaAddress := []byte("mina-address-1") + voteExtensions := []byte("vote-extension-1") + + err := f.keeper.SetVote(f.ctx, blockHeight, minaAddress, voteExtensions) + require.NoError(t, err) + + exists, err := f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.True(t, exists) + + err = f.keeper.RemoveVote(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + + exists, err = f.keeper.VoteExists(f.ctx, blockHeight, minaAddress) + require.NoError(t, err) + require.False(t, exists) + + _, err = f.keeper.GetVote(f.ctx, blockHeight, minaAddress) + require.ErrorIs(t, err, collections.ErrNotFound) +} + +func TestVoteStorageRemoveVotes(t *testing.T) { + f := initFixture(t) + + entries := []voteEntry{ + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + {blockHeight: 3, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + {blockHeight: 8, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + } + + for _, entry := range entries { + err := f.keeper.SetVote(f.ctx, entry.blockHeight, entry.minaAddress, entry.voteExtensions) + require.NoError(t, err) + } + + err := f.keeper.Clear(f.ctx) + require.NoError(t, err) + + for _, entry := range entries { + exists, err := f.keeper.VoteExists(f.ctx, entry.blockHeight, entry.minaAddress) + require.NoError(t, err) + require.False(t, exists) + } + + iter, err := f.keeper.IterateVotes(f.ctx) + require.NoError(t, err) + defer iter.Close() + + require.False(t, iter.Valid()) +} + +func TestVoteStorageIterate(t *testing.T) { + f := initFixture(t) + + entries := []voteEntry{ + {blockHeight: 8, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + {blockHeight: 3, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + } + + for _, entry := range entries { + err := f.keeper.SetVote(f.ctx, entry.blockHeight, entry.minaAddress, entry.voteExtensions) + require.NoError(t, err) + } + + iter, err := f.keeper.IterateVotes(f.ctx) + require.NoError(t, err) + defer iter.Close() + + var got []voteEntry + for iter.Valid() { + key, err := iter.Key() + require.NoError(t, err) + + value, err := iter.Value() + require.NoError(t, err) + + got = append(got, voteEntry{ + blockHeight: key.K1(), + minaAddress: bytes.Clone(key.K2()), + voteExtensions: bytes.Clone(value), + }) + + iter.Next() + } + + expected := []voteEntry{ + {blockHeight: 3, minaAddress: []byte("mina-a"), voteExtensions: []byte("vote-a")}, + {blockHeight: 3, minaAddress: []byte("mina-c"), voteExtensions: []byte("vote-c")}, + {blockHeight: 8, minaAddress: []byte("mina-b"), voteExtensions: []byte("vote-b")}, + } + + require.Equal(t, expected, got) +} diff --git a/x/votepersistence/module/autocli.go b/x/votepersistence/module/autocli.go new file mode 100644 index 00000000..41ede925 --- /dev/null +++ b/x/votepersistence/module/autocli.go @@ -0,0 +1,42 @@ +package votepersistence + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: types.Query_serviceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Shows the parameters of the module", + }, + { + RpcMethod: "VoteExtBodyByHeight", + Use: "vote-ext-body-by-height [block-height]", + Short: "Query vote-ext-body-by-height", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "block_height"}}, + }, + + // this line is used by ignite scaffolding # autocli/query + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: types.Msg_serviceDesc.ServiceName, + EnhanceCustomCommand: true, // only required if you want to use the custom command + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "UpdateParams", + Skip: true, // skipped because authority gated + }, + // this line is used by ignite scaffolding # autocli/tx + }, + }, + } +} diff --git a/x/votepersistence/module/depinject.go b/x/votepersistence/module/depinject.go new file mode 100644 index 00000000..4d6c1c43 --- /dev/null +++ b/x/votepersistence/module/depinject.go @@ -0,0 +1,68 @@ +package votepersistence + +import ( + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/store" + "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" + "github.com/cosmos/cosmos-sdk/codec" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + keyregistrykeeper "github.com/node101-io/pulsar-chain/x/keyregistry/keeper" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var _ depinject.OnePerModuleType = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (AppModule) IsOnePerModuleType() {} + +func init() { + appconfig.Register( + &types.Module{}, + appconfig.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Config *types.Module + StoreService store.KVStoreService + Cdc codec.Codec + AddressCodec address.Codec + + AuthKeeper types.AuthKeeper + BankKeeper types.BankKeeper + StakingKeeper *stakingkeeper.Keeper + KeyregistryKeeper keyregistrykeeper.Keeper +} + +type ModuleOutputs struct { + depinject.Out + + VotepersistenceKeeper keeper.Keeper + Module appmodule.AppModule +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + // default to governance authority if not provided + authority := authtypes.NewModuleAddress(types.GovModuleName) + if in.Config.Authority != "" { + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + } + k := keeper.NewKeeper( + in.StoreService, + in.Cdc, + in.AddressCodec, + in.StakingKeeper, + in.KeyregistryKeeper, + authority, + ) + m := NewAppModule(in.Cdc, k, in.AuthKeeper, in.BankKeeper) + + return ModuleOutputs{VotepersistenceKeeper: k, Module: m} +} diff --git a/x/votepersistence/module/module.go b/x/votepersistence/module/module.go new file mode 100644 index 00000000..b1918551 --- /dev/null +++ b/x/votepersistence/module/module.go @@ -0,0 +1,143 @@ +package votepersistence + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "google.golang.org/grpc" + + "github.com/node101-io/pulsar-chain/x/votepersistence/keeper" + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +var ( + _ module.AppModuleBasic = (*AppModule)(nil) + _ module.AppModule = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) + + _ appmodule.AppModule = (*AppModule)(nil) + _ appmodule.HasBeginBlocker = (*AppModule)(nil) + _ appmodule.HasEndBlocker = (*AppModule)(nil) +) + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + cdc codec.Codec + keeper keeper.Keeper + authKeeper types.AuthKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + authKeeper types.AuthKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + cdc: cdc, + keeper: keeper, + authKeeper: authKeeper, + bankKeeper: bankKeeper, + } +} + +// IsAppModule implements the appmodule.AppModule interface. +func (AppModule) IsAppModule() {} + +// Name returns the name of the module as a string. +func (AppModule) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec +func (AppModule) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(clientCtx.CmdContext, mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message. +func (AppModule) RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registrar) +} + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { + types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(registrar, keeper.NewQueryServerImpl(am.keeper)) + + return nil +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. +// The default GenesisState need to be defined by the module developer and is primarily used for testing. +func (am AppModule) DefaultGenesis(codec.JSONCodec) json.RawMessage { + return am.cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form. +func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := am.cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return genState.Validate() +} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, gs json.RawMessage) { + var genState types.GenesisState + // Initialize global index to index in genesis state + if err := am.cdc.UnmarshalJSON(gs, &genState); err != nil { + panic(fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)) + } + + if err := am.keeper.InitGenesis(ctx, genState); err != nil { + panic(fmt.Errorf("failed to initialize %s genesis state: %w", types.ModuleName, err)) + } +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) json.RawMessage { + genState, err := am.keeper.ExportGenesis(ctx) + if err != nil { + panic(fmt.Errorf("failed to export %s genesis state: %w", types.ModuleName, err)) + } + + bz, err := am.cdc.MarshalJSON(genState) + if err != nil { + panic(fmt.Errorf("failed to marshal %s genesis state: %w", types.ModuleName, err)) + } + + return bz +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. +// It should be incremented on each consensus-breaking change introduced by the module. +// To avoid wrong/empty versions, the initial version should be set to 1. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block. +// The begin block implementation is optional. +func (am AppModule) BeginBlock(_ context.Context) error { + return nil +} + +// EndBlock contains the logic that is automatically triggered at the end of each block. +// The end block implementation is optional. +func (am AppModule) EndBlock(_ context.Context) error { + return nil +} diff --git a/x/votepersistence/module/simulation.go b/x/votepersistence/module/simulation.go new file mode 100644 index 00000000..2c2c708f --- /dev/null +++ b/x/votepersistence/module/simulation.go @@ -0,0 +1,34 @@ +package votepersistence + +import ( + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" +) + +// GenerateGenesisState creates a randomized GenState of the module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + votepersistenceGenesis := types.GenesisState{ + Params: types.DefaultParams(), + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&votepersistenceGenesis) +} + +// RegisterStoreDecoder registers a decoder. +func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + return operations +} + +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{} +} diff --git a/x/votepersistence/types/codec.go b/x/votepersistence/types/codec.go new file mode 100644 index 00000000..56398f5e --- /dev/null +++ b/x/votepersistence/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterInterfaces(registrar codectypes.InterfaceRegistry) { + registrar.RegisterImplementations((*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) + msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc) +} diff --git a/x/votepersistence/types/errors.go b/x/votepersistence/types/errors.go new file mode 100644 index 00000000..f8af82ba --- /dev/null +++ b/x/votepersistence/types/errors.go @@ -0,0 +1,14 @@ +package types + +// DONTCOVER + +import ( + "cosmossdk.io/errors" +) + +// x/votepersistence module sentinel errors +var ( + ErrInvalidSigner = errors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrVoteExtMarkerNotFound = errors.Register(ModuleName, 1101, "vote extension marker not found") + ErrInvalidVoteExtension = errors.Register(ModuleName, 1102, "invalid vote extension") +) diff --git a/x/votepersistence/types/expected_keepers.go b/x/votepersistence/types/expected_keepers.go new file mode 100644 index 00000000..2d71efd9 --- /dev/null +++ b/x/votepersistence/types/expected_keepers.go @@ -0,0 +1,37 @@ +package types + +import ( + "context" + + "cosmossdk.io/core/address" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// AuthKeeper defines the expected interface for the Auth module. +type AuthKeeper interface { + AddressCodec() address.Codec + GetAccount(context.Context, sdk.AccAddress) sdk.AccountI // only used for simulation + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface for the Bank module. +type BankKeeper interface { + SpendableCoins(context.Context, sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here +} + +type StakingKeeper interface { + GetHistoricalInfo(context.Context, int64) (stakingtypes.HistoricalInfo, error) +} + +type KeyregistryKeeper interface { + ValidatorCosmosToMinaHas(context.Context, []byte) (bool, error) + ValidatorGetCosmosToMina(context.Context, []byte) ([]byte, error) +} + +// ParamSubspace defines the expected Subspace interface for parameters. +type ParamSubspace interface { + Get(context.Context, []byte, interface{}) + Set(context.Context, []byte, interface{}) +} diff --git a/x/votepersistence/types/genesis.go b/x/votepersistence/types/genesis.go new file mode 100644 index 00000000..9d633ecd --- /dev/null +++ b/x/votepersistence/types/genesis.go @@ -0,0 +1,14 @@ +package types + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + return gs.Params.Validate() +} diff --git a/x/votepersistence/types/genesis.pb.go b/x/votepersistence/types/genesis.pb.go new file mode 100644 index 00000000..e252c7ba --- /dev/null +++ b/x/votepersistence/types/genesis.pb.go @@ -0,0 +1,327 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the votepersistence module's genesis state. +type GenesisState struct { + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_1055d46b0af7944d, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "pulsarchain.votepersistence.v1.GenesisState") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/genesis.proto", fileDescriptor_1055d46b0af7944d) +} + +var fileDescriptor_1055d46b0af7944d = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x29, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, + 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xad, 0x87, 0xa6, 0x5a, + 0xaf, 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, + 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x54, 0x54, 0x9b, 0x80, 0xb5, 0x05, 0x89, + 0x45, 0x89, 0xb9, 0x50, 0x5b, 0x95, 0x22, 0xb9, 0x78, 0xdc, 0x21, 0xce, 0x08, 0x2e, 0x49, 0x2c, + 0x49, 0x15, 0xf2, 0xe4, 0x62, 0x83, 0xc8, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0xa9, 0xe9, + 0xe1, 0x77, 0x96, 0x5e, 0x00, 0x58, 0xb5, 0x13, 0xe7, 0x89, 0x7b, 0xf2, 0x0c, 0x2b, 0x9e, 0x6f, + 0xd0, 0x62, 0x0c, 0x82, 0x1a, 0xe0, 0x14, 0x72, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0x56, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x79, 0xf9, + 0x29, 0xa9, 0x86, 0x06, 0x86, 0xba, 0x99, 0xf9, 0xfa, 0x10, 0x9b, 0x74, 0x21, 0x0e, 0xaf, 0xc0, + 0x70, 0x7a, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0xdd, 0xc6, 0x80, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x14, 0x23, 0xa4, 0xc5, 0x5d, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/genesis_test.go b/x/votepersistence/types/genesis_test.go new file mode 100644 index 00000000..566e199b --- /dev/null +++ b/x/votepersistence/types/genesis_test.go @@ -0,0 +1,37 @@ +package types_test + +import ( + "testing" + + "github.com/node101-io/pulsar-chain/x/votepersistence/types" + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{}, + valid: true, + }, + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/votepersistence/types/keys.go b/x/votepersistence/types/keys.go new file mode 100644 index 00000000..312cef67 --- /dev/null +++ b/x/votepersistence/types/keys.go @@ -0,0 +1,21 @@ +package types + +import "cosmossdk.io/collections" + +const ( + // ModuleName defines the module name + ModuleName = "votepersistence" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // GovModuleName duplicates the gov module's name to avoid a dependency with x/gov. + // It should be synced with the gov module's name if it is ever changed. + // See: https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/x/gov/types/keys.go#L9 + GovModuleName = "gov" +) + +// ParamsKey is the prefix to retrieve all Params +var ParamsKey = collections.NewPrefix("p_votepersistence") + +var VoteStorageMapPrefix = collections.NewPrefix("vote_storage_map") diff --git a/x/votepersistence/types/module.pb.go b/x/votepersistence/types/module.pb.go new file mode 100644 index 00000000..319820ca --- /dev/null +++ b/x/votepersistence/types/module.pb.go @@ -0,0 +1,324 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/module/v1/module.proto + +package types + +import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Module is the config object for the module. +type Module struct { + // authority defines the custom module authority. + // If not set, defaults to the governance module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_c3d7f592efedc28c, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func init() { + proto.RegisterType((*Module)(nil), "pulsarchain.votepersistence.module.v1.Module") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/module/v1/module.proto", fileDescriptor_c3d7f592efedc28c) +} + +var fileDescriptor_c3d7f592efedc28c = []byte{ + // 219 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2a, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0xcf, 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2f, + 0x33, 0x84, 0xb2, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x54, 0x91, 0xf4, 0xe8, 0xa1, 0xe9, + 0xd1, 0x83, 0xaa, 0x2c, 0x33, 0x94, 0x52, 0x48, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2c, + 0x28, 0xd0, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, 0x48, 0x44, 0x35, 0x48, 0x29, 0x85, 0x8b, 0xcd, + 0x17, 0xcc, 0x17, 0x92, 0xe1, 0xe2, 0x4c, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0x94, + 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x08, 0x58, 0xd9, 0xec, 0x3a, 0x30, 0xed, 0x16, 0xa3, + 0x19, 0x97, 0x49, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x5e, 0x7e, + 0x4a, 0xaa, 0xa1, 0x81, 0xa1, 0x6e, 0x66, 0xbe, 0x3e, 0xc4, 0x39, 0xba, 0x10, 0x3f, 0x54, 0xa0, + 0xfb, 0xc2, 0x29, 0xe4, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xac, 0xc8, + 0x31, 0x4f, 0xbf, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x05, 0x63, 0x40, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x6d, 0xa9, 0xcf, 0xf9, 0x41, 0x01, 0x00, 0x00, +} + +func (m *Module) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintModule(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovModule(uint64(l)) + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/params.go b/x/votepersistence/types/params.go new file mode 100644 index 00000000..d7e00501 --- /dev/null +++ b/x/votepersistence/types/params.go @@ -0,0 +1,17 @@ +package types + +// NewParams creates a new Params instance. +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return NewParams() +} + +// Validate validates the set of params. +func (p Params) Validate() error { + + return nil +} diff --git a/x/votepersistence/types/params.pb.go b/x/votepersistence/types/params.pb.go new file mode 100644 index 00000000..3d572a3f --- /dev/null +++ b/x/votepersistence/types/params.pb.go @@ -0,0 +1,292 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_7d43c53e6aafc30b, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "pulsarchain.votepersistence.v1.Params") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/params.proto", fileDescriptor_7d43c53e6aafc30b) +} + +var fileDescriptor_7d43c53e6aafc30b = []byte{ + // 197 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2e, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, + 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xac, 0x87, 0xa6, 0x58, 0xaf, + 0xcc, 0x50, 0x4a, 0x30, 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, 0xa4, + 0xe7, 0xa7, 0xe7, 0x83, 0x99, 0xfa, 0x20, 0x16, 0x44, 0x54, 0xc9, 0x9c, 0x8b, 0x2d, 0x00, 0x6c, + 0xb0, 0x95, 0xee, 0x8b, 0x05, 0xf2, 0x8c, 0x5d, 0xcf, 0x37, 0x68, 0xa9, 0x20, 0x3b, 0xa4, 0x02, + 0xc3, 0x29, 0x10, 0xe5, 0x4e, 0x21, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, + 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, + 0x65, 0x95, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x97, 0x9f, 0x92, + 0x6a, 0x68, 0x60, 0xa8, 0x9b, 0x99, 0xaf, 0x0f, 0x31, 0x55, 0x17, 0x97, 0xb1, 0x25, 0x95, 0x05, + 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x57, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x76, 0x79, 0x99, + 0xc3, 0x0d, 0x01, 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + return true +} +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/query.pb.go b/x/votepersistence/types/query.pb.go new file mode 100644 index 00000000..8c9a2ecf --- /dev/null +++ b/x/votepersistence/types/query.pb.go @@ -0,0 +1,743 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryVoteExtBodyByHeightRequest defines the QueryVoteExtBodyByHeightRequest message. +type QueryVoteExtBodyByHeightRequest struct { + BlockHeight int64 `protobuf:"varint,1,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` +} + +func (m *QueryVoteExtBodyByHeightRequest) Reset() { *m = QueryVoteExtBodyByHeightRequest{} } +func (m *QueryVoteExtBodyByHeightRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVoteExtBodyByHeightRequest) ProtoMessage() {} +func (*QueryVoteExtBodyByHeightRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2c9976ecef977273, []int{2} +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVoteExtBodyByHeightRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVoteExtBodyByHeightRequest.Merge(m, src) +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryVoteExtBodyByHeightRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVoteExtBodyByHeightRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVoteExtBodyByHeightRequest proto.InternalMessageInfo + +func (m *QueryVoteExtBodyByHeightRequest) GetBlockHeight() int64 { + if m != nil { + return m.BlockHeight + } + return 0 +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "pulsarchain.votepersistence.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "pulsarchain.votepersistence.v1.QueryParamsResponse") + proto.RegisterType((*QueryVoteExtBodyByHeightRequest)(nil), "pulsarchain.votepersistence.v1.QueryVoteExtBodyByHeightRequest") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/query.proto", fileDescriptor_2c9976ecef977273) +} + +var fileDescriptor_2c9976ecef977273 = []byte{ + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcf, 0x6a, 0x13, 0x41, + 0x18, 0xcf, 0x58, 0x0c, 0x38, 0xf5, 0xe2, 0xb4, 0x07, 0x09, 0xb2, 0xd5, 0x3d, 0x88, 0xa4, 0x74, + 0xc7, 0xdd, 0x7a, 0xea, 0x45, 0x08, 0x0a, 0x7a, 0xd3, 0x50, 0x3c, 0xf4, 0x12, 0x67, 0x37, 0x1f, + 0x9b, 0xc1, 0x64, 0xbe, 0xe9, 0xce, 0x64, 0xc9, 0x22, 0x5e, 0x7c, 0x02, 0xc1, 0x93, 0x6f, 0xe0, + 0x45, 0xf0, 0x31, 0x7a, 0x2c, 0x78, 0xf1, 0xa4, 0x92, 0x08, 0xbe, 0x86, 0x64, 0x66, 0x85, 0xd4, + 0x5a, 0xb7, 0xb9, 0x2c, 0xc3, 0xb7, 0xbf, 0xbf, 0xf3, 0x0d, 0xed, 0xea, 0xe9, 0xd8, 0x88, 0x22, + 0x1b, 0x09, 0xa9, 0x78, 0x89, 0x16, 0x34, 0x14, 0x46, 0x1a, 0x0b, 0x2a, 0x03, 0x5e, 0xc6, 0xfc, + 0x78, 0x0a, 0x45, 0x15, 0xe9, 0x02, 0x2d, 0xb2, 0x60, 0x05, 0x1b, 0xfd, 0x85, 0x8d, 0xca, 0xb8, + 0x73, 0x43, 0x4c, 0xa4, 0x42, 0xee, 0xbe, 0x9e, 0xd2, 0xe9, 0x66, 0x68, 0x26, 0x68, 0x78, 0x2a, + 0x0c, 0x78, 0x2d, 0x5e, 0xc6, 0x29, 0x58, 0x11, 0x73, 0x2d, 0x72, 0xa9, 0x84, 0x95, 0xa8, 0x6a, + 0xec, 0x76, 0x8e, 0x39, 0xba, 0x23, 0x5f, 0x9e, 0xea, 0xe9, 0xad, 0x1c, 0x31, 0x1f, 0x03, 0x17, + 0x5a, 0x72, 0xa1, 0x14, 0x5a, 0x47, 0x31, 0xf5, 0xdf, 0xdd, 0x86, 0xf8, 0x5a, 0x14, 0x62, 0xf2, + 0x07, 0x9c, 0x34, 0x80, 0x97, 0xa3, 0x01, 0xcc, 0xec, 0x20, 0xc5, 0x61, 0xdd, 0x39, 0xdc, 0xa6, + 0xec, 0xf9, 0x32, 0xf6, 0x33, 0x27, 0xd4, 0x87, 0xe3, 0x29, 0x18, 0x1b, 0xbe, 0xa4, 0x5b, 0x67, + 0xa6, 0x46, 0xa3, 0x32, 0xc0, 0x9e, 0xd2, 0xb6, 0x37, 0xbc, 0x49, 0x6e, 0x93, 0x7b, 0x9b, 0xc9, + 0xdd, 0xe8, 0xff, 0x37, 0x16, 0x79, 0x7e, 0xef, 0xda, 0xc9, 0xb7, 0x9d, 0xd6, 0xc7, 0x5f, 0x9f, + 0xbb, 0xa4, 0x5f, 0x0b, 0x84, 0x8f, 0xe8, 0x8e, 0x73, 0x78, 0x81, 0x16, 0x1e, 0xcf, 0x6c, 0x0f, + 0x87, 0x55, 0xaf, 0x7a, 0x02, 0x32, 0x1f, 0xd9, 0x3a, 0x04, 0xbb, 0x43, 0xaf, 0xa7, 0x63, 0xcc, + 0x5e, 0x0d, 0x46, 0x6e, 0xec, 0x3c, 0x37, 0xfa, 0x9b, 0x6e, 0xe6, 0x91, 0xc9, 0x87, 0x0d, 0x7a, + 0xd5, 0xc9, 0xb0, 0x4f, 0x84, 0xb6, 0xbd, 0x1b, 0x4b, 0x9a, 0x52, 0x9d, 0x2f, 0xdc, 0xd9, 0x5f, + 0x8b, 0xe3, 0xaf, 0x23, 0x3c, 0x78, 0xfb, 0xe5, 0xe7, 0xfb, 0x2b, 0x0f, 0x58, 0xc2, 0x15, 0x0e, + 0x21, 0xbe, 0x1f, 0xef, 0x49, 0xe4, 0x5e, 0x67, 0xaf, 0x61, 0x63, 0xec, 0x3b, 0xa1, 0x5b, 0xff, + 0xe8, 0xce, 0x1e, 0x5e, 0x2a, 0xc8, 0xc5, 0xb7, 0xd6, 0xd9, 0x6d, 0x12, 0x58, 0xe1, 0x86, 0x47, + 0xae, 0xc1, 0x21, 0xeb, 0xaf, 0xd3, 0xe0, 0xcc, 0x33, 0x1a, 0xa4, 0x55, 0xbd, 0x1f, 0xfe, 0x7a, + 0x75, 0x5b, 0x6f, 0x7a, 0x87, 0x27, 0xf3, 0x80, 0x9c, 0xce, 0x03, 0xf2, 0x63, 0x1e, 0x90, 0x77, + 0x8b, 0xa0, 0x75, 0xba, 0x08, 0x5a, 0x5f, 0x17, 0x41, 0xeb, 0xe8, 0x20, 0x97, 0x76, 0x34, 0x4d, + 0xa3, 0x0c, 0x27, 0x17, 0xfa, 0xce, 0xce, 0x39, 0xdb, 0x4a, 0x83, 0x49, 0xdb, 0xee, 0xd9, 0xee, + 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xaa, 0xa5, 0xd2, 0x62, 0xd8, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*VoteExtBody, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) VoteExtBodyByHeight(ctx context.Context, in *QueryVoteExtBodyByHeightRequest, opts ...grpc.CallOption) (*VoteExtBody, error) { + out := new(VoteExtBody) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Query/VoteExtBodyByHeight", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // VoteExtBodyByHeight Queries a list of VoteExtBodyByHeight items. + VoteExtBodyByHeight(context.Context, *QueryVoteExtBodyByHeightRequest) (*VoteExtBody, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) VoteExtBodyByHeight(ctx context.Context, req *QueryVoteExtBodyByHeightRequest) (*VoteExtBody, error) { + return nil, status.Errorf(codes.Unimplemented, "method VoteExtBodyByHeight not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_VoteExtBodyByHeight_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVoteExtBodyByHeightRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).VoteExtBodyByHeight(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Query/VoteExtBodyByHeight", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).VoteExtBodyByHeight(ctx, req.(*QueryVoteExtBodyByHeightRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var Query_serviceDesc = _Query_serviceDesc +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pulsarchain.votepersistence.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "VoteExtBodyByHeight", + Handler: _Query_VoteExtBodyByHeight_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pulsarchain/votepersistence/v1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryVoteExtBodyByHeightRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVoteExtBodyByHeightRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVoteExtBodyByHeightRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.BlockHeight)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryVoteExtBodyByHeightRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BlockHeight != 0 { + n += 1 + sovQuery(uint64(m.BlockHeight)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryVoteExtBodyByHeightRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVoteExtBodyByHeightRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVoteExtBodyByHeightRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeight", wireType) + } + m.BlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/query.pb.gw.go b/x/votepersistence/types/query.pb.gw.go new file mode 100644 index 00000000..dbc762c5 --- /dev/null +++ b/x/votepersistence/types/query.pb.gw.go @@ -0,0 +1,254 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_VoteExtBodyByHeight_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVoteExtBodyByHeightRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_height") + } + + protoReq.BlockHeight, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_height", err) + } + + msg, err := client.VoteExtBodyByHeight(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_VoteExtBodyByHeight_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVoteExtBodyByHeightRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["block_height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "block_height") + } + + protoReq.BlockHeight, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "block_height", err) + } + + msg, err := server.VoteExtBodyByHeight(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_VoteExtBodyByHeight_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_VoteExtBodyByHeight_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VoteExtBodyByHeight_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_VoteExtBodyByHeight_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_VoteExtBodyByHeight_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VoteExtBodyByHeight_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4}, []string{"node101-io", "pulsar-chain", "votepersistence", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_VoteExtBodyByHeight_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"node101-io", "pulsar-chain", "votepersistence", "v1", "vote_ext_body_by_height", "block_height"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_VoteExtBodyByHeight_0 = runtime.ForwardResponseMessage +) diff --git a/x/votepersistence/types/tx.pb.go b/x/votepersistence/types/tx.pb.go new file mode 100644 index 00000000..31772b17 --- /dev/null +++ b/x/votepersistence/types/tx.pb.go @@ -0,0 +1,603 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUpdateParams is the Msg/UpdateParams request type. +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the module parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_9ef0cb0ba71ad1b3, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9ef0cb0ba71ad1b3, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "pulsarchain.votepersistence.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "pulsarchain.votepersistence.v1.MsgUpdateParamsResponse") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/tx.proto", fileDescriptor_9ef0cb0ba71ad1b3) +} + +var fileDescriptor_9ef0cb0ba71ad1b3 = []byte{ + // 369 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x28, 0xcd, 0x29, + 0x4e, 0x2c, 0x4a, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0xcb, 0x2f, 0x49, 0x2d, 0x48, 0x2d, 0x2a, + 0xce, 0x2c, 0x2e, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x52, 0xa8, 0x87, 0xa6, 0x50, 0xaf, 0xcc, 0x50, 0x4a, 0x30, + 0x31, 0x37, 0x33, 0x2f, 0x5f, 0x1f, 0x4c, 0x42, 0xb4, 0x48, 0x89, 0x27, 0xe7, 0x17, 0xe7, 0xe6, + 0x17, 0xeb, 0xe7, 0x16, 0xa7, 0x83, 0x8c, 0xca, 0x2d, 0x4e, 0x87, 0x4a, 0x48, 0x42, 0x24, 0xe2, + 0xc1, 0x3c, 0x7d, 0x08, 0x07, 0x2a, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x11, 0x07, 0xb1, 0xa0, + 0xa2, 0xda, 0x04, 0x5c, 0x59, 0x90, 0x58, 0x94, 0x98, 0x0b, 0x35, 0x42, 0xe9, 0x1a, 0x23, 0x17, + 0xbf, 0x6f, 0x71, 0x7a, 0x68, 0x41, 0x4a, 0x62, 0x49, 0x6a, 0x00, 0x58, 0x46, 0xc8, 0x8c, 0x8b, + 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, 0xd3, + 0x49, 0xe2, 0xd2, 0x16, 0x5d, 0x11, 0xa8, 0xdd, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0xc1, + 0x25, 0x45, 0x99, 0x79, 0xe9, 0x41, 0x08, 0xa5, 0x42, 0x9e, 0x5c, 0x6c, 0x10, 0xb3, 0x25, 0x98, + 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xd4, 0xf4, 0xf0, 0x07, 0x83, 0x1e, 0xc4, 0x3e, 0x27, 0xce, 0x13, + 0xf7, 0xe4, 0x19, 0x56, 0x3c, 0xdf, 0xa0, 0xc5, 0x18, 0x04, 0x35, 0xc0, 0xca, 0xa1, 0xe9, 0xf9, + 0x06, 0x2d, 0x84, 0xd1, 0x5d, 0xcf, 0x37, 0x68, 0xe9, 0x22, 0x7b, 0xab, 0x02, 0xc3, 0x63, 0x68, + 0x9e, 0x50, 0x92, 0xe4, 0x12, 0x47, 0x13, 0x0a, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, + 0x6a, 0x63, 0xe4, 0x62, 0xf6, 0x2d, 0x4e, 0x17, 0xaa, 0xe0, 0xe2, 0x41, 0xf1, 0xb7, 0x3e, 0x21, + 0xf7, 0xa2, 0x19, 0x28, 0x65, 0x4e, 0xa2, 0x06, 0x98, 0x0b, 0xa4, 0x58, 0x1b, 0x40, 0xbe, 0x75, + 0x0a, 0x39, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, + 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xab, 0xf4, 0xcc, 0x92, + 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xfc, 0x94, 0x54, 0x43, 0x03, 0x43, 0xdd, + 0xcc, 0x7c, 0x7d, 0x88, 0x75, 0xba, 0xb8, 0xc2, 0xa0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, + 0x1c, 0xb3, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xde, 0x4f, 0x5a, 0xaa, 0xae, 0x02, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/pulsarchain.votepersistence.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // UpdateParams defines a (governance) operation for updating the module + // parameters. The authority defaults to the x/gov module account. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/pulsarchain.votepersistence.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pulsarchain.votepersistence.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pulsarchain/votepersistence/v1/tx.proto", +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/votepersistence/types/types.go b/x/votepersistence/types/types.go new file mode 100644 index 00000000..ab1254f4 --- /dev/null +++ b/x/votepersistence/types/types.go @@ -0,0 +1 @@ +package types diff --git a/x/votepersistence/types/vote_ext_body.pb.go b/x/votepersistence/types/vote_ext_body.pb.go new file mode 100644 index 00000000..918fd218 --- /dev/null +++ b/x/votepersistence/types/vote_ext_body.pb.go @@ -0,0 +1,467 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pulsarchain/votepersistence/v1/vote_ext_body.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// VoteExtBody defines the VoteExtBody message. +type VoteExtBody struct { + NextValidatorSetHash []byte `protobuf:"bytes,1,opt,name=next_validator_set_hash,json=nextValidatorSetHash,proto3" json:"next_validator_set_hash,omitempty"` + CurrentStateRoot []byte `protobuf:"bytes,2,opt,name=current_state_root,json=currentStateRoot,proto3" json:"current_state_root,omitempty"` + CurrentBlockHeight int64 `protobuf:"varint,3,opt,name=current_block_height,json=currentBlockHeight,proto3" json:"current_block_height,omitempty"` + ActionsReducedRoot string `protobuf:"bytes,4,opt,name=actions_reduced_root,json=actionsReducedRoot,proto3" json:"actions_reduced_root,omitempty"` +} + +func (m *VoteExtBody) Reset() { *m = VoteExtBody{} } +func (m *VoteExtBody) String() string { return proto.CompactTextString(m) } +func (*VoteExtBody) ProtoMessage() {} +func (*VoteExtBody) Descriptor() ([]byte, []int) { + return fileDescriptor_fc9a8a749a7bb705, []int{0} +} +func (m *VoteExtBody) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *VoteExtBody) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_VoteExtBody.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *VoteExtBody) XXX_Merge(src proto.Message) { + xxx_messageInfo_VoteExtBody.Merge(m, src) +} +func (m *VoteExtBody) XXX_Size() int { + return m.Size() +} +func (m *VoteExtBody) XXX_DiscardUnknown() { + xxx_messageInfo_VoteExtBody.DiscardUnknown(m) +} + +var xxx_messageInfo_VoteExtBody proto.InternalMessageInfo + +func (m *VoteExtBody) GetNextValidatorSetHash() []byte { + if m != nil { + return m.NextValidatorSetHash + } + return nil +} + +func (m *VoteExtBody) GetCurrentStateRoot() []byte { + if m != nil { + return m.CurrentStateRoot + } + return nil +} + +func (m *VoteExtBody) GetCurrentBlockHeight() int64 { + if m != nil { + return m.CurrentBlockHeight + } + return 0 +} + +func (m *VoteExtBody) GetActionsReducedRoot() string { + if m != nil { + return m.ActionsReducedRoot + } + return "" +} + +func init() { + proto.RegisterType((*VoteExtBody)(nil), "pulsarchain.votepersistence.v1.VoteExtBody") +} + +func init() { + proto.RegisterFile("pulsarchain/votepersistence/v1/vote_ext_body.proto", fileDescriptor_fc9a8a749a7bb705) +} + +var fileDescriptor_fc9a8a749a7bb705 = []byte{ + // 298 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0x31, 0x4b, 0xc3, 0x40, + 0x14, 0x07, 0xf0, 0x9e, 0x15, 0xc1, 0xe8, 0x20, 0xa1, 0x60, 0xa7, 0xa3, 0x38, 0x75, 0xb0, 0x49, + 0xa3, 0xb8, 0x38, 0x16, 0x84, 0xce, 0xa9, 0x74, 0x70, 0x39, 0x2e, 0x97, 0x47, 0xef, 0xb0, 0xe6, + 0x85, 0xbb, 0x97, 0xd0, 0x7e, 0x0b, 0x3f, 0x96, 0x63, 0x27, 0x71, 0x94, 0xf6, 0x8b, 0xc8, 0x25, + 0x0d, 0x88, 0xae, 0xf7, 0xbb, 0xff, 0xfb, 0xc3, 0x3f, 0xb8, 0x2b, 0xab, 0xb5, 0x93, 0x56, 0x69, + 0x69, 0x8a, 0xb8, 0x46, 0x82, 0x12, 0xac, 0x33, 0x8e, 0xa0, 0x50, 0x10, 0xd7, 0x49, 0xf3, 0x24, + 0x60, 0x43, 0x22, 0xc3, 0x7c, 0x1b, 0x95, 0x16, 0x09, 0x43, 0xfe, 0x2b, 0x13, 0xfd, 0xc9, 0x44, + 0x75, 0x72, 0xf3, 0xc9, 0x82, 0x8b, 0x25, 0x12, 0x3c, 0x6d, 0x68, 0x86, 0xf9, 0x36, 0x7c, 0x08, + 0xae, 0x0b, 0x7f, 0xa2, 0x96, 0x6b, 0x93, 0x4b, 0x42, 0x2b, 0x1c, 0x90, 0xd0, 0xd2, 0xe9, 0x21, + 0x1b, 0xb1, 0xf1, 0x65, 0x3a, 0xf0, 0xbc, 0xec, 0x74, 0x01, 0x34, 0x97, 0x4e, 0x87, 0xb7, 0x41, + 0xa8, 0x2a, 0x6b, 0xa1, 0x20, 0xe1, 0x48, 0x12, 0x08, 0x8b, 0x48, 0xc3, 0x93, 0x26, 0x71, 0x75, + 0x94, 0x85, 0x87, 0x14, 0x91, 0xc2, 0x69, 0x30, 0xe8, 0x7e, 0x67, 0x6b, 0x54, 0xaf, 0x42, 0x83, + 0x59, 0x69, 0x1a, 0xf6, 0x47, 0x6c, 0xdc, 0x4f, 0xbb, 0x4b, 0x33, 0x4f, 0xf3, 0x46, 0x7c, 0x42, + 0x2a, 0x32, 0x58, 0x38, 0x61, 0x21, 0xaf, 0x14, 0xe4, 0x6d, 0xc3, 0xe9, 0x88, 0x8d, 0xcf, 0xd3, + 0xf0, 0x68, 0x69, 0x4b, 0xbe, 0x63, 0xf6, 0xfc, 0xb1, 0xe7, 0x6c, 0xb7, 0xe7, 0xec, 0x7b, 0xcf, + 0xd9, 0xfb, 0x81, 0xf7, 0x76, 0x07, 0xde, 0xfb, 0x3a, 0xf0, 0xde, 0xcb, 0xe3, 0xca, 0x90, 0xae, + 0xb2, 0x48, 0xe1, 0x5b, 0x5c, 0x60, 0x0e, 0xc9, 0x34, 0x99, 0x18, 0x8c, 0xdb, 0xa1, 0x26, 0xed, + 0xba, 0x9b, 0x7f, 0xfb, 0xd2, 0xb6, 0x04, 0x97, 0x9d, 0x35, 0xab, 0xde, 0xff, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xbd, 0xc8, 0x3f, 0x5d, 0x8b, 0x01, 0x00, 0x00, +} + +func (m *VoteExtBody) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *VoteExtBody) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *VoteExtBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ActionsReducedRoot) > 0 { + i -= len(m.ActionsReducedRoot) + copy(dAtA[i:], m.ActionsReducedRoot) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.ActionsReducedRoot))) + i-- + dAtA[i] = 0x22 + } + if m.CurrentBlockHeight != 0 { + i = encodeVarintVoteExtBody(dAtA, i, uint64(m.CurrentBlockHeight)) + i-- + dAtA[i] = 0x18 + } + if len(m.CurrentStateRoot) > 0 { + i -= len(m.CurrentStateRoot) + copy(dAtA[i:], m.CurrentStateRoot) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.CurrentStateRoot))) + i-- + dAtA[i] = 0x12 + } + if len(m.NextValidatorSetHash) > 0 { + i -= len(m.NextValidatorSetHash) + copy(dAtA[i:], m.NextValidatorSetHash) + i = encodeVarintVoteExtBody(dAtA, i, uint64(len(m.NextValidatorSetHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintVoteExtBody(dAtA []byte, offset int, v uint64) int { + offset -= sovVoteExtBody(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *VoteExtBody) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.NextValidatorSetHash) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + l = len(m.CurrentStateRoot) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + if m.CurrentBlockHeight != 0 { + n += 1 + sovVoteExtBody(uint64(m.CurrentBlockHeight)) + } + l = len(m.ActionsReducedRoot) + if l > 0 { + n += 1 + l + sovVoteExtBody(uint64(l)) + } + return n +} + +func sovVoteExtBody(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozVoteExtBody(x uint64) (n int) { + return sovVoteExtBody(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *VoteExtBody) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: VoteExtBody: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: VoteExtBody: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorSetHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NextValidatorSetHash = append(m.NextValidatorSetHash[:0], dAtA[iNdEx:postIndex]...) + if m.NextValidatorSetHash == nil { + m.NextValidatorSetHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentStateRoot", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentStateRoot = append(m.CurrentStateRoot[:0], dAtA[iNdEx:postIndex]...) + if m.CurrentStateRoot == nil { + m.CurrentStateRoot = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBlockHeight", wireType) + } + m.CurrentBlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentBlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ActionsReducedRoot", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthVoteExtBody + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthVoteExtBody + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ActionsReducedRoot = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipVoteExtBody(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthVoteExtBody + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipVoteExtBody(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowVoteExtBody + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthVoteExtBody + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupVoteExtBody + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthVoteExtBody + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthVoteExtBody = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowVoteExtBody = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupVoteExtBody = fmt.Errorf("proto: unexpected end of group") +)