Skip to content

Commit

Permalink
feat(x/ecocredit)!: add projects to the credit data model (#608)
Browse files Browse the repository at this point in the history
* feat(x/ecocredit)!: add project ID

* fix genesis.proto

* fix proto-lint

* allow any approved issuer to issue batches

* allow user-defined project IDs

* Update proto/regen/ecocredit/v1alpha2/query.proto

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>

* fix

Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
  • Loading branch information
aaronc and ryanchristo authored Nov 18, 2021
1 parent 0d12019 commit 9c97674
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package regen.ecocredit.v1alpha1;
package regen.ecocredit.v1alpha2;

import "cosmos/base/v1beta1/coin.proto";

Expand All @@ -16,6 +16,23 @@ message EventCreateClass {
string admin = 2;
}

// EventCreateProject is an event emitted when a project is created.
message EventCreateProject {

// project_id is the unique ID of the project.
string project_id = 1;

// class_id is the unique ID of credit class for this project.
string class_id = 2;

// issuer is the issuer of the credit batches for this project.
string issuer = 3;

// project_location is the location of the project.
// Full documentation can be found in MsgCreateProject.project_location.
string project_location = 4;
}

// EventCreateBatch is an event emitted when a credit batch is created.
message EventCreateBatch {

Expand All @@ -39,9 +56,12 @@ message EventCreateBatch {
// quantified and verified.
string end_date = 6;

// project_location is the location of the project backing the credits in this
// batch. Full documentation can be found in MsgCreateBatch.project_location.
// project_location is the location of the project.
// Full documentation can be found in MsgCreateProject.project_location.
string project_location = 7;

// project_id is the unique ID of the project this batch belongs to.
string project_id = 8;
}

// EventReceive is an event emitted when credits are received either upon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package regen.ecocredit.v1alpha1;
package regen.ecocredit.v1alpha2;

import "regen/ecocredit/v1alpha1/types.proto";
import "regen/ecocredit/v1alpha2/types.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit";
Expand All @@ -26,6 +26,10 @@ message GenesisState {

// supplies is the list of credit batch tradable/retired supply.
repeated Supply supplies = 6;

// project_info is the list of projects.
repeated ProjectInfo project_info = 7;

}

// Balance represents tradable or retired units of a credit batch with an
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,76 @@
syntax = "proto3";

package regen.ecocredit.v1alpha1;
package regen.ecocredit.v1alpha2;

import "google/api/annotations.proto";
import "regen/ecocredit/v1alpha1/types.proto";
import "regen/ecocredit/v1alpha2/types.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit";

// Msg is the regen.ecocredit.v1alpha1 Query service.
// Msg is the regen.ecocredit.v1alpha2 Query service.
service Query {

// Classes queries for all credit classes with pagination.
rpc Classes(QueryClassesRequest) returns (QueryClassesResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/classes";
"/regen/ecocredit/v1alpha2/classes";
}

// ClassInfo queries for information on a credit class.
rpc ClassInfo(QueryClassInfoRequest) returns (QueryClassInfoResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/classes/{class_id}";
"/regen/ecocredit/v1alpha2/classes/{class_id}";
}

// Projects queries for all projects within a class with pagination.
rpc Projects(QueryProjectsRequest) returns (QueryProjectsResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha2/classes/{class_id}/projects";
}

// ClassInfo queries for information on a project.
rpc ProjectInfo(QueryProjectInfoRequest) returns (QueryProjectInfoResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha2/projects/{project_id}";
}

// Batches queries for all batches in the given credit class with pagination.
// Batches queries for all batches in the given project with pagination.
rpc Batches(QueryBatchesRequest) returns (QueryBatchesResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/classes/{class_id}/batches";
"/regen/ecocredit/v1alpha2/projects/{project_id}/batches";
}

// BatchInfo queries for information on a credit batch.
rpc BatchInfo(QueryBatchInfoRequest) returns (QueryBatchInfoResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/batches/{batch_denom}";
"/regen/ecocredit/v1alpha2/batches/{batch_denom}";
}

// Balance queries the balance (both tradable and retired) of a given credit
// batch for a given account.
rpc Balance(QueryBalanceRequest) returns (QueryBalanceResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/batches/{batch_denom}/balance/{account}";
"/regen/ecocredit/v1alpha2/batches/{batch_denom}/balance/{account}";
}

// Supply queries the tradable and retired supply of a credit batch.
rpc Supply(QuerySupplyRequest) returns (QuerySupplyResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/batches/{batch_denom}/supply";
"/regen/ecocredit/v1alpha2/batches/{batch_denom}/supply";
}

// CreditTypes returns the list of allowed types that credit classes can have.
// See Types/CreditType for more details.
rpc CreditTypes(QueryCreditTypesRequest) returns (QueryCreditTypesResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/credit-types";
"/regen/ecocredit/v1alpha2/credit-types";
}

// Params queries the ecocredit module parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get =
"/regen/ecocredit/v1alpha1/params";
"/regen/ecocredit/v1alpha2/params";
}

// SellOrder queries a sell order by its ID
Expand Down Expand Up @@ -138,18 +152,54 @@ message QueryClassInfoResponse {
ClassInfo info = 1;
}

// QueryProjectsRequest is the Query/Projects request type.
message QueryProjectsRequest {

// class_id is the unique ID of credit class to query.
string class_id = 1;

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryProjectsResponse is the Query/Projects response type.
message QueryProjectsResponse {
// projects are the fetched projects.
repeated ProjectInfo projects = 1;

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryProjectInfoRequest is the Query/Project request type.
message QueryProjectInfoRequest {

// project_id is the unique ID of the project to query.
string project_id = 1;
}

// QueryProjectInfoResponse is the Query/Project response type.
message QueryProjectInfoResponse {

// info is the ProjectInfo for the project.
ProjectInfo info = 1;
}


// QueryBatchesRequest is the Query/Batches request type.
message QueryBatchesRequest {
// class_id is the unique ID of the credit class to query.
string class_id = 1;

// project_id is the unique ID of the project to query.
string project_id = 1;

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryBatchesResponse is the Query/Batches response type.
message QueryBatchesResponse {
// batches are the fetched credit batches within the class.

// batches are the fetched credit batches within the project.
repeated BatchInfo batches = 1;

// pagination defines the pagination in the response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
syntax = "proto3";

package regen.ecocredit.v1alpha1;
package regen.ecocredit.v1alpha2;

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "regen/ecocredit/v1alpha1/types.proto";
import "regen/ecocredit/v1alpha2/types.proto";

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit";

Expand All @@ -16,7 +16,10 @@ service Msg {
// optional metadata.
rpc CreateClass(MsgCreateClass) returns (MsgCreateClassResponse);

// CreateBatch creates a new batch of credits for an existing credit class.
// CreateProject creates a new project within a credit class.
rpc CreateProject(MsgCreateProject) returns (MsgCreateProjectResponse);

// CreateBatch creates a new batch of credits for an existing project.
// This will create a new batch denom with a fixed supply. Issued credits can
// be distributed to recipients in either tradable or retired form.
rpc CreateBatch(MsgCreateBatch) returns (MsgCreateBatchResponse);
Expand Down Expand Up @@ -88,7 +91,6 @@ service Msg {

// MsgCreateClass is the Msg/CreateClass request type.
message MsgCreateClass {

// admin is the address of the account that created the credit class.
string admin = 1;

Expand All @@ -104,19 +106,54 @@ message MsgCreateClass {

// MsgCreateClassResponse is the Msg/CreateClass response type.
message MsgCreateClassResponse {

// class_id is the unique ID of the newly created credit class.
string class_id = 1;
}

// MsgCreateProjectResponse is the Msg/CreateProject request type.
message MsgCreateProject {
// issuer is the address of an approved issuer for the credit class through
// which batches will be issued. It is not required, however, that this same
// issuer issue all batches for a project.
string issuer = 1;

// class_id is the unique ID of the class within which the project is created.
string class_id = 2;

// metadata is any arbitrary metadata attached to the project.
bytes metadata = 3;

// project_location is the location of the project backing the credits in this
// batch. It is a string of the form
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters. country-code is required, while sub-national-code
// and postal-code can be added for increasing precision.
string project_location = 4;

// project_id is an optional user-specified project ID which can be used
// instead of an auto-generated ID. If project_id is provided, it must be
// unique within the credit class and match the regex [A-Za-z0-9]{2,16}
// or else the operation will fail. If project_id is omitted an ID will
// automatically be generated.
string project_id = 5;
}

// MsgCreateProjectResponse is the Msg/CreateProject response type.
message MsgCreateProjectResponse {

// project_id is the ID of the newly created project.
string project_id = 1;
}

// MsgCreateBatch is the Msg/CreateBatch request type.
message MsgCreateBatch {

// issuer is the address of the batch issuer.
string issuer = 1;

// class_id is the unique ID of the class.
string class_id = 2;
// project_id is the unique ID of the project this batch belongs to.
string project_id = 2;

// issuance are the credits issued in the batch.
repeated BatchIssuance issuance = 3;
Expand All @@ -132,14 +169,6 @@ message MsgCreateBatch {
// quantified and verified.
google.protobuf.Timestamp end_date = 6 [ (gogoproto.stdtime) = true ];

// project_location is the location of the project backing the credits in this
// batch. It is a string of the form
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters. country-code is required, while sub-national-code
// and postal-code can be added for increasing precision.
string project_location = 7;

// BatchIssuance represents the issuance of some credits in a batch to a
// single recipient.
message BatchIssuance {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package regen.ecocredit.v1alpha1;
package regen.ecocredit.v1alpha2;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
Expand Down Expand Up @@ -30,18 +30,35 @@ message ClassInfo {
uint64 num_batches = 6;
}

// ProjectInfo represents the high-level on-chain information for a project.
message ProjectInfo {

// project_id is the unique ID of the project.
string project_id = 1;

// class_id is the unique ID of credit class for this project.
string class_id = 2;

// issuer is the issuer of the credit batches for this project.
string issuer = 3;

// project_location is the location of the project.
// Full documentation can be found in MsgCreateProject.project_location.
string project_location = 4;

// metadata is any arbitrary metadata attached to the project.
bytes metadata = 5;
}

// BatchInfo represents the high-level on-chain information for a credit batch.
message BatchInfo {

// class_id is the unique ID of credit class.
string class_id = 1;
// project_id is the unique ID of the project this batch belongs to.
string project_id = 1;

// batch_denom is the unique ID of credit batch.
string batch_denom = 2;

// issuer is the issuer of the credit batch.
string issuer = 3;

// total_amount is the total number of active credits in the credit batch.
// Some of the issued credits may be cancelled and will be removed from
// total_amount and tracked in amount_cancelled. total_amount and
Expand All @@ -65,10 +82,6 @@ message BatchInfo {
// end_date is the end of the period during which this credit batch was
// quantified and verified.
google.protobuf.Timestamp end_date = 8 [ (gogoproto.stdtime) = true ];

// project_location is the location of the project backing the credits in this
// batch. Full documentation can be found in MsgCreateBatch.project_location.
string project_location = 9;
}

// Params defines the updatable global parameters of the ecocredit module for
Expand Down

0 comments on commit 9c97674

Please sign in to comment.