diff --git a/go.mod b/go.mod index f0fa956..7d201fb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/MalteHerrmann/upgrade-local-node-go go 1.21 require ( - github.com/cometbft/cometbft v0.37.2 github.com/cosmos/cosmos-sdk v0.47.4 github.com/evmos/evmos/v14 v14.0.0-rc3 github.com/pkg/errors v0.9.1 @@ -43,6 +42,7 @@ require ( github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/apd/v2 v2.0.2 // indirect github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect + github.com/cometbft/cometbft v0.37.2 // indirect github.com/cometbft/cometbft-db v0.8.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect diff --git a/gov/proposal.go b/gov/proposal.go index afe3307..2fef680 100644 --- a/gov/proposal.go +++ b/gov/proposal.go @@ -18,7 +18,7 @@ func buildUpgradeProposalCommand(targetVersion string, upgradeHeight int) []stri "tx", "gov", "submit-legacy-proposal", "software-upgrade", targetVersion, "--title", fmt.Sprintf("'Upgrade to %s'", targetVersion), "--description", fmt.Sprintf("'Upgrade to %s'", targetVersion), - "--upgrade-height", fmt.Sprintf("%d", upgradeHeight), + "--upgrade-height", strconv.Itoa(upgradeHeight), "--deposit", "100000000000000000000aevmos", "--output", "json", "--no-validate", @@ -149,7 +149,7 @@ func SubmitUpgradeProposal(bin *utils.Binary, targetVersion string, upgradeHeigh // VoteForProposal votes for the proposal with the given ID using the given account. func VoteForProposal(bin *utils.Binary, proposalID int, sender string) (string, error) { out, err := utils.ExecuteBinaryCmd(bin, utils.BinaryCmdArgs{ - Subcommand: []string{"tx", "gov", "vote", fmt.Sprintf("%d", proposalID), "yes"}, + Subcommand: []string{"tx", "gov", "vote", strconv.Itoa(proposalID), "yes"}, From: sender, UseDefaults: true, Quiet: true, @@ -160,3 +160,22 @@ func VoteForProposal(bin *utils.Binary, proposalID int, sender string) (string, return out, nil } + +// DepositForProposal deposits the given amount of Evmos for the proposal with the given proposalID +// from the given account. +func DepositForProposal(bin *utils.Binary, proposalID int, sender string, amount int) (string, error) { + out, err := utils.ExecuteBinaryCmd(bin, utils.BinaryCmdArgs{ + Subcommand: []string{ + "tx", "gov", "deposit", strconv.Itoa(proposalID), strconv.Itoa(amount) + "aevmos", + }, + From: sender, + UseDefaults: true, + Quiet: true, + }) + + if err != nil { + return out, errors.Wrap(err, fmt.Sprintf("failed to deposit for proposal %d", proposalID)) + } + + return out, nil +} diff --git a/main.go b/main.go index d4103a3..b59edda 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,8 @@ func main() { log.Printf( "Possible usages:\n" + " upgrade-local-node-go \n" + - " upgrade-local-node-go vote [proposal-id]\n", + " upgrade-local-node-go vote [proposal-id]\n" + + " upgrade-local-node-go deposit [proposal-id]\n", ) os.Exit(1) } @@ -34,9 +35,10 @@ func main() { log.Fatalf("Error getting accounts: %v", err) } - //nolint:nestif // nesting complexity is fine here, will be reworked with Cobra commands anyway - if os.Args[1] == "vote" { - proposalID, err := getProposalIDForVoting(bin, os.Args) + // TODO: use with Cobra CLI + switch os.Args[1] { + case "vote": + proposalID, err := getProposalIDFromInput(bin, os.Args) if err != nil { log.Fatalf("Error getting proposal ID: %v", err) } @@ -45,7 +47,19 @@ func main() { if err != nil { log.Fatalf("Error submitting votes for proposal %d: %v", proposalID, err) } - } else { + + case "deposit": + proposalID, err := getProposalIDFromInput(bin, os.Args) + if err != nil { + log.Fatalf("Error getting proposal ID: %v", err) + } + + // TODO: replace fixed amount with min deposit from chain params + if _, err = gov.DepositForProposal(bin, proposalID, bin.Accounts[0].Name, 1e9); err != nil { + log.Fatalf("Error depositing for proposal %d: %v", proposalID, err) + } + + default: targetVersion := os.Args[1] if matched, _ := regexp.MatchString(`v\d+\.\d+\.\d(-rc\d+)?`, targetVersion); !matched { log.Fatalf("Invalid target version: %s. Please use the format vX.Y.Z(-rc*).\n", targetVersion) @@ -58,8 +72,8 @@ func main() { } } -// getProposalIDForVoting gets the proposal ID from the command line arguments. -func getProposalIDForVoting(bin *utils.Binary, args []string) (int, error) { +// getProposalIDFromInput gets the proposal ID from the command line arguments. +func getProposalIDFromInput(bin *utils.Binary, args []string) (int, error) { var ( err error proposalID int