forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/gov): add custom fuction to calculate vote results and vp (cos…
- Loading branch information
1 parent
7155a1c
commit 69f03cd
Showing
14 changed files
with
73 additions
and
47 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
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
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,42 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/math" | ||
v1 "cosmossdk.io/x/gov/types/v1" | ||
) | ||
|
||
// CalculateVoteResultsAndVotingPowerFn is a function signature for calculating vote results and voting power | ||
// It can be overridden to customize the voting power calculation for proposals | ||
// It gets the proposal tallied and the validators governance infos (bonded tokens, voting power, etc.) | ||
// It must return the total voting power and the results of the vote | ||
type CalculateVoteResultsAndVotingPowerFn func( | ||
ctx context.Context, | ||
keeper Keeper, | ||
proposalID uint64, | ||
validators map[string]v1.ValidatorGovInfo, | ||
) (totalVoterPower math.LegacyDec, results map[v1.VoteOption]math.LegacyDec, err error) | ||
|
||
// Config is a config struct used for initializing the gov module to avoid using globals. | ||
type Config struct { | ||
// MaxTitleLen defines the amount of characters that can be used for proposal title | ||
MaxTitleLen uint64 | ||
// MaxMetadataLen defines the amount of characters that can be used for proposal metadata | ||
MaxMetadataLen uint64 | ||
// MaxSummaryLen defines the amount of characters that can be used for proposal summary | ||
MaxSummaryLen uint64 | ||
// CalculateVoteResultsAndVotingPowerFn is a function signature for calculating vote results and voting power | ||
// Keeping it nil will use the default implementation | ||
CalculateVoteResultsAndVotingPowerFn CalculateVoteResultsAndVotingPowerFn | ||
} | ||
|
||
// DefaultConfig returns the default config for gov. | ||
func DefaultConfig() Config { | ||
return Config{ | ||
MaxTitleLen: 255, | ||
MaxMetadataLen: 255, | ||
MaxSummaryLen: 10200, | ||
CalculateVoteResultsAndVotingPowerFn: nil, | ||
} | ||
} |
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
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
This file was deleted.
Oops, something went wrong.