Skip to content

Commit

Permalink
Merge pull request #187 from decentrio/dong/fix-gov-proposal-types-dao
Browse files Browse the repository at this point in the history
fix query gov proposals
  • Loading branch information
vuong177 authored Nov 6, 2024
2 parents 113cb6e + 901988e commit a821037
Show file tree
Hide file tree
Showing 16 changed files with 3,728 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cmd/onomyd/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
ibcprovidertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"

daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)

// NewRootCmd initiates the cli for onomy chain.
Expand All @@ -51,7 +53,7 @@ func NewRootCmd() *cobra.Command {
}()

// pull request #171 refactor: Remove ics. So we need re-register proto can read state
RegisterInterfacesICSProvider(tempApplication.InterfaceRegistry())
RegisterInterfacesUsed(tempApplication.InterfaceRegistry())

initClientCtx := client.Context{}.
WithCodec(tempApplication.AppCodec()).
Expand Down Expand Up @@ -167,9 +169,10 @@ var tempDir = func() string {
}

// // pull request #171 refactor: Remove ics. So we need re-register proto can read state
func RegisterInterfacesICSProvider(registry cdctypes.InterfaceRegistry) {
func RegisterInterfacesUsed(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*govtypes.Content)(nil),
&ibcprovidertypes.ConsumerAdditionProposal{},
)
daotypes.RegisterInterfaces(registry)
}
2 changes: 1 addition & 1 deletion cmd/onomyd/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func newApp(
baseappOptions...,
)

RegisterInterfacesICSProvider(app.InterfaceRegistry())
RegisterInterfacesUsed(app.InterfaceRegistry())
return app
}

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ require (
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-sdk v0.50.8
github.com/cosmos/ibc-go/v8 v8.3.2
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142
google.golang.org/grpc v1.64.1
gopkg.in/yaml.v2 v2.4.0 // indirect
)

Expand Down
65 changes: 65 additions & 0 deletions proto/onomyprotocol copy/dao/v1/dao.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
syntax = "proto3";
package onomyprotocol.dao.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/onomyprotocol/onomy/x/dao/types";
option (gogoproto.equal_all) = true;

// FundTreasuryProposal details a dao fund treasury proposal.
message FundTreasuryProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string sender = 1;
string title = 2;
string description = 3;
repeated cosmos.base.v1beta1.Coin amount = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// ExchangeWithTreasuryProposal details a dao exchange with treasury proposal.
message ExchangeWithTreasuryProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string sender = 1;
string title = 2;
string description = 3;
repeated CoinsExchangePair coins_pairs = 4 [
(gogoproto.moretags) = "yaml:\"coins_pairs\"",
(gogoproto.nullable) = false
];
}

// CoinsExchangePair is an ask/bid coins pair to exchange.
message CoinsExchangePair {
cosmos.base.v1beta1.Coin coin_ask = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
cosmos.base.v1beta1.Coin coin_bid = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// FundAccountProposal details a dao fund account proposal.
message FundAccountProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string recipient = 1;
string title = 2;
string description = 3;
repeated cosmos.base.v1beta1.Coin amount = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
19 changes: 19 additions & 0 deletions proto/onomyprotocol copy/dao/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";
package onomyprotocol.dao.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "onomyprotocol/dao/v1/params.proto";

option go_package = "github.com/onomyprotocol/onomy/x/dao/types";

// GenesisState defines the dao module's genesis state.
message GenesisState {
// the dao module managed params
Params params = 1 [(gogoproto.nullable) = false];
// the list of dao module coins
repeated cosmos.base.v1beta1.Coin treasury_balance = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
30 changes: 30 additions & 0 deletions proto/onomyprotocol copy/dao/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package onomyprotocol.dao.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/onomyprotocol/onomy/x/dao/types";

// Params defines the parameters for the module.
message Params {
// option (gogoproto.goproto_stringer) = false;

// the period of blocks to withdraw the dao staking reward
int64 withdraw_reward_period = 1 [(gogoproto.moretags) = "yaml:\"withdraw_reward_period\""];
// the rate of total dao's staking coins to keep unstaked
bytes pool_rate = 2 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// the max rage of total dao's staking coins to be allowed in proposals
bytes max_proposal_rate = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// the max validator's commission to be staked by the dao
bytes max_val_commission = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

}
44 changes: 44 additions & 0 deletions proto/onomyprotocol copy/dao/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
syntax = "proto3";
package onomyprotocol.dao.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/api/annotations.proto";
import "onomyprotocol/dao/v1/params.proto";

option go_package = "github.com/onomyprotocol/onomy/x/dao/types";
option (gogoproto.goproto_stringer_all) = true;
option (gogoproto.goproto_getters_all) = false;

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/onomyprotocol/dao/v1/params";
}

// Treasury queries the dao treasury.
rpc Treasury(QueryTreasuryRequest) returns (QueryTreasuryResponse) {
option (google.api.http).get = "/onomyprotocol/dao/v1/treasury";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryTreasuryRequest is request type for the Query/Treasury RPC method.
message QueryTreasuryRequest {}

// QueryTreasuryResponse is response type for the Query/Treasury RPC method.
message QueryTreasuryResponse {
repeated cosmos.base.v1beta1.Coin treasury_balance = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
33 changes: 33 additions & 0 deletions x/dao/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package types

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// RegisterCodec registers the legacy amino codec.
func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&FundTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundTreasuryProposal), nil)
cdc.RegisterConcrete(&ExchangeWithTreasuryProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeExchangeWithTreasuryProposal), nil)
cdc.RegisterConcrete(&FundAccountProposal{}, fmt.Sprintf("%s/%s", ModuleName, ProposalTypeFundAccountProposal), nil)
}

// RegisterInterfaces registers the cdctypes interface.
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*govtypes.Content)(nil),
&FundTreasuryProposal{},
&ExchangeWithTreasuryProposal{},
&FundAccountProposal{},
)
}

var (
// Amino holds the LegacyAmino codec.
Amino = codec.NewLegacyAmino() //nolint:gochecknoglobals // cosmos sdk style
// ModuleCdc holds the default proto codec.
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) //nolint:gochecknoglobals // cosmos sdk style
)
Loading

0 comments on commit a821037

Please sign in to comment.