From cb3657dd4355c335c2b569dc2e087c91bbc5cf3d Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 9 Sep 2024 18:18:58 -0400 Subject: [PATCH 1/7] chore: lint chore: regenerate proto and lint proto chore: lint --- x/tally/types/filters.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/tally/types/filters.go b/x/tally/types/filters.go index ba4412f4..d68d04c3 100644 --- a/x/tally/types/filters.go +++ b/x/tally/types/filters.go @@ -5,8 +5,6 @@ import ( "encoding/binary" "slices" - "slices" - "golang.org/x/exp/constraints" ) From 053978130f9149247ee060ecd86b84804d3883fe Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 9 Sep 2024 18:57:36 -0400 Subject: [PATCH 2/7] fix: fixing import disappearance due to linting --- x/tally/types/filters.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/tally/types/filters.go b/x/tally/types/filters.go index d68d04c3..ba4412f4 100644 --- a/x/tally/types/filters.go +++ b/x/tally/types/filters.go @@ -5,6 +5,8 @@ import ( "encoding/binary" "slices" + "slices" + "golang.org/x/exp/constraints" ) From 32c6b72406f9553026d00c319abae36e42da68fe Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 23 Sep 2024 15:59:04 -0400 Subject: [PATCH 3/7] refactor: replace vrf signer with seda keys util --- app/utils/seda_keys.go | 156 +++++++++++++++++++++++++ app/utils/vrf_key.go | 240 -------------------------------------- x/pubkey/client/cli/tx.go | 121 +------------------ 3 files changed, 159 insertions(+), 358 deletions(-) create mode 100644 app/utils/seda_keys.go delete mode 100644 app/utils/vrf_key.go diff --git a/app/utils/seda_keys.go b/app/utils/seda_keys.go new file mode 100644 index 00000000..ff8fb82b --- /dev/null +++ b/app/utils/seda_keys.go @@ -0,0 +1,156 @@ +package utils + +import ( + "fmt" + "os" + "path/filepath" + + cmtcrypto "github.com/cometbft/cometbft/crypto" + "github.com/cometbft/cometbft/crypto/secp256k1" + cmtjson "github.com/cometbft/cometbft/libs/json" + cmtos "github.com/cometbft/cometbft/libs/os" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + + pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" +) + +const SEDAKeyFileName = "seda_keys.json" + +var sedaKeyGenerators = []privKeyGenerator{ + func() cmtcrypto.PrivKey { return secp256k1.GenPrivKey() }, // index 0 - secp256k1 +} + +type ( + privKeyGenerator func() cmtcrypto.PrivKey + + indexedPrivKey struct { + Index uint32 `json:"index"` + PrivKey cmtcrypto.PrivKey `json:"priv_key"` + } +) + +// GenerateSEDAKeys generates SEDA keys given a list of private key +// generators, saves them to the SEDA key file, and returns the resulting +// index-public key pairs. Index is assigned incrementally in the order +// of the given private key generators. The key file is stored in the +// directory given by dirPath. +func GenerateSEDAKeys(dirPath string) ([]pubkeytypes.IndexedPubKey, error) { + keys := make([]indexedPrivKey, len(sedaKeyGenerators)) + result := make([]pubkeytypes.IndexedPubKey, len(sedaKeyGenerators)) + for i, generator := range sedaKeyGenerators { + keys[i] = indexedPrivKey{ + Index: uint32(i), + PrivKey: generator(), + } + + // Convert to SDK type for app-level use. + pubKey, err := cryptocodec.FromCmtPubKeyInterface(keys[i].PrivKey.PubKey()) + if err != nil { + return nil, err + } + pkAny, err := codectypes.NewAnyWithValue(pubKey) + if err != nil { + return nil, err + } + result[i] = pubkeytypes.IndexedPubKey{ + Index: uint32(i), + PubKey: pkAny, + } + } + + // The key file is placed in the same directory as the validator key file. + err := saveSEDAKeys(keys, dirPath) + if err != nil { + return nil, err + } + return result, nil +} + +// LoadSEDAPubKeys loads the SEDA key file from the given path and +// returns a list of index-public key pairs. +func LoadSEDAPubKeys(loadPath string) ([]pubkeytypes.IndexedPubKey, error) { + keysJSONBytes, err := os.ReadFile(loadPath) + if err != nil { + return nil, fmt.Errorf("failed to read SEDA keys from %v: %v", loadPath, err) + } + var keys []indexedPrivKey + err = cmtjson.Unmarshal(keysJSONBytes, &keys) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal SEDA keys from %v: %v", loadPath, err) + } + + result := make([]pubkeytypes.IndexedPubKey, len(keys)) + for i, key := range keys { + // Convert to SDK type for app-level use. + pubKey, err := cryptocodec.FromCmtPubKeyInterface(key.PrivKey.PubKey()) + if err != nil { + return nil, err + } + pkAny, err := codectypes.NewAnyWithValue(pubKey) + if err != nil { + return nil, err + } + result[i] = pubkeytypes.IndexedPubKey{ + Index: key.Index, + PubKey: pkAny, + } + } + return result, nil +} + +// saveSEDAKeys saves a given list of IndexedPrivKey in the directory +// at dirPath. +func saveSEDAKeys(keys []indexedPrivKey, dirPath string) error { + savePath := filepath.Join(dirPath, SEDAKeyFileName) + if cmtos.FileExists(savePath) { + return fmt.Errorf("SEDA key file already exists at %s", savePath) + } + err := cmtos.EnsureDir(filepath.Dir(savePath), 0o700) + if err != nil { + return err + } + jsonBytes, err := cmtjson.MarshalIndent(keys, "", " ") + if err != nil { + return fmt.Errorf("failed to marshal SEDA keys: %v", err) + } + err = os.WriteFile(savePath, jsonBytes, 0o600) + if err != nil { + return fmt.Errorf("failed to write SEDA key file: %v", err) + } + return nil +} + +type sedaSigner interface { + Sign(input []byte, index uint32) (signature []byte, err error) +} + +var _ sedaSigner = &sedaKeys{} + +type sedaKeys struct { + keys []indexedPrivKey +} + +// LoadSEDASigner loads the SEDA keys from the given file and returns +// a sedaKeys object. +func LoadSEDASigner(loadPath string) (*sedaKeys, error) { + keysJSONBytes, err := os.ReadFile(loadPath) + if err != nil { + return nil, fmt.Errorf("failed to read SEDA keys from %v: %v", loadPath, err) + } + var keys []indexedPrivKey + err = cmtjson.Unmarshal(keysJSONBytes, &keys) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal SEDA keys from %v: %v", loadPath, err) + } + return &sedaKeys{keys: keys}, nil +} + +func (s *sedaKeys) Sign(input []byte, index uint32) ([]byte, error) { + signature, err := s.keys[index].PrivKey.Sign(input) + if err != nil { + return nil, err + } + return signature, nil +} diff --git a/app/utils/vrf_key.go b/app/utils/vrf_key.go deleted file mode 100644 index b2eeb3e8..00000000 --- a/app/utils/vrf_key.go +++ /dev/null @@ -1,240 +0,0 @@ -package utils - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - - cfg "github.com/cometbft/cometbft/config" - "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/secp256k1" - cmtjson "github.com/cometbft/cometbft/libs/json" - cmtos "github.com/cometbft/cometbft/libs/os" - "github.com/cometbft/cometbft/types" - - "github.com/cosmos/cosmos-sdk/client" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdkcrypto "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - - vrf "github.com/sedaprotocol/vrf-go" -) - -const VRFKeyFileName = "vrf_key.json" - -type VRFKey struct { - Address types.Address `json:"address"` - PubKey sdkcrypto.PubKey `json:"pub_key"` - PrivKey crypto.PrivKey `json:"priv_key"` - - filePath string - vrf *vrf.VRFStruct -} - -// Save persists the VRFKey to its filePath. -func (v VRFKey) Save() error { - outFile := v.filePath - if outFile == "" { - return fmt.Errorf("key's file path is empty") - } - - cmtPubKey, err := cryptocodec.ToCmtPubKeyInterface(v.PubKey) - if err != nil { - return fmt.Errorf("failed to convert key type from SDK to Comet: %v", err) - } - - vrfKeyFile := struct { - PrivKey crypto.PrivKey `json:"priv_key"` - PubKey crypto.PubKey `json:"pub_key"` - }{ - PrivKey: v.PrivKey, - PubKey: cmtPubKey, - } - - jsonBytes, err := cmtjson.MarshalIndent(vrfKeyFile, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal key: %v", err) - } - - err = os.WriteFile(outFile, jsonBytes, 0o600) - if err != nil { - return fmt.Errorf("failed to write key file: %v", err) - } - return nil -} - -// VRFProve uses the VRF key to compute the VRF hash output (beta) -// and the proof that it was computed correctly (pi). -func (v *VRFKey) VRFProve(alpha []byte) (pi, beta []byte, err error) { - pi, err = v.vrf.Prove(v.PrivKey.Bytes(), alpha) - if err != nil { - return nil, nil, err - } - beta, err = v.vrf.ProofToHash(pi) - if err != nil { - return nil, nil, err - } - return pi, beta, nil -} - -// VRFVerify verifies that beta is the correct VRF hash of the alpha -// under private key associated with the given public key. It also -// outputs the hash output beta. -func (v *VRFKey) VRFVerify(publicKey, alpha, pi []byte) (beta []byte, err error) { - beta, err = v.vrf.Verify(publicKey, alpha, pi) - if err != nil { - return nil, err - } - return beta, nil -} - -// SignTransaction signs a given transaction with the VRF key and -// returns the resulting signature. The given account must belong -// to the VRF key. -func (v *VRFKey) SignTransaction( - ctx sdk.Context, txBuilder client.TxBuilder, txConfig client.TxConfig, - signMode txsigning.SignMode, account sdk.AccountI, -) (txsigning.SignatureV2, error) { - var sigV2 txsigning.SignatureV2 - - if !bytes.Equal(account.GetPubKey().Bytes(), v.PubKey.Bytes()) { - return sigV2, fmt.Errorf("the account does not belong to the vrf key") - } - - signerData := authsigning.SignerData{ - ChainID: ctx.ChainID(), - AccountNumber: account.GetAccountNumber(), - Sequence: account.GetSequence(), - PubKey: v.PubKey, - Address: account.GetAddress().String(), - } - - // For SIGN_MODE_DIRECT, calling SetSignatures calls setSignerInfos on - // TxBuilder under the hood, and SignerInfos is needed to generate the sign - // bytes. This is the reason for setting SetSignatures here, with a nil - // signature. - // - // Note: This line is not needed for SIGN_MODE_LEGACY_AMINO, but putting it - // also doesn't affect its generated sign bytes, so for code's simplicity - // sake, we put it here. - nilSig := txsigning.SignatureV2{ - PubKey: v.PubKey, - Data: &txsigning.SingleSignatureData{ - SignMode: signMode, - Signature: nil, - }, - Sequence: account.GetSequence(), - } - - if err := txBuilder.SetSignatures(nilSig); err != nil { - return sigV2, err - } - - bytesToSign, err := authsigning.GetSignBytesAdapter( - ctx, - txConfig.SignModeHandler(), - signMode, - signerData, - txBuilder.GetTx(), - ) - if err != nil { - return sigV2, err - } - - sigBytes, err := v.PrivKey.Sign(bytesToSign) - if err != nil { - return sigV2, err - } - - sigV2 = txsigning.SignatureV2{ - PubKey: v.PubKey, - Data: &txsigning.SingleSignatureData{ - SignMode: signMode, - Signature: sigBytes, - }, - Sequence: account.GetSequence(), - } - return sigV2, nil -} - -func (v *VRFKey) IsNil() bool { - return v == nil -} - -// NewVRFKey generates a new VRFKey from the given key and key file path. -func NewVRFKey(privKey crypto.PrivKey, keyFilePath string) (*VRFKey, error) { - vrfStruct := vrf.NewK256VRF() - pubKey, err := cryptocodec.FromCmtPubKeyInterface(privKey.PubKey()) - if err != nil { - return nil, err - } - return &VRFKey{ - Address: privKey.PubKey().Address(), - PubKey: pubKey, - PrivKey: privKey, - filePath: keyFilePath, - vrf: &vrfStruct, - }, nil -} - -func LoadVRFKey(keyFilePath string) (*VRFKey, error) { - keyJSONBytes, err := os.ReadFile(keyFilePath) - if err != nil { - return nil, fmt.Errorf("error reading VRF key from %v: %v", keyFilePath, err) - } - - vrfKeyFile := struct { - PrivKey crypto.PrivKey `json:"priv_key"` - }{} - err = cmtjson.Unmarshal(keyJSONBytes, &vrfKeyFile) - if err != nil { - return nil, fmt.Errorf("error unmarshalling VRF key from %v: %v", keyFilePath, err) - } - - vrfKey, err := NewVRFKey(vrfKeyFile.PrivKey, keyFilePath) - if err != nil { - return nil, err - } - - return vrfKey, nil -} - -// LoadOrGenVRFKey initializes a VRF key and returns its public key. -// If loadPath is specified, it loads the VRF key file at the specified -// path. Otherwise, it generates a new VRF key, whose entropy is randomly -// generated or obtained from the mnemonic, if provided. -func LoadOrGenVRFKey(config *cfg.Config, loadPath string) (vrfPubKey sdkcrypto.PubKey, err error) { - var vrfKey *VRFKey - if loadPath != "" { - vrfKey, err = LoadVRFKey(loadPath) - if err != nil { - return nil, err - } - } else { - privKey := secp256k1.GenPrivKey() - - // VRF key file is placed in the same directory as the validator key file. - pvKeyFile := config.PrivValidatorKeyFile() - savePath := filepath.Join(filepath.Dir(pvKeyFile), VRFKeyFileName) - if cmtos.FileExists(savePath) { - return nil, fmt.Errorf("vrf key file already exists at %s", savePath) - } - err := cmtos.EnsureDir(filepath.Dir(pvKeyFile), 0o700) - if err != nil { - return nil, err - } - - vrfKey, err = NewVRFKey(privKey, savePath) - if err != nil { - return nil, err - } - err = vrfKey.Save() - if err != nil { - return nil, err - } - } - return vrfKey.PubKey, nil -} diff --git a/x/pubkey/client/cli/tx.go b/x/pubkey/client/cli/tx.go index 6968bfa7..810a6be2 100644 --- a/x/pubkey/client/cli/tx.go +++ b/x/pubkey/client/cli/tx.go @@ -2,31 +2,22 @@ package cli import ( "fmt" - "os" "path/filepath" "github.com/spf13/cobra" - cmtcrypto "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/secp256k1" - cmtjson "github.com/cometbft/cometbft/libs/json" - cmtos "github.com/cometbft/cometbft/libs/os" - "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/server" + "github.com/sedaprotocol/seda-chain/app/utils" "github.com/sedaprotocol/seda-chain/x/pubkey/types" ) const ( - SEDAKeyFileName = "seda_keys.json" - // FlagKeyFile defines a flag to specify an existing key file. FlagKeyFile = "key-file" ) @@ -71,15 +62,12 @@ func AddKey(ac address.Codec) *cobra.Command { var pks []types.IndexedPubKey keyFile, _ := cmd.Flags().GetString(FlagKeyFile) if keyFile != "" { - pks, err = loadSEDAPubKeys(keyFile) + pks, err = utils.LoadSEDAPubKeys(keyFile) if err != nil { return err } } else { - pks, err = generateSEDAKeys( - []privKeyGenerator{secp256k1GenPrivKey}, - filepath.Dir(serverCfg.PrivValidatorKeyFile()), - ) + pks, err = utils.GenerateSEDAKeys(filepath.Dir(serverCfg.PrivValidatorKeyFile())) if err != nil { return err } @@ -97,106 +85,3 @@ func AddKey(ac address.Codec) *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } - -type IndexedPrivKey struct { - Index uint32 `json:"index"` - PrivKey cmtcrypto.PrivKey `json:"priv_key"` -} - -// loadSEDAPubKeys loads the SEDA key file from the given path and -// returns a list of index-public key pairs. -func loadSEDAPubKeys(loadPath string) ([]types.IndexedPubKey, error) { - keysJSONBytes, err := os.ReadFile(loadPath) - if err != nil { - return nil, fmt.Errorf("failed to read SEDA keys from %v: %v", loadPath, err) - } - var keys []IndexedPrivKey - err = cmtjson.Unmarshal(keysJSONBytes, &keys) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal SEDA keys from %v: %v", loadPath, err) - } - - result := make([]types.IndexedPubKey, len(keys)) - for i, key := range keys { - // Convert to SDK type for app-level use. - pubKey, err := cryptocodec.FromCmtPubKeyInterface(key.PrivKey.PubKey()) - if err != nil { - return nil, err - } - pkAny, err := codectypes.NewAnyWithValue(pubKey) - if err != nil { - return nil, err - } - result[i] = types.IndexedPubKey{ - Index: key.Index, - PubKey: pkAny, - } - } - return result, nil -} - -// saveSEDAKeys saves a given list of IndexedPrivKey in the directory -// at dirPath. -func saveSEDAKeys(keys []IndexedPrivKey, dirPath string) error { - savePath := filepath.Join(dirPath, SEDAKeyFileName) - if cmtos.FileExists(savePath) { - return fmt.Errorf("SEDA key file already exists at %s", savePath) - } - err := cmtos.EnsureDir(filepath.Dir(savePath), 0o700) - if err != nil { - return err - } - jsonBytes, err := cmtjson.MarshalIndent(keys, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal SEDA keys: %v", err) - } - err = os.WriteFile(savePath, jsonBytes, 0o600) - if err != nil { - return fmt.Errorf("failed to write SEDA key file: %v", err) - } - return nil -} - -type privKeyGenerator func() cmtcrypto.PrivKey - -func secp256k1GenPrivKey() cmtcrypto.PrivKey { - return secp256k1.GenPrivKey() -} - -// generateSEDAKeys generates SEDA keys given a list of private key -// generators, saves them to the SEDA key file, and returns the resulting -// index-public key pairs. Index is assigned incrementally in the order -// of the given private key generators. The key file is stored in the -// directory given by dirPath. -func generateSEDAKeys(generators []privKeyGenerator, dirPath string) ([]types.IndexedPubKey, error) { - keys := make([]IndexedPrivKey, len(generators)) - result := make([]types.IndexedPubKey, len(generators)) - for i, generator := range generators { - privKey := generator() - keys[i] = IndexedPrivKey{ - Index: uint32(i), - PrivKey: privKey, - } - - // Convert to SDK type for app-level use. - pubKey, err := cryptocodec.FromCmtPubKeyInterface(privKey.PubKey()) - if err != nil { - return nil, err - } - pkAny, err := codectypes.NewAnyWithValue(pubKey) - if err != nil { - return nil, err - } - result[i] = types.IndexedPubKey{ - Index: uint32(i), - PubKey: pkAny, - } - } - - // The key file is placed in the same directory as the validator key file. - err := saveSEDAKeys(keys, dirPath) - if err != nil { - return nil, err - } - return result, nil -} From be310b495e3460026e47d2d7d6bf37dfd96ad228 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 23 Sep 2024 16:11:22 -0400 Subject: [PATCH 4/7] refactor: remove x/randomness and vrf-related txs --- cmd/sedad/gentx/gentx.go | 295 ------------ e2e/validator.go | 12 - x/randomness/client/cli/query.go | 56 --- x/randomness/genesis.go | 28 -- x/randomness/keeper/abci.go | 280 ----------- x/randomness/keeper/keeper.go | 80 ---- x/randomness/keeper/msg_server.go | 33 -- x/randomness/keeper/querier.go | 32 -- x/randomness/keeper/query_plugin.go | 29 -- x/randomness/module.go | 145 ------ x/randomness/types/codec.go | 19 - x/randomness/types/errors.go | 10 - x/randomness/types/expected_keepers.go | 17 - x/randomness/types/genesis.go | 18 - x/randomness/types/genesis.pb.go | 318 ------------- x/randomness/types/keys.go | 12 - x/randomness/types/query.pb.go | 568 ---------------------- x/randomness/types/query.pb.gw.go | 153 ------ x/randomness/types/randomness.pb.go | 391 --------------- x/randomness/types/tx.pb.go | 632 ------------------------- x/staking/client/cli/tx.go | 237 ---------- x/staking/client/cli/utils.go | 129 ----- 22 files changed, 3494 deletions(-) delete mode 100644 cmd/sedad/gentx/gentx.go delete mode 100644 x/randomness/client/cli/query.go delete mode 100644 x/randomness/genesis.go delete mode 100644 x/randomness/keeper/abci.go delete mode 100644 x/randomness/keeper/keeper.go delete mode 100644 x/randomness/keeper/msg_server.go delete mode 100644 x/randomness/keeper/querier.go delete mode 100644 x/randomness/keeper/query_plugin.go delete mode 100644 x/randomness/module.go delete mode 100644 x/randomness/types/codec.go delete mode 100644 x/randomness/types/errors.go delete mode 100644 x/randomness/types/expected_keepers.go delete mode 100644 x/randomness/types/genesis.go delete mode 100644 x/randomness/types/genesis.pb.go delete mode 100644 x/randomness/types/keys.go delete mode 100644 x/randomness/types/query.pb.go delete mode 100644 x/randomness/types/query.pb.gw.go delete mode 100644 x/randomness/types/randomness.pb.go delete mode 100644 x/randomness/types/tx.pb.go delete mode 100644 x/staking/client/cli/tx.go delete mode 100644 x/staking/client/cli/utils.go diff --git a/cmd/sedad/gentx/gentx.go b/cmd/sedad/gentx/gentx.go deleted file mode 100644 index d9afa06f..00000000 --- a/cmd/sedad/gentx/gentx.go +++ /dev/null @@ -1,295 +0,0 @@ -package gentx - -import ( - "bufio" - "bytes" - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - - "github.com/spf13/cobra" - - address "cosmossdk.io/core/address" - "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/server" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/version" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/genutil" - "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/cosmos/cosmos-sdk/x/staking/client/cli" - - "github.com/sedaprotocol/seda-chain/app/utils" - customcli "github.com/sedaprotocol/seda-chain/x/staking/client/cli" - stakingtypes "github.com/sedaprotocol/seda-chain/x/staking/types" -) - -//nolint:revive -func GenTxValidator(msgs []sdk.Msg) error { - if len(msgs) != 1 { - return fmt.Errorf("unexpected number of GenTx messages; got: %d, expected: 1", len(msgs)) - } - if _, ok := msgs[0].(*stakingtypes.MsgCreateValidatorWithVRF); !ok { - return fmt.Errorf("unexpected GenTx message type; expected: MsgCreateValidatorWithVRF, got: %T", msgs[0]) - } - - if m, ok := msgs[0].(sdk.HasValidateBasic); ok { - if err := m.ValidateBasic(); err != nil { - return fmt.Errorf("invalid GenTx '%s': %w", msgs[0], err) - } - } - - return nil -} - -// GenTxCmd builds the application's gentx command. -// -//nolint:revive -func GenTxCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, defaultNodeHome string, valAdddressCodec address.Codec) *cobra.Command { - ipDefault, _ := server.ExternalIP() - fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault) - - cmd := &cobra.Command{ - Use: "gentx [key_name] [amount]", - Short: "Generate a genesis tx carrying a self delegation and VRF public key", - Args: cobra.ExactArgs(2), - Long: fmt.Sprintf(`Generate a genesis transaction that creates a validator with a self-delegation and -VRF public key. The transaction is signed by the key in the Keyring referenced by a given name. A VRF key pair -is generated and stored in the configuration directory during the process. A node ID and consensus pubkey may -optionally be provided. If they are omitted, they will be retrieved from the priv_validator.json file. -The following default parameters are included: - %s - -Example: -$ %s gentx my-key-name 1000000seda --home=/path/to/home/dir --keyring-backend=os --chain-id=sedachain \ - --moniker="myvalidator" \ - --commission-max-change-rate=0.01 \ - --commission-max-rate=1.0 \ - --commission-rate=0.07 \ - --details="..." \ - --security-contact="..." \ - --website="..." -`, defaultsDesc, version.AppName, - ), - RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := server.GetServerContextFromCmd(cmd) - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - cdc := clientCtx.Codec - - config := serverCtx.Config - config.SetRoot(clientCtx.HomeDir) - - nodeID, valPubKey, err := genutil.InitializeNodeValidatorFiles(serverCtx.Config) - if err != nil { - return errors.Wrap(err, "failed to initialize node validator files") - } - vrfPubKey, err := utils.LoadOrGenVRFKey(serverCtx.Config, "") // TODO (#314) - if err != nil { - return errors.Wrap(err, "failed to initialize VRF key") - } - - // read --nodeID, if empty take it from priv_validator.json - if nodeIDString, _ := cmd.Flags().GetString(cli.FlagNodeID); nodeIDString != "" { - nodeID = nodeIDString - } - - // read --pubkey, if empty take it from priv_validator.json - if pkStr, _ := cmd.Flags().GetString(cli.FlagPubKey); pkStr != "" { - if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(pkStr), &valPubKey); err != nil { - return errors.Wrap(err, "failed to unmarshal validator public key") - } - } - - appGenesis, err := types.AppGenesisFromFile(config.GenesisFile()) - if err != nil { - return errors.Wrapf(err, "failed to read genesis doc file %s", config.GenesisFile()) - } - - var genesisState map[string]json.RawMessage - if err = json.Unmarshal(appGenesis.AppState, &genesisState); err != nil { - return errors.Wrap(err, "failed to unmarshal genesis state") - } - - if err = mbm.ValidateGenesis(cdc, txEncCfg, genesisState); err != nil { - return errors.Wrap(err, "failed to validate genesis state") - } - - inBuf := bufio.NewReader(cmd.InOrStdin()) - - name := args[0] - key, err := clientCtx.Keyring.Key(name) - if err != nil { - return errors.Wrapf(err, "failed to fetch '%s' from the keyring", name) - } - - moniker := config.Moniker - if m, _ := cmd.Flags().GetString(cli.FlagMoniker); m != "" { - moniker = m - } - - // set flags for creating a gentx - sdkCfg, err := cli.PrepareConfigForTxCreateValidator(cmd.Flags(), moniker, nodeID, appGenesis.ChainID, valPubKey) - if err != nil { - return errors.Wrap(err, "error creating configuration to create validator msg") - } - createValCfg := customcli.TxCreateValidatorConfig{ - TxCreateValidatorConfig: sdkCfg, - VrfPubKey: vrfPubKey, - } - - amount := args[1] - coins, err := sdk.ParseCoinsNormalized(amount) - if err != nil { - return errors.Wrap(err, "failed to parse coins") - } - addr, err := key.GetAddress() - if err != nil { - return err - } - err = genutil.ValidateAccountInGenesis(genesisState, genBalIterator, addr, coins, cdc) - if err != nil { - return errors.Wrap(err, "failed to validate account in genesis") - } - - txFactory, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - pub, err := key.GetAddress() - if err != nil { - return err - } - clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(pub) - - // The following line comes from a discrepancy between the `gentx` - // and `create-validator` commands: - // - `gentx` expects amount as an arg, - // - `create-validator` expects amount as a required flag. - // ref: https://github.com/cosmos/cosmos-sdk/issues/8251 - // Since gentx doesn't set the amount flag (which `create-validator` - // reads from), we copy the amount arg into the valCfg directly. - // - // Ideally, the `create-validator` command should take a validator - // config file instead of so many flags. - // ref: https://github.com/cosmos/cosmos-sdk/issues/8177 - createValCfg.Amount = amount - - // create a 'create-validator' message - txf, msg, err := customcli.BuildCreateValidatorWithVRFMsg(clientCtx, createValCfg, txFactory, true, valAdddressCodec) - if err != nil { - return errors.Wrap(err, "failed to build create-validator-with-vrf message") - } - - if key.GetType() == keyring.TypeOffline || key.GetType() == keyring.TypeMulti { - cmd.PrintErrln("Offline key passed in. Use `tx sign` command to sign.") - return txf.PrintUnsignedTx(clientCtx, msg) - } - - // write the unsigned transaction to the buffer - w := bytes.NewBuffer([]byte{}) - clientCtx = clientCtx.WithOutput(w) - - if m, ok := msg.(sdk.HasValidateBasic); ok { - if err := m.ValidateBasic(); err != nil { - return err - } - } - - if err = txf.PrintUnsignedTx(clientCtx, msg); err != nil { - return errors.Wrap(err, "failed to print unsigned std tx") - } - - // read the transaction - stdTx, err := readUnsignedGenTxFile(clientCtx, w) - if err != nil { - return errors.Wrap(err, "failed to read unsigned gen tx file") - } - - // sign the transaction and write it to the output file - txBuilder, err := clientCtx.TxConfig.WrapTxBuilder(stdTx) - if err != nil { - return fmt.Errorf("error creating tx builder: %w", err) - } - - err = authclient.SignTx(txFactory, clientCtx, name, txBuilder, true, true) - if err != nil { - return errors.Wrap(err, "failed to sign std tx") - } - - outputDocument, _ := cmd.Flags().GetString(flags.FlagOutputDocument) - if outputDocument == "" { - outputDocument, err = makeOutputFilepath(config.RootDir, nodeID) - if err != nil { - return errors.Wrap(err, "failed to create output file path") - } - } - - if err := writeSignedGenTx(clientCtx, outputDocument, stdTx); err != nil { - return errors.Wrap(err, "failed to write signed gen tx") - } - - cmd.PrintErrf("Genesis transaction written to %q\n", outputDocument) - return nil - }, - } - - cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.Flags().String(flags.FlagOutputDocument, "", "Write the genesis transaction JSON document to the given file instead of the default location") - cmd.Flags().AddFlagSet(fsCreateValidator) - flags.AddTxFlagsToCmd(cmd) - _ = cmd.Flags().MarkHidden(flags.FlagOutput) // signing makes sense to output only json - - return cmd -} - -func makeOutputFilepath(rootDir, nodeID string) (string, error) { - writePath := filepath.Join(rootDir, "config", "gentx") - if err := os.MkdirAll(writePath, 0o700); err != nil { - return "", fmt.Errorf("could not create directory %q: %w", writePath, err) - } - - return filepath.Join(writePath, fmt.Sprintf("gentx-%v.json", nodeID)), nil -} - -func readUnsignedGenTxFile(clientCtx client.Context, r io.Reader) (sdk.Tx, error) { - bz, err := io.ReadAll(r) - if err != nil { - return nil, err - } - - aTx, err := clientCtx.TxConfig.TxJSONDecoder()(bz) - if err != nil { - return nil, err - } - - return aTx, err -} - -func writeSignedGenTx(clientCtx client.Context, outputDocument string, tx sdk.Tx) error { - outputFile, err := os.OpenFile(outputDocument, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o644) - if err != nil { - return err - } - defer outputFile.Close() - - json, err := clientCtx.TxConfig.TxJSONEncoder()(tx) - if err != nil { - return err - } - - _, err = fmt.Fprintf(outputFile, "%s\n", json) - - return err -} diff --git a/e2e/validator.go b/e2e/validator.go index 7e1e5f30..099b18a4 100644 --- a/e2e/validator.go +++ b/e2e/validator.go @@ -30,7 +30,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/sedaprotocol/seda-chain/app" - "github.com/sedaprotocol/seda-chain/app/utils" ) type validator struct { @@ -42,7 +41,6 @@ type validator struct { privateKey cryptotypes.PrivKey consensusKey privval.FilePVKey consensusPrivKey cryptotypes.PrivKey //nolint:unused // unused - vrfKey *utils.VRFKey nodeKey p2p.NodeKey } @@ -130,16 +128,6 @@ func (v *validator) createConsensusKey() error { filePV.Save() v.consensusKey = filePV.Key - - _, err := utils.LoadOrGenVRFKey(config, "") - if err != nil { - return err - } - vrfKey, err := utils.LoadVRFKey(filepath.Join(filepath.Dir(config.PrivValidatorKeyFile()), utils.VRFKeyFileName)) - if err != nil { - return err - } - v.vrfKey = vrfKey return nil } diff --git a/x/randomness/client/cli/query.go b/x/randomness/client/cli/query.go deleted file mode 100644 index 03c5e4ba..00000000 --- a/x/randomness/client/cli/query.go +++ /dev/null @@ -1,56 +0,0 @@ -package cli - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -// GetQueryCmd returns the CLI query commands for this module. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetCmdQuerySeed(), - ) - return cmd -} - -// GetCmdQuerySeed returns the command for querying the current block's seed. -func GetCmdQuerySeed() *cobra.Command { - cmd := &cobra.Command{ - Use: "seed", - Short: "Retrieve current block's seed", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, _ []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Seed( - cmd.Context(), - &types.QuerySeedRequest{}, - ) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} diff --git a/x/randomness/genesis.go b/x/randomness/genesis.go deleted file mode 100644 index 2a400d2e..00000000 --- a/x/randomness/genesis.go +++ /dev/null @@ -1,28 +0,0 @@ -package randomness - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/randomness/keeper" - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -// InitGenesis puts data from genesis state into store. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) { - err := k.Seed.Set(ctx, data.Seed) - if err != nil { - panic(err) - } -} - -// ExportGenesis extracts data from store to genesis state. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { - seed, err := k.Seed.Get(ctx) - if err != nil { - return types.GenesisState{} - } - - return types.GenesisState{ - Seed: seed, - } -} diff --git a/x/randomness/keeper/abci.go b/x/randomness/keeper/abci.go deleted file mode 100644 index 5bed5d07..00000000 --- a/x/randomness/keeper/abci.go +++ /dev/null @@ -1,280 +0,0 @@ -package keeper - -import ( - "bytes" - "encoding/hex" - - abci "github.com/cometbft/cometbft/abci/types" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -type ProposalHandler struct { - txVerifier baseapp.ProposalTxVerifier - txSelector baseapp.TxSelector -} - -func NewDefaultProposalHandler(txVerifier baseapp.ProposalTxVerifier) *ProposalHandler { - return &ProposalHandler{ - txVerifier: txVerifier, - txSelector: baseapp.NewDefaultTxSelector(), - } -} - -type vrfSigner interface { - VRFProve(alpha []byte) (pi, beta []byte, err error) - VRFVerify(publicKey, alpha, pi []byte) (beta []byte, err error) - SignTransaction(ctx sdk.Context, txBuilder client.TxBuilder, txConfig client.TxConfig, - signMode signing.SignMode, account sdk.AccountI) (signing.SignatureV2, error) - IsNil() bool -} - -func (h *ProposalHandler) PrepareProposalHandler( - txConfig client.TxConfig, - vrfSigner vrfSigner, - keeper Keeper, - authKeeper types.AccountKeeper, - _ types.StakingKeeper, -) sdk.PrepareProposalHandler { - return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { - if vrfSigner.IsNil() { - return nil, types.ErrNilVRFSigner - } - - defer h.txSelector.Clear() - - var maxBlockGas uint64 - if b := ctx.ConsensusParams().Block; b != nil { - //nolint:gosec // G115: We should always have a gas limit for blocks. - maxBlockGas = uint64(b.MaxGas) - } - - // Seed transaction - // alpha = (seed_{i-1} || timestamp) - prevSeed, err := keeper.GetSeed(ctx) - if err != nil { - return nil, err - } - if prevSeed == "" { - return nil, types.ErrEmptyPreviousSeed - } - timestamp, err := req.Time.MarshalBinary() - if err != nil { - return nil, err - } - alpha := append([]byte(prevSeed), timestamp...) - - // produce VRF proof - pi, beta, err := vrfSigner.VRFProve(alpha) - if err != nil { - return nil, err - } - - // generate and sign NewSeed tx - vrfPubKey, err := keeper.GetValidatorVRFPubKey(ctx, sdk.ConsAddress(req.ProposerAddress).String()) - if err != nil { - return nil, err - } - account := authKeeper.GetAccount(ctx, sdk.AccAddress(vrfPubKey.Address().Bytes())) - err = account.SetPubKey(vrfPubKey) // checked later when signing tx with VRF key - if err != nil { - return nil, err - } - newSeedTx, newSeedTxBz, err := generateAndSignNewSeedTx(ctx, txConfig, vrfSigner, account, &types.MsgNewSeed{ - Prover: account.GetAddress().String(), - Pi: hex.EncodeToString(pi), - Beta: hex.EncodeToString(beta), - }) - if err != nil { - return nil, err - } - - //nolint:gosec // G115: We should always have a bytes limit for transactions - maxTxBytes := uint64(req.MaxTxBytes) - stop := h.txSelector.SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, newSeedTx, newSeedTxBz) - if stop { - return nil, types.ErrNewSeedTxNotIncluded - } - - // include txs in the proposal until max tx bytes or block gas limits are reached - for _, txBz := range req.Txs { - tx, err := h.txVerifier.TxDecode(txBz) - if err != nil { - return nil, err - } - - // do not include any NewSeed txs - _, ok := decodeNewSeedTx(tx) - if ok { - continue - } - - stop := h.txSelector.SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, tx, txBz) - if stop { - break - } - } - - res := new(abci.ResponsePrepareProposal) - res.Txs = h.txSelector.SelectedTxs(ctx) - return res, nil - } -} - -func (h *ProposalHandler) ProcessProposalHandler( - vrfSigner vrfSigner, - keeper Keeper, - _ types.StakingKeeper, -) sdk.ProcessProposalHandler { - return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { - var totalTxGas uint64 - var maxBlockGas uint64 - if b := ctx.ConsensusParams().Block; b != nil { - //nolint:gosec // G115: We should always have a gas limit for blocks. - maxBlockGas = uint64(b.MaxGas) - } - - // process the NewSeed tx - tx, err := h.txVerifier.TxDecode(req.Txs[0]) - if err != nil { - return nil, err - } - - if maxBlockGas > 0 { - gasTx, ok := tx.(baseapp.GasTx) - if ok { - totalTxGas += gasTx.GetGas() - } - - if totalTxGas > maxBlockGas { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - } - - msg, ok := decodeNewSeedTx(tx) - if !ok { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - // get block proposer's validator public key - pubKey, err := keeper.GetValidatorVRFPubKey(ctx, sdk.ConsAddress(req.ProposerAddress).String()) - if err != nil { - return nil, err - } - - prevSeed, err := keeper.GetSeed(ctx) - if err != nil { - return nil, err - } - if prevSeed == "" { - return nil, types.ErrEmptyPreviousSeed - } - timestamp, err := req.Time.MarshalBinary() - if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - alpha := append([]byte(prevSeed), timestamp...) - - pi, err := hex.DecodeString(msg.Pi) - if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - // verify VRF proof - beta, err := vrfSigner.VRFVerify(pubKey.Bytes(), pi, alpha) - if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - // sanity check - msgBeta, err := hex.DecodeString(msg.Beta) - if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - if !bytes.Equal(beta, msgBeta) { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - // loop through the other txs to perform mandatory checks - for _, txBytes := range req.Txs[1:] { - tx, err := h.txVerifier.ProcessProposalVerifyTx(txBytes) - if err != nil { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - // reject proposal that includes NewSeed tx in any position other - // than top of tx list - _, ok := decodeNewSeedTx(tx) - if ok { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - - if maxBlockGas > 0 { - gasTx, ok := tx.(baseapp.GasTx) - if ok { - totalTxGas += gasTx.GetGas() - } - - if totalTxGas > maxBlockGas { - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err - } - } - } - - return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil - } -} - -// generateAndSignNewSeedTx generates and signs a transaction containing -// a given NewSeed message. It returns a transaction encoded into bytes. -func generateAndSignNewSeedTx(ctx sdk.Context, txConfig client.TxConfig, vrfSigner vrfSigner, account sdk.AccountI, msg *types.MsgNewSeed) (sdk.Tx, []byte, error) { - // build a transaction containing the given message - txBuilder := txConfig.NewTxBuilder() - err := txBuilder.SetMsgs(msg) - if err != nil { - return nil, nil, err - } - txBuilder.SetGasLimit(200000) - txBuilder.SetFeeAmount(sdk.NewCoins()) - txBuilder.SetFeePayer(account.GetAddress()) - - // sign the transaction - sig, err := vrfSigner.SignTransaction( - ctx, - txBuilder, - txConfig, - signing.SignMode_SIGN_MODE_DIRECT, - account, - ) - if err != nil { - return nil, nil, err - } - err = txBuilder.SetSignatures(sig) - if err != nil { - return nil, nil, err - } - - tx := txBuilder.GetTx() - txBytes, err := txConfig.TxEncoder()(tx) - if err != nil { - return nil, nil, err - } - return tx, txBytes, nil -} - -func decodeNewSeedTx(tx sdk.Tx) (*types.MsgNewSeed, bool) { - msgs := tx.GetMsgs() - if len(msgs) != 1 { - return nil, false - } - msgNewSeed, ok := msgs[0].(*types.MsgNewSeed) - if !ok { - return nil, false - } - return msgNewSeed, true -} diff --git a/x/randomness/keeper/keeper.go b/x/randomness/keeper/keeper.go deleted file mode 100644 index b78b0ed6..00000000 --- a/x/randomness/keeper/keeper.go +++ /dev/null @@ -1,80 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - "cosmossdk.io/collections" - storetypes "cosmossdk.io/core/store" - "cosmossdk.io/log" - - "github.com/cosmos/cosmos-sdk/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -var ( - SeedPrefix = collections.NewPrefix(0) - ValidatorVRFPrefix = collections.NewPrefix(1) -) - -// GetValidatorVRFKeyPrefixFull gets the key for the validator VRF object. -func GetValidatorVRFKeyPrefixFull(consensusAddr sdk.ConsAddress) []byte { - return append(ValidatorVRFPrefix, address.MustLengthPrefix(consensusAddr)...) -} - -type Keeper struct { - Schema collections.Schema - Seed collections.Item[string] - ValidatorVRFPubKeys collections.Map[string, cryptotypes.PubKey] -} - -func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService) *Keeper { - sb := collections.NewSchemaBuilder(storeService) - - return &Keeper{ - Seed: collections.NewItem(sb, SeedPrefix, "seed", collections.StringValue), - ValidatorVRFPubKeys: collections.NewMap(sb, ValidatorVRFPrefix, "validator_vrf_pubkeys", collections.StringKey, codec.CollInterfaceValue[cryptotypes.PubKey](cdc)), - } -} - -// GetSeed returns the seed. -func (k Keeper) GetSeed(ctx sdk.Context) (string, error) { - seed, err := k.Seed.Get(ctx) - if err != nil { - return "", err - } - return seed, nil -} - -// GetValidatorVRFPubKey retrieves from the store the VRF public key -// corresponding to the given validator consensus address. -func (k Keeper) GetValidatorVRFPubKey(ctx sdk.Context, consensusAddr string) (cryptotypes.PubKey, error) { - addr, err := sdk.ConsAddressFromBech32(consensusAddr) - if err != nil { - return nil, err - } - validatorVRFKeyPrefixFull := GetValidatorVRFKeyPrefixFull(addr) - vrfPubKey, err := k.ValidatorVRFPubKeys.Get(ctx, string(validatorVRFKeyPrefixFull)) - if err != nil { - return nil, err - } - - return vrfPubKey, nil -} - -func (k Keeper) SetValidatorVRFPubKey(goCtx context.Context, consensusAddr string, vrfPubKey cryptotypes.PubKey) error { - addr, err := sdk.ConsAddressFromBech32(consensusAddr) - if err != nil { - return err - } - validatorVRFKeyPrefixFull := GetValidatorVRFKeyPrefixFull(addr) - return k.ValidatorVRFPubKeys.Set(goCtx, string(validatorVRFKeyPrefixFull), vrfPubKey) -} - -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) -} diff --git a/x/randomness/keeper/msg_server.go b/x/randomness/keeper/msg_server.go deleted file mode 100644 index 5a2cb9df..00000000 --- a/x/randomness/keeper/msg_server.go +++ /dev/null @@ -1,33 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/randomness/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{} - -func (k msgServer) NewSeed(goCtx context.Context, msg *types.MsgNewSeed) (*types.MsgNewSeedResponse, error) { - sdkCtx := sdk.UnwrapSDKContext(goCtx) - err := k.Keeper.Seed.Set(sdkCtx, msg.Beta) - if err != nil { - return nil, err - } - - // TO-DO event? - - return &types.MsgNewSeedResponse{}, nil -} diff --git a/x/randomness/keeper/querier.go b/x/randomness/keeper/querier.go deleted file mode 100644 index e2a44ec8..00000000 --- a/x/randomness/keeper/querier.go +++ /dev/null @@ -1,32 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -type Querier struct { - Keeper -} - -func NewQuerierImpl(keeper Keeper) *Querier { - return &Querier{ - keeper, - } -} - -func (q Querier) Seed(c context.Context, _ *types.QuerySeedRequest) (*types.QuerySeedResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - seed, err := q.Keeper.Seed.Get(ctx) - if err != nil { - return nil, err - } - - return &types.QuerySeedResponse{ - Seed: seed, - BlockHeight: ctx.BlockHeight(), - }, nil -} diff --git a/x/randomness/keeper/query_plugin.go b/x/randomness/keeper/query_plugin.go deleted file mode 100644 index 8e0a0aec..00000000 --- a/x/randomness/keeper/query_plugin.go +++ /dev/null @@ -1,29 +0,0 @@ -package keeper - -import ( - "encoding/json" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -func SeedQueryPlugin(randomnessKeeper *Querier) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { - return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { - var contractQuery types.QuerySeedRequest - if err := json.Unmarshal(request, &contractQuery); err != nil { - return nil, err - } - - seedQueryResponse, err := randomnessKeeper.Seed(ctx, &contractQuery) - if err != nil { - return nil, err - } - - bz, err := json.Marshal(seedQueryResponse) - if err != nil { - return nil, err - } - return bz, nil - } -} diff --git a/x/randomness/module.go b/x/randomness/module.go deleted file mode 100644 index a1305973..00000000 --- a/x/randomness/module.go +++ /dev/null @@ -1,145 +0,0 @@ -package randomness - -import ( - "context" - "encoding/json" - - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - - abci "github.com/cometbft/cometbft/abci/types" - - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/x/randomness/client/cli" - "github.com/sedaprotocol/seda-chain/x/randomness/keeper" - "github.com/sedaprotocol/seda-chain/x/randomness/types" -) - -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} -) - -// ---------------------------------------------------------------------------- -// AppModuleBasic -// ---------------------------------------------------------------------------- - -// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. -type AppModuleBasic struct { - cdc codec.BinaryCodec -} - -func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { - return AppModuleBasic{cdc: cdc} -} - -// IsOnePerModuleType implements the depinject.OnePerModuleType interface. -func (am AppModule) IsOnePerModuleType() {} - -// IsAppModule implements the appmodule.AppModule interface. -func (am AppModule) IsAppModule() {} - -// Name returns the name of the module as a string -func (AppModuleBasic) Name() string { - return types.ModuleName -} - -// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} - -// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message -func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { - types.RegisterInterfaces(reg) -} - -// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) -} - -// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return errorsmod.Wrapf(err, "failed to unmarshal %s genesis state", types.ModuleName) - } - return types.ValidateGenesis(data) -} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module -func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { - panic(err) - } -} - -// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module -func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - -// ---------------------------------------------------------------------------- -// AppModule -// ---------------------------------------------------------------------------- - -// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement -type AppModule struct { - AppModuleBasic - - keeper keeper.Keeper -} - -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { - return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, - } -} - -// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries -func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(cfg.QueryServer(), keeper.Querier{Keeper: am.keeper}) -} - -// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// InitGenesis performs the module's genesis initialization. It returns no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(gs, &genesisState) - InitGenesis(ctx, am.keeper, genesisState) - return []abci.ValidatorUpdate{} -} - -// ExportGenesis returns the module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(&gs) -} - -// 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 -func (am AppModule) BeginBlock(_ sdk.Context) {} - -// EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(_ sdk.Context) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/x/randomness/types/codec.go b/x/randomness/types/codec.go deleted file mode 100644 index 4f0a3e3b..00000000 --- a/x/randomness/types/codec.go +++ /dev/null @@ -1,19 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/types/msgservice" -) - -func RegisterCodec(_ *codec.LegacyAmino) { -} - -func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) -} - -var ( - Amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/randomness/types/errors.go b/x/randomness/types/errors.go deleted file mode 100644 index 66be5e24..00000000 --- a/x/randomness/types/errors.go +++ /dev/null @@ -1,10 +0,0 @@ -package types - -import "cosmossdk.io/errors" - -var ( - ErrEmptyRandomnessSeed = errors.Register(ModuleName, 2, "randomness seed is empty") - ErrNilVRFSigner = errors.Register(ModuleName, 3, "vrf signer is nil") - ErrEmptyPreviousSeed = errors.Register(ModuleName, 4, "previous seed is empty") - ErrNewSeedTxNotIncluded = errors.Register(ModuleName, 5, "failed to include a new seed tx in the block") -) diff --git a/x/randomness/types/expected_keepers.go b/x/randomness/types/expected_keepers.go deleted file mode 100644 index 0629defa..00000000 --- a/x/randomness/types/expected_keepers.go +++ /dev/null @@ -1,17 +0,0 @@ -package types - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -type StakingKeeper interface { - GetValidatorByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (validator types.Validator, err error) -} - -type AccountKeeper interface { - GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI - SetAccount(ctx context.Context, acc sdk.AccountI) -} diff --git a/x/randomness/types/genesis.go b/x/randomness/types/genesis.go deleted file mode 100644 index 8e549022..00000000 --- a/x/randomness/types/genesis.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -const DefaultSeed = "sedouards" - -// ValidateGenesis ensures validity of given randomness genesis state. -func ValidateGenesis(data GenesisState) error { - if data.Seed == "" { - return ErrEmptyRandomnessSeed - } - return nil -} - -// DefaultGenesisState returns default state for randomness module. -func DefaultGenesisState() *GenesisState { - return &GenesisState{ - Seed: DefaultSeed, - } -} diff --git a/x/randomness/types/genesis.pb.go b/x/randomness/types/genesis.pb.go deleted file mode 100644 index 771b1634..00000000 --- a/x/randomness/types/genesis.pb.go +++ /dev/null @@ -1,318 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/randomness/v1/genesis.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 - -// GenesisState defines the randomness module's genesis state with a seed. -type GenesisState struct { - Seed string `protobuf:"bytes,1,opt,name=seed,proto3" json:"seed,omitempty"` -} - -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_7099e3dee686bc86, []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) GetSeed() string { - if m != nil { - return m.Seed - } - return "" -} - -func init() { - proto.RegisterType((*GenesisState)(nil), "sedachain.randomness.v1.GenesisState") -} - -func init() { - proto.RegisterFile("sedachain/randomness/v1/genesis.proto", fileDescriptor_7099e3dee686bc86) -} - -var fileDescriptor_7099e3dee686bc86 = []byte{ - // 168 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x4a, 0xcc, 0x4b, 0xc9, 0xcf, 0xcd, 0x4b, 0x2d, 0x2e, - 0xd6, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, - 0xc9, 0x17, 0x12, 0x87, 0x2b, 0xd3, 0x43, 0x28, 0xd3, 0x2b, 0x33, 0x54, 0x52, 0xe2, 0xe2, 0x71, - 0x87, 0xa8, 0x0c, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0x12, 0xe2, 0x62, 0x29, 0x4e, 0x4d, 0x4d, 0x91, - 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x9d, 0xfc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, - 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, - 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x34, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, - 0x1f, 0x64, 0x03, 0xd8, 0xb2, 0xe4, 0xfc, 0x1c, 0x30, 0x47, 0x17, 0xe2, 0xac, 0x0a, 0x64, 0x87, - 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0xd5, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, - 0x76, 0x81, 0x24, 0x28, 0xbd, 0x00, 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 - if len(m.Seed) > 0 { - i -= len(m.Seed) - copy(dAtA[i:], m.Seed) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.Seed))) - 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 = len(m.Seed) - if l > 0 { - 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 Seed", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Seed = string(dAtA[iNdEx:postIndex]) - 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/randomness/types/keys.go b/x/randomness/types/keys.go deleted file mode 100644 index 5e7979b8..00000000 --- a/x/randomness/types/keys.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -const ( - // ModuleName defines the module name - ModuleName = "randomness" - - // StoreKey defines the primary module store key - StoreKey = ModuleName - - // RouterKey defines the module's message routing key - RouterKey = ModuleName -) diff --git a/x/randomness/types/query.pb.go b/x/randomness/types/query.pb.go deleted file mode 100644 index fa84417e..00000000 --- a/x/randomness/types/query.pb.go +++ /dev/null @@ -1,568 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/randomness/v1/query.proto - -package types - -import ( - context "context" - fmt "fmt" - 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 - -// The message for getting the random modules seed. -type QuerySeedRequest struct { -} - -func (m *QuerySeedRequest) Reset() { *m = QuerySeedRequest{} } -func (m *QuerySeedRequest) String() string { return proto.CompactTextString(m) } -func (*QuerySeedRequest) ProtoMessage() {} -func (*QuerySeedRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_aefaf0cd21517ead, []int{0} -} -func (m *QuerySeedRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QuerySeedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QuerySeedRequest.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 *QuerySeedRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QuerySeedRequest.Merge(m, src) -} -func (m *QuerySeedRequest) XXX_Size() int { - return m.Size() -} -func (m *QuerySeedRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QuerySeedRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QuerySeedRequest proto.InternalMessageInfo - -// The message for returning the random modules seed. -type QuerySeedResponse struct { - Seed string `protobuf:"bytes,1,opt,name=seed,proto3" json:"seed,omitempty"` - BlockHeight int64 `protobuf:"varint,2,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` -} - -func (m *QuerySeedResponse) Reset() { *m = QuerySeedResponse{} } -func (m *QuerySeedResponse) String() string { return proto.CompactTextString(m) } -func (*QuerySeedResponse) ProtoMessage() {} -func (*QuerySeedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_aefaf0cd21517ead, []int{1} -} -func (m *QuerySeedResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QuerySeedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QuerySeedResponse.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 *QuerySeedResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QuerySeedResponse.Merge(m, src) -} -func (m *QuerySeedResponse) XXX_Size() int { - return m.Size() -} -func (m *QuerySeedResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QuerySeedResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QuerySeedResponse proto.InternalMessageInfo - -func (m *QuerySeedResponse) GetSeed() string { - if m != nil { - return m.Seed - } - return "" -} - -func (m *QuerySeedResponse) GetBlockHeight() int64 { - if m != nil { - return m.BlockHeight - } - return 0 -} - -func init() { - proto.RegisterType((*QuerySeedRequest)(nil), "sedachain.randomness.v1.QuerySeedRequest") - proto.RegisterType((*QuerySeedResponse)(nil), "sedachain.randomness.v1.QuerySeedResponse") -} - -func init() { - proto.RegisterFile("sedachain/randomness/v1/query.proto", fileDescriptor_aefaf0cd21517ead) -} - -var fileDescriptor_aefaf0cd21517ead = []byte{ - // 284 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2e, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x4a, 0xcc, 0x4b, 0xc9, 0xcf, 0xcd, 0x4b, 0x2d, 0x2e, - 0xd6, 0x2f, 0x33, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, - 0x12, 0x87, 0x2b, 0xd2, 0x43, 0x28, 0xd2, 0x2b, 0x33, 0x94, 0x92, 0x49, 0xcf, 0xcf, 0x4f, 0xcf, - 0x49, 0xd5, 0x4f, 0x2c, 0xc8, 0xd4, 0x4f, 0xcc, 0xcb, 0xcb, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, - 0x2b, 0x86, 0x68, 0x53, 0x12, 0xe2, 0x12, 0x08, 0x04, 0x99, 0x12, 0x9c, 0x9a, 0x9a, 0x12, 0x94, - 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0xa2, 0xe4, 0xc5, 0x25, 0x88, 0x24, 0x56, 0x5c, 0x90, 0x9f, 0x57, - 0x9c, 0x2a, 0x24, 0xc4, 0xc5, 0x52, 0x9c, 0x9a, 0x9a, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, - 0x04, 0x66, 0x0b, 0x29, 0x72, 0xf1, 0x24, 0xe5, 0xe4, 0x27, 0x67, 0xc7, 0x67, 0xa4, 0x66, 0xa6, - 0x67, 0x94, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x30, 0x07, 0x71, 0x83, 0xc5, 0x3c, 0xc0, 0x42, 0x46, - 0x3d, 0x8c, 0x5c, 0xac, 0x60, 0xc3, 0x84, 0x9a, 0x18, 0xb9, 0x58, 0x40, 0x26, 0x0a, 0x69, 0xea, - 0xe1, 0x70, 0xaa, 0x1e, 0xba, 0x4b, 0xa4, 0xb4, 0x88, 0x51, 0x0a, 0x71, 0xa0, 0x92, 0x72, 0xd3, - 0xe5, 0x27, 0x93, 0x99, 0x64, 0x85, 0xa4, 0xf5, 0x41, 0x7a, 0x74, 0x31, 0xc2, 0x0b, 0xe4, 0x62, - 0x27, 0xff, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, - 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4d, 0xcf, 0x2c, - 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x05, 0x1b, 0x00, 0x0e, 0x9e, 0xe4, 0xfc, 0x1c, 0x64, - 0xd3, 0x2a, 0x90, 0xcd, 0x2b, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xab, 0x33, 0x06, 0x04, - 0x00, 0x00, 0xff, 0xff, 0x55, 0x8c, 0x94, 0x61, 0xa4, 0x01, 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 { - // For getting the random modules seed. - Seed(ctx context.Context, in *QuerySeedRequest, opts ...grpc.CallOption) (*QuerySeedResponse, error) -} - -type queryClient struct { - cc grpc1.ClientConn -} - -func NewQueryClient(cc grpc1.ClientConn) QueryClient { - return &queryClient{cc} -} - -func (c *queryClient) Seed(ctx context.Context, in *QuerySeedRequest, opts ...grpc.CallOption) (*QuerySeedResponse, error) { - out := new(QuerySeedResponse) - err := c.cc.Invoke(ctx, "/sedachain.randomness.v1.Query/Seed", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -type QueryServer interface { - // For getting the random modules seed. - Seed(context.Context, *QuerySeedRequest) (*QuerySeedResponse, error) -} - -// UnimplementedQueryServer can be embedded to have forward compatible implementations. -type UnimplementedQueryServer struct { -} - -func (*UnimplementedQueryServer) Seed(ctx context.Context, req *QuerySeedRequest) (*QuerySeedResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Seed not implemented") -} - -func RegisterQueryServer(s grpc1.Server, srv QueryServer) { - s.RegisterService(&_Query_serviceDesc, srv) -} - -func _Query_Seed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QuerySeedRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Seed(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/sedachain.randomness.v1.Query/Seed", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Seed(ctx, req.(*QuerySeedRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "sedachain.randomness.v1.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Seed", - Handler: _Query_Seed_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "sedachain/randomness/v1/query.proto", -} - -func (m *QuerySeedRequest) 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 *QuerySeedRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QuerySeedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QuerySeedResponse) 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 *QuerySeedResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QuerySeedResponse) 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] = 0x10 - } - if len(m.Seed) > 0 { - i -= len(m.Seed) - copy(dAtA[i:], m.Seed) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Seed))) - i-- - dAtA[i] = 0xa - } - 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 *QuerySeedRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QuerySeedResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Seed) - if l > 0 { - n += 1 + l + sovQuery(uint64(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 *QuerySeedRequest) 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: QuerySeedRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QuerySeedRequest: 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 *QuerySeedResponse) 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: QuerySeedResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QuerySeedResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Seed", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - 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 ErrInvalidLengthQuery - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Seed = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - 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/randomness/types/query.pb.gw.go b/x/randomness/types/query.pb.gw.go deleted file mode 100644 index ef561cb9..00000000 --- a/x/randomness/types/query.pb.gw.go +++ /dev/null @@ -1,153 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: sedachain/randomness/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_Seed_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QuerySeedRequest - var metadata runtime.ServerMetadata - - msg, err := client.Seed(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Seed_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QuerySeedRequest - var metadata runtime.ServerMetadata - - msg, err := server.Seed(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_Seed_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_Seed_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_Seed_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_Seed_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_Seed_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_Seed_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Query_Seed_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"seda-chain", "randomness", "seed"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_Seed_0 = runtime.ForwardResponseMessage -) diff --git a/x/randomness/types/randomness.pb.go b/x/randomness/types/randomness.pb.go deleted file mode 100644 index e040a599..00000000 --- a/x/randomness/types/randomness.pb.go +++ /dev/null @@ -1,391 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/randomness/v1/randomness.proto - -package types - -import ( - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - types "github.com/cosmos/cosmos-sdk/codec/types" - 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 - -// ValidatorVRF is the randomness validator's VRF key information -type ValidatorVRF struct { - // operator_address defines the address of the validator's operator; bech - // encoded in JSON. - OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` - // vrf_pubkey is the public key of the validator's VRF key pair - VrfPubkey *types.Any `protobuf:"bytes,2,opt,name=vrf_pubkey,json=vrfPubkey,proto3" json:"vrf_pubkey,omitempty"` -} - -func (m *ValidatorVRF) Reset() { *m = ValidatorVRF{} } -func (m *ValidatorVRF) String() string { return proto.CompactTextString(m) } -func (*ValidatorVRF) ProtoMessage() {} -func (*ValidatorVRF) Descriptor() ([]byte, []int) { - return fileDescriptor_5bb7c7510d674163, []int{0} -} -func (m *ValidatorVRF) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ValidatorVRF) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ValidatorVRF.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 *ValidatorVRF) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidatorVRF.Merge(m, src) -} -func (m *ValidatorVRF) XXX_Size() int { - return m.Size() -} -func (m *ValidatorVRF) XXX_DiscardUnknown() { - xxx_messageInfo_ValidatorVRF.DiscardUnknown(m) -} - -var xxx_messageInfo_ValidatorVRF proto.InternalMessageInfo - -func (m *ValidatorVRF) GetOperatorAddress() string { - if m != nil { - return m.OperatorAddress - } - return "" -} - -func (m *ValidatorVRF) GetVrfPubkey() *types.Any { - if m != nil { - return m.VrfPubkey - } - return nil -} - -func init() { - proto.RegisterType((*ValidatorVRF)(nil), "sedachain.randomness.v1.ValidatorVRF") -} - -func init() { - proto.RegisterFile("sedachain/randomness/v1/randomness.proto", fileDescriptor_5bb7c7510d674163) -} - -var fileDescriptor_5bb7c7510d674163 = []byte{ - // 291 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x28, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x4a, 0xcc, 0x4b, 0xc9, 0xcf, 0xcd, 0x4b, 0x2d, 0x2e, - 0xd6, 0x2f, 0x33, 0x44, 0xe2, 0xe9, 0x15, 0x14, 0xe5, 0x97, 0xe4, 0x0b, 0x89, 0xc3, 0x55, 0xea, - 0x21, 0xc9, 0x95, 0x19, 0x4a, 0x49, 0xa6, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x83, 0x95, 0x25, - 0x95, 0xa6, 0xe9, 0x27, 0xe6, 0x55, 0x42, 0xf4, 0x48, 0x49, 0x26, 0xe7, 0x17, 0xe7, 0xe6, 0x17, - 0xc7, 0x83, 0x79, 0xfa, 0x10, 0x0e, 0x44, 0x4a, 0x69, 0x11, 0x23, 0x17, 0x4f, 0x58, 0x62, 0x4e, - 0x66, 0x4a, 0x62, 0x49, 0x7e, 0x51, 0x58, 0x90, 0x9b, 0x90, 0x33, 0x97, 0x40, 0x7e, 0x41, 0x6a, - 0x11, 0x88, 0x1b, 0x9f, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, - 0xe9, 0x24, 0x71, 0x69, 0x8b, 0xae, 0x08, 0x54, 0xb3, 0x23, 0x44, 0x26, 0xb8, 0xa4, 0x28, 0x33, - 0x2f, 0x3d, 0x88, 0x1f, 0xa6, 0x03, 0x2a, 0x2c, 0xe4, 0xcb, 0xc5, 0x55, 0x56, 0x94, 0x16, 0x5f, - 0x50, 0x9a, 0x94, 0x9d, 0x5a, 0x29, 0xc1, 0xa4, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa2, 0x07, 0x71, - 0xa0, 0x1e, 0xcc, 0x81, 0x7a, 0x8e, 0x79, 0x95, 0x4e, 0x12, 0xa7, 0x10, 0x86, 0x26, 0x17, 0x55, - 0x16, 0x94, 0xe4, 0xeb, 0x05, 0x94, 0x26, 0x79, 0xa7, 0x56, 0x06, 0x71, 0x96, 0x15, 0xa5, 0x05, - 0x80, 0x0d, 0x70, 0xf2, 0x3f, 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, 0xd3, - 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x50, 0xc0, 0x80, 0xcd, 0x4e, - 0xce, 0xcf, 0x01, 0x73, 0x74, 0x21, 0x01, 0x5a, 0x81, 0x1c, 0xa4, 0x25, 0x95, 0x05, 0xa9, 0xc5, - 0x49, 0x6c, 0x60, 0x75, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x57, 0x43, 0x56, 0x56, 0x77, - 0x01, 0x00, 0x00, -} - -func (m *ValidatorVRF) 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 *ValidatorVRF) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ValidatorVRF) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.VrfPubkey != nil { - { - size, err := m.VrfPubkey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRandomness(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.OperatorAddress) > 0 { - i -= len(m.OperatorAddress) - copy(dAtA[i:], m.OperatorAddress) - i = encodeVarintRandomness(dAtA, i, uint64(len(m.OperatorAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintRandomness(dAtA []byte, offset int, v uint64) int { - offset -= sovRandomness(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *ValidatorVRF) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.OperatorAddress) - if l > 0 { - n += 1 + l + sovRandomness(uint64(l)) - } - if m.VrfPubkey != nil { - l = m.VrfPubkey.Size() - n += 1 + l + sovRandomness(uint64(l)) - } - return n -} - -func sovRandomness(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozRandomness(x uint64) (n int) { - return sovRandomness(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *ValidatorVRF) 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 ErrIntOverflowRandomness - } - 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: ValidatorVRF: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ValidatorVRF: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRandomness - } - 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 ErrInvalidLengthRandomness - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRandomness - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.OperatorAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field VrfPubkey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRandomness - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRandomness - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRandomness - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.VrfPubkey == nil { - m.VrfPubkey = &types.Any{} - } - if err := m.VrfPubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRandomness(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRandomness - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRandomness(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, ErrIntOverflowRandomness - } - 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, ErrIntOverflowRandomness - } - 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, ErrIntOverflowRandomness - } - 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, ErrInvalidLengthRandomness - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupRandomness - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthRandomness - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthRandomness = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRandomness = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupRandomness = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/randomness/types/tx.pb.go b/x/randomness/types/tx.pb.go deleted file mode 100644 index d711ef9d..00000000 --- a/x/randomness/types/tx.pb.go +++ /dev/null @@ -1,632 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/randomness/v1/tx.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/msgservice" - 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 - -// The message for submitting a new seed to the chain. -type MsgNewSeed struct { - Prover string `protobuf:"bytes,1,opt,name=prover,proto3" json:"prover,omitempty"` - Pi string `protobuf:"bytes,2,opt,name=pi,proto3" json:"pi,omitempty"` - Beta string `protobuf:"bytes,3,opt,name=beta,proto3" json:"beta,omitempty"` -} - -func (m *MsgNewSeed) Reset() { *m = MsgNewSeed{} } -func (m *MsgNewSeed) String() string { return proto.CompactTextString(m) } -func (*MsgNewSeed) ProtoMessage() {} -func (*MsgNewSeed) Descriptor() ([]byte, []int) { - return fileDescriptor_9575b460ec9dfc32, []int{0} -} -func (m *MsgNewSeed) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgNewSeed) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgNewSeed.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 *MsgNewSeed) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgNewSeed.Merge(m, src) -} -func (m *MsgNewSeed) XXX_Size() int { - return m.Size() -} -func (m *MsgNewSeed) XXX_DiscardUnknown() { - xxx_messageInfo_MsgNewSeed.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgNewSeed proto.InternalMessageInfo - -func (m *MsgNewSeed) GetProver() string { - if m != nil { - return m.Prover - } - return "" -} - -func (m *MsgNewSeed) GetPi() string { - if m != nil { - return m.Pi - } - return "" -} - -func (m *MsgNewSeed) GetBeta() string { - if m != nil { - return m.Beta - } - return "" -} - -// The response message for submitting a new seed to the chain. -type MsgNewSeedResponse struct { -} - -func (m *MsgNewSeedResponse) Reset() { *m = MsgNewSeedResponse{} } -func (m *MsgNewSeedResponse) String() string { return proto.CompactTextString(m) } -func (*MsgNewSeedResponse) ProtoMessage() {} -func (*MsgNewSeedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_9575b460ec9dfc32, []int{1} -} -func (m *MsgNewSeedResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgNewSeedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgNewSeedResponse.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 *MsgNewSeedResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgNewSeedResponse.Merge(m, src) -} -func (m *MsgNewSeedResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgNewSeedResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgNewSeedResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgNewSeedResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*MsgNewSeed)(nil), "sedachain.randomness.v1.MsgNewSeed") - proto.RegisterType((*MsgNewSeedResponse)(nil), "sedachain.randomness.v1.MsgNewSeedResponse") -} - -func init() { proto.RegisterFile("sedachain/randomness/v1/tx.proto", fileDescriptor_9575b460ec9dfc32) } - -var fileDescriptor_9575b460ec9dfc32 = []byte{ - // 262 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x28, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x4a, 0xcc, 0x4b, 0xc9, 0xcf, 0xcd, 0x4b, 0x2d, 0x2e, - 0xd6, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xab, - 0xd0, 0x43, 0xa8, 0xd0, 0x2b, 0x33, 0x94, 0x12, 0x4f, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0xcf, - 0x2d, 0x4e, 0x07, 0x69, 0xc8, 0x2d, 0x4e, 0x87, 0xe8, 0x50, 0x0a, 0xe5, 0xe2, 0xf2, 0x2d, 0x4e, - 0xf7, 0x4b, 0x2d, 0x0f, 0x4e, 0x4d, 0x4d, 0x11, 0x12, 0xe3, 0x62, 0x2b, 0x28, 0xca, 0x2f, 0x4b, - 0x2d, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0xf2, 0x84, 0xf8, 0xb8, 0x98, 0x0a, 0x32, - 0x25, 0x98, 0xc0, 0x62, 0x4c, 0x05, 0x99, 0x42, 0x42, 0x5c, 0x2c, 0x49, 0xa9, 0x25, 0x89, 0x12, - 0xcc, 0x60, 0x11, 0x30, 0xdb, 0x8a, 0xbb, 0xe9, 0xf9, 0x06, 0x2d, 0xa8, 0x06, 0x25, 0x11, 0x2e, - 0x21, 0x84, 0xb1, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x46, 0x49, 0x5c, 0xcc, 0xbe, - 0xc5, 0xe9, 0x42, 0xd1, 0x5c, 0xec, 0x30, 0x0b, 0x95, 0xf5, 0x70, 0xb8, 0x58, 0x0f, 0xa1, 0x5d, - 0x4a, 0x9b, 0x08, 0x45, 0x30, 0x3b, 0x9c, 0xfc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, - 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, - 0x8e, 0x21, 0xca, 0x34, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x64, - 0x20, 0x38, 0x00, 0x92, 0xf3, 0x73, 0xc0, 0x1c, 0x5d, 0x48, 0xb8, 0x56, 0x20, 0x87, 0x6c, 0x49, - 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0x9d, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x19, 0x34, - 0x88, 0xac, 0x7e, 0x01, 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 { - // NewSeed defines a method for submitting a new seed to the chain. - NewSeed(ctx context.Context, in *MsgNewSeed, opts ...grpc.CallOption) (*MsgNewSeedResponse, error) -} - -type msgClient struct { - cc grpc1.ClientConn -} - -func NewMsgClient(cc grpc1.ClientConn) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) NewSeed(ctx context.Context, in *MsgNewSeed, opts ...grpc.CallOption) (*MsgNewSeedResponse, error) { - out := new(MsgNewSeedResponse) - err := c.cc.Invoke(ctx, "/sedachain.randomness.v1.Msg/NewSeed", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -type MsgServer interface { - // NewSeed defines a method for submitting a new seed to the chain. - NewSeed(context.Context, *MsgNewSeed) (*MsgNewSeedResponse, error) -} - -// UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} - -func (*UnimplementedMsgServer) NewSeed(ctx context.Context, req *MsgNewSeed) (*MsgNewSeedResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method NewSeed not implemented") -} - -func RegisterMsgServer(s grpc1.Server, srv MsgServer) { - s.RegisterService(&_Msg_serviceDesc, srv) -} - -func _Msg_NewSeed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgNewSeed) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).NewSeed(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/sedachain.randomness.v1.Msg/NewSeed", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).NewSeed(ctx, req.(*MsgNewSeed)) - } - return interceptor(ctx, in, info, handler) -} - -var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "sedachain.randomness.v1.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "NewSeed", - Handler: _Msg_NewSeed_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "sedachain/randomness/v1/tx.proto", -} - -func (m *MsgNewSeed) 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 *MsgNewSeed) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgNewSeed) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Beta) > 0 { - i -= len(m.Beta) - copy(dAtA[i:], m.Beta) - i = encodeVarintTx(dAtA, i, uint64(len(m.Beta))) - i-- - dAtA[i] = 0x1a - } - if len(m.Pi) > 0 { - i -= len(m.Pi) - copy(dAtA[i:], m.Pi) - i = encodeVarintTx(dAtA, i, uint64(len(m.Pi))) - i-- - dAtA[i] = 0x12 - } - if len(m.Prover) > 0 { - i -= len(m.Prover) - copy(dAtA[i:], m.Prover) - i = encodeVarintTx(dAtA, i, uint64(len(m.Prover))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgNewSeedResponse) 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 *MsgNewSeedResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgNewSeedResponse) 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 *MsgNewSeed) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Prover) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Pi) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Beta) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgNewSeedResponse) 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 *MsgNewSeed) 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: MsgNewSeed: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgNewSeed: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Prover", 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.Prover = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pi", 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.Pi = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Beta", 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.Beta = string(dAtA[iNdEx:postIndex]) - 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 *MsgNewSeedResponse) 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: MsgNewSeedResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgNewSeedResponse: 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/staking/client/cli/tx.go b/x/staking/client/cli/tx.go deleted file mode 100644 index 4fbef68e..00000000 --- a/x/staking/client/cli/tx.go +++ /dev/null @@ -1,237 +0,0 @@ -package cli - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - flag "github.com/spf13/pflag" - - "cosmossdk.io/core/address" - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/server" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/version" - stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" - "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/sedaprotocol/seda-chain/app/utils" - customtypes "github.com/sedaprotocol/seda-chain/x/staking/types" -) - -// default values -var ( - DefaultTokens = sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction) - defaultAmount = DefaultTokens.String() + sdk.DefaultBondDenom //nolint:unused // unused - defaultCommissionRate = "0.1" //nolint:unused // unused - defaultCommissionMaxRate = "0.2" //nolint:unused // unused - defaultCommissionMaxChangeRate = "0.01" //nolint:unused // unused - defaultMinSelfDelegation = "1" //nolint:unused // unused -) - -// NewTxCmd returns a root CLI command handler for all x/staking transaction commands. -func NewTxCmd(valAddrCodec, ac address.Codec) *cobra.Command { - stakingTxCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Staking transaction subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - stakingTxCmd.AddCommand( - NewCreateValidatorWithVRFCmd(valAddrCodec), - stakingcli.NewEditValidatorCmd(valAddrCodec), - stakingcli.NewDelegateCmd(valAddrCodec, ac), - stakingcli.NewRedelegateCmd(valAddrCodec, ac), - stakingcli.NewUnbondCmd(valAddrCodec, ac), - stakingcli.NewCancelUnbondingDelegation(valAddrCodec, ac), - ) - - return stakingTxCmd -} - -func NewCreateValidatorWithVRFCmd(ac address.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "create-validator-vrf [path/to/validator.json]", - Short: "create new validator initialized with a self-delegation to it", - Args: cobra.ExactArgs(1), - Long: `Create a new validator initialized with a self-delegation by submitting a JSON file with the new validator details.`, - Example: strings.TrimSpace( - fmt.Sprintf(` -$ %s tx create-validator-vrf path/to/validator.json --from keyname - -Where validator.json contains: - -{ - "pubkey": { - "@type":"/cosmos.crypto.ed25519.PubKey", - "key":"oWg2ISpLF405Jcm2vXV+2v4fnjodh6aafuIdeoW+rUw=" - }, - "amount": "1000000stake", - "moniker": "myvalidator", - "identity": "optional identity signature (ex. UPort or Keybase)", - "website": "validator's (optional) website", - "security": "validator's (optional) security contact email", - "details": "validator's (optional) details", - "commission-rate": "0.1", - "commission-max-rate": "0.2", - "commission-max-change-rate": "0.01", - "min-self-delegation": "1" -} - -where we can get the pubkey using "%s tendermint show-validator" -`, version.AppName, version.AppName)), - RunE: func(cmd *cobra.Command, args []string) error { - serverCtx := server.GetServerContextFromCmd(cmd) - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) - if err != nil { - return err - } - - validator, err := parseAndValidateValidatorJSON(clientCtx.Codec, args[0]) - if err != nil { - return err - } - - validator.VRFPubKey, err = utils.LoadOrGenVRFKey(serverCtx.Config, "") // TODO (#314) - if err != nil { - return errorsmod.Wrap(err, "failed to initialize VRF key") - } - - txf, msg, err := newBuildCreateValidatorWithVRFMsg(clientCtx, txf, cmd.Flags(), validator, ac) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) - }, - } - - cmd.Flags().String(stakingcli.FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", flags.FlagGenerateOnly)) - cmd.Flags().String(stakingcli.FlagNodeID, "", "The node's ID") - flags.AddTxFlagsToCmd(cmd) - - _ = cmd.MarkFlagRequired(flags.FlagFrom) - - return cmd -} - -func newBuildCreateValidatorWithVRFMsg(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet, val validator, valAc address.Codec) (tx.Factory, *customtypes.MsgCreateValidatorWithVRF, error) { - valAddr := clientCtx.GetFromAddress() - - description := types.NewDescription( - val.Moniker, - val.Identity, - val.Website, - val.Security, - val.Details, - ) - - valStr, err := valAc.BytesToString(sdk.ValAddress(valAddr)) - if err != nil { - return txf, nil, err - } - msg, err := customtypes.NewMsgCreateValidatorWithVRF( - valStr, val.PubKey, val.VRFPubKey, val.Amount, description, val.CommissionRates, val.MinSelfDelegation, - ) - if err != nil { - return txf, nil, err - } - if err := msg.Validate(valAc); err != nil { - return txf, nil, err - } - - genOnly, _ := fs.GetBool(flags.FlagGenerateOnly) - if genOnly { - ip, _ := fs.GetString(stakingcli.FlagIP) - p2pPort, _ := fs.GetUint(stakingcli.FlagP2PPort) - nodeID, _ := fs.GetString(stakingcli.FlagNodeID) - - if nodeID != "" && ip != "" && p2pPort > 0 { - txf = txf.WithMemo(fmt.Sprintf("%s@%s:%d", nodeID, ip, p2pPort)) - } - } - - return txf, msg, nil -} - -type TxCreateValidatorConfig struct { - stakingcli.TxCreateValidatorConfig - VrfPubKey cryptotypes.PubKey -} - -func BuildCreateValidatorWithVRFMsg(clientCtx client.Context, config TxCreateValidatorConfig, txBldr tx.Factory, generateOnly bool, valCodec address.Codec) (tx.Factory, sdk.Msg, error) { - amount, err := sdk.ParseCoinNormalized(config.Amount) - if err != nil { - return txBldr, nil, err - } - - valAddr := clientCtx.GetFromAddress() - description := types.NewDescription( - config.Moniker, - config.Identity, - config.Website, - config.SecurityContact, - config.Details, - ) - - // get the initial validator commission parameters - rateStr := config.CommissionRate - maxRateStr := config.CommissionMaxRate - maxChangeRateStr := config.CommissionMaxChangeRate - commissionRates, err := buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr) - if err != nil { - return txBldr, nil, err - } - - // get the initial validator min self delegation - msbStr := config.MinSelfDelegation - minSelfDelegation, ok := math.NewIntFromString(msbStr) - - if !ok { - return txBldr, nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer") - } - - valStr, err := valCodec.BytesToString(sdk.ValAddress(valAddr)) - if err != nil { - return txBldr, nil, err - } - - msg, err := customtypes.NewMsgCreateValidatorWithVRF( - valStr, - config.PubKey, - config.VrfPubKey, - amount, - description, - commissionRates, - minSelfDelegation, - ) - if err != nil { - return txBldr, msg, err - } - - if generateOnly { - ip := config.IP - p2pPort := config.P2PPort - nodeID := config.NodeID - - if nodeID != "" && ip != "" && p2pPort > 0 { - txBldr = txBldr.WithMemo(fmt.Sprintf("%s@%s:%d", nodeID, ip, p2pPort)) - } - } - - return txBldr, msg, nil -} diff --git a/x/staking/client/cli/utils.go b/x/staking/client/cli/utils.go deleted file mode 100644 index 3c89ea99..00000000 --- a/x/staking/client/cli/utils.go +++ /dev/null @@ -1,129 +0,0 @@ -package cli - -import ( - "encoding/json" - "errors" - "fmt" - "os" - - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// validator struct to define the fields of the validator -type validator struct { - Amount sdk.Coin - PubKey cryptotypes.PubKey - VRFPubKey cryptotypes.PubKey - Moniker string - Identity string - Website string - Security string - Details string - CommissionRates types.CommissionRates - MinSelfDelegation math.Int -} - -func parseAndValidateValidatorJSON(cdc codec.Codec, path string) (validator, error) { - type internalVal struct { - Amount string `json:"amount"` - PubKey json.RawMessage `json:"pubkey"` - VRFPubKey json.RawMessage `json:"vrf_pubkey"` - Moniker string `json:"moniker"` - Identity string `json:"identity,omitempty"` - Website string `json:"website,omitempty"` - Security string `json:"security,omitempty"` - Details string `json:"details,omitempty"` - CommissionRate string `json:"commission-rate"` - CommissionMaxRate string `json:"commission-max-rate"` - CommissionMaxChange string `json:"commission-max-change-rate"` - MinSelfDelegation string `json:"min-self-delegation"` - } - - contents, err := os.ReadFile(path) - if err != nil { - return validator{}, err - } - - var v internalVal - err = json.Unmarshal(contents, &v) - if err != nil { - return validator{}, err - } - - if v.Amount == "" { - return validator{}, fmt.Errorf("must specify amount of coins to bond") - } - amount, err := sdk.ParseCoinNormalized(v.Amount) - if err != nil { - return validator{}, err - } - - if v.PubKey == nil { - return validator{}, fmt.Errorf("must specify the JSON encoded pubkey") - } - var pk cryptotypes.PubKey - if err := cdc.UnmarshalInterfaceJSON(v.PubKey, &pk); err != nil { - return validator{}, err - } - - if v.Moniker == "" { - return validator{}, fmt.Errorf("must specify the moniker name") - } - - commissionRates, err := buildCommissionRates(v.CommissionRate, v.CommissionMaxRate, v.CommissionMaxChange) - if err != nil { - return validator{}, err - } - - if v.MinSelfDelegation == "" { - return validator{}, fmt.Errorf("must specify minimum self delegation") - } - minSelfDelegation, ok := math.NewIntFromString(v.MinSelfDelegation) - if !ok { - return validator{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer") - } - - return validator{ - Amount: amount, - PubKey: pk, - Moniker: v.Moniker, - Identity: v.Identity, - Website: v.Website, - Security: v.Security, - Details: v.Details, - CommissionRates: commissionRates, - MinSelfDelegation: minSelfDelegation, - }, nil -} - -func buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionRates, err error) { - if rateStr == "" || maxRateStr == "" || maxChangeRateStr == "" { - return commission, errors.New("must specify all validator commission parameters") - } - - rate, err := math.LegacyNewDecFromStr(rateStr) - if err != nil { - return commission, err - } - - maxRate, err := math.LegacyNewDecFromStr(maxRateStr) - if err != nil { - return commission, err - } - - maxChangeRate, err := math.LegacyNewDecFromStr(maxChangeRateStr) - if err != nil { - return commission, err - } - - commission = types.NewCommissionRates(rate, maxRate, maxChangeRate) - - return commission, nil -} From 3899979269cb8fbeb337ecab7f43ee3e6a94f801 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 23 Sep 2024 17:14:34 -0400 Subject: [PATCH 5/7] refactor: make SEDASigner interface exported --- app/utils/seda_keys.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/utils/seda_keys.go b/app/utils/seda_keys.go index ff8fb82b..f9760bce 100644 --- a/app/utils/seda_keys.go +++ b/app/utils/seda_keys.go @@ -122,19 +122,19 @@ func saveSEDAKeys(keys []indexedPrivKey, dirPath string) error { return nil } -type sedaSigner interface { +type SEDASigner interface { Sign(input []byte, index uint32) (signature []byte, err error) } -var _ sedaSigner = &sedaKeys{} +var _ SEDASigner = &sedaKeys{} type sedaKeys struct { keys []indexedPrivKey } -// LoadSEDASigner loads the SEDA keys from the given file and returns -// a sedaKeys object. -func LoadSEDASigner(loadPath string) (*sedaKeys, error) { +// LoadSEDASigner loads the SEDA keys from a given file and returns +// a SEDASigner interface. +func LoadSEDASigner(loadPath string) (SEDASigner, error) { keysJSONBytes, err := os.ReadFile(loadPath) if err != nil { return nil, fmt.Errorf("failed to read SEDA keys from %v: %v", loadPath, err) From a8b0f80ab4216ddf36be3bd7ca1068fcc0fbe853 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Thu, 26 Sep 2024 09:38:30 -0400 Subject: [PATCH 6/7] chore: Add SEDAKeyIndex type and its constant values --- app/utils/seda_keys.go | 24 +++++++++++++++++------- x/pubkey/types/query.pb.go | 6 ++++-- x/tally/types/filters.go | 3 +-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/utils/seda_keys.go b/app/utils/seda_keys.go index f9760bce..758e9a2a 100644 --- a/app/utils/seda_keys.go +++ b/app/utils/seda_keys.go @@ -16,17 +16,27 @@ import ( pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" ) +// SEDAKeyFileName defines the SEDA key file name. const SEDAKeyFileName = "seda_keys.json" -var sedaKeyGenerators = []privKeyGenerator{ - func() cmtcrypto.PrivKey { return secp256k1.GenPrivKey() }, // index 0 - secp256k1 +// SEDAKeyIndex enumerates the SEDA key indices. +type SEDAKeyIndex uint32 + +const ( + Secp256k1 SEDAKeyIndex = iota +) + +// sedaKeyGenerators maps the key index to the corresponding private +// key generator. +var sedaKeyGenerators = map[SEDAKeyIndex]privKeyGenerator{ + Secp256k1: func() cmtcrypto.PrivKey { return secp256k1.GenPrivKey() }, } type ( privKeyGenerator func() cmtcrypto.PrivKey indexedPrivKey struct { - Index uint32 `json:"index"` + Index SEDAKeyIndex `json:"index"` PrivKey cmtcrypto.PrivKey `json:"priv_key"` } ) @@ -41,7 +51,7 @@ func GenerateSEDAKeys(dirPath string) ([]pubkeytypes.IndexedPubKey, error) { result := make([]pubkeytypes.IndexedPubKey, len(sedaKeyGenerators)) for i, generator := range sedaKeyGenerators { keys[i] = indexedPrivKey{ - Index: uint32(i), + Index: i, PrivKey: generator(), } @@ -93,7 +103,7 @@ func LoadSEDAPubKeys(loadPath string) ([]pubkeytypes.IndexedPubKey, error) { return nil, err } result[i] = pubkeytypes.IndexedPubKey{ - Index: key.Index, + Index: uint32(key.Index), PubKey: pkAny, } } @@ -123,7 +133,7 @@ func saveSEDAKeys(keys []indexedPrivKey, dirPath string) error { } type SEDASigner interface { - Sign(input []byte, index uint32) (signature []byte, err error) + Sign(input []byte, index SEDAKeyIndex) (signature []byte, err error) } var _ SEDASigner = &sedaKeys{} @@ -147,7 +157,7 @@ func LoadSEDASigner(loadPath string) (SEDASigner, error) { return &sedaKeys{keys: keys}, nil } -func (s *sedaKeys) Sign(input []byte, index uint32) ([]byte, error) { +func (s *sedaKeys) Sign(input []byte, index SEDAKeyIndex) ([]byte, error) { signature, err := s.keys[index].PrivKey.Sign(input) if err != nil { return nil, err diff --git a/x/pubkey/types/query.pb.go b/x/pubkey/types/query.pb.go index 16687ace..d802dd50 100644 --- a/x/pubkey/types/query.pb.go +++ b/x/pubkey/types/query.pb.go @@ -30,7 +30,8 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// QueryValidatorKeysRequest is request type for the Query/ValidatorKeys RPC method. +// QueryValidatorKeysRequest is request type for the Query/ValidatorKeys RPC +// method. type QueryValidatorKeysRequest struct { ValidatorAddr string `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3" json:"validator_addr,omitempty"` } @@ -75,7 +76,8 @@ func (m *QueryValidatorKeysRequest) GetValidatorAddr() string { return "" } -// QueryValidatorKeysResponse is response type for the Query/ValidatorKeys RPC method. +// QueryValidatorKeysResponse is response type for the Query/ValidatorKeys RPC +// method. type QueryValidatorKeysResponse struct { ValidatorPubKeys ValidatorPubKeys `protobuf:"bytes,1,opt,name=validator_pub_keys,json=validatorPubKeys,proto3" json:"validator_pub_keys"` } diff --git a/x/tally/types/filters.go b/x/tally/types/filters.go index ba4412f4..58dea23f 100644 --- a/x/tally/types/filters.go +++ b/x/tally/types/filters.go @@ -5,9 +5,8 @@ import ( "encoding/binary" "slices" - "slices" - "golang.org/x/exp/constraints" + "slices" ) type Filter interface { From 9de1c6fcd0da7af912f6a65d0183b22378c68adb Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Thu, 26 Sep 2024 09:56:32 -0400 Subject: [PATCH 7/7] chore: Remove randomness module proto files --- proto/sedachain/randomness/v1/genesis.proto | 7 ------ proto/sedachain/randomness/v1/query.proto | 23 ------------------ .../sedachain/randomness/v1/randomness.proto | 18 -------------- proto/sedachain/randomness/v1/tx.proto | 24 ------------------- 4 files changed, 72 deletions(-) delete mode 100644 proto/sedachain/randomness/v1/genesis.proto delete mode 100644 proto/sedachain/randomness/v1/query.proto delete mode 100644 proto/sedachain/randomness/v1/randomness.proto delete mode 100644 proto/sedachain/randomness/v1/tx.proto diff --git a/proto/sedachain/randomness/v1/genesis.proto b/proto/sedachain/randomness/v1/genesis.proto deleted file mode 100644 index 8d350fa2..00000000 --- a/proto/sedachain/randomness/v1/genesis.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; -package sedachain.randomness.v1; - -option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types"; - -// GenesisState defines the randomness module's genesis state with a seed. -message GenesisState { string seed = 1; } diff --git a/proto/sedachain/randomness/v1/query.proto b/proto/sedachain/randomness/v1/query.proto deleted file mode 100644 index aa04912e..00000000 --- a/proto/sedachain/randomness/v1/query.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; -package sedachain.randomness.v1; - -import "google/api/annotations.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types"; - -// Query Service is the definition for the random modules gRPC query methods. -service Query { - // For getting the random modules seed. - rpc Seed(QuerySeedRequest) returns (QuerySeedResponse) { - option (google.api.http).get = "/seda-chain/randomness/seed"; - } -} - -// The message for getting the random modules seed. -message QuerySeedRequest {} - -// The message for returning the random modules seed. -message QuerySeedResponse { - string seed = 1; - int64 block_height = 2; -} diff --git a/proto/sedachain/randomness/v1/randomness.proto b/proto/sedachain/randomness/v1/randomness.proto deleted file mode 100644 index 59362940..00000000 --- a/proto/sedachain/randomness/v1/randomness.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; -package sedachain.randomness.v1; - -import "google/protobuf/any.proto"; -import "cosmos_proto/cosmos.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types"; - -// ValidatorVRF is the randomness validator's VRF key information -message ValidatorVRF { - // operator_address defines the address of the validator's operator; bech - // encoded in JSON. - string operator_address = 1 - [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - // vrf_pubkey is the public key of the validator's VRF key pair - google.protobuf.Any vrf_pubkey = 2 - [ (cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey" ]; -} diff --git a/proto/sedachain/randomness/v1/tx.proto b/proto/sedachain/randomness/v1/tx.proto deleted file mode 100644 index ddc43f4b..00000000 --- a/proto/sedachain/randomness/v1/tx.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; -package sedachain.randomness.v1; - -import "cosmos/msg/v1/msg.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types"; - -// Msg service defines the gRPC tx methods. -service Msg { - // NewSeed defines a method for submitting a new seed to the chain. - rpc NewSeed(MsgNewSeed) returns (MsgNewSeedResponse); -} - -// The message for submitting a new seed to the chain. -message MsgNewSeed { - option (cosmos.msg.v1.signer) = "prover"; - - string prover = 1; // address of VRF key used to produce proof - string pi = 2; // VRF proof - string beta = 3; // VRF hash -} - -// The response message for submitting a new seed to the chain. -message MsgNewSeedResponse {}