Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignite network request remove-account #2999

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [#2955](https://github.com/ignite/cli/pull/2955/) Add `ignite network request add-account` command.
- [#2995](https://github.com/ignite/cli/pull/2995/) Add `ignite network request remove-validator` command.
- [#2999](https://github.com/ignite/cli/pull/2999/) Add `ignite network request remove-account` command.

### Changes

Expand Down
1 change: 1 addition & 0 deletions ignite/cmd/network_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewNetworkRequest() *cobra.Command {
NewNetworkRequestReject(),
NewNetworkRequestVerify(),
NewNetworkRequestAddAccount(),
NewNetworkRequestRemoveAccount(),
NewNetworkRequestRemoveValidator(),
)

Expand Down
60 changes: 60 additions & 0 deletions ignite/cmd/network_request_remove_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ignitecmd

import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cosmosutil"
"github.com/ignite/cli/ignite/services/network"
"github.com/ignite/cli/ignite/services/network/networktypes"
)

// NewNetworkRequestRemoveAccount creates a new command to send remove account request
func NewNetworkRequestRemoveAccount() *cobra.Command {
c := &cobra.Command{
Use: "remove-account [launch-id] [address]",
Short: "Send request to remove account",
RunE: networkRequestRemoveAccountHandler,
Args: cobra.ExactArgs(2),
}

flagSetClearCache(c)
c.Flags().AddFlagSet(flagNetworkFrom())
c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetKeyringBackend())
c.Flags().AddFlagSet(flagSetKeyringDir())
return c
}

func networkRequestRemoveAccountHandler(cmd *cobra.Command, args []string) error {
session := cliui.New(cliui.StartSpinner())
defer session.End()

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
}

// parse launch ID
launchID, err := network.ParseID(args[0])
if err != nil {
return err
}

// get the address for the account and change the prefix for Ignite Chain
address, err := cosmosutil.ChangeAddressPrefix(args[1], networktypes.SPN)
if err != nil {
return err
}

n, err := nb.Network()
if err != nil {
return err
}

return n.SendAccountRemoveRequest(
cmd.Context(),
launchID,
address,
)
}
44 changes: 44 additions & 0 deletions ignite/services/network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,47 @@ func (n Network) SendValidatorRemoveRequest(
}
return nil
}

// SendAccountRemoveRequest creates the RequestRemoveAccount message to SPN
func (n Network) SendAccountRemoveRequest(
ctx context.Context,
launchID uint64,
address string,
) error {
addr, err := n.account.Address(networktypes.SPN)
if err != nil {
return err
}

msg := launchtypes.NewMsgSendRequest(
addr,
launchID,
launchtypes.NewAccountRemoval(
address,
),
)

n.ev.Send("Broadcasting transaction", events.ProgressStarted())

res, err := n.cosmos.BroadcastTx(ctx, n.account, msg)
if err != nil {
return err
}

var requestRes launchtypes.MsgSendRequestResponse
if err := res.Decode(&requestRes); err != nil {
return err
}

if requestRes.AutoApproved {
n.ev.Send("Account removed from network by the coordinator!", events.ProgressFinished())
} else {
n.ev.Send(
fmt.Sprintf(
"Request %d to remove account from the network has been submitted!", requestRes.RequestID,
),
events.ProgressFinished(),
)
}
return nil
}