-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Multiple Validators in One Transaction (#677)
Co-authored-by: riley-stride <104941670+riley-stride@users.noreply.github.com>
- Loading branch information
1 parent
7e7335a
commit 4ce1317
Showing
34 changed files
with
794 additions
and
1,054 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
syntax = "proto3"; | ||
package stride.stakeibc; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "stride/stakeibc/validator.proto"; | ||
option go_package = "github.com/Stride-Labs/stride/v7/x/stakeibc/types"; | ||
|
||
message AddValidatorProposal { | ||
message AddValidatorsProposal { | ||
option (gogoproto.equal) = true; | ||
option (gogoproto.goproto_getters) = false; | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
string title = 1; | ||
string description = 2; | ||
string host_zone = 3; | ||
string validator_name = 4; | ||
string validator_address = 5 | ||
[ (cosmos_proto.scalar) = "cosmos.AddressString" ]; | ||
repeated Validator validators = 4; | ||
string deposit = 6 [ (gogoproto.moretags) = "yaml:\"deposit\"" ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/Stride-Labs/stride/v7/x/stakeibc/types" | ||
) | ||
|
||
type ValidatorsList struct { | ||
Validators []*types.Validator `json:"validators,omitempty"` | ||
} | ||
|
||
// Parse a JSON with a list of validators in the format | ||
// { | ||
// "validators": [ | ||
// {"name": "val1", "address": "cosmosXXX", "weight": 1}, | ||
// {"name": "val2", "address": "cosmosXXX", "weight": 2} | ||
// ] | ||
// } | ||
func parseAddValidatorsFile(validatorsFile string) (validators ValidatorsList, err error) { | ||
fileContents, err := os.ReadFile(validatorsFile) | ||
if err != nil { | ||
return validators, err | ||
} | ||
|
||
if err = json.Unmarshal(fileContents, &validators); err != nil { | ||
return validators, err | ||
} | ||
|
||
return validators, nil | ||
} | ||
|
||
func CmdAddValidators() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add-validators [host-zone] [validator-list-file]", | ||
Short: "Broadcast message add-validators", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
hostZone := args[0] | ||
validatorListProposalFile := args[1] | ||
|
||
validators, err := parseAddValidatorsFile(validatorListProposalFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgAddValidators( | ||
clientCtx.GetFromAddress().String(), | ||
hostZone, | ||
validators.Validators, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.