-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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(gov): support v1.Proposal in v1beta1.Proposal.Content #14347
Changes from all commits
1deaae1
2cd0bae
75bc9c5
42c4241
3a1150e
5d7b706
e4d00bb
3467512
55153fb
f1bc550
2860ed9
05b6db4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
|
||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
|
@@ -13,6 +14,7 @@ import ( | |
// ConvertToLegacyProposal takes a new proposal and attempts to convert it to the | ||
// legacy proposal format. This conversion is best effort. New proposal types that | ||
// don't have a legacy message will return a "nil" content. | ||
// Returns error when the amount of messages in `proposal` is different than one. | ||
func ConvertToLegacyProposal(proposal v1.Proposal) (v1beta1.Proposal, error) { | ||
var err error | ||
legacyProposal := v1beta1.Proposal{ | ||
|
@@ -46,6 +48,9 @@ func ConvertToLegacyProposal(proposal v1.Proposal) (v1beta1.Proposal, error) { | |
if err != nil { | ||
return v1beta1.Proposal{}, err | ||
} | ||
if len(msgs) != 1 { | ||
return v1beta1.Proposal{}, sdkerrors.ErrInvalidType.Wrap("can't convert a gov/v1 Proposal to gov/v1beta1 Proposal when amount of proposal messages is more than one") | ||
} | ||
for _, msg := range msgs { | ||
if legacyMsg, ok := msg.(*v1.MsgExecLegacyContent); ok { | ||
// check that the content struct can be unmarshalled | ||
|
@@ -54,9 +59,16 @@ func ConvertToLegacyProposal(proposal v1.Proposal) (v1beta1.Proposal, error) { | |
return v1beta1.Proposal{}, err | ||
} | ||
legacyProposal.Content = legacyMsg.Content | ||
return legacyProposal, nil | ||
} | ||
} | ||
return legacyProposal, nil | ||
// hack to fill up the content with the first message | ||
julienrbrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// this is to support clients that have not yet (properly) use gov/v1 endpoints | ||
// https://github.com/cosmos/cosmos-sdk/issues/14334 | ||
// VerifyBasic assures that we have at least one message. | ||
legacyProposal.Content, err = codectypes.NewAnyWithValue(msgs[0]) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first idea I had, was to create a simple message:
and fill it using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, the current way you have is best imo. |
||
return legacyProposal, err | ||
} | ||
|
||
func ConvertToLegacyTallyResult(tally *v1.TallyResult) (v1beta1.TallyResult, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for loop isn't needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes... too late :/ Is it worth to create another PR?