Skip to content

Commit

Permalink
add deposit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann committed Dec 17, 2023
1 parent 3b55bfd commit 473208b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions gov/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
28 changes: 21 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func main() {
log.Printf(
"Possible usages:\n" +
" upgrade-local-node-go <target_version>\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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 473208b

Please sign in to comment.