-
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(x/ecocredit): default values for new ORM params (#1293)
* feat(x/ecocredit): default values for new ORM params * fix comment
- Loading branch information
1 parent
d97c576
commit 9a49021
Showing
14 changed files
with
223 additions
and
105 deletions.
There are no files selected for viewing
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,25 @@ | ||
package core | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// DefaultParams returns a default set of parameters. | ||
func DefaultParams() Params { | ||
return NewParams( | ||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultCreditClassFee)), | ||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultBasketFee)), | ||
[]string{}, | ||
false, | ||
) | ||
} | ||
|
||
// DefaultCreditTypes returns a default set of credit types. | ||
func DefaultCreditTypes() []CreditType { | ||
return []CreditType{ | ||
{ | ||
Name: "carbon", | ||
Abbreviation: "C", | ||
Unit: "metric ton CO2 equivalent", | ||
Precision: PRECISION, | ||
}, | ||
} | ||
} |
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,33 @@ | ||
package core | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// Validate performs a basic validation of credit batch | ||
func (b Batch) Validate() error { | ||
if err := ValidateBatchDenom(b.Denom); err != nil { | ||
return err | ||
} | ||
|
||
if b.ProjectKey == 0 { | ||
return sdkerrors.ErrInvalidRequest.Wrap("project key cannot be zero") | ||
} | ||
|
||
if b.StartDate == nil { | ||
return sdkerrors.ErrInvalidRequest.Wrap("must provide a start date for the credit batch") | ||
} | ||
if b.EndDate == nil { | ||
return sdkerrors.ErrInvalidRequest.Wrap("must provide an end date for the credit batch") | ||
} | ||
if b.EndDate.Compare(*b.StartDate) != 1 { | ||
return sdkerrors.ErrInvalidRequest.Wrapf("the batch end date (%s) must be the same as or after the batch start date (%s)", b.EndDate.String(), b.StartDate.String()) | ||
} | ||
|
||
if _, err := sdk.AccAddressFromBech32(sdk.AccAddress(b.Issuer).String()); err != nil { | ||
return sdkerrors.Wrap(err, "issuer") | ||
} | ||
|
||
return nil | ||
} |
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,33 @@ | ||
package core | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/regen-network/regen-ledger/x/ecocredit" | ||
) | ||
|
||
// Validate performs a basic validation of credit class | ||
func (c Class) Validate() error { | ||
if len(c.Metadata) > MaxMetadataLength { | ||
return ecocredit.ErrMaxLimit.Wrap("credit class metadata") | ||
} | ||
|
||
if _, err := sdk.AccAddressFromBech32(sdk.AccAddress(c.Admin).String()); err != nil { | ||
return sdkerrors.Wrap(err, "admin") | ||
} | ||
|
||
if len(c.Id) == 0 { | ||
return sdkerrors.ErrInvalidRequest.Wrap("class id cannot be empty") | ||
} | ||
|
||
if err := ValidateClassId(c.Id); err != nil { | ||
return err | ||
} | ||
|
||
if len(c.CreditTypeAbbrev) == 0 { | ||
return sdkerrors.ErrInvalidRequest.Wrap("must specify a credit type abbreviation") | ||
} | ||
|
||
return nil | ||
} |
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,19 @@ | ||
package core | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// Validate performs a basic validation of credit class issuers | ||
func (c ClassIssuer) Validate() error { | ||
if c.ClassKey == 0 { | ||
return sdkerrors.ErrInvalidRequest.Wrap("class key cannot be zero") | ||
} | ||
|
||
if _, err := sdk.AccAddressFromBech32(sdk.AccAddress(c.Issuer).String()); err != nil { | ||
return sdkerrors.Wrap(err, "issuer") | ||
} | ||
|
||
return nil | ||
} |
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,33 @@ | ||
package core | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/regen-network/regen-ledger/x/ecocredit" | ||
) | ||
|
||
// Validate performs a basic validation of project | ||
func (p Project) Validate() error { | ||
if _, err := sdk.AccAddressFromBech32(sdk.AccAddress(p.Admin).String()); err != nil { | ||
return sdkerrors.Wrap(err, "admin") | ||
} | ||
|
||
if p.ClassKey == 0 { | ||
return sdkerrors.ErrInvalidRequest.Wrap("class key cannot be zero") | ||
} | ||
|
||
if err := ValidateJurisdiction(p.Jurisdiction); err != nil { | ||
return err | ||
} | ||
|
||
if len(p.Metadata) > MaxMetadataLength { | ||
return ecocredit.ErrMaxLimit.Wrap("project metadata") | ||
} | ||
|
||
if err := ValidateProjectId(p.Id); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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.