Skip to content

Commit

Permalink
fix: remove arg requirement from gen-batch-json and move ecocredit in…
Browse files Browse the repository at this point in the history
…to app.go (#472)

* fix: use max args

* fix: remove cli args req

* update stable app config to include group and ecocredit

* fix: add rapid to modules importing ecocredit

* refactor: change gen-batch-json usage string

* fix: only ecocredit in config

* refactor: move ecocredit to app.go, remove from experimental

* fix: lint

* fix: experimental config

* fix: gen-batch-json command strings updated

* fix go mods

Co-authored-by: technicallyty <[email protected]>
  • Loading branch information
technicallyty and technicallyty authored Aug 13, 2021
1 parent a06e533 commit 7287f51
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 40 deletions.
20 changes: 19 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"net/http"
"os"

moduletypes "github.com/regen-network/regen-ledger/types/module"
ecocreditmodule "github.com/regen-network/regen-ledger/x/ecocredit/module"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -130,6 +133,7 @@ var (
vesting.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
ecocreditmodule.Module{},
}, setCustomModuleBasics()...)...,
)

Expand Down Expand Up @@ -346,8 +350,21 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
&stakingKeeper, govRouter,
)

// register experimental modules here
// register custom modules here
app.smm = setCustomModules(app, interfaceRegistry)
ecocreditModule := ecocreditmodule.NewModule(
app.GetSubspace(ecocredit.DefaultParamspace),
app.BankKeeper,
)
newModules := []moduletypes.Module{ecocreditModule}
err := app.smm.RegisterModules(newModules)
if err != nil {
panic(err)
}
err = app.smm.CompleteInitialization()
if err != nil {
panic(err)
}
app.smm.RegisterInvariants(&app.CrisisKeeper)

var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
Expand Down Expand Up @@ -650,6 +667,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(ecocredit.DefaultParamspace)
initCustomParamsKeeper(&paramsKeeper)

return paramsKeeper
Expand Down
21 changes: 4 additions & 17 deletions app/experimental_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/authz"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
Expand All @@ -22,7 +24,6 @@ import (
"github.com/regen-network/regen-ledger/types/module/server"
data "github.com/regen-network/regen-ledger/x/data/module"
ecocredittypes "github.com/regen-network/regen-ledger/x/ecocredit"
ecocredit "github.com/regen-network/regen-ledger/x/ecocredit/module"
group "github.com/regen-network/regen-ledger/x/group/module"
)

Expand All @@ -33,7 +34,6 @@ func setCustomModuleBasics() []module.AppModuleBasic {
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
),
data.Module{},
ecocredit.Module{},
group.Module{},
}
}
Expand All @@ -52,15 +52,9 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry)
newModuleManager := server.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry))

// BEGIN HACK: this is a total, ugly hack until x/auth & x/bank supports ADR 033 or we have a suitable alternative
ecocreditModule := ecocredit.NewModule(
app.GetSubspace(ecocredittypes.DefaultParamspace),
app.BankKeeper,
)

groupModule := group.Module{AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper}
// use a separate newModules from the global NewModules here because we need to pass state into the group module
newModules := []moduletypes.Module{
ecocreditModule,
data.Module{},
groupModule,
}
Expand All @@ -70,11 +64,6 @@ func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry)
}
// END HACK

err = newModuleManager.CompleteInitialization()
if err != nil {
panic(err)
}

/* New Module Wiring END */
return newModuleManager
}
Expand Down Expand Up @@ -114,7 +103,7 @@ func (app *RegenApp) registerUpgradeHandlers() {
if upgradeInfo.Name == "v0.43.0-beta1-upgrade" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
// TODO We should also add store upgrades for group, data, and ecocredit
Added: []string{"authz", "feegrant"},
Added: []string{authz.ModuleName, feegrant.ModuleName, ecocredittypes.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
Expand All @@ -140,6 +129,4 @@ func (app *RegenApp) setCustomSimulationManager() []module.AppModuleSimulation {
}
}

func initCustomParamsKeeper(paramsKeeper *paramskeeper.Keeper) {
paramsKeeper.Subspace(ecocredittypes.DefaultParamspace)
}
func initCustomParamsKeeper(paramsKeeper *paramskeeper.Keeper) {}
9 changes: 6 additions & 3 deletions app/stable_appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/authz"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ecocredittypes "github.com/regen-network/regen-ledger/x/ecocredit"

"github.com/regen-network/regen-ledger/types/module/server"
)
Expand All @@ -33,8 +36,8 @@ func setCustomModuleBasics() []module.AppModuleBasic {

// setCustomModules registers new modules with the server module manager.
// It does nothing here and returns an empty manager since we're not using experimental mode.
func setCustomModules(_ *RegenApp, _ types.InterfaceRegistry) *server.Manager {
return &server.Manager{}
func setCustomModules(app *RegenApp, interfaceRegistry types.InterfaceRegistry) *server.Manager {
return server.NewManager(app.BaseApp, codec.NewProtoCodec(interfaceRegistry))
}
func setCustomKVStoreKeys() []string {
return []string{}
Expand Down Expand Up @@ -76,7 +79,7 @@ func (app *RegenApp) registerUpgradeHandlers() {

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{"authz", "feegrant"},
Added: []string{authz.ModuleName, feegrant.ModuleName, ecocredittypes.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
Expand Down
2 changes: 1 addition & 1 deletion types/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/tendermint/tendermint v0.34.11
github.com/tendermint/tm-db v0.6.4
google.golang.org/grpc v1.38.0
pgregory.net/rapid v0.4.7 // indirect
pgregory.net/rapid v0.4.7
)

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
1 change: 1 addition & 0 deletions x/data/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
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 v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
21 changes: 9 additions & 12 deletions x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,20 @@ const (

func TxGenBatchJSONCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "gen-batch-json [--class-id class_id] [--issuances issuances] [--start-date start_date] [--end-date end_date] [--project-location project_location] [--metadata metadata]",
Use: "gen-batch-json --class-id [class_id] --issuances [issuances] --start-date [start_date] --end-date [end_date] --project-location [project_location] --metadata [metadata]",
Short: "Generates JSON to represent a new credit batch for use with create-batch command",
Long: `Generates JSON to represent a new credit batch for use with create-batch command.
Parameters:
issuer: issuer address
class_id: credit class
start_date: The beginning of the period during which this credit batch was
Required Flags:
class_id: id of the credit class
issuances: the amount of issuances to generate
start-date: The beginning of the period during which this credit batch was
quantified and verified. Format: yyyy-mm-dd.
end_date: The end of the period during which this credit batch was
end-date: The end of the period during which this credit batch was
quantified and verified. Format: yyyy-mm-dd.
metadata: base64 encoded issuance metadata
issuance: YAML encode issuance list. Note: numerical values must be written in strings.
eg: '[{recipient: "regensdgkjhs2345u79ghisodg", tradable_amount: "10", retired_amount: "2", retirement_location: "YY-ZZ 12345"}]'
Note: "tradable_amount" and "retired_amount" default to 0.
Note: "retirement_location" is only required when "retired_amount" is positive.`,
Args: cobra.ExactArgs(6),
project-location: the location of the credit batch (see documentation for proper project-location formats).
metadata: base64 encoded issuance metadata`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
classId, err := cmd.Flags().GetString(FlagClassId)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion x/ecocredit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.15

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cockroachdb/apd/v2 v2.0.2
github.com/cosmos/cosmos-sdk v0.43.0-rc0
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/gogo/protobuf v1.3.3
Expand Down
8 changes: 3 additions & 5 deletions x/group/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.43.0-beta1/go.mod h1:rpCPaC3MnityU4Io4CDZqZB4GMtPqNeYXxPk8iRqmYM=
github.com/cosmos/cosmos-sdk v0.43.0-rc0 h1:+WGHEo1N/2zRSpWpKmuquTjDskL4j9K6zTc7CfDpfOM=
github.com/cosmos/cosmos-sdk v0.43.0-rc0/go.mod h1:ctcrTEAhei9s8O3KSNvL0dxe+fVQGp07QyRb/7H9JYE=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
Expand Down Expand Up @@ -636,7 +637,6 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pariz/gountries v0.0.0-20200430155801-1c6a393df9c7/go.mod h1:U0ETmPPEsfd7CpUKNMYi68xIOL8Ww4jPZlaqNngcwqs=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down Expand Up @@ -712,12 +712,8 @@ github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzy
github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI=
github.com/regen-network/regen-ledger v1.0.0 h1:J3raJqWRUKRBtSMAA6E4ZbdlR6gTr5Fx3xyHBEvE3oU=
github.com/regen-network/regen-ledger v1.0.0/go.mod h1:qW0GomcarXVf82TctmfVpCUQ+wVEmq2Ny41heagK7D4=
github.com/regen-network/regen-ledger/x/data v0.0.0-20210602121340-fa967f821a6e h1:CoCwz8MGTn9yReHzqsQWIook/o9yUrO+q4iZoUEFvG0=
github.com/regen-network/regen-ledger/x/data v0.0.0-20210602121340-fa967f821a6e/go.mod h1:QFDn0RMBBgxcTjRvmdN9jLFFQdki9aKz2yDYhvP5l9I=
github.com/regen-network/regen-ledger/x/ecocredit v0.0.0-20210602121340-fa967f821a6e h1:OTwZr+ICbsiEUuOA51P7goFyjPMK0ZSF8Zs7VxC4hcM=
github.com/regen-network/regen-ledger/x/ecocredit v0.0.0-20210602121340-fa967f821a6e/go.mod h1:c8a1jex76k1i23wRhEH2MNCufzJ4KKVQGh1P4UJsnms=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -1344,6 +1340,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
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 v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down

0 comments on commit 7287f51

Please sign in to comment.