forked from ignite/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor service * command * add command * improve error * changelog * Update ignite/services/network/join.go Co-authored-by: Jerónimo Albi <[email protected]> * remove unused * changelog * import * Update ignite/cmd/network_request_add_account.go Co-authored-by: Jerónimo Albi <[email protected]> * Update changelog.md Co-authored-by: Alex Johnson <[email protected]> * Update ignite/cmd/network_request_add_account.go Co-authored-by: Thomas Bruyelle <[email protected]> * revert command Co-authored-by: Jerónimo Albi <[email protected]> Co-authored-by: Alex Johnson <[email protected]> Co-authored-by: Thomas Bruyelle <[email protected]>
- Loading branch information
1 parent
50ebf3a
commit 459cd84
Showing
5 changed files
with
161 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ignite/cli/ignite/pkg/cliui" | ||
"github.com/ignite/cli/ignite/services/network" | ||
"github.com/ignite/cli/ignite/services/network/networkchain" | ||
) | ||
|
||
// NewNetworkRequestAddAccount creates a new command to send add account request | ||
func NewNetworkRequestAddAccount() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "add-account [launch-id] [address] [coins]", | ||
Short: "Send request to add account", | ||
RunE: networkRequestAddAccountHandler, | ||
Args: cobra.RangeArgs(2, 3), | ||
} | ||
|
||
flagSetClearCache(c) | ||
c.Flags().AddFlagSet(flagNetworkFrom()) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagSetKeyringDir()) | ||
return c | ||
} | ||
|
||
func networkRequestAddAccountHandler(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 | ||
} | ||
|
||
address := args[1] | ||
|
||
n, err := nb.Network() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
chainLaunch, err := n.ChainLaunch(cmd.Context(), launchID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c, err := nb.Chain(networkchain.SourceLaunch(chainLaunch)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var balance sdk.Coins | ||
if c.IsAccountBalanceFixed() { | ||
balance = c.AccountBalance() | ||
if len(args) == 3 { | ||
return fmt.Errorf( | ||
"balance can't be provided, balance has been set by coordinator to %s", | ||
balance.String(), | ||
) | ||
} | ||
} else { | ||
if len(args) < 3 { | ||
return errors.New("account balance expected") | ||
} | ||
balanceStr := args[2] | ||
balance, err = sdk.ParseCoinsNormalized(balanceStr) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return n.SendAccountRequest( | ||
cmd.Context(), | ||
launchID, | ||
address, | ||
balance, | ||
) | ||
} |
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