Skip to content

Commit

Permalink
Merge branch 'master' into ty/535-credit_update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo authored Sep 23, 2021
2 parents c5d559c + 30765ed commit 059a45a
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A distributed ledger for ecology built on top of the
## Getting Started


See [Getting Started](docs/getting-started.md) for instructions how to install and run the blockchain.
See [Getting Started](docs/getting-started/README.md) for instructions how to install and run the blockchain.

## Core Features

Expand Down
10 changes: 5 additions & 5 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ module.exports = {
title: 'Overview',
path: '/modules/ecocredit/'
},
// '/modules/ecocredit/01_concepts',
// '/modules/ecocredit/02_state',
// '/modules/ecocredit/03_messages',
// '/modules/ecocredit/04_events',
// '/modules/ecocredit/05_client',
'/modules/ecocredit/01_concepts',
'/modules/ecocredit/02_state',
'/modules/ecocredit/03_messages',
'/modules/ecocredit/04_events',
'/modules/ecocredit/05_client',
{
title: 'Protobuf Documentation',
path: '/modules/ecocredit/protobuf'
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In order to install the `regen` binary, you'll need the following:
- Make `>=4`
- Go `>=1.15`

For more information, see [Prerequisites](./prerequisites).
For more information, see [Prerequisites](prerequisites.md).

## Install Regen

Expand Down
6 changes: 3 additions & 3 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5925,9 +5925,9 @@ pretty-time@^1.1.0:
integrity sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==

prismjs@^1.13.0:
version "1.24.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.24.0.tgz#0409c30068a6c52c89ef7f1089b3ca4de56be2ac"
integrity sha512-SqV5GRsNqnzCL8k5dfAjCNhUrF3pR0A9lTDSCUZeh/LIshheXJEaP0hwLz2t4XHivd2J/v2HR+gRnigzeKe3cQ==
version "1.25.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.25.0.tgz#6f822df1bdad965734b310b315a23315cf999756"
integrity sha512-WCjJHl1KEWbnkQom1+SzftbtXMKQoezOCYs5rECqMN+jP+apI7ftoflyqigqzopSO3hMhTEb0mFClA8lkolgEg==

process-nextick-args@~2.0.0:
version "2.0.1"
Expand Down
4 changes: 4 additions & 0 deletions x/data/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ The data module is intended to be a versatile module for anchoring, signing, and
3. **[Msg Service](03_messages.md)**
4. **[Events](04_events.md)**
5. **[Client](05_client.md)** -->

## Protobuf

For a complete list of the Protobuf definitions, see the [Protobuf Documentation](./protobuf.html).
15 changes: 14 additions & 1 deletion x/ecocredit/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/regen-network/regen-ledger/x/ecocredit"
)

// QueryCmd returns the parent command for all x/data CLI query commands
// QueryCmd returns the parent command for all x/ecocredit query commands.
func QueryCmd(name string) *cobra.Command {
cmd := &cobra.Command{
SuggestionsMinimumDistance: 2,
Expand Down Expand Up @@ -36,6 +36,7 @@ func qflags(cmd *cobra.Command) *cobra.Command {
return cmd
}

// QueryClassesCmd returns a query command that lists all credit classes.
func QueryClassesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "classes",
Expand All @@ -62,6 +63,8 @@ func QueryClassesCmd() *cobra.Command {
return qflags(cmd)
}

// QueryClassInfoCmd returns a query command that retrieves information for a
// given credit class.
func QueryClassInfoCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "class-info [class_id]",
Expand All @@ -80,6 +83,8 @@ func QueryClassInfoCmd() *cobra.Command {
})
}

// QueryBatchesCmd returns a query command that retrieves credit batches for a
// given credit class.
func QueryBatchesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "batches [class_id]",
Expand Down Expand Up @@ -107,6 +112,8 @@ func QueryBatchesCmd() *cobra.Command {
return qflags(cmd)
}

// QueryBatchInfoCmd returns a query command that retrieves information for a
// given credit batch.
func QueryBatchInfoCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "batch-info [batch_denom]",
Expand All @@ -127,6 +134,8 @@ func QueryBatchInfoCmd() *cobra.Command {
})
}

// QueryBalanceCmd returns a query command that retrieves the tradable and
// retired balances for a given credit batch and account address.
func QueryBalanceCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "balance [batch_denom] [account]",
Expand All @@ -146,6 +155,8 @@ func QueryBalanceCmd() *cobra.Command {
})
}

// QuerySupplyCmd returns a query command that retrieves the tradable and
// retired supply of credits for a given credit batch.
func QuerySupplyCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "supply [batch_denom]",
Expand All @@ -165,6 +176,8 @@ func QuerySupplyCmd() *cobra.Command {
})
}

// QueryCreditTypesCmd returns a query command that retrieves the list of
// approved credit types.
func QueryCreditTypesCmd() *cobra.Command {
return qflags(&cobra.Command{
Use: "types",
Expand Down
12 changes: 10 additions & 2 deletions x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func txflags(cmd *cobra.Command) *cobra.Command {
return cmd
}

// TxCreateClassCmd returns a transaction command that creates a credit class.
func TxCreateClassCmd() *cobra.Command {
return txflags(&cobra.Command{
Use: "create-class [issuer[,issuer]*] [credit type name] [metadata]",
Expand Down Expand Up @@ -120,6 +121,8 @@ const (
FlagMetadata string = "metadata"
)

// TxGenBatchJSONCmd returns a transaction command that generates JSON to
// represent a new credit batch.
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]",
Expand Down Expand Up @@ -224,6 +227,7 @@ Required Flags:
return cmd
}

// TxCreateBatchCmd returns a transaction command that creates a credit batch.
func TxCreateBatchCmd() *cobra.Command {

return txflags(&cobra.Command{
Expand Down Expand Up @@ -272,6 +276,8 @@ Parameters:
})
}

// TxSendCmd returns a transaction command that sends credits from one account
// to another.
func TxSendCmd() *cobra.Command {
return txflags(&cobra.Command{
Use: "send [recipient] [credits]",
Expand All @@ -281,7 +287,7 @@ func TxSendCmd() *cobra.Command {
Parameters:
recipient: recipient address
credits: YAML encoded credit list. Note: numerical values must be written in strings.
eg: '[{batch_denom: "100/2", tradable_amount: "5", retired_amount: "0", retirement_location: "YY-ZZ 12345"}]'
eg: '[{batch_denom: "C01-20210101-20220101-001", tradable_amount: "5", retired_amount: "0", retirement_location: "YY-ZZ 12345"}]'
Note: "retirement_location" is only required when "retired_amount" is positive.`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -302,6 +308,7 @@ Parameters:
})
}

// TxRetireCmd returns a transaction command that retires credits.
func TxRetireCmd() *cobra.Command {
return txflags(&cobra.Command{
Use: "retire [credits] [retirement_location]",
Expand All @@ -310,7 +317,7 @@ func TxRetireCmd() *cobra.Command {
Parameters:
credits: YAML encoded credit list. Note: numerical values must be written in strings.
eg: '[{batch_denom: "100/2", amount: "5"}]'
eg: '[{batch_denom: "C01-20210101-20220101-001", amount: "5"}]'
retirement_location: A string representing the location of the buyer or
beneficiary of retired credits. It has the form
<country-code>[-<region-code>[ <postal-code>]], where
Expand All @@ -337,6 +344,7 @@ Parameters:
})
}

// TxCancelCmd returns a transaction command that cancels credits.
func TxCancelCmd() *cobra.Command {
return txflags(&cobra.Command{
Use: "cancel [credits]",
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func parseCredits(creditsStr string) (credits, error) {
}, nil
}

// ParseDate parses a date using the format yyyy-mm-dd.
func ParseDate(field string, date string) (time.Time, error) {
t, err := time.Parse("2006-01-02", date)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func FormatClassID(creditType CreditType, classSeqNo uint64) string {
// - <batch seq no> is the sequence number of the batch, padded to at least
// three digits
//
// e.g C01-20190101-20200101-001
// e.g. C01-20190101-20200101-001
//
// NB: This might differ from the actual denomination used.
func FormatDenom(classId string, batchSeqNo uint64, startDate *time.Time, endDate *time.Time) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions x/ecocredit/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// AccountKeeper defines the expected interface needed to create and retrieve accounts.
type AccountKeeper interface {
// Return a new account with the next account number. Does not save the new account to the store.
NewAccount(sdk.Context, authtypes.AccountI) authtypes.AccountI
Expand All @@ -16,10 +17,9 @@ type AccountKeeper interface {
SetAccount(sdk.Context, authtypes.AccountI)
}

// BankKeeper defines the expected interface needed to retrieve account balances.
// BankKeeper defines the expected interface needed to burn and send coins and to retrieve account balances.
type BankKeeper interface {
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

}
1 change: 1 addition & 0 deletions x/ecocredit/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Module struct {
bankKeeper ecocredit.BankKeeper
}

// NewModule returns a new Module object.
func NewModule(paramSpace paramtypes.Subspace, accountKeeper ecocredit.AccountKeeper, bankKeeper ecocredit.BankKeeper) Module {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(ecocredit.ParamKeyTable())
Expand Down
10 changes: 10 additions & 0 deletions x/ecocredit/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (m MsgCreateClass) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgCreateClass) ValidateBasic() error {

if len(m.Metadata) > MaxMetadataLength {
Expand Down Expand Up @@ -58,6 +59,7 @@ func (m *MsgCreateClass) ValidateBasic() error {
return nil
}

// GetSigners returns the expected signers for MsgCreateClass.
func (m *MsgCreateClass) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Admin)
return []sdk.AccAddress{addr}
Expand All @@ -74,6 +76,7 @@ func (m MsgCreateBatch) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgCreateBatch) ValidateBasic() error {

if len(m.Metadata) > MaxMetadataLength {
Expand Down Expand Up @@ -131,6 +134,7 @@ func (m *MsgCreateBatch) ValidateBasic() error {
return nil
}

// GetSigners returns the expected signers for MsgCreateBatch.
func (m *MsgCreateBatch) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Issuer)
return []sdk.AccAddress{addr}
Expand All @@ -147,6 +151,7 @@ func (m MsgSend) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgSend) ValidateBasic() error {

if _, err := sdk.AccAddressFromBech32(m.Sender); err != nil {
Expand Down Expand Up @@ -184,6 +189,7 @@ func (m *MsgSend) ValidateBasic() error {
return nil
}

// GetSigners returns the expected signers for MsgSend.
func (m *MsgSend) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Sender)
return []sdk.AccAddress{addr}
Expand All @@ -200,6 +206,7 @@ func (m MsgRetire) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgRetire) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
return sdkerrors.Wrap(err, "holder")
Expand All @@ -225,6 +232,7 @@ func (m *MsgRetire) ValidateBasic() error {
return nil
}

// GetSigners returns the expected signers for MsgRetire.
func (m *MsgRetire) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Holder)
return []sdk.AccAddress{addr}
Expand All @@ -241,6 +249,7 @@ func (m MsgCancel) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgCancel) ValidateBasic() error {

if _, err := sdk.AccAddressFromBech32(m.Holder); err != nil {
Expand All @@ -263,6 +272,7 @@ func (m *MsgCancel) ValidateBasic() error {
return nil
}

// GetSigners returns the expected signers for MsgCancel.
func (m *MsgCancel) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Holder)
return []sdk.AccAddress{addr}
Expand Down
3 changes: 3 additions & 0 deletions x/ecocredit/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
PRECISION uint32 = 6
)

// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
Expand Down Expand Up @@ -156,6 +157,7 @@ func validateCreditTypeAbbreviation(abbr string) error {
return nil
}

// NewParams creates a new Params object.
func NewParams(creditClassFee sdk.Coins, allowlist []string, allowlistEnabled bool, creditTypes []*CreditType) Params {
return Params{
CreditClassFee: creditClassFee,
Expand All @@ -165,6 +167,7 @@ func NewParams(creditClassFee sdk.Coins, allowlist []string, allowlistEnabled bo
}
}

// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return NewParams(
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultCreditClassFeeTokens)),
Expand Down
Loading

0 comments on commit 059a45a

Please sign in to comment.