Skip to content

Commit

Permalink
feat: Add Table-Store (aka ORM) package - Index and Iterator (cosmos#…
Browse files Browse the repository at this point in the history
…10451)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

ref: cosmos#9237, cosmos#9156

This PR is a follow-up of cosmos#10415 and cosmos#9751.
It adds multi-key secondary indexes, iterator and pagination support.

There will be one last follow-up PR for adding import/export genesis features.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
blushi authored and blewater committed Dec 8, 2021
1 parent 9e15df4 commit 530647b
Show file tree
Hide file tree
Showing 30 changed files with 3,231 additions and 154 deletions.
27 changes: 0 additions & 27 deletions types/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ const RootCodespace = "sdk"
// UndefinedCodespace when we explicitly declare no codespace
const UndefinedCodespace = "undefined"

// mathCodespace is the codespace for all errors defined in math package
const mathCodespace = "math"

// mathCodespace is the codespace for all errors defined in orm package
const ormCodespace = "orm"

var (
// errInternal should never be exposed, but we reserve this code for non-specified errors
errInternal = Register(UndefinedCodespace, 1, "internal")
Expand Down Expand Up @@ -153,27 +147,6 @@ var (

// ErrAppConfig defines an error occurred if min-gas-prices field in BaseConfig is empty.
ErrAppConfig = Register(RootCodespace, 40, "error in app.toml")

// ErrInvalidDecString defines an error for an invalid decimal string
ErrInvalidDecString = Register(mathCodespace, 41, "invalid decimal string")

// ErrORMIteratorDone defines an error when an iterator is done
ErrORMIteratorDone = Register(ormCodespace, 42, "iterator done")

// ErrORMInvalidIterator defines an error for an invalid iterator
ErrORMInvalidIterator = Register(ormCodespace, 43, "invalid iterator")

// ErrORMUniqueConstraint defines an error when a value already exists at a given key
ErrORMUniqueConstraint = Register(ormCodespace, 44, "unique constraint violation")

// ErrORMEmptyModel defines an error when an empty model is provided for building a table
ErrORMEmptyModel = Register(ormCodespace, 45, "invalid argument")

// ErrORMKeyMaxLength defines an error when a key exceeds max length
ErrORMKeyMaxLength = Register(ormCodespace, 46, "key exceeds max length")

// ErrORMEmptyKey defines an error for an empty key
ErrORMEmptyKey = Register(ormCodespace, 47, "cannot use empty key")
)

// Register returns an error instance that should be used as the base for
Expand Down
9 changes: 9 additions & 0 deletions x/group/errors/math.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package errors

import "github.com/cosmos/cosmos-sdk/types/errors"

// mathCodespace is the codespace for all errors defined in math package
const mathCodespace = "math"

// ErrInvalidDecString defines an error for an invalid decimal string
var ErrInvalidDecString = errors.Register(mathCodespace, 10, "invalid decimal string")
28 changes: 28 additions & 0 deletions x/group/errors/orm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package errors

import (
"github.com/cosmos/cosmos-sdk/types/errors"
)

// mathCodespace is the codespace for all errors defined in orm package
const ormCodespace = "orm"

var (
// ErrORMIteratorDone defines an error when an iterator is done
ErrORMIteratorDone = errors.Register(ormCodespace, 11, "iterator done")

// ErrORMInvalidIterator defines an error for an invalid iterator
ErrORMInvalidIterator = errors.Register(ormCodespace, 12, "invalid iterator")

// ErrORMUniqueConstraint defines an error when a value already exists at a given key
ErrORMUniqueConstraint = errors.Register(ormCodespace, 13, "unique constraint violation")

// ErrORMInvalidArgument defines an error when an invalid argument is provided as part of ORM functions
ErrORMInvalidArgument = errors.Register(ormCodespace, 14, "invalid argument")

// ErrORMKeyMaxLength defines an error when a key exceeds max length
ErrORMKeyMaxLength = errors.Register(ormCodespace, 15, "key exceeds max length")

// ErrORMEmptyKey defines an error for an empty key
ErrORMEmptyKey = errors.Register(ormCodespace, 47, "cannot use empty key")
)
12 changes: 7 additions & 5 deletions x/group/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require (
require github.com/tendermint/tm-db v0.6.4

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
Expand All @@ -26,7 +25,7 @@ require (
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/iavl v0.17.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
Expand All @@ -35,16 +34,18 @@ require (
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.12.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lazyledger/smt v0.2.1-0.20210709230900-03ea40719554 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
Expand All @@ -68,7 +69,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.9.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/tendermint v0.34.14 // indirect
Expand All @@ -78,6 +79,7 @@ require (
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
Loading

0 comments on commit 530647b

Please sign in to comment.