Skip to content

Commit

Permalink
refactor(x/ecocredit): clean up commands and examples (#1288)
Browse files Browse the repository at this point in the history
* refactor(x/ecocredit): clean up commands and command examples

* refactor(x/ecocredit): clean up commands and command examples

* fix format and import

* update credit types query

* Apply suggestions from code review

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* update changelog

* improve basket query examples and update test batch denom

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
  • Loading branch information
ryanchristo and technicallyty authored Jul 21, 2022
1 parent d83d79a commit 5ce8e9e
Show file tree
Hide file tree
Showing 16 changed files with 414 additions and 480 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#1274](https://github.com/regen-network/regen-ledger/pull/1274) Add `cancel-sell-order` command

#### Changed

- [#1288](https://github.com/regen-network/regen-ledger/pull/1288) Rename `types` query command to `credit-types`
- [#1288](https://github.com/regen-network/regen-ledger/pull/1288) Rename `balance` query command to `batch-balance`
- [#1288](https://github.com/regen-network/regen-ledger/pull/1288) Rename `supply` query command to `batch-supply`
- [#1288](https://github.com/regen-network/regen-ledger/pull/1288) Rename `buy-direct-batch` transaction command to `buy-direct-bulk`

#### Fixed

- [#1278](https://github.com/regen-network/regen-ledger/pull/1278) Fix `open` not set in `Msg/CreateBatch`
Expand Down
10 changes: 5 additions & 5 deletions x/ecocredit/client/basket/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func QueryBasketCmd() *cobra.Command {
Use: "basket [basket-denom]",
Short: "Gets the info for a basket",
Long: "Retrieves the information for a basket given a specific basket denom",
Example: "regen q ecocredit basket SOMEBASKET",
Example: "regen q ecocredit basket eco.uC.NCT",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -46,7 +46,7 @@ func QueryBasketsCmd() *cobra.Command {
Long: "Retrieves all baskets currently in state, with optional pagination",
Example: `
regen q ecocredit baskets
regen q ecocredit baskets --offset 1 --limit 10
regen q ecocredit baskets --limit 10 --offset 10
`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -82,7 +82,7 @@ func QueryBasketBalanceCmd() *cobra.Command {
Short: "Retrieves the balance of a credit batch in the basket",
Long: "Retrieves the balance of a credit batch in the basket",
Example: `
regen q ecocredit basket-balance BASKET C01-20210101-20220101-001
regen q ecocredit basket-balance eco.uC.NCT C01-001-20210101-20220101-001
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -116,8 +116,8 @@ func QueryBasketBalancesCmd() *cobra.Command {
Short: "Retrieves the balance of each credit batch for the given basket denom",
Long: "Retrieves the balance of each credit batch for the given basket denom",
Example: `
regen q ecocredit basket-balances BASKET1
regen q ecocredit basket-balances BASKET1 --offset 1 --limit 10
regen q ecocredit basket-balances eco.uC.NCT
regen q ecocredit basket-balances eco.uC.NCT --limit 10 --offset 10
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
104 changes: 48 additions & 56 deletions x/ecocredit/client/basket/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
FlagDisableAutoRetire = "disable-auto-retire"
FlagCreditTypeAbbreviation = "credit-type-abbreviation"
FlagCreditTypeAbbrev = "credit-type-abbrev"
FlagAllowedClasses = "allowed-classes"
FlagMinimumStartDate = "minimum-start-date"
FlagStartDateWindow = "start-date-window"
Expand All @@ -36,33 +36,28 @@ func TxCreateBasketCmd() *cobra.Command {
Long: strings.TrimSpace(`Creates a bank denom that wraps credits
Parameters:
name: the name used to create a bank denom for this basket token.
- name: the name used to create a bank denom for this basket token
Flags:
disable-auto-retire: disables the auto-retirement of credits upon taking credits
from the basket. The credits will be auto-retired if disable_auto_retire is
false unless the credits were previously put into the basket by the address
picking them from the basket, in which case they will remain tradable.
credit-type-abbreviation: filters against credits from this credit type abbreviation (e.g. "BIO").
allowed_classes: comma separated (no spaces) list of credit classes allowed to be put in
the basket (e.g. "C01,C02").
min-start-date: the earliest start date for batches of credits allowed into the basket.
start-date-window: the duration of time (in seconds) measured into the past which sets a
cutoff for batch start dates when adding new credits to the basket.
basket-fee: the fee that the curator will pay to create the basket. It must be >= the
required Params.basket_creation_fee. We include the fee explicitly here so that the
curator explicitly acknowledges paying this fee and is not surprised to learn that the
paid a big fee and didn't know beforehand.
description: the description to be used in the basket coin's bank denom metadata.`),
Example: `
$regen tx ecocredit create-basket HEAED
--from regen...
--credit-type-abbreviation=FOO
--allowed_classes="class1,class2"
--basket-fee=100regen
--description="any description"
`,
Args: cobra.ExactArgs(1),
- disable-auto-retire: disables the auto-retirement of credits upon taking credits
from the basket. The credits will be auto-retired if disable_auto_retire is
false unless the credits were previously put into the basket by the address
picking them from the basket, in which case they will remain tradable.
- credit-type-abbrev: filters against credits from this credit type abbreviation (e.g. "BIO").
- allowed_classes: comma separated (no spaces) list of credit classes allowed to be put in
the basket (e.g. "C01,C02").
- min-start-date: the earliest start date for batches of credits allowed into the basket.
- start-date-window: the duration of time (in seconds) measured into the past which sets a
cutoff for batch start dates when adding new credits to the basket.
- basket-fee: the fee that the curator will pay to create the basket. It must be >= the
required Params.basket_creation_fee. We include the fee explicitly here so that the
curator explicitly acknowledges paying this fee and is not surprised to learn that they
paid a big fee and didn't know beforehand.
- description: the description to be used in the basket coin's bank denom metadata.`),
Example: `regen tx ecocredit create-basket NCT --credit-type-abbrev C --allowed_classes C01,C02 basket-fee 100000000uregen description "NCT basket"`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -74,7 +69,7 @@ Flags:
return err
}

creditTypeName, err := cmd.Flags().GetString(FlagCreditTypeAbbreviation)
creditTypeName, err := cmd.Flags().GetString(FlagCreditTypeAbbrev)
if err != nil {
return err
}
Expand Down Expand Up @@ -158,35 +153,33 @@ Flags:

// command flags
cmd.Flags().Bool(FlagDisableAutoRetire, false, "dictates whether credits will be auto-retired upon taking")
cmd.Flags().String(FlagCreditTypeAbbreviation, "", "filters against credits from this credit type abbreviation (e.g. \"C\")")
cmd.Flags().String(FlagCreditTypeAbbrev, "", "filters against credits from this credit type abbreviation (e.g. \"C\")")
cmd.Flags().StringSlice(FlagAllowedClasses, []string{}, "comma separated (no spaces) list of credit classes allowed to be put in the basket (e.g. \"C01,C02\")")
cmd.Flags().String(FlagMinimumStartDate, "", "the earliest start date for batches of credits allowed into the basket (e.g. \"2012-01-01\")")
cmd.Flags().Uint64(FlagStartDateWindow, 0, "sets a cutoff for batch start dates when adding new credits to the basket (e.g. 1325404800)")
cmd.Flags().String(FlagBasketFee, "", "the fee that the curator will pay to create the basket (e.g. \"20regen\")")
cmd.Flags().String(FlagDenomDescription, "", "the description to be used in the bank denom metadata.")

// required flags
cmd.MarkFlagRequired(FlagCreditTypeAbbreviation)
cmd.MarkFlagRequired(FlagCreditTypeAbbrev)
cmd.MarkFlagRequired(FlagAllowedClasses)

return txFlags(cmd)
}

func TxPutInBasketCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "put-in-basket [basket_denom] [credits]",
Short: "add credits to the basket",
Long: strings.TrimSpace(`add credits to the basket.
Use: "put-in-basket [basket-denom] [credits-json]",
Short: "Add credits to a basket",
Long: strings.TrimSpace(`Add credits to a basket.
Parameters:
basket_denom: basket identifier
credits: path to JSON file containing credits to put in the basket
Flags:
from: account address of the owner
`),
Example: `
regen tx ecocredit put-in-basket eco.uC.NCT credits.json
Where the credits.json file contains:
- basket-denom: basket identifier
- credits-json: path to JSON file containing credits to put in the basket`),
Example: `regen tx ecocredit put-in-basket eco.uC.NCT credits.json
Example JSON:
[
{
Expand All @@ -197,8 +190,7 @@ Where the credits.json file contains:
"batch_denom": "C01-001-20210101-20220101-001",
"amount": "10.5"
}
]
`,
]`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -230,25 +222,25 @@ Where the credits.json file contains:

func TxTakeFromBasketCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "take-from-basket [basket_denom] [amount]",
Use: "take-from-basket [basket-denom] [amount]",
Short: "Takes credits from a basket",
Long: strings.TrimSpace(`takes credits from a basket starting from the oldest credits first.
Long: strings.TrimSpace(`Takes credits from a basket starting from the oldest credits first.
Parameters:
basket_denom: denom identifying basket from which we redeem credits.
amount: amount is a positive integer number of basket tokens to convert into credits.
- basket-denom: denom identifying basket from which we redeem credits.
- amount: number of basket tokens to convert into credits.
Flags:
from: account address of the owner of the basket.
retirement-jurisdiction: retirement jurisdiction is the optional retirement jurisdiction for the credits
which will be used only if --retire-on-take flag is true.
retire-on-take: retire on take is a boolean that dictates whether the ecocredits
received in exchange for the basket tokens will be received as
retired or tradable credits.
- retirement-jurisdiction: optional retirement jurisdiction
for the credits which will be used only if --retire-on-take flag is true.
- retire-on-take: boolean that dictates whether the ecocredits received
in exchange for the basket tokens will be received as retired or tradable credits.
`),
Example: `
regen tx ecocredit take-from-basket eco.uC.NCT 1000
regen tx ecocredit take-from-basket eco.uC.NCT 1000 --retire-on-take true --retirement-jurisdiction AQ
`,
Example: `regen tx ecocredit take-from-basket eco.uC.NCT 1000
regen tx ecocredit take-from-basket eco.uC.NCT 1000 --retire-on-take=true --retirement-jurisdiction "US-WA 98225"`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
53 changes: 21 additions & 32 deletions x/ecocredit/client/marketplace/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import (
// QuerySellOrderCmd returns a query command that retrieves information for a given sell order.
func QuerySellOrderCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sell-order [sell_order_id]",
Short: "Retrieve information for a given sell order",
Long: `Retrieve information for a given sell order`,
Example: `
regen q ecocredit sell-order 1
regen q ecocredit sell-order 1 --output json
`,
Args: cobra.ExactArgs(1),
Use: "sell-order [sell-order-id]",
Short: "Retrieve information for a given sell order",
Long: "Retrieve information for a given sell order.",
Example: "regen q ecocredit sell-order 1",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := sdkclient.GetClientQueryContext(cmd)
if err != nil {
Expand Down Expand Up @@ -52,12 +49,10 @@ regen q ecocredit sell-order 1 --output json
func QuerySellOrdersCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sell-orders",
Short: "List all sell orders with pagination",
Long: `Retrieve sell orders with pagination`,
Example: `
regen q sell-orders
regen q sell-orders --limit 10 --offset 2
`,
Short: "List all sell orders",
Long: `List all sell orders with optional pagination flags.`,
Example: `regen q sell-orders
regen q sell-orders --limit 10 --offset 10`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := sdkclient.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -90,12 +85,10 @@ regen q sell-orders --limit 10 --offset 2
func QuerySellOrdersBySellerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sell-orders-by-seller [seller]",
Short: "List all sell orders by seller address with pagination",
Long: `Retrieve sell orders by seller address with pagination`,
Example: `
regen q ecocredit sell-orders-by-seller regen1fv85...zkfu
regen q ecocredit sell-orders-by-seller regen1fv85...zkfu --limit 10 --offset 2
`,
Short: "List all sell orders by seller",
Long: `List all sell orders by seller with optional pagination flags.`,
Example: `regen q ecocredit sell-orders-by-seller regen18xvpj53vaupyfejpws5sktv5lnas5xj2phm3cf
regen q ecocredit sell-orders-by-seller regen18xvpj53vaupyfejpws5sktv5lnas5xj2phm3cf --limit 10 --offset 10`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := sdkclient.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -129,12 +122,10 @@ regen q ecocredit sell-orders-by-seller regen1fv85...zkfu --limit 10 --offset 2
func QuerySellOrdersByBatchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "sell-orders-by-batch [batch_denom]",
Short: "List all sell orders by batch denom with pagination",
Long: "Retrieve sell orders by batch by denom with pagination",
Example: `
regen q ecocredit sell-orders-by-batch C01-001-20210101-20210201-001
regen q ecocredit sell-orders-by-batch C01-001-20210101-20210201-001 --limit 10 --offset 2
`,
Short: "List all sell orders by batch denom",
Long: "List all sell orders by batch by denom with optional pagination flags.",
Example: `regen q ecocredit sell-orders-by-batch C01-001-20200101-20210101-001
regen q ecocredit sell-orders-by-batch C01-001-20200101-20210101-001 --limit 10 --offset 10`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := sdkclient.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -167,12 +158,10 @@ regen q ecocredit sell-orders-by-batch C01-001-20210101-20210201-001 --limit 10
func QueryAllowedDenomsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "allowed-denoms",
Short: "List all allowed denoms with pagination",
Long: "Retrieve allowed denoms with pagination",
Example: `
regen q ecocredit allowed-denoms
regen q ecocredit allowed-denoms --limit 10 --offset 2
`,
Short: "List all allowed denoms",
Long: "List all allowed denoms with optional pagination flags.",
Example: `regen q ecocredit allowed-denoms
regen q ecocredit allowed-denoms --limit 10 --offset 10`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := sdkclient.GetClientQueryContext(cmd)
Expand Down
Loading

0 comments on commit 5ce8e9e

Please sign in to comment.