-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from initia-labs/refactoring/go-workspace
refactoring: go workspace
- Loading branch information
Showing
113 changed files
with
8,946 additions
and
2,022 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
steps: | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 | ||
go-version: 1.22 | ||
- uses: technote-space/get-diff-action@v5 | ||
id: git_diff | ||
with: | ||
|
@@ -60,7 +60,7 @@ jobs: | |
- name: Setup go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 | ||
go-version: 1.22 | ||
# for private repo access | ||
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/ | ||
- run: | | ||
|
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,58 @@ | ||
package collection | ||
|
||
import ( | ||
"errors" | ||
|
||
"cosmossdk.io/collections" | ||
"cosmossdk.io/collections/codec" | ||
) | ||
|
||
// NewPrefix returns a new prefix | ||
func NewPrefix[T interface{ int | string | []byte }](submodule string, identifier T) collections.Prefix { | ||
return append([]byte(submodule), []byte(collections.NewPrefix(identifier))...) | ||
} | ||
|
||
// AddMap adds a map collection to the keeper | ||
func AddMap[K, V any](k IndexerKeeper, prefix collections.Prefix, name string, kc codec.KeyCodec[K], vc codec.ValueCodec[V]) (*collections.Map[K, V], error) { | ||
if k.IsSealed() { | ||
return nil, errors.New("cannot add collection to sealed keeper") | ||
} | ||
m := collections.NewMap(k.GetSchemaBuilder(), prefix, name, kc, vc) | ||
return &m, nil | ||
} | ||
|
||
// AddSequence adds a sequence collection to the keeper | ||
func AddSequence(k IndexerKeeper, prefix collections.Prefix, name string) (*collections.Sequence, error) { | ||
if k.IsSealed() { | ||
return nil, errors.New("cannot add collection to sealed keeper") | ||
} | ||
seq := collections.NewSequence(k.GetSchemaBuilder(), prefix, name) | ||
return &seq, nil | ||
} | ||
|
||
// AddKeySet adds a key set collection to the keeper | ||
func AddKeySet[K any](k IndexerKeeper, prefix collections.Prefix, name string, kc codec.KeyCodec[K]) (*collections.KeySet[K], error) { | ||
if k.IsSealed() { | ||
return nil, errors.New("cannot add collection to sealed keeper") | ||
} | ||
ks := collections.NewKeySet(k.GetSchemaBuilder(), prefix, name, kc) | ||
return &ks, nil | ||
} | ||
|
||
// AddValueSet adds a value set collection to the keeper | ||
func AddIndexedMap[PrimaryKey, Value any, Idx collections.Indexes[PrimaryKey, Value]](k IndexerKeeper, prefix collections.Prefix, name string, pkCodec codec.KeyCodec[PrimaryKey], valueCodec codec.ValueCodec[Value], indices Idx) (*collections.IndexedMap[PrimaryKey, Value, Idx], error) { | ||
if k.IsSealed() { | ||
return nil, errors.New("cannot add collection to sealed keeper") | ||
} | ||
im := collections.NewIndexedMap(k.GetSchemaBuilder(), prefix, name, pkCodec, valueCodec, indices) | ||
return im, nil | ||
} | ||
|
||
// AddItem adds an item collection to the keeper | ||
func AddItem[V any](k IndexerKeeper, prefix collections.Prefix, name string, vc codec.ValueCodec[V]) (*collections.Item[V], error) { | ||
if k.IsSealed() { | ||
return nil, errors.New("cannot add collection to sealed keeper") | ||
} | ||
item := collections.NewItem(k.GetSchemaBuilder(), prefix, name, vc) | ||
return &item, 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,10 @@ | ||
package collection | ||
|
||
import ( | ||
"cosmossdk.io/collections" | ||
) | ||
|
||
type IndexerKeeper interface { | ||
IsSealed() bool | ||
GetSchemaBuilder() *collections.SchemaBuilder | ||
} |
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.