Skip to content

Commit

Permalink
fin
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hanna committed Sep 16, 2024
1 parent bf92e1e commit a03b46d
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 106 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
cosmossdk.io/math v1.3.0
cosmossdk.io/simapp v0.0.0-20230602123434-616841b9704d
cosmossdk.io/tools/rosetta v0.2.1
github.com/chzyer/readline v1.5.1
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.10.0
github.com/cosmos/cosmos-proto v1.0.0-beta.4
Expand All @@ -19,6 +20,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.1
github.com/manifoldco/promptui v0.9.0
github.com/ory/dockertest/v3 v3.10.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.6.0
Expand Down Expand Up @@ -66,7 +68,6 @@ require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand Down Expand Up @@ -145,7 +146,6 @@ require (
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.11 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
Expand Down Expand Up @@ -221,4 +221,7 @@ replace (

// following versions might cause unexpected behavior
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

// replace broken cosmos-sdk dep
nhooyr.io/websocket => github.com/coder/websocket v1.8.6
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ github.com/cockroachdb/pebble v1.0.0/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7Hpx
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coder/websocket v1.8.6 h1:OmNKdwUvLj7VvHnl5o8skaVghSPLjWdHGCnFbkWqs9w=
github.com/coder/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI=
github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA=
github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M=
Expand Down Expand Up @@ -1953,8 +1955,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k=
nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
7 changes: 7 additions & 0 deletions proto/atomone/gov/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ message GenesisState {
//
// Since: cosmos-sdk 0.47
Params params = 8;
// The constitution allows builders to lay a foundation and define purpose.
// This is an immutable string set in genesis.
// There are no amendments, to go outside of scope, just fork.
// constitution is an immutable string in genesis for a chain builder to lay out their vision, ideas and ideals.
//
// Since: cosmos-sdk 0.48
string constitution = 9;
}
13 changes: 13 additions & 0 deletions proto/atomone/gov/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ option go_package = "github.com/atomone-hub/atomone/x/gov/types/v1";

// Query defines the gRPC querier service for gov module
service Query {
// Constitution queries the chain's constitution.
rpc Constitution(QueryConstitutionRequest) returns (QueryConstitutionResponse) {
option (google.api.http).get = "/cosmos/gov/v1/constitution";
}

// Proposal queries proposal details based on ProposalID.
rpc Proposal(QueryProposalRequest) returns (QueryProposalResponse) {
option (google.api.http).get = "/atomone/gov/v1/proposals/{proposal_id}";
Expand Down Expand Up @@ -53,6 +58,14 @@ service Query {
}
}

// QueryConstitutionRequest is the request type for the Query/Constitution RPC method
message QueryConstitutionRequest {}

// QueryConstitutionResponse is the response type for the Query/Constitution RPC method
message QueryConstitutionResponse {
string constitution = 1;
}

// QueryProposalRequest is the request type for the Query/Proposal RPC method.
message QueryProposalRequest {
// proposal_id defines the unique id of the proposal.
Expand Down
23 changes: 23 additions & 0 deletions x/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryDeposit(),
GetCmdQueryDeposits(),
GetCmdQueryTally(),
GetCmdConstitution(),
)

return govQueryCmd
Expand Down Expand Up @@ -653,3 +654,25 @@ $ %s query gov proposer 1

return cmd
}

func GetCmdConstitution() *cobra.Command {
return &cobra.Command{
Use: "constitution",
Short: "Get the constitution",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := v1.NewQueryClient(clientCtx)

resp, err := queryClient.Constitution(cmd.Context(), &v1.QueryConstitutionRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(resp)
},
}
}
24 changes: 24 additions & 0 deletions x/gov/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"

"github.com/atomone-hub/atomone/x/gov/client/cli"
)
Expand Down Expand Up @@ -382,3 +383,26 @@ func (s *CLITestSuite) TestCmdQueryVote() {
})
}
}

func (s *CLITestSuite) TestCmdGetConstitution() {
testCases := []struct {
name string
expOutput string
}{
{
name: "get constitution",
expOutput: "constitution",
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdConstitution()
out, err := clitestutil.ExecTestCLICmd(s.clientCtx, cmd, []string{})
s.Require().NoError(err)
s.Require().Contains(out.String(), tc.expOutput)
})
}
}
3 changes: 3 additions & 0 deletions x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
if err := k.SetParams(ctx, *data.Params); err != nil {
panic(fmt.Sprintf("%s module params has not been set", types.ModuleName))
}
k.SetConstitution(ctx, data.Constitution)

// check if the deposits pool account exists
moduleAcc := k.GetGovernanceAccount(ctx)
Expand Down Expand Up @@ -60,6 +61,7 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
startingProposalID, _ := k.GetProposalID(ctx)
proposals := k.GetProposals(ctx)
params := k.GetParams(ctx)
constitution := k.GetConstitution(ctx)

var proposalsDeposits v1.Deposits
var proposalsVotes v1.Votes
Expand All @@ -77,5 +79,6 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
Votes: proposalsVotes,
Proposals: proposals,
Params: &params,
Constitution: constitution,
}
}
19 changes: 19 additions & 0 deletions x/gov/keeper/constitution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package keeper

import (
"github.com/atomone-hub/atomone/x/gov/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func (keeper Keeper) GetConstitution(ctx sdk.Context) (constitution string) {
store := ctx.KVStore(keeper.storeKey)
bz := store.Get(types.KeyConstitution)

return string(bz)
}

func (keeper Keeper) SetConstitution(ctx sdk.Context, constitution string) {
store := ctx.KVStore(keeper.storeKey)
store.Set([]byte(types.KeyConstitution), []byte(constitution))

Check failure on line 18 in x/gov/keeper/constitution.go

View workflow job for this annotation

GitHub Actions / Analyze

unnecessary conversion (unconvert)

Check failure on line 18 in x/gov/keeper/constitution.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unnecessary conversion (unconvert)
}
7 changes: 7 additions & 0 deletions x/gov/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import (

var _ v1.QueryServer = Keeper{}

func (q Keeper) Constitution(c context.Context, req *v1.QueryConstitutionRequest) (*v1.QueryConstitutionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
constitution := q.GetConstitution(ctx)

return &v1.QueryConstitutionResponse{Constitution: constitution}, nil
}

// Proposal returns proposal details based on ProposalID
func (q Keeper) Proposal(c context.Context, req *v1.QueryProposalRequest) (*v1.QueryProposalResponse, error) {
if req == nil {
Expand Down
3 changes: 3 additions & 0 deletions x/gov/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ var (

// ParamsKey is the key to query all gov params
ParamsKey = []byte{0x30}

// KeyConstitution is the key string used to store the chain's constitution
KeyConstitution = []byte("constitution")
)

var lenTime = len(sdk.FormatTimeBytes(time.Now()))
Expand Down
106 changes: 82 additions & 24 deletions x/gov/types/v1/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a03b46d

Please sign in to comment.