WIP on std codec

This commit is contained in:
Aaron Craelius 2020-02-26 20:14:08 -05:00
parent 2cf8a5e955
commit 8bd648eef1
4 changed files with 1055 additions and 8 deletions

1015
codec/std/std.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,28 @@
syntax = "proto3";
package cosmos_sdk.x.v1;
import "third_party/proto/cosmos-proto/cosmos.proto";
import "third_party/proto/gogoproto/gogo.proto";
import "x/gov/types/types.proto";
import "x/params/types/proposal/types.proto";
import "x/upgrade/types/types.proto";
import "x/distribution/types/types.proto";
option go_package = "github.com/cosmos/cosmos-sdk/codec/std";
message StdProposal {
oneof sum {
cosmos_sdk.x.gov.v1.TextProposal text = 1;
cosmos_sdk.x.params.v1.ParameterChangeProposal parameter_change = 2;
cosmos_sdk.x.upgrade.v1.SoftwareUpgradeProposal software_upgrade = 3;
cosmos_sdk.x.upgrade.v1.CancelSoftwareUpgradeProposal cancel_software_upgrade = 4;
cosmos_sdk.x.distribution.v1.CommunityPoolSpendProposal community_pool_spend = 5;
cosmos_sdk.x.gov.v1.ProposalBase base = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
Content content = 2 [(gogoproto.nullable) = false];
message Content {
option (cosmos_proto.interface_type) = "github.com/cosmos/cosmos-sdk/x/gov/types.Content";
oneof sum {
cosmos_sdk.x.gov.v1.TextProposal text = 1;
cosmos_sdk.x.params.v1.ParameterChangeProposal parameter_change = 2;
cosmos_sdk.x.upgrade.v1.SoftwareUpgradeProposal software_upgrade = 3;
cosmos_sdk.x.upgrade.v1.CancelSoftwareUpgradeProposal cancel_software_upgrade = 4;
cosmos_sdk.x.distribution.v1.CommunityPoolSpendProposal community_pool_spend = 5;
}
}
}

View File

@ -1,7 +1,6 @@
package simapp
import (
"github.com/cosmos/cosmos-sdk/x/gov/types"
"io"
"os"
@ -208,7 +207,7 @@ func NewSimApp(
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
app.GovKeeper = gov.NewKeeper(
types.NewAminoGovCodec(app.cdc), keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.SupplyKeeper,
appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.SupplyKeeper,
&stakingKeeper, govRouter,
)

View File

@ -2,6 +2,7 @@ package codec
import (
"github.com/cosmos/cosmos-sdk/codec"
cosmos_sdk_x_v1 "github.com/cosmos/cosmos-sdk/codec/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
@ -9,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/evidence"
eviexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
@ -151,6 +153,26 @@ func (c *Codec) UnmarshalEvidenceJSON(bz []byte) (eviexported.Evidence, error) {
return evidence.GetEvidence(), nil
}
func (c *Codec) MarshalProposal(p types.Proposal) ([]byte, error) {
stdProposal := &cosmos_sdk_x_v1.StdProposal{ProposalBase: p.ProposalBase}
if err := stdProposal.Content.SetContent(p.Content); err != nil {
return nil, err
}
return c.Marshaler.MarshalBinaryBare(stdProposal)
}
func (c *Codec) UnmarshalProposal(bz []byte) (types.Proposal, error) {
stdProposal := &cosmos_sdk_x_v1.StdProposal{}
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, stdProposal); err != nil {
return nil, err
}
return types.Proposal{
//Content: stdProposal.Content.GetContent(),
ProposalBase: stdProposal.ProposalBase,
}, nil
}
// ----------------------------------------------------------------------------
// necessary types and interfaces registered. This codec is provided to all the
// modules the application depends on.