Skip to content

Commit

Permalink
Merge pull request #34 from initia-labs/refactoring/go-workspace
Browse files Browse the repository at this point in the history
refactoring: go workspace
  • Loading branch information
Vritra4 authored Apr 21, 2024
2 parents a1d97e6 + 7c48886 commit 65777b3
Show file tree
Hide file tree
Showing 113 changed files with 8,946 additions and 2,022 deletions.
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.
4 changes: 2 additions & 2 deletions github/workflows/lint.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand Down
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ all: lint test
### Protobuf ###
###############################################################################

protoVer=0.13.0
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand All @@ -122,15 +122,6 @@ proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh

proto-swagger-gen:
@echo "Generating Swagger files"
@$(protoImage) sh ./scripts/protoc-swagger-gen.sh
$(MAKE) update-swagger-docs

proto-pulsar-gen:
@echo "Generating Dep-Inj Protobuf files"
@$(protoImage) sh ./scripts/protocgen-pulsar.sh

proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

Expand All @@ -140,7 +131,7 @@ proto-lint:
proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main

.PHONY: proto-all proto-gen proto-swagger-gen proto-pulsar-gen proto-format proto-lint proto-check-breaking
.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking

########################################
### Tools & dependencies
Expand Down
58 changes: 58 additions & 0 deletions collection/collection.go
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
}
10 changes: 10 additions & 0 deletions collection/expected_keeper.go
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
}
20 changes: 6 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.22.2
require (
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.1
cosmossdk.io/store v1.0.2
github.com/cometbft/cometbft v0.38.5
Expand All @@ -16,8 +15,6 @@ require (
github.com/cosmos/gogoproto v1.4.11
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/initia-labs/initia v0.2.4
github.com/initia-labs/movevm v0.2.5
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
Expand All @@ -31,23 +28,21 @@ require (
require (
cosmossdk.io/api v0.7.3 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/x/tx v0.13.1 // indirect
cosmossdk.io/x/upgrade v0.1.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/IGLOU-EU/go-wildcard v1.0.3 // indirect
github.com/aptos-labs/serde-reflection/serde-generate/runtime/golang v0.0.0-20231213012317-73b6bbf74833 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
Expand All @@ -59,8 +54,6 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.1 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down Expand Up @@ -99,6 +92,7 @@ require (
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.2 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v1.0.2
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
Expand All @@ -107,7 +101,6 @@ require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/initia-labs/OPinit v0.2.3
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand All @@ -116,7 +109,6 @@ require (
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
Expand All @@ -125,6 +117,8 @@ require (
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -139,7 +133,7 @@ require (
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/skip-mev/slinky v0.2.2 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down Expand Up @@ -174,13 +168,11 @@ replace (

github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240313050640-ff14560eeb21
github.com/cosmos/iavl => github.com/initia-labs/iavl v0.0.0-20240208034922-5d81c449d4c0
github.com/cosmos/ibc-apps/modules/async-icq/v8 => github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.1-0.20240124225747-f055ce5b405c

// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2

github.com/ethereum/go-ethereum => github.com/initia-labs/evm v0.0.0-20240327052100-aa794f2fc009
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
Loading

0 comments on commit 65777b3

Please sign in to comment.