-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecocredit): allow denom proposal handler (#1072)
* wip: ask denom proposal * chore: move proposal to core * feat: ask denom proposal handler * fix: add ask denom setup to integration tests * fix: add ask denom to cli integration tests * chore: add proto message comment * fix: grpc test use default bond denom * chore: cleanup * feat: added event to credit type handler * chore: fix param changes test * perf: switch to single regexp match for credit type validation * chore: fix error strings, cli doc * chore: cleanup * fix: cli example str * refactor: consolidate naming * chore: remove edit * chore: cleanup * chore: apply suggestions from code review Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> * chore: fix cli string, remove exponent check * chore: address review, cleanup askDenom remnants, change event name * chore: imports * fix: integration test fail * chore: check SI units * fix: add type registration * chore: address review comments * refactor: AllowedDenomProposal -> AllowDenomProposal * refactor: file rename add_allowed_denom.go -> allow_denom.go * refactor: change handle function name * chore: address review * chore: use go install * Revert "chore: use go install" This reverts commit 4499637. * refactor: change handlefunc name * chore: fix example string, remove flags * Update x/ecocredit/client/marketplace/proposal.go Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> * fix: add required gov proposal type registration for credit type proposal Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com> Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> Co-authored-by: Tyler Goodman <tylergoodman@Tylers-MacBook-Pro.local>
- Loading branch information
1 parent
8231250
commit ea43f14
Showing
52 changed files
with
2,671 additions
and
3,114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "proto3"; | ||
|
||
package regen.ecocredit.marketplace.v1; | ||
|
||
import "regen/ecocredit/marketplace/v1/state.proto"; | ||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/marketplace"; | ||
|
||
// AllowDenomProposal is a gov Content type for approving a denom for use in the | ||
// marketplace. | ||
message AllowDenomProposal { | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
// title is the title of the proposal. | ||
string title = 1; | ||
|
||
// description is the description of the proposal. | ||
string description = 2; | ||
|
||
// denom contains coin denom information that will be added to the | ||
// list of allowed denoms for use in the marketplace. | ||
AllowedDenom denom = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package marketplace | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client" | ||
"github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
"github.com/cosmos/cosmos-sdk/x/gov/client/rest" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
"github.com/regen-network/regen-ledger/x/ecocredit/marketplace" | ||
) | ||
|
||
var AllowDenomProposalHandler = govclient.NewProposalHandler(TxAllowDenomProposal, func(context client.Context) rest.ProposalRESTHandler { | ||
return rest.ProposalRESTHandler{ | ||
SubRoute: "", | ||
Handler: nil, | ||
} | ||
}) | ||
|
||
func TxAllowDenomProposal() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "allow-denom-proposal [path_to_file.json] [flags]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Submit a proposal to add a denom to the list of allowed denoms", | ||
Long: strings.TrimSpace(`Submit a proposal to add a denom to the list of allowed denoms for use in the marketplace. | ||
The json file MUST take the following form: | ||
{ | ||
"title": "some title", | ||
"description": "some description", | ||
"denom": { | ||
"bank_denom": "uregen", | ||
"display_denom": "regen", | ||
"exponent": 6 | ||
} | ||
} | ||
The bank denom is the underlying coin denom (i.e. ibc/CDC4587874B85BEA4FCEC3CEA5A1195139799A1FEE711A07D972537E18FD). | ||
Display denom is used for display purposes, and serves as the name of the coin denom (i.e. ATOM). Exponent is used to | ||
relate the bank_denom to the display_denom and is informational`), | ||
Example: `regen tx gov submit-proposal allow-denom-proposal my_file.json --deposit=100regen`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
proposalFile, err := ioutil.ReadFile(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var proposal marketplace.AllowDenomProposal | ||
err = json.Unmarshal(proposalFile, &proposal) | ||
if err != nil { | ||
return err | ||
} | ||
if err := proposal.ValidateBasic(); err != nil { | ||
return fmt.Errorf("invalid proposal: %w", err) | ||
} | ||
|
||
depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) | ||
if err != nil { | ||
return err | ||
} | ||
deposit, err := sdk.ParseCoinsNormalized(depositStr) | ||
if err != nil { | ||
return err | ||
} | ||
var content types.Content = &proposal | ||
msg, err := types.NewMsgSubmitProposal(content, deposit, clientCtx.GetFromAddress()) | ||
if err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.