Skip to content

Commit

Permalink
feat: ignite network request remove-account (#2999)
Browse files Browse the repository at this point in the history
* implement

* changelog

* rename variabel

* rename variabel

* Update ignite/cmd/network_request.go

Co-authored-by: Lucas Bertrand <[email protected]>

Co-authored-by: Lucas Bertrand <[email protected]>
  • Loading branch information
Alex Johnson and lumtis authored Oct 26, 2022
1 parent f7a1704 commit c3579d0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
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
}

0 comments on commit c3579d0

Please sign in to comment.