Skip to content

Commit

Permalink
feat: Update and gen proto for regen-ledger v4.0 upgrade (#37)
Browse files Browse the repository at this point in the history
* docs: add TS proto gen documentation

* feat: add and gen latest regen-ledger proto, cosmos/app and cosmos/orm using github.com/cosmos/cosmos-sdk/api v0.1.0-alpha5
  • Loading branch information
blushi authored Jun 27, 2022
1 parent f23a409 commit 0d0abff
Show file tree
Hide file tree
Showing 79 changed files with 28,806 additions and 1,165 deletions.
12 changes: 11 additions & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,18 @@ Feel free to comment on [issue #2](https://github.com/regen-network/regen-js/iss

The list of all available methods to call can be found in:

- [Regen Ledger Docs](https://docs.regen.network/getting-started.html) for Regen-specific modules (`x/data`, `x/ecocredit`)
- [Regen Ledger Docs](https://docs.regen.network) for Regen-specific modules (`x/data`, `x/ecocredit`)
- [Cosmos SDK Docs](https://docs.cosmos.network/master) for all other modules (`x/bank`, `x/staking`...)

Alternatively, you can just explore the [`./src/generated/` folder](./src/generated), all methods are commented in the code.

## TypeScript protobuf generation

For now, we update the source proto files manually in the `proto` folder.

To generate corresponding TypeScript types, use the following command:
```sh
yarn gen
```

In the near future, we'll want to automate this using [Buf Schema Registry](https://buf.build/explore) (https://github.com/regen-network/regen-js/issues/29).
15 changes: 15 additions & 0 deletions packages/api/proto/cosmos/app/module/v1alpha1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package cosmos.app.module.v1alpha1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the module config object for the cosmos.app v1 app module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/cosmos/cosmos-sdk/app"
use_package: {
name: "cosmos.app.v1alpha1"
}
};
}
36 changes: 36 additions & 0 deletions packages/api/proto/cosmos/app/v1alpha1/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax = "proto3";

package cosmos.app.v1alpha1;

import "google/protobuf/any.proto";

// Config represents the configuration for a Cosmos SDK ABCI app.
// It is intended that all state machine logic including the version of
// baseapp and tx handlers (and possibly even Tendermint) that an app needs
// can be described in a config object. For compatibility, the framework should
// allow a mixture of declarative and imperative app wiring, however, apps
// that strive for the maximum ease of maintainability should be able to describe
// their state machine with a config object alone.
message Config {
// modules are the module configurations for the app.
repeated ModuleConfig modules = 1;
}

// ModuleConfig is a module configuration for an app.
message ModuleConfig {
// name is the unique name of the module within the app. It should be a name
// that persists between different versions of a module so that modules
// can be smoothly upgraded to new versions.
//
// For example, for the module cosmos.bank.module.v1.Module, we may chose
// to simply name the module "bank" in the app. When we upgrade to
// cosmos.bank.module.v2.Module, the app-specific name "bank" stays the same
// and the framework knows that the v2 module should receive all the same state
// that the v1 module had. Note: modules should provide info on which versions
// they can migrate from in the ModuleDescriptor.can_migration_from field.
string name = 1;

// config is the config object for the module. Module config messages should
// define a ModuleDescriptor using the cosmos.app.v1alpha1.is_module extension.
google.protobuf.Any config = 2;
}
93 changes: 93 additions & 0 deletions packages/api/proto/cosmos/app/v1alpha1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
syntax = "proto3";

package cosmos.app.v1alpha1;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
// module indicates that this proto type is a config object for an app module
// and optionally provides other descriptive information about the module.
// It is recommended that a new module config object and go module is versioned
// for every state machine breaking version of a module. The recommended
// pattern for doing this is to put module config objects in a separate proto
// package from the API they expose. Ex: the cosmos.group.v1 API would be
// exposed by module configs cosmos.group.module.v1, cosmos.group.module.v2, etc.
ModuleDescriptor module = 57193479;
}

// ModuleDescriptor describes an app module.
message ModuleDescriptor {
// go_import names the package that should be imported by an app to load the
// module in the runtime module registry. Either go_import must be defined here
// or the go_package option must be defined at the file level to indicate
// to users where to location the module implementation. go_import takes
// precedence over go_package when both are defined.
string go_import = 1;

// use_package refers to a protobuf package that this module
// uses and exposes to the world. In an app, only one module should "use"
// or own a single protobuf package. It is assumed that the module uses
// all of the .proto files in a single package.
repeated PackageReference use_package = 2;

// can_migrate_from defines which module versions this module can migrate
// state from. The framework will check that one module version is able to
// migrate from a previous module version before attempting to update its
// config. It is assumed that modules can transitively migrate from earlier
// versions. For instance if v3 declares it can migrate from v2, and v2
// declares it can migrate from v1, the framework knows how to migrate
// from v1 to v3, assuming all 3 module versions are registered at runtime.
repeated MigrateFromInfo can_migrate_from = 3;
}

// PackageReference is a reference to a protobuf package used by a module.
message PackageReference {
// name is the fully-qualified name of the package.
string name = 1;

// revision is the optional revision of the package that is being used.
// Protobuf packages used in Cosmos should generally have a major version
// as the last part of the package name, ex. foo.bar.baz.v1.
// The revision of a package can be thought of as the minor version of a
// package which has additional backwards compatible definitions that weren't
// present in a previous version.
//
// A package should indicate its revision with a source code comment
// above the package declaration in one of its fields containing the
// test "Revision N" where N is an integer revision. All packages start
// at revision 0 the first time they are released in a module.
//
// When a new version of a module is released and items are added to existing
// .proto files, these definitions should contain comments of the form
// "Since Revision N" where N is an integer revision.
//
// When the module runtime starts up, it will check the pinned proto
// image and panic if there are runtime protobuf definitions that are not
// in the pinned descriptor which do not have
// a "Since Revision N" comment or have a "Since Revision N" comment where
// N is <= to the revision specified here. This indicates that the protobuf
// files have been updated, but the pinned file descriptor hasn't.
//
// If there are items in the pinned file descriptor with a revision
// greater than the value indicated here, this will also cause a panic
// as it may mean that the pinned descriptor for a legacy module has been
// improperly updated or that there is some other versioning discrepancy.
// Runtime protobuf definitions will also be checked for compatibility
// with pinned file descriptors to make sure there are no incompatible changes.
//
// This behavior ensures that:
// * pinned proto images are up-to-date
// * protobuf files are carefully annotated with revision comments which
// are important good client UX
// * protobuf files are changed in backwards and forwards compatible ways
uint32 revision = 2;
}

// MigrateFromInfo is information on a module version that a newer module
// can migrate from.
message MigrateFromInfo {

// module is the fully-qualified protobuf name of the module config object
// for the previous module version, ex: "cosmos.group.module.v1.Module".
string module = 1;
}
22 changes: 22 additions & 0 deletions packages/api/proto/cosmos/app/v1alpha1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package cosmos.app.v1alpha1;

import "cosmos/app/v1alpha1/config.proto";

// Query is the app module query service.
service Query {

// Config returns the current app config.
rpc Config(QueryConfigRequest) returns (QueryConfigResponse) {}
}

// QueryConfigRequest is the Query/Config request type.
message QueryConfigRequest {}

// QueryConfigRequest is the Query/Config response type.
message QueryConfigResponse {

// config is the current app config.
Config config = 1;
}
14 changes: 14 additions & 0 deletions packages/api/proto/cosmos/orm/module/v1alpha1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";

package cosmos.orm.module.v1alpha1;

import "cosmos/app/v1alpha1/module.proto";

// Module defines the ORM module which adds providers to the app container for
// module-scoped DB's. In the future it may provide gRPC services for interacting
// with ORM data.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/cosmos/cosmos-sdk/orm"
};
}
107 changes: 107 additions & 0 deletions packages/api/proto/cosmos/orm/v1alpha1/orm.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
syntax = "proto3";

package cosmos.orm.v1alpha1;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {

// table specifies that this message will be used as an ORM table. It cannot
// be used together with the singleton option.
TableDescriptor table = 104503790;

// singleton specifies that this message will be used as an ORM singleton. It cannot
// be used together with the table option.
SingletonDescriptor singleton = 104503791;
}

// TableDescriptor describes an ORM table.
message TableDescriptor {

// primary_key defines the primary key for the table.
PrimaryKeyDescriptor primary_key = 1;

// index defines one or more secondary indexes.
repeated SecondaryIndexDescriptor index = 2;

// id is a non-zero integer ID that must be unique within the
// tables and singletons in this file. It may be deprecated in the future when this
// can be auto-generated.
uint32 id = 3;
}

// PrimaryKeyDescriptor describes a table primary key.
message PrimaryKeyDescriptor {

// fields is a comma-separated list of fields in the primary key. Spaces are
// not allowed. Supported field types, their encodings, and any applicable constraints
// are described below.
// - uint32 are encoded as 2,3,4 or 5 bytes using a compact encoding that
// is suitable for sorted iteration (not varint encoding). This type is
// well-suited for small integers.
// - uint64 are encoded as 2,4,6 or 9 bytes using a compact encoding that
// is suitable for sorted iteration (not varint encoding). This type is
// well-suited for small integers such as auto-incrementing sequences.
// - fixed32, fixed64 are encoded as big-endian fixed width bytes and support
// sorted iteration. These types are well-suited for encoding fixed with
// decimals as integers.
// - string's are encoded as raw bytes in terminal key segments and null-terminated
// in non-terminal segments. Null characters are thus forbidden in strings.
// string fields support sorted iteration.
// - bytes are encoded as raw bytes in terminal segments and length-prefixed
// with a single byte in non-terminal segments. Because of this byte arrays
// longer than 255 bytes are unsupported and bytes fields should not
// be assumed to be lexically sorted. If you have a byte array longer than
// 255 bytes that you'd like to index, you should consider hashing it first.
// - int32, sint32, int64, sint64, sfixed32, sfixed64 are encoded as fixed width bytes with
// an encoding that enables sorted iteration.
// - google.protobuf.Timestamp and google.protobuf.Duration are encoded
// as 12 bytes using an encoding that enables sorted iteration.
// - enum fields are encoded using varint encoding and do not support sorted
// iteration.
// - bool fields are encoded as a single byte 0 or 1.
//
// All other fields types are unsupported in keys including repeated and
// oneof fields.
//
// Primary keys are prefixed by the varint encoded table id and the byte 0x0
// plus any additional prefix specified by the schema.
string fields = 1;

// auto_increment specifies that the primary key is generated by an
// auto-incrementing integer. If this is set to true fields must only
// contain one field of that is of type uint64.
bool auto_increment = 2;
}

// PrimaryKeyDescriptor describes a table secondary index.
message SecondaryIndexDescriptor {

// fields is a comma-separated list of fields in the index. The supported
// field types are the same as those for PrimaryKeyDescriptor.fields.
// Index keys are prefixed by the varint encoded table id and the varint
// encoded index id plus any additional prefix specified by the schema.
//
// In addition the the field segments, non-unique index keys are suffixed with
// any additional primary key fields not present in the index fields so that the
// primary key can be reconstructed. Unique indexes instead of being suffixed
// store the remaining primary key fields in the value..
string fields = 1;

// id is a non-zero integer ID that must be unique within the indexes for this
// table and less than 32768. It may be deprecated in the future when this can
// be auto-generated.
uint32 id = 2;

// unique specifies that this an unique index.
bool unique = 3;
}

// TableDescriptor describes an ORM singleton table which has at most one instance.
message SingletonDescriptor {

// id is a non-zero integer ID that must be unique within the
// tables and singletons in this file. It may be deprecated in the future when this
// can be auto-generated.
uint32 id = 1;
}
76 changes: 76 additions & 0 deletions packages/api/proto/cosmos/orm/v1alpha1/schema.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
syntax = "proto3";

package cosmos.orm.v1alpha1;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
// module_schema is used to define the ORM schema for an app module.
// All module config messages that use module_schema must also declare
// themselves as app module config messages using the cosmos.app.v1.is_module
// option.
ModuleSchemaDescriptor module_schema = 104503792;
}

// ModuleSchemaDescriptor describe's a module's ORM schema.
message ModuleSchemaDescriptor {
repeated FileEntry schema_file = 1;

// FileEntry describes an ORM file used in a module.
message FileEntry {
// id is a prefix that will be varint encoded and prepended to all the
// table keys specified in the file's tables.
uint32 id = 1;

// proto_file_name is the name of a file .proto in that contains
// table definitions. The .proto file must be in a package that the
// module has referenced using cosmos.app.v1.ModuleDescriptor.use_package.
string proto_file_name = 2;

// storage_type optionally indicates the type of storage this file's
// tables should used. If it is left unspecified, the default KV-storage
// of the app will be used.
StorageType storage_type = 3;
}

// prefix is an optional prefix that precedes all keys in this module's
// store.
bytes prefix = 2;
}

// StorageType
enum StorageType {
// STORAGE_TYPE_DEFAULT_UNSPECIFIED indicates the persistent
// KV-storage where primary key entries are stored in merkle-tree
// backed commitment storage and indexes and seqs are stored in
// fast index storage. Note that the Cosmos SDK before store/v2
// does not support this.
STORAGE_TYPE_DEFAULT_UNSPECIFIED = 0;

// STORAGE_TYPE_MEMORY indicates in-memory storage that will be
// reloaded every time an app restarts. Tables with this type of storage
// will by default be ignored when importing and exporting a module's
// state from JSON.
STORAGE_TYPE_MEMORY = 1;

// STORAGE_TYPE_TRANSIENT indicates transient storage that is reset
// at the end of every block. Tables with this type of storage
// will by default be ignored when importing and exporting a module's
// state from JSON.
STORAGE_TYPE_TRANSIENT = 2;

// STORAGE_TYPE_INDEX indicates persistent storage which is not backed
// by a merkle-tree and won't affect the app hash. Note that the Cosmos SDK
// before store/v2 does not support this.
STORAGE_TYPE_INDEX = 3;

// STORAGE_TYPE_INDEX indicates persistent storage which is backed by
// a merkle-tree. With this type of storage, both primary and index keys
// will affect the app hash and this is generally less efficient
// than using STORAGE_TYPE_DEFAULT_UNSPECIFIED which separates index
// keys into index storage. Note that modules built with the
// Cosmos SDK before store/v2 must specify STORAGE_TYPE_COMMITMENT
// instead of STORAGE_TYPE_DEFAULT_UNSPECIFIED or STORAGE_TYPE_INDEX
// because this is the only type of persistent storage available.
STORAGE_TYPE_COMMITMENT = 4;
}
Loading

0 comments on commit 0d0abff

Please sign in to comment.