Skip to content

Commit

Permalink
Merge pull request #450 from AssetMantle/deepanshutr/master
Browse files Browse the repository at this point in the history
Deepanshutr/master
  • Loading branch information
deepanshutr committed Sep 2, 2024
2 parents 7c1b155 + 51cdf2e commit 584dc0c
Show file tree
Hide file tree
Showing 685 changed files with 10,918 additions and 20,147 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AssetMantle/schema v0.0.0-20240206102051-27352b802163
github.com/CosmWasm/wasmd v0.45.0
github.com/Shopify/sarama v1.19.0
github.com/cometbft/cometbft v0.37.5
github.com/cometbft/cometbft v0.37.7
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.11
github.com/cosmos/gogoproto v1.4.10
Expand All @@ -22,7 +22,7 @@ require (
google.golang.org/grpc v1.62.1
)

replace github.com/AssetMantle/schema => ../schema
//replace github.com/AssetMantle/schema => ../schema

require (
cloud.google.com/go v0.112.0 // indirect
Expand Down Expand Up @@ -115,6 +115,7 @@ require (
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE
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=
github.com/cometbft/cometbft v0.37.5 h1:/U/TlgMh4NdnXNo+YU9T2NMCWyhXNDF34Mx582jlvq0=
github.com/cometbft/cometbft v0.37.5/go.mod h1:QC+mU0lBhKn8r9qvmnq53Dmf3DWBt4VtkcKw2C81wxY=
github.com/cometbft/cometbft v0.37.7 h1:pwC0PNfGcbKbAKyK/sWm+LwuiYmT00C3bF2nEnnjJ/k=
github.com/cometbft/cometbft v0.37.7/go.mod h1:gFGCFXNGDci6tMLemANPGTfU+j4+oH63PjeLe0iIjJk=
github.com/cometbft/cometbft-db v0.8.0 h1:vUMDaH3ApkX8m0KZvOFFy9b5DZHBAjsnEuo9AKVZpjo=
github.com/cometbft/cometbft-db v0.8.0/go.mod h1:6ASCP4pfhmrCBpfk01/9E1SI29nD3HfVHrY4PG8x5c0=
github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4=
Expand Down Expand Up @@ -774,6 +774,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
Expand Down
11 changes: 2 additions & 9 deletions helpers/base/cli_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ package base

import (
"fmt"
"github.com/AssetMantle/modules/utilities/rest"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/spf13/cobra"

"github.com/AssetMantle/modules/helpers"
Expand Down Expand Up @@ -85,12 +82,8 @@ func (cliCommand cliCommand) ReadString(cliFlag helpers.CLIFlag) string {
panic(fmt.Errorf("uregistered flag %v type %T", cliFlag.GetName(), cliFlag.GetValue()))
}

func (cliCommand cliCommand) ReadBaseReq(context client.Context) rest.BaseReq {
return rest.BaseReq{
From: context.GetFromAddress().String(),
ChainID: context.ChainID,
Simulate: context.Simulate,
}
func (cliCommand cliCommand) ReadCommonTransactionRequest(context client.Context) helpers.CommonTransactionRequest {
return helpers.NewCommonTransactionRequestFromContext(context)
}
func (cliCommand cliCommand) CreateCommand(runE func(command *cobra.Command, args []string) error) *cobra.Command {
command := &cobra.Command{
Expand Down
11 changes: 5 additions & 6 deletions helpers/base/cli_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package base

import (
"github.com/AssetMantle/modules/utilities/rest"
"reflect"
"testing"

Expand Down Expand Up @@ -103,11 +102,11 @@ func Test_cliCommand_ReadBaseReq(t *testing.T) {
name string
fields fields
args args
want rest.BaseReq
want helpers.CommonTransactionRequest
}{

{"+ve", fields{"", "", "", testCliFlagList}, args{client.Context{ChainID: "chainID"}}, rest.BaseReq{ChainID: "chainID"}},
{"-ve for nil", fields{"", "", "", nil}, args{client.Context{ChainID: ""}}, rest.BaseReq{ChainID: ""}},
{"+ve", fields{"", "", "", testCliFlagList}, args{client.Context{ChainID: "chainID"}}, helpers.PrototypeCommonTransactionRequest()},
{"-ve for nil", fields{"", "", "", nil}, args{client.Context{ChainID: ""}}, helpers.PrototypeCommonTransactionRequest()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -117,8 +116,8 @@ func Test_cliCommand_ReadBaseReq(t *testing.T) {
long: tt.fields.long,
cliFlagList: tt.fields.cliFlagList,
}
if got := cliCommand.ReadBaseReq(tt.args.context); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReadBaseReq() = %v, want %v", got, tt.want)
if got := cliCommand.ReadCommonTransactionRequest(tt.args.context); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReadCommonTransactionRequest() = %v, want %v", got, tt.want)
}
})
}
Expand Down
1 change: 0 additions & 1 deletion helpers/base/cli_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package base

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down
5 changes: 0 additions & 5 deletions helpers/base/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package base

import (
"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/utilities/rest/id_getters/docs"
schemaCodec "github.com/AssetMantle/schema/codec"
sdkClient "github.com/cosmos/cosmos-sdk/client"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
sdkCodecTypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -33,9 +31,6 @@ func (codec codec) InterfaceRegistry() sdkCodecTypes.InterfaceRegistry {
func (codec codec) Initialize(moduleManager helpers.ModuleManager) helpers.Codec {
std.RegisterLegacyAminoCodec(codec.legacyAmino)
std.RegisterInterfaces(codec.interfaceRegistry)
helpers.RegisterLegacyAminoCodec(codec.legacyAmino)
schemaCodec.RegisterLegacyAminoCodec(codec.legacyAmino)
docs.RegisterLegacyAminoCodec(codec.legacyAmino)
moduleManager.RegisterLegacyAminoCodec(codec.legacyAmino)
moduleManager.RegisterInterfaces(codec.interfaceRegistry)
return codec
Expand Down
1 change: 0 additions & 1 deletion helpers/base/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package base

import (
"context"

"github.com/AssetMantle/modules/helpers"
)

Expand Down
3 changes: 1 addition & 2 deletions helpers/base/invariants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package base

import (
sdkTypes "github.com/cosmos/cosmos-sdk/types"

"github.com/AssetMantle/modules/helpers"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
)

type invariants struct {
Expand Down
3 changes: 1 addition & 2 deletions helpers/base/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"bytes"
"context"
"fmt"
sdkTypes "github.com/cosmos/cosmos-sdk/types"

prefixStore "github.com/cosmos/cosmos-sdk/store/prefix"
storeTypes "github.com/cosmos/cosmos-sdk/store/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"

"github.com/AssetMantle/modules/helpers"
Expand Down
94 changes: 12 additions & 82 deletions helpers/base/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ package base
import (
"encoding/json"
"fmt"
storeTypes "github.com/cosmos/cosmos-sdk/store/types"
"math/rand"

abciTypes "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
sdkCodec "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
storeTypes "github.com/cosmos/cosmos-sdk/store/types"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
sdkModuleTypes "github.com/cosmos/cosmos-sdk/types/module"
simulationTypes "github.com/cosmos/cosmos-sdk/types/simulation"
paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"math/rand"

"github.com/AssetMantle/modules/helpers"
)
Expand Down Expand Up @@ -49,26 +48,13 @@ type module struct {

var _ helpers.Module = (*module)(nil)

func (module module) IsOnePerModuleType() {
//TODO implement me
panic("implement me")
}

func (module module) IsAppModule() {
//TODO implement me
panic("implement me")
}
func (module module) Name() string {
return module.name
}
func (module module) GetTransactions() helpers.Transactions {
return module.transactions
}
func (module module) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) {
for _, transaction := range module.transactionsPrototype().Get() {
transaction.RegisterLegacyAminoCodec(legacyAmino)
}
}
func (module module) RegisterLegacyAminoCodec(_ *sdkCodec.LegacyAmino) {}
func (module module) RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) {
for _, transaction := range module.transactionsPrototype().Get() {
transaction.RegisterInterfaces(interfaceRegistry)
Expand All @@ -82,29 +68,19 @@ func (module module) ValidateGenesis(jsonCodec sdkCodec.JSONCodec, _ client.TxEn
return genesisState.ValidateBasic(module.parameterManagerPrototype())
}
func (module module) RegisterRESTRoutes(context client.Context, router *mux.Router) {
router.HandleFunc("/"+module.Name()+"/parameters", module.parameterManagerPrototype().RESTQueryHandler(context)).Methods("GET")

for _, query := range module.queriesPrototype().Get() {
router.HandleFunc("/"+module.Name()+"/"+query.GetName(), query.RESTQueryHandler(context)).Methods("GET")
}

for _, transaction := range module.transactionsPrototype().Get() {
router.HandleFunc("/"+module.Name()+"/"+transaction.GetName(), transaction.RESTRequestHandler(context)).Methods("POST")
}
}
func (module module) RegisterGRPCGatewayRoutes(context client.Context, serveMux *runtime.ServeMux) {
for _, query := range module.queriesPrototype().Get() {
query.RegisterGRPCGatewayRoute(context, serveMux)
router.HandleFunc(query.GetServicePath(), query.RESTQueryHandler(context)).Methods("GET")
}

for _, transaction := range module.transactionsPrototype().Get() {
transaction.RegisterGRPCGatewayRoute(context, serveMux)
router.HandleFunc(transaction.GetServicePath(), transaction.RESTRequestHandler(context)).Methods("POST")
}
}
func (module module) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
func (module module) GetTxCmd() *cobra.Command {
rootTransactionCommand := &cobra.Command{
Use: module.name,
Short: "GetProperty root transaction command.",
Short: module.name + " root transaction command.",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
Expand All @@ -124,7 +100,7 @@ func (module module) GetTxCmd() *cobra.Command {
func (module module) GetQueryCmd() *cobra.Command {
rootQueryCommand := &cobra.Command{
Use: module.name,
Short: "GetProperty root query command.",
Short: module.Name() + " root query command.",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
Expand All @@ -145,62 +121,23 @@ func (module module) GenerateGenesisState(simulationState *sdkModuleTypes.Simula
module.simulatorPrototype().RandomizedGenesisState(simulationState)
}
func (module module) ProposalMsgs(simulationState sdkModuleTypes.SimulationState) []simulationTypes.WeightedProposalMsg {
//TODO implement me
panic("implement me")
}
func (module module) ProposalContents(simulationState sdkModuleTypes.SimulationState) []simulationTypes.WeightedProposalContent {
return module.simulatorPrototype().WeightedProposalContentList(simulationState)
return module.simulatorPrototype().ProposalMessages(simulationState)
}
func (module module) RandomizedParams(r *rand.Rand) []simulationTypes.LegacyParamChange {
return module.simulatorPrototype().ParamChangeList(r)
}
func (module module) RegisterStoreDecoder(storeDecoderRegistry sdkTypes.StoreDecoderRegistry) {
storeDecoderRegistry[module.name] = module.mapperPrototype().StoreDecoder
}
func (module module) WeightedOperations(simulationState sdkModuleTypes.SimulationState) []simulationTypes.WeightedOperation {
return module.simulatorPrototype().WeightedOperations(simulationState, module)
}
func (module module) RegisterStoreDecoder(storeDecoderRegistry sdkTypes.StoreDecoderRegistry) {
storeDecoderRegistry[module.name] = module.mapperPrototype().StoreDecoder
}
func (module module) RegisterInvariants(invariantRegistry sdkTypes.InvariantRegistry) {
module.invariantsPrototype().Register(invariantRegistry)
}

// TODO remove if unnecessary
//
// func (module module) Route() sdkTypes.Route {
// return sdkTypes.NewRoute(module.Name(), func(context sdkTypes.Context, msg sdkTypes.Msg) (*sdkTypes.Result, error) {
// if module.transactions == nil {
// panic(fmt.Errorf("transactions for module %s not initialized", module.Name()))
// }
//
// if message, ok := msg.(helpers.Message); ok {
// if transaction := module.transactions.GetTransaction(message.Type()); transaction != nil {
// return transaction.HandleMessage(sdkTypes.WrapSDKContext(context.WithEventManager(sdkTypes.NewEventManager())), message)
// }
// }
// return nil, fmt.Errorf("message type %T is not supported by module %s", msg, module.Name())
// })
// }
func (module module) QuerierRoute() string {
return module.name
}

// func (module module) LegacyQuerierHandler(_ *sdkCodec.LegacyAmino) sdkTypes.Querier {
// return func(context sdkTypes.Context, path []string, requestQuery abciTypes.RequestQuery) ([]byte, error) {
// if module.queries == nil {
// panic(fmt.Errorf("queries for module %s not initialized", module.Name()))
// }
//
// if query := module.queries.GetQuery(path[0]); query != nil {
// return query.HandleQuery(sdkTypes.WrapSDKContext(context), requestQuery)
// }
//
// if path[0] == "parameters" {
// return CodecPrototype().MarshalJSON(module.parameterManager.Fetch(sdkTypes.WrapSDKContext(context)).Get())
// }
//
// return nil, fmt.Errorf("unknown query path, %v for module %v", path[0], module.Name())
// }
// }
func (module module) RegisterServices(configurator sdkModuleTypes.Configurator) {
for _, query := range module.queries.Get() {
query.RegisterService(configurator)
Expand Down Expand Up @@ -247,13 +184,6 @@ func (module module) GetAuxiliary(auxiliaryName string) helpers.Auxiliary {

panic(fmt.Errorf("auxiliary %v not found/initialized", auxiliaryName))
}
func (module module) DecodeModuleTransactionRequest(transactionName string, rawMessage json.RawMessage) (sdkTypes.Msg, error) {
if transaction := module.transactionsPrototype().GetTransaction(transactionName); transaction != nil {
return transaction.DecodeTransactionRequest(rawMessage)
}

return nil, fmt.Errorf("transaction %s is not supported by module %s", transactionName, module.Name())
}
func (module module) Initialize(kvStoreKey *storeTypes.KVStoreKey, paramsSubspace paramsTypes.Subspace, auxiliaryKeepers ...interface{}) helpers.Module {
module.mapper = module.mapperPrototype().Initialize(kvStoreKey)

Expand Down
Loading

0 comments on commit 584dc0c

Please sign in to comment.