feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
package group
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
proto "github.com/gogo/protobuf/proto"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-12-10 03:02:11 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group/errors"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group/internal/math"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/group/internal/orm"
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type DecisionPolicyResult struct {
|
|
|
|
Allow bool
|
|
|
|
Final bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecisionPolicy is the persistent set of rules to determine the result of election on a proposal.
|
|
|
|
type DecisionPolicy interface {
|
|
|
|
codec.ProtoMarshaler
|
|
|
|
|
|
|
|
ValidateBasic() error
|
2021-12-10 03:02:11 -08:00
|
|
|
GetTimeout() time.Duration
|
2022-02-14 05:48:17 -08:00
|
|
|
Allow(tallyResult TallyResult, totalPower string, votingDuration time.Duration) (DecisionPolicyResult, error)
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
Validate(g GroupInfo) error
|
|
|
|
}
|
|
|
|
|
2021-12-10 03:02:11 -08:00
|
|
|
// Implements DecisionPolicy Interface
|
|
|
|
var _ DecisionPolicy = &ThresholdDecisionPolicy{}
|
|
|
|
|
|
|
|
// NewThresholdDecisionPolicy creates a threshold DecisionPolicy
|
|
|
|
func NewThresholdDecisionPolicy(threshold string, timeout time.Duration) DecisionPolicy {
|
|
|
|
return &ThresholdDecisionPolicy{threshold, timeout}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ThresholdDecisionPolicy) ValidateBasic() error {
|
|
|
|
if _, err := math.NewPositiveDecFromString(p.Threshold); err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "threshold")
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout := p.Timeout
|
|
|
|
|
|
|
|
if timeout <= time.Nanosecond {
|
|
|
|
return sdkerrors.Wrap(errors.ErrInvalid, "timeout")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow allows a proposal to pass when the tally of yes votes equals or exceeds the threshold before the timeout.
|
2022-02-14 05:48:17 -08:00
|
|
|
func (p ThresholdDecisionPolicy) Allow(tallyResult TallyResult, totalPower string, votingDuration time.Duration) (DecisionPolicyResult, error) {
|
2022-02-11 01:12:57 -08:00
|
|
|
timeout := p.Timeout
|
2021-12-10 03:02:11 -08:00
|
|
|
if timeout <= votingDuration {
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: true}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
threshold, err := math.NewPositiveDecFromString(p.Threshold)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
yesCount, err := math.NewNonNegativeDecFromString(tallyResult.YesCount)
|
2021-12-10 03:02:11 -08:00
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
if yesCount.Cmp(threshold) >= 0 {
|
|
|
|
return DecisionPolicyResult{Allow: true, Final: true}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPowerDec, err := math.NewNonNegativeDecFromString(totalPower)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
totalCounts, err := tallyResult.TotalCounts()
|
2021-12-10 03:02:11 -08:00
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
undecided, err := math.SubNonNegative(totalPowerDec, totalCounts)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
sum, err := yesCount.Add(undecided)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
if sum.Cmp(threshold) < 0 {
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: true}, nil
|
|
|
|
}
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: false}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate returns an error if policy threshold is greater than the total group weight
|
|
|
|
func (p *ThresholdDecisionPolicy) Validate(g GroupInfo) error {
|
|
|
|
threshold, err := math.NewPositiveDecFromString(p.Threshold)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "threshold")
|
|
|
|
}
|
|
|
|
totalWeight, err := math.NewNonNegativeDecFromString(g.TotalWeight)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "group total weight")
|
|
|
|
}
|
|
|
|
if threshold.Cmp(totalWeight) > 0 {
|
2022-01-21 02:52:26 -08:00
|
|
|
return sdkerrors.Wrapf(errors.ErrInvalid, "policy threshold %s should not be greater than the total group weight %s", p.Threshold, g.TotalWeight)
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-11 01:12:57 -08:00
|
|
|
// Implements DecisionPolicy Interface
|
|
|
|
var _ DecisionPolicy = &PercentageDecisionPolicy{}
|
|
|
|
|
|
|
|
// NewPercentageDecisionPolicy creates a new percentage DecisionPolicy
|
|
|
|
func NewPercentageDecisionPolicy(percentage string, timeout time.Duration) DecisionPolicy {
|
|
|
|
return &PercentageDecisionPolicy{percentage, timeout}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p PercentageDecisionPolicy) ValidateBasic() error {
|
|
|
|
percentage, err := math.NewPositiveDecFromString(p.Percentage)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "percentage threshold")
|
|
|
|
}
|
|
|
|
if percentage.Cmp(math.NewDecFromInt64(1)) == 1 {
|
|
|
|
return sdkerrors.Wrap(errors.ErrInvalid, "percentage must be > 0 and <= 1")
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout := p.Timeout
|
|
|
|
if timeout <= time.Nanosecond {
|
|
|
|
return sdkerrors.Wrap(errors.ErrInvalid, "timeout")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PercentageDecisionPolicy) Validate(g GroupInfo) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow allows a proposal to pass when the tally of yes votes equals or exceeds the percentage threshold before the timeout.
|
2022-02-14 05:48:17 -08:00
|
|
|
func (p PercentageDecisionPolicy) Allow(tally TallyResult, totalPower string, votingDuration time.Duration) (DecisionPolicyResult, error) {
|
2022-02-11 01:12:57 -08:00
|
|
|
timeout := p.Timeout
|
|
|
|
if timeout <= votingDuration {
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: true}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
percentage, err := math.NewPositiveDecFromString(p.Percentage)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
yesCount, err := math.NewNonNegativeDecFromString(tally.YesCount)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
totalPowerDec, err := math.NewNonNegativeDecFromString(totalPower)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
yesPercentage, err := yesCount.Quo(totalPowerDec)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if yesPercentage.Cmp(percentage) >= 0 {
|
|
|
|
return DecisionPolicyResult{Allow: true, Final: true}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
totalCounts, err := tally.TotalCounts()
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
undecided, err := math.SubNonNegative(totalPowerDec, totalCounts)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
sum, err := yesCount.Add(undecided)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
sumPercentage, err := sum.Quo(totalPowerDec)
|
|
|
|
if err != nil {
|
|
|
|
return DecisionPolicyResult{}, err
|
|
|
|
}
|
|
|
|
if sumPercentage.Cmp(percentage) < 0 {
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: true}, nil
|
|
|
|
}
|
|
|
|
return DecisionPolicyResult{Allow: false, Final: false}, nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
var _ orm.Validateable = GroupPolicyInfo{}
|
2021-12-10 03:02:11 -08:00
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
// NewGroupPolicyInfo creates a new GroupPolicyInfo instance
|
2022-03-01 00:35:37 -08:00
|
|
|
func NewGroupPolicyInfo(address sdk.AccAddress, group uint64, admin sdk.AccAddress, metadata string,
|
2022-01-06 08:29:46 -08:00
|
|
|
version uint64, decisionPolicy DecisionPolicy, createdAt time.Time) (GroupPolicyInfo, error) {
|
2022-01-05 00:54:52 -08:00
|
|
|
p := GroupPolicyInfo{
|
2022-01-06 08:29:46 -08:00
|
|
|
Address: address.String(),
|
|
|
|
GroupId: group,
|
|
|
|
Admin: admin.String(),
|
|
|
|
Metadata: metadata,
|
|
|
|
Version: version,
|
|
|
|
CreatedAt: createdAt,
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
err := p.SetDecisionPolicy(decisionPolicy)
|
|
|
|
if err != nil {
|
2022-01-05 00:54:52 -08:00
|
|
|
return GroupPolicyInfo{}, err
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
func (g *GroupPolicyInfo) SetDecisionPolicy(decisionPolicy DecisionPolicy) error {
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
msg, ok := decisionPolicy.(proto.Message)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("can't proto marshal %T", msg)
|
|
|
|
}
|
|
|
|
any, err := codectypes.NewAnyWithValue(msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
g.DecisionPolicy = any
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
func (g GroupPolicyInfo) GetDecisionPolicy() DecisionPolicy {
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
decisionPolicy, ok := g.DecisionPolicy.GetCachedValue().(DecisionPolicy)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return decisionPolicy
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
2022-01-05 00:54:52 -08:00
|
|
|
func (g GroupPolicyInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
var decisionPolicy DecisionPolicy
|
|
|
|
return unpacker.UnpackAny(g.DecisionPolicy, &decisionPolicy)
|
|
|
|
}
|
|
|
|
|
2022-01-11 00:56:35 -08:00
|
|
|
func (g GroupInfo) PrimaryKeyFields() []interface{} {
|
2022-02-14 05:48:17 -08:00
|
|
|
return []interface{}{g.Id}
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g GroupInfo) ValidateBasic() error {
|
2022-02-14 05:48:17 -08:00
|
|
|
if g.Id == 0 {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "group's GroupId")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := sdk.AccAddressFromBech32(g.Admin)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "admin")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := math.NewNonNegativeDecFromString(g.TotalWeight); err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "total weight")
|
|
|
|
}
|
|
|
|
if g.Version == 0 {
|
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "version")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
func (g GroupPolicyInfo) PrimaryKeyFields() []interface{} {
|
2021-12-10 03:02:11 -08:00
|
|
|
addr, err := sdk.AccAddressFromBech32(g.Address)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return []interface{}{addr.Bytes()}
|
|
|
|
}
|
|
|
|
|
2022-01-11 00:56:35 -08:00
|
|
|
func (g Proposal) PrimaryKeyFields() []interface{} {
|
2022-02-14 05:48:17 -08:00
|
|
|
return []interface{}{g.Id}
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
func (g GroupPolicyInfo) ValidateBasic() error {
|
2021-12-10 03:02:11 -08:00
|
|
|
_, err := sdk.AccAddressFromBech32(g.Admin)
|
|
|
|
if err != nil {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(err, "group policy admin")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
_, err = sdk.AccAddressFromBech32(g.Address)
|
|
|
|
if err != nil {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(err, "group policy account address")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.GroupId == 0 {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "group policy's group id")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
if g.Version == 0 {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "group policy version")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
policy := g.GetDecisionPolicy()
|
|
|
|
|
|
|
|
if policy == nil {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "group policy's decision policy")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
if err := policy.ValidateBasic(); err != nil {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(err, "group policy's decision policy")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g GroupMember) PrimaryKeyFields() []interface{} {
|
|
|
|
addr, err := sdk.AccAddressFromBech32(g.Member.Address)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return []interface{}{g.GroupId, addr.Bytes()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g GroupMember) ValidateBasic() error {
|
|
|
|
if g.GroupId == 0 {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "group member's group id")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
err := g.Member.ValidateBasic()
|
|
|
|
if err != nil {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(err, "group member")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Proposal) ValidateBasic() error {
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
if p.Id == 0 {
|
2022-01-11 00:56:35 -08:00
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "proposal id")
|
|
|
|
}
|
|
|
|
_, err := sdk.AccAddressFromBech32(p.Address)
|
|
|
|
if err != nil {
|
2022-01-21 02:52:26 -08:00
|
|
|
return sdkerrors.Wrap(err, "proposal group policy address")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
|
|
|
if p.GroupVersion == 0 {
|
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "proposal group version")
|
|
|
|
}
|
|
|
|
if p.GroupPolicyVersion == 0 {
|
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "proposal group policy version")
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
_, err = p.FinalTallyResult.GetYesCount()
|
2022-01-11 00:56:35 -08:00
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return sdkerrors.Wrap(err, "proposal FinalTallyResult yes count")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
_, err = p.FinalTallyResult.GetNoCount()
|
2022-01-11 00:56:35 -08:00
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return sdkerrors.Wrap(err, "proposal FinalTallyResult no count")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
_, err = p.FinalTallyResult.GetAbstainCount()
|
2022-01-11 00:56:35 -08:00
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return sdkerrors.Wrap(err, "proposal FinalTallyResult abstain count")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
_, err = p.FinalTallyResult.GetNoWithVetoCount()
|
2022-01-11 00:56:35 -08:00
|
|
|
if err != nil {
|
2022-02-14 05:48:17 -08:00
|
|
|
return sdkerrors.Wrap(err, "proposal FinalTallyResult veto count")
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Vote) PrimaryKeyFields() []interface{} {
|
|
|
|
addr, err := sdk.AccAddressFromBech32(v.Voter)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return []interface{}{v.ProposalId, addr.Bytes()}
|
|
|
|
}
|
|
|
|
|
2022-01-11 00:56:35 -08:00
|
|
|
var _ orm.Validateable = Vote{}
|
|
|
|
|
|
|
|
func (v Vote) ValidateBasic() error {
|
|
|
|
|
|
|
|
_, err := sdk.AccAddressFromBech32(v.Voter)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "voter")
|
|
|
|
}
|
|
|
|
if v.ProposalId == 0 {
|
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "voter ProposalId")
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
if v.Option == VOTE_OPTION_UNSPECIFIED {
|
|
|
|
return sdkerrors.Wrap(errors.ErrEmpty, "voter vote option")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
if _, ok := VoteOption_name[int32(v.Option)]; !ok {
|
|
|
|
return sdkerrors.Wrap(errors.ErrInvalid, "vote option")
|
2022-01-11 00:56:35 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
2022-01-05 00:54:52 -08:00
|
|
|
func (q QueryGroupPoliciesByGroupResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
|
|
|
return unpackGroupPolicies(unpacker, q.GroupPolicies)
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
2022-01-05 00:54:52 -08:00
|
|
|
func (q QueryGroupPoliciesByAdminResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
|
|
|
return unpackGroupPolicies(unpacker, q.GroupPolicies)
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
}
|
|
|
|
|
2022-01-05 00:54:52 -08:00
|
|
|
func unpackGroupPolicies(unpacker codectypes.AnyUnpacker, accs []*GroupPolicyInfo) error {
|
feat: Add group module proto definitions and basic types (#9631)
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->
## Description
ref: https://github.com/cosmos/cosmos-sdk/issues/7633
<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->
Following up on https://github.com/cosmos/cosmos-sdk/pull/9089, this PR is the first step towards the migration of [x/group](https://github.com/regen-network/regen-ledger/tree/master/x/group) into the SDK. It introduces the group module proto definitions (types, tx, query) and other types.
The rest of the code (module, server, client, genesis...) is dependent on various other discussions (https://github.com/cosmos/cosmos-sdk/issues/9238, https://github.com/cosmos/cosmos-sdk/discussions/9182, https://github.com/cosmos/cosmos-sdk/issues/9237, https://github.com/cosmos/cosmos-sdk/issues/7773) and will be added in follow-up PRs incrementally.
---
### Author Checklist
*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*
I have...
- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed
### Reviewers Checklist
*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*
I have...
- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2021-07-09 00:36:16 -07:00
|
|
|
for _, g := range accs {
|
|
|
|
err := g.UnpackInterfaces(unpacker)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-12-10 03:02:11 -08:00
|
|
|
|
|
|
|
type operation func(x, y math.Dec) (math.Dec, error)
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t *TallyResult) operation(vote Vote, weight string, op operation) error {
|
2021-12-10 03:02:11 -08:00
|
|
|
weightDec, err := math.NewPositiveDecFromString(weight)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
yesCount, err := t.GetYesCount()
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "yes count")
|
|
|
|
}
|
|
|
|
noCount, err := t.GetNoCount()
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "no count")
|
|
|
|
}
|
|
|
|
abstainCount, err := t.GetAbstainCount()
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "abstain count")
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
vetoCount, err := t.GetNoWithVetoCount()
|
2021-12-10 03:02:11 -08:00
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "veto count")
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
switch vote.Option {
|
|
|
|
case VOTE_OPTION_YES:
|
2021-12-10 03:02:11 -08:00
|
|
|
yesCount, err := op(yesCount, weightDec)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "yes count")
|
|
|
|
}
|
|
|
|
t.YesCount = yesCount.String()
|
2022-02-14 05:48:17 -08:00
|
|
|
case VOTE_OPTION_NO:
|
2021-12-10 03:02:11 -08:00
|
|
|
noCount, err := op(noCount, weightDec)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "no count")
|
|
|
|
}
|
|
|
|
t.NoCount = noCount.String()
|
2022-02-14 05:48:17 -08:00
|
|
|
case VOTE_OPTION_ABSTAIN:
|
2021-12-10 03:02:11 -08:00
|
|
|
abstainCount, err := op(abstainCount, weightDec)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "abstain count")
|
|
|
|
}
|
|
|
|
t.AbstainCount = abstainCount.String()
|
2022-02-14 05:48:17 -08:00
|
|
|
case VOTE_OPTION_NO_WITH_VETO:
|
2021-12-10 03:02:11 -08:00
|
|
|
vetoCount, err := op(vetoCount, weightDec)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrap(err, "veto count")
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
t.NoWithVetoCount = vetoCount.String()
|
2021-12-10 03:02:11 -08:00
|
|
|
default:
|
2022-02-14 05:48:17 -08:00
|
|
|
return sdkerrors.Wrapf(errors.ErrInvalid, "unknown vote option %s", vote.Option.String())
|
2021-12-10 03:02:11 -08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t TallyResult) GetYesCount() (math.Dec, error) {
|
2021-12-10 03:02:11 -08:00
|
|
|
yesCount, err := math.NewNonNegativeDecFromString(t.YesCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
return yesCount, nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t TallyResult) GetNoCount() (math.Dec, error) {
|
2021-12-10 03:02:11 -08:00
|
|
|
noCount, err := math.NewNonNegativeDecFromString(t.NoCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
return noCount, nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t TallyResult) GetAbstainCount() (math.Dec, error) {
|
2021-12-10 03:02:11 -08:00
|
|
|
abstainCount, err := math.NewNonNegativeDecFromString(t.AbstainCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
return abstainCount, nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t TallyResult) GetNoWithVetoCount() (math.Dec, error) {
|
|
|
|
vetoCount, err := math.NewNonNegativeDecFromString(t.NoWithVetoCount)
|
2021-12-10 03:02:11 -08:00
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
return vetoCount, nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t *TallyResult) Add(vote Vote, weight string) error {
|
2021-12-10 03:02:11 -08:00
|
|
|
if err := t.operation(vote, weight, math.Add); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TotalCounts is the sum of all weights.
|
2022-02-14 05:48:17 -08:00
|
|
|
func (t TallyResult) TotalCounts() (math.Dec, error) {
|
2021-12-10 03:02:11 -08:00
|
|
|
yesCount, err := t.GetYesCount()
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, sdkerrors.Wrap(err, "yes count")
|
|
|
|
}
|
|
|
|
noCount, err := t.GetNoCount()
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, sdkerrors.Wrap(err, "no count")
|
|
|
|
}
|
|
|
|
abstainCount, err := t.GetAbstainCount()
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, sdkerrors.Wrap(err, "abstain count")
|
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
vetoCount, err := t.GetNoWithVetoCount()
|
2021-12-10 03:02:11 -08:00
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, sdkerrors.Wrap(err, "veto count")
|
|
|
|
}
|
|
|
|
|
|
|
|
totalCounts := math.NewDecFromInt64(0)
|
|
|
|
totalCounts, err = totalCounts.Add(yesCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
totalCounts, err = totalCounts.Add(noCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
totalCounts, err = totalCounts.Add(abstainCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
totalCounts, err = totalCounts.Add(vetoCount)
|
|
|
|
if err != nil {
|
|
|
|
return math.Dec{}, err
|
|
|
|
}
|
|
|
|
return totalCounts, nil
|
|
|
|
}
|
2021-12-15 07:17:28 -08:00
|
|
|
|
2022-02-14 05:48:17 -08:00
|
|
|
// VoteOptionFromString returns a VoteOption from a string. It returns an error
|
2021-12-15 07:17:28 -08:00
|
|
|
// if the string is invalid.
|
2022-02-14 05:48:17 -08:00
|
|
|
func VoteOptionFromString(str string) (VoteOption, error) {
|
|
|
|
vo, ok := VoteOption_value[str]
|
2021-12-15 07:17:28 -08:00
|
|
|
if !ok {
|
2022-02-14 05:48:17 -08:00
|
|
|
return VOTE_OPTION_UNSPECIFIED, fmt.Errorf("'%s' is not a valid vote option", str)
|
2021-12-15 07:17:28 -08:00
|
|
|
}
|
2022-02-14 05:48:17 -08:00
|
|
|
return VoteOption(vo), nil
|
2021-12-15 07:17:28 -08:00
|
|
|
}
|