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: add request verification on send #7

Merged
merged 15 commits into from
Jan 9, 2023
21 changes: 19 additions & 2 deletions cmd/network_chain_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,25 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {
}
}

// create the message to add the validator.
return n.Join(cmd.Context(), c, launchID, gentxPath, joinOptions...)
// create requests to join as a validator
joinRequests, err := n.GetJoinRequestContents(cmd.Context(), c, launchID, gentxPath, joinOptions...)
if err != nil {
return err
}

// simulate the join requests
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
joinRequests...,
); err != nil {
return err
}

// send join requests
return n.SendRequests(cmd.Context(), launchID, joinRequests)
}

// askPublicAddress prepare questions to interactively ask for a publicAddress
Expand Down
26 changes: 25 additions & 1 deletion cmd/network_chain_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/tendermint/spn/pkg/chainid"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networkchain"
Expand Down Expand Up @@ -323,7 +324,30 @@ func networkChainPublishHandler(cmd *cobra.Command, args []string) error {
}

if !amountCoins.IsZero() {
if err := n.SendAccountRequestForCoordinator(cmd.Context(), launchID, amountCoins); err != nil {
// create a request to add an account to the genesis
addr, err := n.AccountAddress()
if err != nil {
return err
}
addAccountRequest := launchtypes.NewGenesisAccount(
launchID,
addr,
amountCoins,
)

// simulate the add account request
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
addAccountRequest,
); err != nil {
return err
}

// send the request
if err := n.SendRequest(cmd.Context(), launchID, addAccountRequest); err != nil {
return err
}
}
Expand Down
24 changes: 22 additions & 2 deletions cmd/network_request_add_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cosmosutil"
"github.com/spf13/cobra"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networkchain"
Expand Down Expand Up @@ -47,6 +48,11 @@ func networkRequestAddAccountHandler(cmd *cobra.Command, args []string) error {
session := cliui.New(cliui.StartSpinner())
defer session.End()

cacheStorage, err := newCache(cmd)
if err != nil {
return err
}

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
Expand Down Expand Up @@ -99,10 +105,24 @@ func networkRequestAddAccountHandler(cmd *cobra.Command, args []string) error {
}
}

return n.SendAccountRequest(
cmd.Context(),
// create the add account request
addAccountRequest := launchtypes.NewGenesisAccount(
launchID,
address,
balance,
)

// simulate the add account request
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
addAccountRequest,
); err != nil {
return err
}

// send the request
return n.SendRequest(cmd.Context(), launchID, addAccountRequest)
}
4 changes: 2 additions & 2 deletions cmd/network_request_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func networkRequestApproveHandler(cmd *cobra.Command, args []string) error {

// if requests must be verified, we simulate the chain in a temporary directory with the requests
if !noVerification {
if err := verifyRequest(cmd.Context(), cacheStorage, nb, launchID, ids...); err != nil {
if err := verifyRequests(cmd.Context(), cacheStorage, nb, launchID, ids...); err != nil {
return errors.Wrap(err, "request(s) not valid")
}
session.Printf("%s Request(s) %s verified\n", icons.OK, numbers.List(ids, "#"))
Expand All @@ -102,7 +102,7 @@ func networkRequestApproveHandler(cmd *cobra.Command, args []string) error {
for _, id := range ids {
reviewals = append(reviewals, network.ApproveRequest(id))
}
if err := n.SubmitRequest(cmd.Context(), launchID, reviewals...); err != nil {
if err := n.SubmitRequestReviewals(cmd.Context(), launchID, reviewals...); err != nil {
return err
}

Expand Down
24 changes: 22 additions & 2 deletions cmd/network_request_change_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/spf13/cobra"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networkchain"
Expand All @@ -29,6 +30,11 @@ func networkRequestChangeParamHandler(cmd *cobra.Command, args []string) error {
session := cliui.New(cliui.StartSpinner())
defer session.End()

cacheStorage, err := newCache(cmd)
if err != nil {
return err
}

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
Expand Down Expand Up @@ -71,11 +77,25 @@ func networkRequestChangeParamHandler(cmd *cobra.Command, args []string) error {
return err
}

return n.SendParamChangeRequest(
cmd.Context(),
// create the param change request
paramChangeRequest := launchtypes.NewParamChange(
launchID,
module,
param,
value,
)

// simulate the param change request
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
paramChangeRequest,
); err != nil {
return err
}

// send the request
return n.SendRequest(cmd.Context(), launchID, paramChangeRequest)
}
2 changes: 1 addition & 1 deletion cmd/network_request_reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func networkRequestRejectHandler(cmd *cobra.Command, args []string) error {
for _, id := range ids {
reviewals = append(reviewals, network.RejectRequest(id))
}
if err := n.SubmitRequest(cmd.Context(), launchID, reviewals...); err != nil {
if err := n.SubmitRequestReviewals(cmd.Context(), launchID, reviewals...); err != nil {
return err
}

Expand Down
25 changes: 22 additions & 3 deletions cmd/network_request_remove_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cosmosutil"
"github.com/spf13/cobra"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networktypes"
Expand All @@ -30,6 +31,11 @@ func networkRequestRemoveAccountHandler(cmd *cobra.Command, args []string) error
session := cliui.New(cliui.StartSpinner())
defer session.End()

cacheStorage, err := newCache(cmd)
if err != nil {
return err
}

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
Expand All @@ -52,9 +58,22 @@ func networkRequestRemoveAccountHandler(cmd *cobra.Command, args []string) error
return err
}

return n.SendAccountRemoveRequest(
cmd.Context(),
launchID,
// create the remove account request
removeAccountRequest := launchtypes.NewAccountRemoval(
address,
)

// simulate the remove account request
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
removeAccountRequest,
); err != nil {
return err
}

// send the request
return n.SendRequest(cmd.Context(), launchID, removeAccountRequest)
}
25 changes: 22 additions & 3 deletions cmd/network_request_remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/cosmosutil"
"github.com/spf13/cobra"
launchtypes "github.com/tendermint/spn/x/launch/types"

"github.com/ignite/cli-plugin-network/network"
"github.com/ignite/cli-plugin-network/network/networktypes"
Expand All @@ -30,6 +31,11 @@ func networkRequestRemoveValidatorHandler(cmd *cobra.Command, args []string) err
session := cliui.New(cliui.StartSpinner())
defer session.End()

cacheStorage, err := newCache(cmd)
if err != nil {
return err
}

nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return err
Expand All @@ -52,9 +58,22 @@ func networkRequestRemoveValidatorHandler(cmd *cobra.Command, args []string) err
return err
}

return n.SendValidatorRemoveRequest(
cmd.Context(),
launchID,
// create the remove validator request
removeValidatorRequest := launchtypes.NewValidatorRemoval(
address,
)

// simulate the remove validator request
if err := verifyRequestsFromRequestContents(
cmd.Context(),
cacheStorage,
nb,
launchID,
removeValidatorRequest,
); err != nil {
return err
}

// send the request
return n.SendRequest(cmd.Context(), launchID, removeValidatorRequest)
}
Loading