-
Notifications
You must be signed in to change notification settings - Fork 564
feat(cmd/network): add network reward set
command
#2086
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
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
cb7f773
add `n chain reward-set` command
Pantani 2559b61
fix comments for reward-set cmd
Pantani d00debb
improve the log messages
Pantani 675cbe9
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 8ef9588
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 1b1da0f
fix block indentation
Pantani f6ad87a
add reward flags to the publish command
Pantani 15204a1
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani dabf70b
run make format
Pantani fdd058b
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani f8dfc30
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani f202c3d
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani b31fdaf
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani e606187
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 20257da
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 513ac09
Merge remote-tracking branch 'origin/develop' into feat/network-rewar…
Pantani 44a5dd3
fix the spn upgrade version
Pantani aa193c7
improve the log message
Pantani bff928c
add validator account flag
Pantani 5986754
improve the reward log with the new message response
Pantani 90267c3
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani b1a2ec2
improve the events messages and logs
Pantani c885f78
improve the event message options adding the icon
Pantani 891266a
fix method names and text color
Pantani 6ded79c
fix events struct comment
Pantani 06d4980
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani e080ca9
fix lint
Pantani e07214f
move chain reward to reward
Pantani 04ecdf3
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani d8a9635
improve the error return message
Pantani b976847
update spn version
Pantani 9169d75
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 58ba196
fix events unit tests
Pantani de035f4
Merge remote-tracking branch 'origin/develop' into feat/network-rewar…
Pantani 1c8438d
fix duplicated log message
Pantani 45a0583
fix reward height flag
Pantani 9f9054b
Merge branch 'develop' into feat/network-reward-set-cmd
Pantani 2800591
update spn version
Pantani 5278cc3
Merge remote-tracking branch 'origin/develop' into feat/network-rewar…
Pantani d81ecc2
Merge remote-tracking branch 'origin/develop' into feat/network-rewar…
Pantani 7499c4a
Merge branch 'develop' into feat/network-reward-set-cmd
ilgooz 9558771
Apply suggestions from code review
ilgooz 427e6c7
Apply suggestions from code review
ilgooz ad1e38d
Apply suggestions from code review
ilgooz 99ee665
Apply suggestions from code review
ilgooz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
package starportcmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewNetworkReward creates a new chain reward command | ||
func NewNetworkReward() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "reward", | ||
Short: "Manage network rewards", | ||
} | ||
c.AddCommand( | ||
NewNetworkRewardSet(), | ||
) | ||
return c | ||
} |
This file contains hidden or 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,58 @@ | ||
package starportcmd | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/tendermint/starport/starport/services/network" | ||
) | ||
|
||
// NewNetworkRewardSet creates a new chain reward set command to | ||
// add the chain reward to the network as a coordinator. | ||
func NewNetworkRewardSet() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "set [launch-id] [last-reward-height] [coins]", | ||
Short: "set a network chain reward", | ||
Args: cobra.ExactArgs(3), | ||
RunE: networkChainRewardSetHandler, | ||
} | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagNetworkFrom()) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
return c | ||
} | ||
|
||
func networkChainRewardSetHandler(cmd *cobra.Command, args []string) error { | ||
nb, err := newNetworkBuilder(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
defer nb.Cleanup() | ||
|
||
// parse launch ID | ||
launchID, err := network.ParseID(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// parse the last reward height | ||
lastRewardHeight, err := strconv.ParseInt(args[1], 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
coins, err := sdk.ParseCoinsNormalized(args[2]) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse coins: %w", err) | ||
} | ||
|
||
n, err := nb.Network() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return n.SetReward(launchID, lastRewardHeight, coins) | ||
} |
This file contains hidden or 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 hidden or 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,69 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
rewardtypes "github.com/tendermint/spn/x/reward/types" | ||
|
||
"github.com/tendermint/starport/starport/pkg/clispinner" | ||
"github.com/tendermint/starport/starport/pkg/events" | ||
"github.com/tendermint/starport/starport/services/network/networktypes" | ||
) | ||
|
||
// SetReward set a chain reward | ||
func (n Network) SetReward(launchID uint64, lastRewardHeight int64, coins sdk.Coins) error { | ||
n.ev.Send(events.New( | ||
events.StatusOngoing, | ||
fmt.Sprintf("Setting reward %s to the chain %d at height %d", | ||
coins.String(), | ||
launchID, | ||
lastRewardHeight, | ||
), | ||
)) | ||
|
||
msg := rewardtypes.NewMsgSetRewards( | ||
n.account.Address(networktypes.SPN), | ||
launchID, | ||
lastRewardHeight, | ||
coins, | ||
) | ||
res, err := n.cosmos.BroadcastTx(n.account.Name, msg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var setRewardRes rewardtypes.MsgSetRewardsResponse | ||
if err := res.Decode(&setRewardRes); err != nil { | ||
return err | ||
} | ||
|
||
if setRewardRes.PreviousCoins.Empty() { | ||
n.ev.Send(events.New( | ||
events.StatusDone, | ||
"The reward pool was empty", | ||
events.Icon(clispinner.Info), | ||
)) | ||
} else { | ||
n.ev.Send(events.New(events.StatusDone, | ||
fmt.Sprintf( | ||
"Previous reward pool %s at height %d is overwritten", | ||
coins.String(), | ||
lastRewardHeight, | ||
), | ||
events.Icon(clispinner.Info), | ||
)) | ||
} | ||
|
||
if setRewardRes.NewCoins.Empty() { | ||
n.ev.Send(eve 6201 nts.New(events.StatusDone, "The reward pool is removed")) | ||
} else { | ||
n.ev.Send(events.New(events.StatusDone, fmt.Sprintf( | ||
"%s will be distributed to validators at height %d. The chain %d is now an incentivized testnet", | ||
coins.String(), | ||
lastRewardHeight, | ||
launchID, | ||
))) | ||
} | ||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.