diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c573501..6ee5547 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,6 @@ jobs: golangci: name: golangci-lint runs-on: ubuntu-latest - timeout-minutes: 6 steps: - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6.0.1 @@ -20,9 +19,10 @@ jobs: **/**.go go.mod go.sum - - uses: golangci/golangci-lint-action@master + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 with: - version: v1.28 - args: --timeout 10m - github-token: ${{ secrets.github_token }} + version: latest + args: --out-format=tab + skip-go-installation: true if: env.GIT_DIFF diff --git a/.github/workflows/proto.yaml b/.github/workflows/proto.yaml index 534dbfe..6539a20 100644 --- a/.github/workflows/proto.yaml +++ b/.github/workflows/proto.yaml @@ -18,4 +18,4 @@ jobs: steps: - uses: actions/checkout@v3 - name: check-breakage - run: make proto-check-breaking + run: make proto-check-breaking \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac60adb..ce2f8b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,8 @@ jobs: **/**.go go.mod go.sum - - name: run tests and generate coverage - run: make test-cover + - name: run all tests and generate coverage + run: go test -v -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic `go list ./... | grep -v simapp` if: env.GIT_DIFF - name: Upload codecov report uses: codecov/codecov-action@v2.1.0 diff --git a/.golangci.yml b/.golangci.yml index 1a55755..af64922 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ run: tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 5m linters: disable-all: true @@ -11,30 +11,27 @@ linters: - depguard - dogsled - errcheck + - exportloopref - goconst - gocritic - gofmt - goimports - - golint - gosec - gosimple - govet - ineffassign - - maligned - misspell - nakedret + - nolintlint - prealloc - - scopelint + - revive - staticcheck - structcheck - stylecheck - typecheck - unconvert - - unused - unparam - - misspell - # - wsl - - nolintlint + - unused issues: exclude-rules: @@ -55,9 +52,14 @@ issues: - text: "ST1016:" linters: - stylecheck + - path: "migrations" + text: "SA1019:" + linters: + - staticcheck + max-issues-per-linter: 10000 max-same-issues: 10000 - + linters-settings: dogsled: max-blank-identifiers: 3 @@ -68,4 +70,4 @@ linters-settings: allow-unused: false allow-leading-space: true require-explanation: false - require-specific: false \ No newline at end of file + require-specific: false diff --git a/Makefile b/Makefile index 015fc38..0973594 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ APP = ./passage MOCKS_DIR = $(CURDIR)/tests/mocks HTTPS_GIT := https://github.com/envadiv/Passage3D.git DOCKER := $(shell which docker) -DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf +DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 export GO111MODULE = on @@ -384,9 +384,11 @@ devdoc-update: containerProtoVer=v0.2 containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer) -containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer) -containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer) -containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer) +containerProtoGen=passage3d-proto-gen-$(containerProtoVer) +containerProtoGenSwagger=passage3d-proto-gen-swagger-$(containerProtoVer) +containerProtoFmt=passage3d-proto-fmt-$(containerProtoVer) +containerProtoLint=passage3d-proto-lint-$(containerProtoVer) +containerProtoBreaking=passage3d-proto-break-$(containerProtoVer) proto-all: proto-format proto-lint proto-gen @@ -412,10 +414,14 @@ proto-format: proto-lint: - @$(DOCKER_BUF) lint --error-format=json + @echo "Checking Proto-Lint" + @if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoLint}$$"; then docker start -a $(containerProtoLint); else docker run --name $(containerProtoLint) -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 \ + lint --error-format=json ; fi proto-check-breaking: - @$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=master + @echo "Checking Proto Breaking " + @if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoBreaking}$$"; then docker start -a $(containerProtoBreaking); else docker run --name $(containerProtoBreaking) -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8 \ + breaking --against $(HTTPS_GIT)#branch=main ; fi TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.0-rc6/proto/tendermint diff --git a/app/addr_prefixes.go b/app/addr_prefixes.go index a91edc5..36b568a 100644 --- a/app/addr_prefixes.go +++ b/app/addr_prefixes.go @@ -2,7 +2,6 @@ package app import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" ) @@ -23,6 +22,10 @@ const ( ) func init() { + SetAddressPrefixes() +} + +func SetAddressPrefixes() { config := sdk.GetConfig() config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub) @@ -34,5 +37,5 @@ func init() { } return fmt.Errorf("unexpected address length %d", n) }) - config.Seal() + //config.Seal() } diff --git a/app/app.go b/app/app.go index 1e8b14d..14c63cc 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,10 @@ import ( "os" "path/filepath" + appparams "github.com/envadiv/Passage3D/app/params" + + "github.com/envadiv/Passage3D/x/claim" + "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -25,7 +29,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -92,6 +95,9 @@ import ( ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper" + claimkeeper "github.com/envadiv/Passage3D/x/claim/keeper" + claimtypes "github.com/envadiv/Passage3D/x/claim/types" + // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) @@ -126,6 +132,9 @@ var ( vesting.AppModuleBasic{}, ibc.AppModuleBasic{}, transfer.AppModuleBasic{}, // i.e ibc-transfer module + + // passage3d claim module + claim.AppModuleBasic{}, ) // module account permissions @@ -137,6 +146,7 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimtypes.ModuleName: {authtypes.Minter}, } ) @@ -184,6 +194,8 @@ type PassageApp struct { ScopedIBCKeeper capabilitykeeper.ScopedKeeper ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ClaimKeeper claimkeeper.Keeper + // the module manager mm *module.Manager @@ -206,7 +218,7 @@ func init() { // NewPassageApp returns a reference to an initialized PassageApp. func NewPassageApp( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, - homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, + homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *PassageApp { @@ -224,7 +236,7 @@ func NewPassageApp( minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, - authzkeeper.StoreKey, + authzkeeper.StoreKey, claimtypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) // NOTE: The testingkey is just mounted for testing purposes. Actual applications should @@ -285,6 +297,9 @@ func NewPassageApp( app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp) + // airdorp module keeper + app.ClaimKeeper = claimkeeper.NewKeeper(appCodec, keys[claimtypes.StoreKey], app.AccountKeeper, app.BankKeeper, &stakingKeeper, app.DistrKeeper, app.GetSubspace(claimtypes.ModuleName)) + // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks( @@ -377,6 +392,7 @@ func NewPassageApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transferModule, + claim.NewAppModule(appCodec, app.ClaimKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -401,6 +417,7 @@ func NewPassageApp( genutiltypes.ModuleName, authz.ModuleName, feegrant.ModuleName, + claimtypes.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, ) @@ -420,6 +437,7 @@ func NewPassageApp( evidencetypes.ModuleName, authz.ModuleName, feegrant.ModuleName, + claimtypes.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, @@ -449,6 +467,7 @@ func NewPassageApp( paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, + claimtypes.ModuleName, ) // Uncomment if you want to set a custom migration order here. @@ -685,6 +704,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(claimtypes.ModuleName) return paramsKeeper } diff --git a/app/app_test.go b/app/app_test.go index a529996..708ff7a 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + "github.com/envadiv/Passage3D/x/claim" "os" "testing" @@ -38,7 +39,7 @@ import ( ) func TestSimAppExportAndBlockedAddrs(t *testing.T) { - encCfg := MakeTestEncodingConfig() + encCfg := MakeEncodingConfig() db := dbm.NewMemDB() app := NewPassageApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) @@ -76,7 +77,7 @@ func TestGetMaccPerms(t *testing.T) { func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() - encCfg := MakeTestEncodingConfig() + encCfg := MakeEncodingConfig() logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) @@ -186,6 +187,7 @@ func TestRunMigrations(t *testing.T) { "capability": capability.AppModule{}.ConsensusVersion(), "ibc": ibc.AppModule{}.ConsensusVersion(), "transfer": transfer.AppModule{}.ConsensusVersion(), + "claim": claim.AppModule{}.ConsensusVersion(), }, ) if tc.expRunErr { @@ -201,7 +203,7 @@ func TestRunMigrations(t *testing.T) { func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() - encCfg := MakeTestEncodingConfig() + encCfg := MakeEncodingConfig() logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) @@ -244,7 +246,7 @@ func TestInitGenesisOnMigration(t *testing.T) { } func TestUpgradeStateOnGenesis(t *testing.T) { - encCfg := MakeTestEncodingConfig() + encCfg := MakeEncodingConfig() db := dbm.NewMemDB() app := NewPassageApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg, EmptyAppOptions{}) genesisState := NewDefaultGenesisState(encCfg.Marshaler) diff --git a/app/encoding.go b/app/encoding.go index fd2d01e..6ffeb47 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,16 +1,13 @@ package app import ( - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" + "github.com/envadiv/Passage3D/app/params" ) -// MakeTestEncodingConfig creates an EncodingConfig for testing. This function -// should be used only in tests or when creating a new app instance (NewApp*()). -// App user shouldn't create new codecs - use the app.AppCodec instead. -// [DEPRECATED] -func MakeTestEncodingConfig() simappparams.EncodingConfig { - encodingConfig := simappparams.MakeTestEncodingConfig() +// MakeEncodingConfig creates an EncodingConfig for testing. +func MakeEncodingConfig() params.EncodingConfig { + encodingConfig := params.MakeTestEncodingConfig() std.RegisterLegacyAminoCodec(encodingConfig.Amino) std.RegisterInterfaces(encodingConfig.InterfaceRegistry) ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) diff --git a/app/params/encoding.go b/app/params/encoding.go index 2cd1626..3d634ab 100644 --- a/app/params/encoding.go +++ b/app/params/encoding.go @@ -10,8 +10,7 @@ import ( // This is provided for compatibility between protobuf and amino implementations. type EncodingConfig struct { InterfaceRegistry types.InterfaceRegistry - // NOTE: this field will be renamed to Codec - Marshaler codec.Codec - TxConfig client.TxConfig - Amino *codec.LegacyAmino + Marshaler codec.Codec + TxConfig client.TxConfig + Amino *codec.LegacyAmino } diff --git a/app/sim_bench_test.go b/app/sim_bench_test.go index 6818f67..b479da9 100644 --- a/app/sim_bench_test.go +++ b/app/sim_bench_test.go @@ -33,7 +33,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { } }() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( @@ -83,7 +83,7 @@ func BenchmarkInvariants(b *testing.B) { } }() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) // run randomized simulation _, simParams, simErr := simulation.SimulateFromSeed( diff --git a/app/sim_test.go b/app/sim_test.go index e7ccf63..3694607 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -68,7 +68,7 @@ func TestFullAppSimulation(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "Passage", app.Name()) // run randomized simulation @@ -106,7 +106,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "PassageApp", app.Name()) // Run randomized simulation @@ -146,7 +146,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewPassageApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewPassageApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState @@ -202,7 +202,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(dir)) }() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "Passage", app.Name()) // Run randomized simulation @@ -247,7 +247,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewPassageApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) + newApp := NewPassageApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, fauxMerkleModeOpt) require.Equal(t, "Passage", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ @@ -298,7 +298,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) + app := NewPassageApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt()) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/app/test_helpers.go b/app/test_helpers.go index 0c111eb..72a97b9 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -53,7 +53,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{ func setup(withGenesis bool, invCheckPeriod uint) (*PassageApp, GenesisState) { db := dbm.NewMemDB() - encCdc := MakeTestEncodingConfig() + encCdc := MakeEncodingConfig() app := NewPassageApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}) if withGenesis { return app, NewDefaultGenesisState(encCdc.Marshaler) diff --git a/buf.work.yaml b/buf.work.yaml new file mode 100644 index 0000000..b6a432e --- /dev/null +++ b/buf.work.yaml @@ -0,0 +1,5 @@ +version: v1 + +directories: + - ./proto + - ./third_party/proto diff --git a/cmd/passage/cmd/root.go b/cmd/passage/cmd/root.go index ce59d02..1585256 100644 --- a/cmd/passage/cmd/root.go +++ b/cmd/passage/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + appparams "github.com/envadiv/Passage3D/app/params" "io" "os" "path/filepath" @@ -22,7 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" @@ -36,8 +36,8 @@ import ( // NewRootCmd creates a new root command for simd. It is called once in the // main function. -func NewRootCmd() (*cobra.Command, params.EncodingConfig) { - encodingConfig := app.MakeTestEncodingConfig() +func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) { + encodingConfig := app.MakeEncodingConfig() initClientCtx := client.Context{}. WithCodec(encodingConfig.Marshaler). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). @@ -137,7 +137,7 @@ lru_size = 0` return customAppTemplate, customAppConfig } -func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { +func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig) { cfg := sdk.GetConfig() cfg.Seal() @@ -224,7 +224,7 @@ func txCommand() *cobra.Command { } type appCreator struct { - encCfg params.EncodingConfig + encCfg appparams.EncodingConfig } // newApp is an appCreator diff --git a/cmd/passage/cmd/testnet.go b/cmd/passage/cmd/testnet.go index 443f789..9e483e8 100644 --- a/cmd/passage/cmd/testnet.go +++ b/cmd/passage/cmd/testnet.go @@ -387,14 +387,12 @@ func calculateIP(ip string, i int) (string, error) { } func writeFile(name string, dir string, contents []byte) error { - writePath := filepath.Join(dir) - file := filepath.Join(writePath, name) - - err := tmos.EnsureDir(writePath, 0755) + err := tmos.EnsureDir(dir, 0755) if err != nil { return err } + file := filepath.Join(dir, name) err = tmos.WriteFile(file, contents, 0644) if err != nil { return err diff --git a/go.mod b/go.mod index 71d8cc5..bff9484 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,17 @@ require ( github.com/tendermint/tm-db v0.6.6 ) +require ( + github.com/gogo/protobuf v1.3.3 + github.com/golang/protobuf v1.5.2 + github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/regen-network/cosmos-proto v0.3.1 // indirect + google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb + google.golang.org/grpc v1.45.0 + google.golang.org/protobuf v1.27.1 + gopkg.in/yaml.v2 v2.4.0 +) + require ( filippo.io/edwards25519 v1.0.0-beta.2 // indirect github.com/99designs/keyring v1.1.6 // indirect @@ -50,15 +61,12 @@ require ( github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/gateway v1.1.0 // indirect - github.com/gogo/protobuf v1.3.3 // indirect - github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.3 // indirect github.com/google/btree v1.0.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect - github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect @@ -89,7 +97,6 @@ require ( github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect - github.com/regen-network/cosmos-proto v0.3.1 // indirect github.com/rs/cors v1.8.2 // indirect github.com/rs/zerolog v1.23.0 // indirect github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect @@ -109,11 +116,7 @@ require ( golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect golang.org/x/text v0.3.7 // indirect - google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb // indirect - google.golang.org/grpc v1.45.0 // indirect - google.golang.org/protobuf v1.27.1 // indirect gopkg.in/ini.v1 v1.66.2 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect nhooyr.io/websocket v1.8.6 // indirect ) diff --git a/proto/buf.gen.gogo.yaml b/proto/buf.gen.gogo.yaml new file mode 100644 index 0000000..448aff1 --- /dev/null +++ b/proto/buf.gen.gogo.yaml @@ -0,0 +1,8 @@ +version: v1beta1 +plugins: + - name: gocosmos + out: .. + opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types + - name: grpc-gateway + out: .. + opt: logtostderr=true,allow_colon_final_segments=true diff --git a/proto/buf.lock b/proto/buf.lock new file mode 100644 index 0000000..bca069c --- /dev/null +++ b/proto/buf.lock @@ -0,0 +1,31 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: cosmos-proto + branch: main + commit: 1935555c206d4afb9e94615dfd0fad31 + digest: b1-TNqW6xj2Pjha5Uoj9a-5uOeRo4mwswKfyqMcN3I_gZ0= + create_time: 2021-12-02T22:04:00.31049Z + - remote: buf.build + owner: cosmos + repository: cosmos-sdk + branch: main + commit: af8d763f189a4482b59f9f283b446293 + digest: b1-_yAm1-e1B5X3nv4-_DX5VR8YY0C_A42zokN3WshF9IE= + create_time: 2022-01-05T19:59:53.846919Z + - remote: buf.build + owner: cosmos + repository: gogo-proto + branch: main + commit: bee5511075b7499da6178d9e4aaa628b + digest: b1-rrBIustouD-S80cVoZ_rM0qJsmei9AgbXy9GPQu6vxg= + create_time: 2021-12-02T20:01:17.069307Z + - remote: buf.build + owner: googleapis + repository: googleapis + branch: main + commit: 4bdf33e750fb409da9d403e1e98031f4 + digest: b1-nRh8ZFyOdE0aPKb2J5eIo9Z6p6dkcuVuc3ug-17r_KU= + create_time: 2022-01-27T15:08:58.860206Z diff --git a/proto/buf.yaml b/proto/buf.yaml new file mode 100644 index 0000000..705c285 --- /dev/null +++ b/proto/buf.yaml @@ -0,0 +1,36 @@ +# Generated by "buf config migrate-v1beta1". Edit as necessary, and +# remove this comment when you're finished. +# +# This module represents the "proto" root found in +# the previous configuration. +version: v1beta1 +name: buf.build/passage3d/passage +deps: + - buf.build/cosmos/cosmos-sdk + - buf.build/cosmos/gogo-proto + - buf.build/googleapis/googleapis + +breaking: + use: + - FILE + ignore: + - confio + - cosmos_proto + - gogoproto + - google + - tendermint + +lint: + use: + - DEFAULT + - COMMENTS + - FILE_LOWER_SNAKE_CASE + except: + - UNARY_RPC + - COMMENT_FIELD + - SERVICE_SUFFIX + - PACKAGE_VERSION_SUFFIX + - RPC_REQUEST_STANDARD_NAME + ignore: + - tendermint + diff --git a/proto/passage3d/claim/v1beta1/claim_record.proto b/proto/passage3d/claim/v1beta1/claim_record.proto new file mode 100644 index 0000000..b548d7b --- /dev/null +++ b/proto/passage3d/claim/v1beta1/claim_record.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package passage3d.claim.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmos/bank/v1beta1/genesis.proto"; + +option go_package = "github.com/envadiv/passage3d/x/claim/types"; + +// A Claim Records is the metadata of claim data per address +message ClaimRecord { + // address of claim user + string address = 1 [(gogoproto.moretags) = "yaml:\"address\""]; + + // claimable amount for claim actions + repeated cosmos.base.v1beta1.Coin claimable_amount = 2 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"claimable_amount\"" + ]; + // true if action is completed + // index of bool in array refers to action enum # + repeated bool action_completed = 4 [ + (gogoproto.moretags) = "yaml:\"action_completed\"" + ]; +} diff --git a/proto/passage3d/claim/v1beta1/genesis.proto b/proto/passage3d/claim/v1beta1/genesis.proto new file mode 100644 index 0000000..0286e3f --- /dev/null +++ b/proto/passage3d/claim/v1beta1/genesis.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package passage3d.claim.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "passage3d/claim/v1beta1/params.proto"; +import "passage3d/claim/v1beta1/claim_record.proto"; + +option go_package = "github.com/envadiv/passage3d/x/claim/types"; + +// GenesisState defines the claim module's genesis state. +message GenesisState { + // balance of the claim module's account + cosmos.base.v1beta1.Coin module_account_balance = 1 [ + (gogoproto.moretags) = "yaml:\"module_account_balance\"", + (gogoproto.nullable) = false + ]; + + // params defines all the parameters of the module. + Params params = 2 [ + (gogoproto.moretags) = "yaml:\"params\"", + (gogoproto.nullable) = false + ]; + + // list of claim records, one for every airdrop recipient + repeated ClaimRecord claim_records = 3 [ + (gogoproto.moretags) = "yaml:\"claim_records\"", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/passage3d/claim/v1beta1/params.proto b/proto/passage3d/claim/v1beta1/params.proto new file mode 100644 index 0000000..bed40f5 --- /dev/null +++ b/proto/passage3d/claim/v1beta1/params.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; +package passage3d.claim.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; + +option go_package = "github.com/envadiv/passage3d/x/claim/types"; + +// Params defines the claim module's parameters. +message Params { + option (gogoproto.goproto_stringer) = false; + bool airdrop_enabled = 1; + + // airdrop starting time + google.protobuf.Timestamp airdrop_start_time = 2 [ + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"airdrop_start_time\"" + ]; + + google.protobuf.Duration duration_until_decay = 3 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "duration_until_decay,omitempty", + (gogoproto.moretags) = "yaml:\"duration_until_decay\"" + ]; + + google.protobuf.Duration duration_of_decay = 4 [ + (gogoproto.nullable) = false, + (gogoproto.stdduration) = true, + (gogoproto.jsontag) = "duration_of_decay,omitempty", + (gogoproto.moretags) = "yaml:\"duration_of_decay\"" + ]; + + // denom of claimable asset + string claim_denom = 5; +} diff --git a/proto/passage3d/claim/v1beta1/query.proto b/proto/passage3d/claim/v1beta1/query.proto new file mode 100644 index 0000000..9f83944 --- /dev/null +++ b/proto/passage3d/claim/v1beta1/query.proto @@ -0,0 +1,103 @@ +syntax = "proto3"; +package passage3d.claim.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "passage3d/claim/v1beta1/params.proto"; +import "passage3d/claim/v1beta1/claim_record.proto"; + +option go_package = "github.com/envadiv/passage3d/x/claim/types"; + +// Query defines the gRPC querier service. +service Query { + // ModuleAccountBalance RPC returns the claim module account balance + rpc ModuleAccountBalance(QueryModuleAccountBalanceRequest) returns (QueryModuleAccountBalanceResponse) { + option (google.api.http).get = "/passage3d/claim/v1beta1/module_account_balance"; + } + + // Params RPC returns claim module params + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/passage3d/claim/v1beta1/params"; + } + + // ClaimRecord RPC returns claim record for an address + rpc ClaimRecord(QueryClaimRecordRequest) returns (QueryClaimRecordResponse) { + option (google.api.http).get = "/passage3d/claim/v1beta1/claim_record/{address}"; + } + + // ClaimableForAction RPC returns claimable amount for an action of an address + rpc ClaimableForAction(QueryClaimableForActionRequest) returns (QueryClaimableForActionResponse) { + option (google.api.http).get = "/passage3d/claim/v1beta1/claimable_for_action/{address}/{action}"; + } + + // TotalClaimable RPC returns total claimable amount for address + rpc TotalClaimable(QueryTotalClaimableRequest) returns (QueryTotalClaimableResponse) { + option (google.api.http).get = "/passage3d/claim/v1beta1/total_claimable/{address}"; + } + +} + +// QueryModuleAccountBalanceRequest is the request type for the Query/ModuleAccountBalance RPC method. +message QueryModuleAccountBalanceRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryModuleAccountBalanceResponse { + // params defines the parameters of the module. + repeated cosmos.base.v1beta1.Coin module_account_balance = 1 [ + (gogoproto.moretags) = "yaml:\"coins\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1 [(gogoproto.nullable) = false]; +} + +// QueryClaimRecordRequest is the request type for the Query/ClaimRecord RPC method. +message QueryClaimRecordRequest { + string address = 1 [(gogoproto.moretags) = "yaml:\"address\""]; +} + +// QueryClaimRecordResponse is the response type for the Query/ClaimRecord RPC method. +message QueryClaimRecordResponse { + ClaimRecord claim_record = 1 [ + (gogoproto.moretags) = "yaml:\"claim_record\"", + (gogoproto.nullable) = false + ]; +} + +// QueryClaimableForActionRequest is the request type for the Query/ClaimRecord RPC method. +message QueryClaimableForActionRequest { + string address = 1 [(gogoproto.moretags) = "yaml:\"address\""]; + string action = 2 [(gogoproto.moretags) = "yaml:\"action\""]; +} + +// QueryClaimableForActionResponse is the response type for the Query/ClaimRecord RPC method. +message QueryClaimableForActionResponse { + cosmos.base.v1beta1.Coin amount = 1 [ + (gogoproto.moretags) = "yaml:\"amount\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin" + ]; +} + +// QueryTotalClaimableRequest is the request type for the Query/TotalClaimableRequest RPC method. +message QueryTotalClaimableRequest { + string address = 1 [(gogoproto.moretags) = "yaml:\"address\""]; +} + +// QueryTotalClaimableResponse is the response type for the Query/TotalClaimableResponse RPC method. +message QueryTotalClaimableResponse { + repeated cosmos.base.v1beta1.Coin coins = 1 [ + (gogoproto.moretags) = "yaml:\"coins\"", + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} diff --git a/proto/passage3d/claim/v1beta1/tx.proto b/proto/passage3d/claim/v1beta1/tx.proto new file mode 100644 index 0000000..0c9aaa9 --- /dev/null +++ b/proto/passage3d/claim/v1beta1/tx.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; +package passage3d.claim.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "github.com/envadiv/passage3d/x/claim/types"; + +// Msg defines the Msg service. +service Msg { + // InitialClaim defines RPC service for claim + rpc Claim(MsgClaim) returns (MsgClaimResponse); +} + +// MsgInitialClaim defines request message for InitialClaim RPC request +message MsgClaim { + string sender = 1; + string claim_action = 2; +} + +// MsgInitialClaimResponse defines response for InitialClaim RPC request +message MsgClaimResponse { + // total initial claimable amount for the user + cosmos.base.v1beta1.Coin claimed_amount = 2 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"claimed_amount\"" + ]; +} diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 5f4e125..6ce1bfc 100644 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -2,52 +2,34 @@ set -eo pipefail -protoc_gen_gocosmos() { - if ! grep "github.com/gogo/protobuf => github.com/regen-network/protobuf" go.mod &>/dev/null ; then - echo -e "\tPlease run this command from somewhere inside the passage3d folder." - return 1 - fi - - go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null -} - -protoc_gen_gocosmos -go mod tidy - -proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) +# get protoc executions +go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null +# get cosmos sdk from github +go get github.com/cosmos/cosmos-sdk 2>/dev/null + +# Get the path of the cosmos-sdk repo from go/pkg/mod +cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk) +proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) for dir in $proto_dirs; do + # generate protobuf bind buf protoc \ -I "proto" \ - -I "third_party/proto" \ + -I "$cosmos_sdk_dir/third_party/proto" \ + -I "$cosmos_sdk_dir/proto" \ --gocosmos_out=plugins=interfacetype+grpc,\ -Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\ -Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\ -Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\ -Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,\ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ - $(find "${dir}" -maxdepth 1 -name '*.proto') - - # command to generate gRPC gateway (*.pb.gw.go in respective modules) files - buf protoc \ - -I "proto" \ - -I "third_party/proto" \ - --grpc-gateway_out=logtostderr=true,allow_colon_final_segments=true:. \ - $(find "${dir}" -maxdepth 1 -name '*.proto') - - # get the module name, e.g. from "./proto/regen/data/v1alpha1", extract "data" - module=$(basename $(dirname $dir)) + $(find "${dir}" -name '*.proto') - mkdir -p ./docs/modules/${module} - - # command to generate docs using protoc-gen-doc + # generate grpc gateway buf protoc \ -I "proto" \ - -I "third_party/proto" \ - --doc_out=./x/${module}/spec \ - --doc_opt=docs/markdown.tmpl,protobuf.md \ + -I "$cosmos_sdk_dir/third_party/proto" \ + -I "$cosmos_sdk_dir/proto" \ + --grpc-gateway_out=logtostderr=true:. \ $(find "${dir}" -maxdepth 1 -name '*.proto') - done # move proto files to the right places -cp -r github.com/envadiv/Passage3D/* ./ +cp -r github.com/envadiv/passage3d/* ./ +rm -rf github.com + diff --git a/testutil/network/network.go b/testutil/network/network.go new file mode 100644 index 0000000..6f0b248 --- /dev/null +++ b/testutil/network/network.go @@ -0,0 +1,496 @@ +package network + +import ( + "bufio" + "context" + "encoding/json" + "errors" + "fmt" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server/api" + srvconfig "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/envadiv/Passage3D/app" + "github.com/envadiv/Passage3D/app/params" + "github.com/stretchr/testify/require" + tmcfg "github.com/tendermint/tendermint/config" + tmflags "github.com/tendermint/tendermint/libs/cli/flags" + "github.com/tendermint/tendermint/libs/log" + tmrand "github.com/tendermint/tendermint/libs/rand" + "github.com/tendermint/tendermint/node" + tmclient "github.com/tendermint/tendermint/rpc/client" + dbm "github.com/tendermint/tm-db" + "google.golang.org/grpc" + "io/ioutil" + "net/http" + "net/url" + "os" + "path/filepath" + "sync" + "testing" + "time" +) + +// package-wide network lock to only allow one test network at a time +var lock = new(sync.Mutex) + +// AppConstructor defines a function which accepts a network configuration and +// creates an ABCI Application to provide to Tendermint. +type AppConstructor = func(val Validator) servertypes.Application + +// NewAppConstructor returns a new app AppConstructor +func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { + return func(val Validator) servertypes.Application { + return app.NewPassageApp( + val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), + val.Ctx.Config.RootDir, 0, + encodingCfg, + app.EmptyAppOptions{}, + baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), + baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), + ) + } +} + +// Config defines the necessary configuration used to bootstrap and start an +// in-process local testing network. +type Config struct { + Codec codec.Codec + LegacyAmino *codec.LegacyAmino // TODO: Remove! + InterfaceRegistry codectypes.InterfaceRegistry + + TxConfig client.TxConfig + AccountRetriever client.AccountRetriever + AppConstructor AppConstructor // the ABCI application constructor + GenesisState map[string]json.RawMessage // custom gensis state to provide + TimeoutCommit time.Duration // the consensus commitment timeout + ChainID string // the network chain-id + NumValidators int // the total number of validators to create and bond + Mnemonics []string // custom user-provided validator operator mnemonics + BondDenom string // the staking bond denomination + MinGasPrices string // the minimum gas prices each validator will accept + AccountTokens sdk.Int // the amount of unique validator tokens (e.g. 1000node0) + StakingTokens sdk.Int // the amount of tokens each validator has available to stake + BondedTokens sdk.Int // the amount of tokens each validator stakes + PruningStrategy string // the pruning strategy each validator will have + EnableLogging bool // enable Tendermint logging to STDOUT + CleanupDir bool // remove base temporary directory during cleanup + SigningAlgo string // signing algorithm for keys + KeyringOptions []keyring.Option +} + +// DefaultConfig returns a sane default configuration suitable for nearly all +// testing requirements. +func DefaultConfig() Config { + encCfg := app.MakeEncodingConfig() + + return Config{ + Codec: encCfg.Marshaler, + TxConfig: encCfg.TxConfig, + LegacyAmino: encCfg.Amino, + InterfaceRegistry: encCfg.InterfaceRegistry, + AccountRetriever: authtypes.AccountRetriever{}, + AppConstructor: NewAppConstructor(encCfg), + GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Marshaler), + TimeoutCommit: 2 * time.Second, + ChainID: "chain-" + tmrand.NewRand().Str(6), + NumValidators: 4, + BondDenom: sdk.DefaultBondDenom, + MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), + AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), + StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), + BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + PruningStrategy: storetypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.Secp256k1Type), + KeyringOptions: []keyring.Option{}, + } +} + +type ( + // Network defines a local in-process testing network using app. It can be + // configured to start any number of validators, each with its own RPC and API + // clients. Typically, this test network would be used in client and integration + // testing where user input is expected. + // + // Note, due to Tendermint constraints in regards to RPC functionality, there + // may only be one test network running at a time. Thus, any caller must be + // sure to Cleanup after testing is finished in order to allow other tests + // to create networks. In addition, only the first validator will have a valid + // RPC and API server/client. + Network struct { + T *testing.T + BaseDir string + Validators []*Validator + + Config Config + } + + // Validator defines an in-process Tendermint validator node. Through this object, + // a client can make RPC and API calls and interact with any client command + // or handler. + Validator struct { + AppConfig *srvconfig.Config + ClientCtx client.Context + Ctx *server.Context + Dir string + NodeID string + PubKey cryptotypes.PubKey + Moniker string + APIAddress string + RPCAddress string + P2PAddress string + Address sdk.AccAddress + ValAddress sdk.ValAddress + RPCClient tmclient.Client + + tmNode *node.Node + api *api.Server + grpc *grpc.Server + grpcWeb *http.Server + } +) + +// New creates a new Network for integration tests. +func New(t *testing.T, cfg Config) *Network { + // only one caller/test can create and use a network at a time + t.Log("acquiring test network lock") + lock.Lock() + + baseDir, err := ioutil.TempDir(t.TempDir(), cfg.ChainID) + require.NoError(t, err) + t.Logf("created temporary directory: %s", baseDir) + + network := &Network{ + T: t, + BaseDir: baseDir, + Validators: make([]*Validator, cfg.NumValidators), + Config: cfg, + } + + t.Log("preparing test network...") + + monikers := make([]string, cfg.NumValidators) + nodeIDs := make([]string, cfg.NumValidators) + valPubKeys := make([]cryptotypes.PubKey, cfg.NumValidators) + + var ( + genAccounts []authtypes.GenesisAccount + genBalances []banktypes.Balance + genFiles []string + ) + + buf := bufio.NewReader(os.Stdin) + + // generate private keys, node IDs, and initial transactions + for i := 0; i < cfg.NumValidators; i++ { + appCfg := srvconfig.DefaultConfig() + appCfg.Pruning = cfg.PruningStrategy + appCfg.MinGasPrices = cfg.MinGasPrices + appCfg.API.Enable = true + appCfg.API.Swagger = false + appCfg.Telemetry.Enabled = false + + ctx := server.NewDefaultContext() + tmCfg := ctx.Config + tmCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit + + // Only allow the first validator to expose an RPC, API and gRPC + // server/client due to Tendermint in-process constraints. + apiAddr := "" + tmCfg.RPC.ListenAddress = "" + appCfg.GRPC.Enable = false + appCfg.GRPCWeb.Enable = false + if i == 0 { + apiListenAddr, _, err := server.FreeTCPAddr() + require.NoError(t, err) + appCfg.API.Address = apiListenAddr + + apiURL, err := url.Parse(apiListenAddr) + require.NoError(t, err) + apiAddr = fmt.Sprintf("http://%s:%s", apiURL.Hostname(), apiURL.Port()) + + rpcAddr, _, err := server.FreeTCPAddr() + require.NoError(t, err) + tmCfg.RPC.ListenAddress = rpcAddr + + _, grpcPort, err := server.FreeTCPAddr() + require.NoError(t, err) + appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort) + appCfg.GRPC.Enable = true + + _, grpcWebPort, err := server.FreeTCPAddr() + require.NoError(t, err) + appCfg.GRPCWeb.Address = fmt.Sprintf("0.0.0.0:%s", grpcWebPort) + appCfg.GRPCWeb.Enable = true + } + + logger := log.NewNopLogger() + if cfg.EnableLogging { + logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger, _ = tmflags.ParseLogLevel("info", logger, tmcfg.DefaultLogLevel) + } + + ctx.Logger = logger + + nodeDirName := fmt.Sprintf("node%d", i) + nodeDir := filepath.Join(network.BaseDir, nodeDirName, "simd") + clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli") + gentxsDir := filepath.Join(network.BaseDir, "gentxs") + + require.NoError(t, os.MkdirAll(filepath.Join(nodeDir, "config"), 0755)) + require.NoError(t, os.MkdirAll(clientDir, 0755)) + + tmCfg.SetRoot(nodeDir) + tmCfg.Moniker = nodeDirName + monikers[i] = nodeDirName + + proxyAddr, _, err := server.FreeTCPAddr() + require.NoError(t, err) + tmCfg.ProxyApp = proxyAddr + + p2pAddr, _, err := server.FreeTCPAddr() + require.NoError(t, err) + + tmCfg.P2P.ListenAddress = p2pAddr + tmCfg.P2P.AddrBookStrict = false + tmCfg.P2P.AllowDuplicateIP = true + + nodeID, pubKey, err := genutil.InitializeNodeValidatorFiles(tmCfg) + require.NoError(t, err) + nodeIDs[i] = nodeID + valPubKeys[i] = pubKey + + kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, cfg.KeyringOptions...) + require.NoError(t, err) + + keyringAlgos, _ := kb.SupportedAlgorithms() + algo, err := keyring.NewSigningAlgoFromString(cfg.SigningAlgo, keyringAlgos) + require.NoError(t, err) + + var mnemonic string + if i < len(cfg.Mnemonics) { + mnemonic = cfg.Mnemonics[i] + } + + addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, mnemonic, true, algo) + require.NoError(t, err) + + info := map[string]string{"secret": secret} + infoBz, err := json.Marshal(info) + require.NoError(t, err) + + // save private key seed words + require.NoError(t, writeFile(fmt.Sprintf("%v.json", "key_seed"), clientDir, infoBz)) + + balances := sdk.NewCoins( + sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), cfg.AccountTokens), + sdk.NewCoin(cfg.BondDenom, cfg.StakingTokens), + ) + + genFiles = append(genFiles, tmCfg.GenesisFile()) + genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: balances.Sort()}) + genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) + + commission, err := sdk.NewDecFromStr("0.5") + require.NoError(t, err) + + createValMsg, err := stakingtypes.NewMsgCreateValidator( + sdk.ValAddress(addr), + valPubKeys[i], + sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens), + stakingtypes.NewDescription(nodeDirName, "", "", "", ""), + stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()), + sdk.OneInt(), + ) + require.NoError(t, err) + + p2pURL, err := url.Parse(p2pAddr) + require.NoError(t, err) + + memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port()) + fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0))) + txBuilder := cfg.TxConfig.NewTxBuilder() + require.NoError(t, txBuilder.SetMsgs(createValMsg)) + txBuilder.SetFeeAmount(fee) // Arbitrary fee + txBuilder.SetGasLimit(1000000) // Need at least 100386 + txBuilder.SetMemo(memo) + + txFactory := tx.Factory{} + txFactory = txFactory. + WithChainID(cfg.ChainID). + WithMemo(memo). + WithKeybase(kb). + WithTxConfig(cfg.TxConfig) + + err = tx.Sign(txFactory, nodeDirName, txBuilder, true) + require.NoError(t, err) + + txBz, err := cfg.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) + require.NoError(t, err) + require.NoError(t, writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz)) + + srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg) + + clientCtx := client.Context{}. + WithKeyringDir(clientDir). + WithKeyring(kb). + WithHomeDir(tmCfg.RootDir). + WithChainID(cfg.ChainID). + WithInterfaceRegistry(cfg.InterfaceRegistry). + WithCodec(cfg.Codec). + WithLegacyAmino(cfg.LegacyAmino). + WithTxConfig(cfg.TxConfig). + WithAccountRetriever(cfg.AccountRetriever) + + network.Validators[i] = &Validator{ + AppConfig: appCfg, + ClientCtx: clientCtx, + Ctx: ctx, + Dir: filepath.Join(network.BaseDir, nodeDirName), + NodeID: nodeID, + PubKey: pubKey, + Moniker: nodeDirName, + RPCAddress: tmCfg.RPC.ListenAddress, + P2PAddress: tmCfg.P2P.ListenAddress, + APIAddress: apiAddr, + Address: addr, + ValAddress: sdk.ValAddress(addr), + } + } + + require.NoError(t, initGenFiles(cfg, genAccounts, genBalances, genFiles)) + require.NoError(t, collectGenFiles(cfg, network.Validators, network.BaseDir)) + + t.Log("starting test network...") + for _, v := range network.Validators { + require.NoError(t, startInProcess(cfg, v)) + } + + t.Log("started test network") + + // Ensure we cleanup incase any test was abruptly halted (e.g. SIGINT) as any + // defer in a test would not be called. + server.TrapSignal(network.Cleanup) + + return network +} + +// LatestHeight returns the latest height of the network or an error if the +// query fails or no validators exist. +func (n *Network) LatestHeight() (int64, error) { + if len(n.Validators) == 0 { + return 0, errors.New("no validators available") + } + + status, err := n.Validators[0].RPCClient.Status(context.Background()) + if err != nil { + return 0, err + } + + return status.SyncInfo.LatestBlockHeight, nil +} + +// WaitForHeight performs a blocking check where it waits for a block to be +// committed after a given block. If that height is not reached within a timeout, +// an error is returned. Regardless, the latest height queried is returned. +func (n *Network) WaitForHeight(h int64) (int64, error) { + return n.WaitForHeightWithTimeout(h, 10*time.Second) +} + +// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can +// provide a custom timeout. +func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) { + ticker := time.NewTicker(time.Second) + timeout := time.After(t) + + if len(n.Validators) == 0 { + return 0, errors.New("no validators available") + } + + var latestHeight int64 + val := n.Validators[0] + + for { + select { + case <-timeout: + ticker.Stop() + return latestHeight, errors.New("timeout exceeded waiting for block") + case <-ticker.C: + status, err := val.RPCClient.Status(context.Background()) + if err == nil && status != nil { + latestHeight = status.SyncInfo.LatestBlockHeight + if latestHeight >= h { + return latestHeight, nil + } + } + } + } +} + +// WaitForNextBlock waits for the next block to be committed, returning an error +// upon failure. +func (n *Network) WaitForNextBlock() error { + lastBlock, err := n.LatestHeight() + if err != nil { + return err + } + + _, err = n.WaitForHeight(lastBlock + 1) + if err != nil { + return err + } + + return err +} + +// Cleanup removes the root testing (temporary) directory and stops both the +// Tendermint and API services. It allows other callers to create and start +// test networks. This method must be called when a test is finished, typically +// in a defer. +func (n *Network) Cleanup() { + defer func() { + lock.Unlock() + n.T.Log("released test network lock") + }() + + n.T.Log("cleaning up test network...") + + for _, v := range n.Validators { + if v.tmNode != nil && v.tmNode.IsRunning() { + _ = v.tmNode.Stop() + } + + if v.api != nil { + _ = v.api.Close() + } + + if v.grpc != nil { + v.grpc.Stop() + if v.grpcWeb != nil { + _ = v.grpcWeb.Close() + } + } + } + + if n.Config.CleanupDir { + _ = os.RemoveAll(n.BaseDir) + } + + n.T.Log("finished cleaning up test network") +} diff --git a/testutil/network/util.go b/testutil/network/util.go new file mode 100644 index 0000000..cc3b262 --- /dev/null +++ b/testutil/network/util.go @@ -0,0 +1,210 @@ +package network + +import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/server/api" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + "github.com/tendermint/tendermint/node" + "github.com/tendermint/tendermint/p2p" + pvm "github.com/tendermint/tendermint/privval" + "github.com/tendermint/tendermint/proxy" + + servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" + srvtypes "github.com/cosmos/cosmos-sdk/server/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + tmos "github.com/tendermint/tendermint/libs/os" + "github.com/tendermint/tendermint/rpc/client/local" + "github.com/tendermint/tendermint/types" + tmtime "github.com/tendermint/tendermint/types/time" + "path/filepath" + "time" +) + +func startInProcess(cfg Config, val *Validator) error { + logger := val.Ctx.Logger + tmCfg := val.Ctx.Config + tmCfg.Instrumentation.Prometheus = false + + if err := val.AppConfig.ValidateBasic(); err != nil { + return err + } + + nodeKey, err := p2p.LoadOrGenNodeKey(tmCfg.NodeKeyFile()) + if err != nil { + return err + } + + app := cfg.AppConstructor(*val) + + genDocProvider := node.DefaultGenesisDocProviderFunc(tmCfg) + tmNode, err := node.NewNode( + tmCfg, + pvm.LoadOrGenFilePV(tmCfg.PrivValidatorKeyFile(), tmCfg.PrivValidatorStateFile()), + nodeKey, + proxy.NewLocalClientCreator(app), + genDocProvider, + node.DefaultDBProvider, + node.DefaultMetricsProvider(tmCfg.Instrumentation), + logger.With("module", val.Moniker), + ) + if err != nil { + return err + } + + if err := tmNode.Start(); err != nil { + return err + } + + val.tmNode = tmNode + + if val.RPCAddress != "" { + val.RPCClient = local.New(tmNode) + } + + // We'll need a RPC client if the validator exposes a gRPC or REST endpoint. + if val.APIAddress != "" || val.AppConfig.GRPC.Enable { + val.ClientCtx = val.ClientCtx. + WithClient(val.RPCClient) + + // Add the tx service in the gRPC router. + app.RegisterTxService(val.ClientCtx) + + // Add the tendermint queries service in the gRPC router. + app.RegisterTendermintService(val.ClientCtx) + } + + if val.APIAddress != "" { + apiSrv := api.New(val.ClientCtx, logger.With("module", "api-server")) + app.RegisterAPIRoutes(apiSrv, val.AppConfig.API) + + errCh := make(chan error) + + go func() { + if err := apiSrv.Start(*val.AppConfig); err != nil { + errCh <- err + } + }() + + select { + case err := <-errCh: + return err + case <-time.After(srvtypes.ServerStartTime): // assume server started successfully + } + + val.api = apiSrv + } + + if val.AppConfig.GRPC.Enable { + grpcSrv, err := servergrpc.StartGRPCServer(val.ClientCtx, app, val.AppConfig.GRPC.Address) + if err != nil { + return err + } + + val.grpc = grpcSrv + + if val.AppConfig.GRPCWeb.Enable { + val.grpcWeb, err = servergrpc.StartGRPCWeb(grpcSrv, *val.AppConfig) + if err != nil { + return err + } + } + } + + return nil +} + +func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { + genTime := tmtime.Now() + + for i := 0; i < cfg.NumValidators; i++ { + tmCfg := vals[i].Ctx.Config + + nodeDir := filepath.Join(outputDir, vals[i].Moniker, "simd") + gentxsDir := filepath.Join(outputDir, "gentxs") + + tmCfg.Moniker = vals[i].Moniker + tmCfg.SetRoot(nodeDir) + + initCfg := genutiltypes.NewInitConfig(cfg.ChainID, gentxsDir, vals[i].NodeID, vals[i].PubKey) + + genFile := tmCfg.GenesisFile() + genDoc, err := types.GenesisDocFromFile(genFile) + if err != nil { + return err + } + + appState, err := genutil.GenAppStateFromConfig(cfg.Codec, cfg.TxConfig, + tmCfg, initCfg, *genDoc, banktypes.GenesisBalancesIterator{}) + if err != nil { + return err + } + + // overwrite each validator's genesis file to have a canonical genesis time + if err := genutil.ExportGenesisFileWithTime(genFile, cfg.ChainID, nil, appState, genTime); err != nil { + return err + } + } + + return nil +} + +func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string) error { + + // set the accounts in the genesis state + var authGenState authtypes.GenesisState + cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[authtypes.ModuleName], &authGenState) + + accounts, err := authtypes.PackAccounts(genAccounts) + if err != nil { + return err + } + + authGenState.Accounts = append(authGenState.Accounts, accounts...) + cfg.GenesisState[authtypes.ModuleName] = cfg.Codec.MustMarshalJSON(&authGenState) + + // set the balances in the genesis state + var bankGenState banktypes.GenesisState + cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[banktypes.ModuleName], &bankGenState) + + bankGenState.Balances = append(bankGenState.Balances, genBalances...) + cfg.GenesisState[banktypes.ModuleName] = cfg.Codec.MustMarshalJSON(&bankGenState) + + appGenStateJSON, err := json.MarshalIndent(cfg.GenesisState, "", " ") + if err != nil { + return err + } + + genDoc := types.GenesisDoc{ + ChainID: cfg.ChainID, + AppState: appGenStateJSON, + Validators: nil, + } + + // generate empty genesis files for each validator and save + for i := 0; i < cfg.NumValidators; i++ { + if err := genDoc.SaveAs(genFiles[i]); err != nil { + return err + } + } + + return nil +} + +func writeFile(name string, dir string, contents []byte) error { + writePath := filepath.Join(dir) + file := filepath.Join(writePath, name) + + err := tmos.EnsureDir(writePath, 0755) + if err != nil { + return err + } + + err = tmos.WriteFile(file, contents, 0644) + if err != nil { + return err + } + + return nil +} diff --git a/third_party/proto/buf.lock b/third_party/proto/buf.lock new file mode 100644 index 0000000..dff37ae --- /dev/null +++ b/third_party/proto/buf.lock @@ -0,0 +1,10 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: gogo-proto + branch: main + commit: bee5511075b7499da6178d9e4aaa628b + digest: b1-rrBIustouD-S80cVoZ_rM0qJsmei9AgbXy9GPQu6vxg= + create_time: 2021-12-02T20:01:17.069307Z diff --git a/third_party/proto/buf.yaml b/third_party/proto/buf.yaml new file mode 100644 index 0000000..2aad5fd --- /dev/null +++ b/third_party/proto/buf.yaml @@ -0,0 +1,37 @@ +# Generated by "buf config migrate-v1beta1". Edit as necessary, and +# remove this comment when you're finished. +# +# This module represents the "third_party/proto" root found in +# the previous configuration. +version: v1 +deps: + - buf.build/cosmos/gogo-proto +build: + excludes: + - google/protobuf +breaking: + use: + - FILE + ignore: + - confio + - cosmos_proto + - gogoproto + - google + - tendermint +lint: + use: + - DEFAULT + - COMMENTS + - FILE_LOWER_SNAKE_CASE + except: + - UNARY_RPC + - COMMENT_FIELD + - SERVICE_SUFFIX + - PACKAGE_VERSION_SUFFIX + - RPC_REQUEST_STANDARD_NAME + ignore: + - confio + - cosmos_proto + - gogoproto + - google + - tendermint diff --git a/third_party/proto/google/protobuf/any.proto b/third_party/proto/google/protobuf/any.proto new file mode 100644 index 0000000..58b5115 --- /dev/null +++ b/third_party/proto/google/protobuf/any.proto @@ -0,0 +1,164 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package google.protobuf; + +import "gogoproto/gogo.proto"; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option go_package = "types"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "AnyProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// `Any` contains an arbitrary serialized protocol buffer message along with a +// URL that describes the type of the serialized message. +// +// Protobuf library provides support to pack/unpack Any values in the form +// of utility functions or additional generated methods of the Any type. +// +// Example 1: Pack and unpack a message in C++. +// +// Foo foo = ...; +// Any any; +// any.PackFrom(foo); +// ... +// if (any.UnpackTo(&foo)) { +// ... +// } +// +// Example 2: Pack and unpack a message in Java. +// +// Foo foo = ...; +// Any any = Any.pack(foo); +// ... +// if (any.is(Foo.class)) { +// foo = any.unpack(Foo.class); +// } +// +// Example 3: Pack and unpack a message in Python. +// +// foo = Foo(...) +// any = Any() +// any.Pack(foo) +// ... +// if any.Is(Foo.DESCRIPTOR): +// any.Unpack(foo) +// ... +// +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := ptypes.MarshalAny(foo) +// ... +// foo := &pb.Foo{} +// if err := ptypes.UnmarshalAny(any, foo); err != nil { +// ... +// } +// +// The pack methods provided by protobuf library will by default use +// 'type.googleapis.com/full.type.name' as the type URL and the unpack +// methods only use the fully qualified type name after the last '/' +// in the type URL, for example "foo.bar.com/x/y.z" will yield type +// name "y.z". +// +// +// JSON +// ==== +// The JSON representation of an `Any` value uses the regular +// representation of the deserialized, embedded message, with an +// additional field `@type` which contains the type URL. Example: +// +// package google.profile; +// message Person { +// string first_name = 1; +// string last_name = 2; +// } +// +// { +// "@type": "type.googleapis.com/google.profile.Person", +// "firstName": , +// "lastName": +// } +// +// If the embedded message type is well-known and has a custom JSON +// representation, that representation will be embedded adding a field +// `value` which holds the custom JSON in addition to the `@type` +// field. Example (for message [google.protobuf.Duration][]): +// +// { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": "1.212s" +// } +// +message Any { + // A URL/resource name that uniquely identifies the type of the serialized + // protocol buffer message. This string must contain at least + // one "/" character. The last segment of the URL's path must represent + // the fully qualified name of the type (as in + // `path/google.protobuf.Duration`). The name should be in a canonical form + // (e.g., leading "." is not accepted). + // + // In practice, teams usually precompile into the binary all types that they + // expect it to use in the context of Any. However, for URLs which use the + // scheme `http`, `https`, or no scheme, one can optionally set up a type + // server that maps type URLs to message definitions as follows: + // + // * If no scheme is provided, `https` is assumed. + // * An HTTP GET on the URL must yield a [google.protobuf.Type][] + // value in binary format, or produce an error. + // * Applications are allowed to cache lookup results based on the + // URL, or have them precompiled into a binary to avoid any + // lookup. Therefore, binary compatibility needs to be preserved + // on changes to types. (Use versioned type names to manage + // breaking changes.) + // + // Note: this functionality is not currently available in the official + // protobuf release, and it is not used for type URLs beginning with + // type.googleapis.com. + // + // Schemes other than `http`, `https` (or the empty scheme) might be + // used with implementation specific semantics. + // + string type_url = 1; + + // Must be a valid serialized protocol buffer of the above specified type. + bytes value = 2; + + option (gogoproto.typedecl) = false; + option (gogoproto.goproto_stringer) = false; + option (gogoproto.gostring) = false; + option (gogoproto.stringer) = false; +} + +option (gogoproto.goproto_registration) = false; diff --git a/x/claim/abci.go b/x/claim/abci.go new file mode 100644 index 0000000..4017d95 --- /dev/null +++ b/x/claim/abci.go @@ -0,0 +1,28 @@ +package claim + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/keeper" + abci "github.com/tendermint/tendermint/abci/types" +) + +// BeginBlocker is called on every block +func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { +} + +// EndBlocker is called on every block +func EndBlocker(ctx sdk.Context, k keeper.Keeper) { + params := k.GetParams(ctx) + if !params.IsAirdropEnabled(ctx.BlockTime()) { + return + } + // End Airdrop + goneTime := ctx.BlockTime().Sub(params.AirdropStartTime) + if goneTime > params.DurationUntilDecay+params.DurationOfDecay { + // airdrop time passed + err := k.EndAirdrop(ctx) + if err != nil { + panic(err) + } + } +} diff --git a/x/claim/client/cli/query.go b/x/claim/client/cli/query.go new file mode 100644 index 0000000..90c0f01 --- /dev/null +++ b/x/claim/client/cli/query.go @@ -0,0 +1,203 @@ +package cli + +import ( + "context" + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/version" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/envadiv/Passage3D/x/claim/types" + "github.com/spf13/cobra" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + claimQueryCmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + claimQueryCmd.AddCommand( + GetCmdQueryModuleAccountBalance(), + GetCmdQueryParams(), + GetCmdQueryClaimRecord(), + GetCmdQueryClaimableForAction(), + GetCmdQueryTotalClaimable(), + ) + + return claimQueryCmd +} + +// GetCmdQueryModuleAccountBalance implements a command to return the current module account balance +func GetCmdQueryModuleAccountBalance() *cobra.Command { + cmd := &cobra.Command{ + Use: "module-account-balance", + Short: "Query the current claim module's account balance", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryModuleAccountBalanceRequest{} + res, err := queryClient.ModuleAccountBalance(context.Background(), req) + + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdQueryParams implements a command to return the current minting +// parameters. +func GetCmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the current claims parameters", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryParamsRequest{} + res, err := queryClient.Params(context.Background(), params) + + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdQueryClaimRecord implements the query claim-records command. +func GetCmdQueryClaimRecord() *cobra.Command { + cmd := &cobra.Command{ + Use: "claim-record [address]", + Args: cobra.ExactArgs(1), + Short: "Query the claim record for an account.", + Long: strings.TrimSpace( + fmt.Sprintf(`Query the claim record for an account. +This contains an address' initial claimable amounts, and the completed actions. + +Example: +$ %s query claim claim-record
+`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + // Query store + res, err := queryClient.ClaimRecord(context.Background(), &types.QueryClaimRecordRequest{Address: args[0]}) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetCmdQueryClaimableForAction implements the query claimable for action command. +func GetCmdQueryClaimableForAction() *cobra.Command { + cmd := &cobra.Command{ + Use: "claimable-for-action [address] [action]", + Args: cobra.ExactArgs(2), + Short: "Query an address' claimable amount for a specific action", + Long: strings.TrimSpace( + fmt.Sprintf(`Query an address' claimable amount for a specific action (ActionInitialClaim) +Example: +$ %s query claim claimable-for-action pasg1wuanjx7l4mjdm48p5uqarukm3aus508wxmhljt ActionInitialClaim +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + _, ok := types.Action_value[args[1]] + if !ok { + return fmt.Errorf("invalid action type: %s", args[1]) + } + + // Query store + res, err := queryClient.ClaimableForAction(context.Background(), &types.QueryClaimableForActionRequest{ + Address: args[0], + Action: args[1], + }) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// GetCmdQueryTotalClaimable implements the query total claimable for address. +func GetCmdQueryTotalClaimable() *cobra.Command { + cmd := &cobra.Command{ + Use: "total-claimable [address]", + Args: cobra.ExactArgs(1), + Short: "Query the total claimable amount remaining for an account.", + Long: strings.TrimSpace( + fmt.Sprintf(`Query the total claimable amount remaining for an account. +Example: +$ %s query claim total-claimable osmo1ey69r37gfxvxg62sh4r0ktpuc46pzjrm23kcrx +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + // Query store + res, err := queryClient.TotalClaimable(context.Background(), &types.QueryTotalClaimableRequest{ + Address: args[0], + }) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/claim/client/cli/tx.go b/x/claim/client/cli/tx.go new file mode 100644 index 0000000..05b27fa --- /dev/null +++ b/x/claim/client/cli/tx.go @@ -0,0 +1,67 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/envadiv/Passage3D/x/claim/types" + "github.com/spf13/cobra" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + claimTxCmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + claimTxCmd.AddCommand(CmdInitialClaim()) + + return claimTxCmd +} + +func CmdInitialClaim() *cobra.Command { + cmd := &cobra.Command{ + Use: "claim [claim_action]", + Short: "Claim amount based on action from airdrop, claim action are (ActionInitialClaim)", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + claimAction := args[0] + if len(claimAction) == 0 { + return fmt.Errorf("action type is required") + } + + v, ok := types.Action_value[claimAction] + if !ok { + return fmt.Errorf("invalid action type: %s", claimAction) + } + if v != types.ActionInitialClaim { + return fmt.Errorf("invalid action type: %s, %s is not allowed", claimAction, claimAction) + } + + msg := types.NewMsgClaim( + clientCtx.GetFromAddress().String(), + claimAction, + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/claim/client/testutil/cli_test.go b/x/claim/client/testutil/cli_test.go new file mode 100644 index 0000000..ca541df --- /dev/null +++ b/x/claim/client/testutil/cli_test.go @@ -0,0 +1,13 @@ +package testutil + +import ( + "github.com/envadiv/Passage3D/testutil/network" + "github.com/stretchr/testify/suite" + "testing" +) + +func TestIntegrationTestSuite(t *testing.T) { + cfg := network.DefaultConfig() + cfg.NumValidators = 2 + suite.Run(t, NewIntegrationTestSuite(cfg)) +} diff --git a/x/claim/client/testutil/suite.go b/x/claim/client/testutil/suite.go new file mode 100644 index 0000000..6c89d88 --- /dev/null +++ b/x/claim/client/testutil/suite.go @@ -0,0 +1,173 @@ +package testutil + +import ( + "fmt" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/app" + "github.com/envadiv/Passage3D/testutil/network" + "github.com/envadiv/Passage3D/x/claim/client/cli" + claimtypes "github.com/envadiv/Passage3D/x/claim/types" + "github.com/stretchr/testify/suite" + tmcli "github.com/tendermint/tendermint/libs/cli" +) + +var addr1 sdk.AccAddress +var addr2 sdk.AccAddress + +var claimRecords []claimtypes.ClaimRecord + +func init() { + app.SetAddressPrefixes() + addr1 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr2 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + claimRecords = []claimtypes.ClaimRecord{ + { + Address: addr1.String(), + ClaimableAmount: sdk.NewCoins(sdk.NewInt64Coin(claimtypes.DefaultClaimDenom, 10)), + ActionCompleted: []bool{false, false, false, false}, + }, + { + Address: addr2.String(), + ClaimableAmount: sdk.NewCoins(sdk.NewInt64Coin(claimtypes.DefaultClaimDenom, 20)), + ActionCompleted: []bool{false, false, false, false}, + }, + } +} + +type IntegrationTestSuite struct { + suite.Suite + + cfg network.Config + network *network.Network +} + +func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { + return &IntegrationTestSuite{cfg: cfg} +} + +func (s *IntegrationTestSuite) SetupSuite() { + s.T().Log("setting up integration test suite") + + genState := app.ModuleBasics.DefaultGenesis(s.cfg.Codec) + claimGenState := claimtypes.DefaultGenesis() + claimGenState.ModuleAccountBalance = sdk.NewCoin(claimtypes.DefaultClaimDenom, sdk.NewInt(30)) + claimGenState.ClaimRecords = claimRecords + claimGenStateBz := s.cfg.Codec.MustMarshalJSON(claimGenState) + genState[claimtypes.ModuleName] = claimGenStateBz + + s.cfg.GenesisState = genState + s.network = network.New(s.T(), s.cfg) + + _, err := s.network.WaitForHeight(1) + s.Require().NoError(err) +} + +func (s *IntegrationTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") + s.network.Cleanup() +} + +func (s *IntegrationTestSuite) TestCmdQueryClaimRecord() { + val := s.network.Validators[0] + + testCases := []struct { + name string + args []string + }{ + { + "query claim record", + []string{ + addr1.String(), + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + }, + }, + } + + for _, tc := range testCases { + tc := tc + + s.Run(tc.name, func() { + cmd := cli.GetCmdQueryClaimRecord() + clientCtx := val.ClientCtx + + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) + s.Require().NoError(err) + + var result claimtypes.QueryClaimRecordResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) + s.Require().Equal(result.GetClaimRecord(), claimRecords[0]) + }) + } +} + +func (s *IntegrationTestSuite) TestCmdQueryClaimableForAction() { + val := s.network.Validators[0] + + testCases := []struct { + name string + args []string + coins sdk.Coins + }{ + { + "query claimable-for-action amount", + []string{ + addr2.String(), + claimtypes.Action_name[0], + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + }, + sdk.Coins{sdk.NewCoin(claimtypes.DefaultClaimDenom, sdk.NewInt(20))}, + }, + } + + for _, tc := range testCases { + tc := tc + + s.Run(tc.name, func() { + cmd := cli.GetCmdQueryClaimableForAction() + clientCtx := val.ClientCtx + + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) + s.Require().NoError(err) + + var result claimtypes.QueryClaimableForActionResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) + s.Require().Equal(result.Amount.String(), tc.coins.String()) + }) + } +} + +func (s *IntegrationTestSuite) TestCmdQueryModuleAccountBalance() { + val := s.network.Validators[0] + + testCases := []struct { + name string + args []string + coins sdk.Coins + }{ + { + "query module-account-balance", + []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + }, + sdk.Coins{sdk.NewCoin(claimtypes.DefaultClaimDenom, sdk.NewInt(30))}, + }, + } + + for _, tc := range testCases { + tc := tc + + s.Run(tc.name, func() { + cmd := cli.GetCmdQueryModuleAccountBalance() + clientCtx := val.ClientCtx + + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) + s.Require().NoError(err) + + var result claimtypes.QueryModuleAccountBalanceResponse + s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &result)) + s.Require().Equal(result.ModuleAccountBalance.String(), tc.coins.String()) + }) + } +} diff --git a/x/claim/genesis.go b/x/claim/genesis.go new file mode 100644 index 0000000..66068be --- /dev/null +++ b/x/claim/genesis.go @@ -0,0 +1,39 @@ +package claim + +import ( + "time" + + abci "github.com/tendermint/tendermint/abci/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/keeper" + "github.com/envadiv/Passage3D/x/claim/types" +) + +// InitGenesis initializes the claim module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) []abci.ValidatorUpdate { + // set up the module account with balance + k.CreateModuleAccount(ctx, genState.ModuleAccountBalance) + + // If it's the chain genesis, set the airdrop start time to be now, and set up the needed module accounts. + if genState.Params.AirdropStartTime.Equal(time.Time{}) { + genState.Params.AirdropStartTime = ctx.BlockTime() + } + err := k.SetClaimRecords(ctx, genState.ClaimRecords) + if err != nil { + panic(err) + } + + k.SetParams(ctx, genState.Params) + return nil +} + +// ExportGenesis returns the claim module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + params := k.GetParams(ctx) + genesis.Params = params + genesis.ModuleAccountBalance = k.GetModuleAccountBalance(ctx) + genesis.ClaimRecords = k.GetClaimRecords(ctx) + return genesis +} diff --git a/x/claim/genesis_test.go b/x/claim/genesis_test.go new file mode 100644 index 0000000..0a4e444 --- /dev/null +++ b/x/claim/genesis_test.go @@ -0,0 +1,112 @@ +package claim_test + +import ( + "testing" + "time" + + "github.com/envadiv/Passage3D/x/claim" + "github.com/envadiv/Passage3D/x/claim/types" + + simapp "github.com/envadiv/Passage3D/app" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +var now = time.Now().UTC() +var acc1 = sdk.AccAddress("addr1---------------") +var acc2 = sdk.AccAddress("addr2---------------") +var testGenesis = types.GenesisState{ + ModuleAccountBalance: sdk.NewInt64Coin(types.DefaultClaimDenom, 1500000000), + Params: types.Params{ + AirdropEnabled: true, + AirdropStartTime: now, + DurationUntilDecay: types.DefaultDurationUntilDecay, + DurationOfDecay: types.DefaultDurationOfDecay, + ClaimDenom: types.DefaultClaimDenom, + }, + ClaimRecords: []types.ClaimRecord{ + { + Address: acc1.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 1000000000), + }, ActionCompleted: []bool{false}, + }, + { + Address: acc2.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 500000000), + }, ActionCompleted: []bool{false}, + }, + }, +} + +func TestClaimInitGenesis(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + genesis := testGenesis + claim.InitGenesis(ctx, app.ClaimKeeper, genesis) + coin := app.ClaimKeeper.GetModuleAccountBalance(ctx) + require.Equal(t, coin.String(), genesis.ModuleAccountBalance.String()) + + params := app.ClaimKeeper.GetParams(ctx) + require.Equal(t, params, genesis.Params) + + claimRecords := app.ClaimKeeper.GetClaimRecords(ctx) + require.Equal(t, claimRecords, genesis.ClaimRecords) +} + +func TestClaimExportGenesis(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + genesis := testGenesis + claim.InitGenesis(ctx, app.ClaimKeeper, genesis) + + claimRecord, err := app.ClaimKeeper.GetClaimRecord(ctx, acc2) + require.NoError(t, err) + require.Equal(t, claimRecord, testGenesis.ClaimRecords[1]) + + claimableAmount, err := app.ClaimKeeper.ClaimCoinsForAction(ctx, acc2, types.ActionInitialClaim) + require.NoError(t, err) + require.Equal(t, claimableAmount, sdk.NewInt64Coin(types.DefaultClaimDenom, 500000000)) + + genesisExported := claim.ExportGenesis(ctx, app.ClaimKeeper) + require.Equal(t, genesisExported.ModuleAccountBalance, genesis.ModuleAccountBalance.Sub(claimableAmount)) + require.Equal(t, genesisExported.Params, genesis.Params) + require.Equal(t, genesisExported.ClaimRecords, []types.ClaimRecord{ + testGenesis.ClaimRecords[0], + { + Address: acc2.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 500000000), + }, + ActionCompleted: []bool{true}, + }, + }) +} + +func TestMarshalUnmarshalGenesis(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + + encodingConfig := simapp.MakeEncodingConfig() + appCodec := encodingConfig.Marshaler + am := claim.NewAppModule(appCodec, app.ClaimKeeper) + + genesis := testGenesis + claim.InitGenesis(ctx, app.ClaimKeeper, genesis) + + genesisExported := am.ExportGenesis(ctx, appCodec) + assert.NotPanics(t, func() { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + ctx = ctx.WithBlockTime(now.Add(time.Second)) + am := claim.NewAppModule(appCodec, app.ClaimKeeper) + am.InitGenesis(ctx, appCodec, genesisExported) + }) +} diff --git a/x/claim/keeper/claim.go b/x/claim/keeper/claim.go new file mode 100644 index 0000000..35f3b2f --- /dev/null +++ b/x/claim/keeper/claim.go @@ -0,0 +1,260 @@ +package keeper + +import ( + "fmt" + "github.com/cosmos/cosmos-sdk/store/prefix" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/envadiv/Passage3D/x/claim/types" + "github.com/gogo/protobuf/proto" +) + +// GetModuleAccountAddress gets module account address of claim module +func (k Keeper) GetModuleAccountAddress(ctx sdk.Context) sdk.AccAddress { + return k.accountKeeper.GetModuleAddress(types.ModuleName) +} + +// GetModuleAccountBalance gets the airdrop coin balance of module account +func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coin { + moduleAccAddr := k.GetModuleAccountAddress(ctx) + return k.bankKeeper.GetBalance(ctx, moduleAccAddr, types.DefaultClaimDenom) +} + +// CreateModuleAccount creates the module account with amount +func (k Keeper) CreateModuleAccount(ctx sdk.Context, amount sdk.Coin) { + moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) + k.accountKeeper.SetModuleAccount(ctx, moduleAcc) + + mintCoins := sdk.NewCoins(amount) + + existingModuleAcctBalance := k.bankKeeper.GetBalance(ctx, k.accountKeeper.GetModuleAddress(types.ModuleName), amount.Denom) + if existingModuleAcctBalance.IsPositive() { + actual := existingModuleAcctBalance.Add(amount) + ctx.Logger().Info(fmt.Sprintf("WARNING! There is a bug in claims on InitGenesis, that you are subject to."+ + " You likely expect the claims module account balance to be %d %s, but it will actually be %d %s due to this bug.", + amount.Amount.Int64(), amount.Denom, actual.Amount.Int64(), actual.Denom)) + } + + if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, mintCoins); err != nil { + panic(err) + } +} + +// SetClaimRecords set claimable amount from balances object +func (k Keeper) SetClaimRecords(ctx sdk.Context, claimRecords []types.ClaimRecord) error { + for _, claimRecord := range claimRecords { + err := k.SetClaimRecord(ctx, claimRecord) + if err != nil { + return err + } + } + return nil +} + +// SetClaimRecord sets a claim record for an address in store +func (k Keeper) SetClaimRecord(ctx sdk.Context, claimRecord types.ClaimRecord) error { + store := ctx.KVStore(k.storeKey) + prefixStore := prefix.NewStore(store, types.ClaimRecordsStorePrefix) + + bz, err := proto.Marshal(&claimRecord) + if err != nil { + return err + } + + addr, err := sdk.AccAddressFromBech32(claimRecord.Address) + if err != nil { + return err + } + + prefixStore.Set(addr, bz) + return nil +} + +// GetClaimRecords get claimables for genesis export +func (k Keeper) GetClaimRecords(ctx sdk.Context) []types.ClaimRecord { + store := ctx.KVStore(k.storeKey) + prefixStore := prefix.NewStore(store, types.ClaimRecordsStorePrefix) + + iterator := prefixStore.Iterator(nil, nil) + defer iterator.Close() + + var claimRecords []types.ClaimRecord + for ; iterator.Valid(); iterator.Next() { + + claimRecord := types.ClaimRecord{} + + err := proto.Unmarshal(iterator.Value(), &claimRecord) + if err != nil { + panic(err) + } + + claimRecords = append(claimRecords, claimRecord) + } + return claimRecords +} + +// GetClaimRecord returns the claim record for a specific address +func (k Keeper) GetClaimRecord(ctx sdk.Context, addr sdk.AccAddress) (types.ClaimRecord, error) { + store := ctx.KVStore(k.storeKey) + prefixStore := prefix.NewStore(store, types.ClaimRecordsStorePrefix) + if !prefixStore.Has(addr) { + return types.ClaimRecord{}, nil + } + bz := prefixStore.Get(addr) + + claimRecord := types.ClaimRecord{} + err := proto.Unmarshal(bz, &claimRecord) + if err != nil { + return types.ClaimRecord{}, err + } + + return claimRecord, nil +} + +// GetClaimableAmountForAction returns claimable amount for a specific action done by an address +func (k Keeper) GetClaimableAmountForAction(ctx sdk.Context, addr sdk.AccAddress, action int32) (sdk.Coin, error) { + claimRecord, err := k.GetClaimRecord(ctx, addr) + if err != nil { + return sdk.Coin{}, err + } + + if claimRecord.Address == "" { + return sdk.Coin{}, nil + } + + // if action already completed, nothing is claimable + if claimRecord.ActionCompleted[action] { + return sdk.Coin{}, nil + } + + params := k.GetParams(ctx) + + // If we are before the start time, do nothing. + // This case _shouldn't_ occur on chain, since the + // start time ought to be chain start time. + // TODO (gsk967): need to show claims to user before airdrop start + //if ctx.BlockTime().Before(params.AirdropStartTime) { + // return sdk.Coin{}, nil + //} + + claimablePerAction := claimRecord.ClaimableAmount[action] + + elapsedAirdropTime := ctx.BlockTime().Sub(params.AirdropStartTime) + // Are we early enough in the airdrop s.t. there's no decay? + if elapsedAirdropTime <= params.DurationUntilDecay { + return claimablePerAction, nil + } + + // The entire airdrop has completed + if elapsedAirdropTime > params.DurationUntilDecay+params.DurationOfDecay { + return sdk.Coin{}, nil + } + + // Positive, since goneTime > params.DurationUntilDecay + decayTime := elapsedAirdropTime - params.DurationUntilDecay + decayPercent := sdk.NewDec(decayTime.Nanoseconds()).QuoInt64(params.DurationOfDecay.Nanoseconds()) + claimablePercent := sdk.OneDec().Sub(decayPercent) + + claimablePerAction = sdk.NewCoin(claimablePerAction.Denom, claimablePerAction.Amount.ToDec().Mul(claimablePercent).RoundInt()) + return claimablePerAction, nil +} + +// GetUserTotalClaimable returns total claimable amount of an address +func (k Keeper) GetUserTotalClaimable(ctx sdk.Context, addr sdk.AccAddress) (sdk.Coins, error) { + claimRecord, err := k.GetClaimRecord(ctx, addr) + + if err != nil { + return sdk.Coins{}, err + } + if claimRecord.Address == "" { + return sdk.Coins{}, nil + } + + totalClaimable := sdk.Coins{} + + for action := range types.Action_name { + claimableForAction, err := k.GetClaimableAmountForAction(ctx, addr, action) + if err != nil { + return sdk.Coins{}, err + } + if !claimableForAction.IsNil() { + totalClaimable = totalClaimable.Add(claimableForAction) + } + } + return totalClaimable, nil +} + +// ClaimCoinsForAction remove claimable amount entry and transfer it to user's account +func (k Keeper) ClaimCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, action int32) (sdk.Coin, error) { + params := k.GetParams(ctx) + if !params.IsAirdropEnabled(ctx.BlockTime()) { + return sdk.Coin{}, types.ErrAirdropNotEnabled + } + + claimableAmount, err := k.GetClaimableAmountForAction(ctx, addr, action) + if err != nil { + return claimableAmount, err + } + + if claimableAmount.IsNil() { + return claimableAmount, nil + } + + claimRecord, err := k.GetClaimRecord(ctx, addr) + if err != nil { + return sdk.Coin{}, err + } + + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, sdk.NewCoins(claimableAmount)) + if err != nil { + return sdk.Coin{}, err + } + + claimRecord.ActionCompleted[action] = true + + err = k.SetClaimRecord(ctx, claimRecord) + if err != nil { + return claimableAmount, err + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeClaim, + sdk.NewAttribute(sdk.AttributeKeySender, addr.String()), + sdk.NewAttribute(sdk.AttributeKeyAction, types.Action_name[action]), + sdk.NewAttribute(sdk.AttributeKeyAmount, claimableAmount.String()), + ), + }) + + return claimableAmount, nil +} + +// fundRemainingToCommunity fund remaining to the community when airdrop period end +func (k Keeper) fundRemainingToCommunity(ctx sdk.Context) error { + moduleAccAddr := k.GetModuleAccountAddress(ctx) + amt := k.GetModuleAccountBalance(ctx) + ctx.Logger().Info(fmt.Sprintf( + "Sending %d %s to community pool, corresponding to the 'unclaimed airdrop'", amt.Amount.Int64(), amt.Denom)) + return k.distrKeeper.FundCommunityPool(ctx, sdk.NewCoins(amt), moduleAccAddr) +} + +func (k Keeper) EndAirdrop(ctx sdk.Context) error { + err := k.fundRemainingToCommunity(ctx) + if err != nil { + return err + } + k.clearInitialClaimables(ctx) + return nil +} + +// ClearClaimables clear claimable amounts +func (k Keeper) clearInitialClaimables(ctx sdk.Context) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.ClaimRecordsStorePrefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + key := iterator.Key() + store.Delete(key) + } +} diff --git a/x/claim/keeper/claim_test.go b/x/claim/keeper/claim_test.go new file mode 100644 index 0000000..83d2343 --- /dev/null +++ b/x/claim/keeper/claim_test.go @@ -0,0 +1,100 @@ +package keeper_test + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/types" +) + +func (suite *KeeperTestSuite) TestAirdropFlow() { + addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr2 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr3 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr4 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + + claimRecords := []types.ClaimRecord{ + { + Address: addr1.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 1000), + }, + ActionCompleted: []bool{false}, + }, + { + Address: addr2.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 1000), + }, + ActionCompleted: []bool{false}, + }, + { + Address: addr4.String(), + ClaimableAmount: []sdk.Coin{ + sdk.NewInt64Coin(types.DefaultClaimDenom, 1000), + }, + ActionCompleted: []bool{false}, + }, + } + + err := suite.app.ClaimKeeper.SetClaimRecords(suite.ctx, claimRecords) + suite.Require().NoError(err) + + coins1, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr1) + suite.Require().NoError(err) + suite.Require().True(coins1.IsAllGTE(sdk.NewCoins(claimRecords[0].ClaimableAmount[0]))) + + coins2, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr2) + suite.Require().NoError(err) + suite.Require().True(coins2.IsAllGTE(sdk.NewCoins(claimRecords[1].ClaimableAmount[0]))) + + coins3, err := suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr3) + suite.Require().NoError(err) + suite.Require().Equal(coins3, sdk.Coins{}) + + _, err = suite.app.ClaimKeeper.ClaimCoinsForAction(suite.ctx, addr4, types.ActionInitialClaim) + suite.Require().NoError(err) + // get balance after rest actions done + coins1 = suite.app.BankKeeper.GetAllBalances(suite.ctx, addr4) + suite.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) + + // get completed activities + claimRecord, err := suite.app.ClaimKeeper.GetClaimRecord(suite.ctx, addr1) + suite.Require().NoError(err) + for i := range types.Action_name { + suite.Require().False(claimRecord.ActionCompleted[i]) + } + + // do actions + // initial claim + action, err := suite.app.ClaimKeeper.ClaimCoinsForAction(suite.ctx, addr1, types.ActionInitialClaim) + suite.Require().NoError(err) + suite.Require().Equal(action.String(), claimRecords[0].ClaimableAmount[0].String()) + // get balance after rest actions done + coins1 = suite.app.BankKeeper.GetAllBalances(suite.ctx, addr1) + suite.Require().Equal(coins1.String(), sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 1000)).String()) + + // after actions module account balance will decrease (initial : 10000000) -> (9998000) + moduleAccAddr := suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) + coins := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAccAddr, types.DefaultClaimDenom) + suite.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 9998000).String()) + + // get claimable after withdrawing all + coins1, err = suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr1) + suite.Require().NoError(err) + fmt.Println(coins1.String()) + suite.Require().True(coins1.Empty()) + + err = suite.app.ClaimKeeper.EndAirdrop(suite.ctx) + suite.Require().NoError(err) + + // after airdrop end all module account balance move to community pool account + moduleAccAddr = suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) + coins = suite.app.BankKeeper.GetBalance(suite.ctx, moduleAccAddr, types.DefaultClaimDenom) + suite.Require().Equal(coins.String(), sdk.NewInt64Coin(types.DefaultClaimDenom, 0).String()) + + coins2, err = suite.app.ClaimKeeper.GetUserTotalClaimable(suite.ctx, addr2) + suite.Require().NoError(err) + suite.Require().Equal(coins2, sdk.Coins{}) +} diff --git a/x/claim/keeper/grpc_query.go b/x/claim/keeper/grpc_query.go new file mode 100644 index 0000000..682c17a --- /dev/null +++ b/x/claim/keeper/grpc_query.go @@ -0,0 +1,91 @@ +package keeper + +import ( + "context" + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/types" +) + +// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper +type Querier struct { + Keeper +} + +var _ types.QueryServer = Keeper{} + +// ModuleAccountBalance returns claim module account balance. +func (k Keeper) ModuleAccountBalance(c context.Context, _ *types.QueryModuleAccountBalanceRequest) (*types.QueryModuleAccountBalanceResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + moduleAccBal := sdk.NewCoins(k.GetModuleAccountBalance(ctx)) + + return &types.QueryModuleAccountBalanceResponse{ModuleAccountBalance: moduleAccBal}, nil +} + +// Params returns params of the claim module. +func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + params := k.GetParams(ctx) + return &types.QueryParamsResponse{Params: params}, nil +} + +func (k Keeper) ClaimRecord(goCtx context.Context, req *types.QueryClaimRecordRequest) (*types.QueryClaimRecordResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + addr, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, err + } + + claimRecord, err := k.GetClaimRecord(ctx, addr) + return &types.QueryClaimRecordResponse{ClaimRecord: claimRecord}, err +} + +func (k Keeper) ClaimableForAction(goCtx context.Context, req *types.QueryClaimableForActionRequest) (*types.QueryClaimableForActionResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + addr, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, err + } + + action, ok := types.Action_value[req.Action] + if !ok { + return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid action type: %s", req.Action)) + } + + claimableAmountForAction, err := k.GetClaimableAmountForAction(ctx, addr, action) + + return &types.QueryClaimableForActionResponse{ + Amount: claimableAmountForAction, + }, err +} + +func (k Keeper) TotalClaimable(goCtx context.Context, req *types.QueryTotalClaimableRequest) (*types.QueryTotalClaimableResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + addr, err := sdk.AccAddressFromBech32(req.Address) + if err != nil { + return nil, err + } + + coins, err := k.GetUserTotalClaimable(ctx, addr) + + return &types.QueryTotalClaimableResponse{ + Coins: coins, + }, err +} diff --git a/x/claim/keeper/grpc_query_test.go b/x/claim/keeper/grpc_query_test.go new file mode 100644 index 0000000..efec2ca --- /dev/null +++ b/x/claim/keeper/grpc_query_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "context" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/types" + "time" +) + +func (suite *KeeperTestSuite) TestGrpcQueryParams() { + grpcClient := suite.queryClient + + resp, _ := grpcClient.Params(context.Background(), &types.QueryParamsRequest{}) + suite.Require().Equal(resp.GetParams().ClaimDenom, types.DefaultClaimDenom) +} + +func (suite *KeeperTestSuite) TestGrpcQueryModuleAccountBalance() { + grpcClient := suite.queryClient + + resp, _ := grpcClient.ModuleAccountBalance(context.Background(), &types.QueryModuleAccountBalanceRequest{}) + suite.Require().Equal(resp.ModuleAccountBalance.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))).String()) +} + +func (suite *KeeperTestSuite) TestGrpcQueryClaimRecords() { + grpcClient, ctx, k := suite.queryClient, suite.ctx, suite.app.ClaimKeeper + ctx = ctx.WithBlockTime(time.Now()) + + addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr2 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + + claimRecords := []types.ClaimRecord{ + { + Address: addr1.String(), + ClaimableAmount: sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 100)), + ActionCompleted: []bool{false}, + }, + { + Address: addr2.String(), + ClaimableAmount: sdk.NewCoins(sdk.NewInt64Coin(types.DefaultClaimDenom, 200)), + ActionCompleted: []bool{false}, + }, + } + + err := k.SetClaimRecords(ctx, claimRecords) + suite.Require().NoError(err) + + resp, err := grpcClient.ClaimRecord(context.Background(), &types.QueryClaimRecordRequest{Address: addr1.String()}) + suite.Require().NoError(err) + suite.Require().Equal(resp.GetClaimRecord(), claimRecords[0]) + + //// get claim record for action + //actionResp, err := grpcClient.TotalClaimable(context.Background(), &types.QueryTotalClaimableRequest{Address: addr1.String()}) + //suite.Require().NoError(err) + //suite.Require().Equal(actionResp.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(100))).String()) +} diff --git a/x/claim/keeper/keeper.go b/x/claim/keeper/keeper.go new file mode 100644 index 0000000..8740390 --- /dev/null +++ b/x/claim/keeper/keeper.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/envadiv/Passage3D/x/claim/types" + "github.com/tendermint/tendermint/libs/log" +) + +// Keeper struct +type Keeper struct { + cdc codec.Codec + storeKey sdk.StoreKey + accountKeeper authkeeper.AccountKeeper + bankKeeper bankkeeper.Keeper + stakingKeeper types.StakingKeeper + distrKeeper distrkeeper.Keeper + paramstore paramtypes.Subspace +} + +// NewKeeper returns keeper +func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, sk types.StakingKeeper, dk distrkeeper.Keeper, ps paramtypes.Subspace) Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return Keeper{ + cdc: cdc, + storeKey: storeKey, + accountKeeper: ak, + bankKeeper: bk, + stakingKeeper: sk, + distrKeeper: dk, + paramstore: ps, + } +} + +// Logger returns logger +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/claim/keeper/keeper_test.go b/x/claim/keeper/keeper_test.go new file mode 100644 index 0000000..cf08ace --- /dev/null +++ b/x/claim/keeper/keeper_test.go @@ -0,0 +1,49 @@ +package keeper_test + +import ( + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/app" + "github.com/envadiv/Passage3D/x/claim/keeper" + "github.com/envadiv/Passage3D/x/claim/types" + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "testing" + "time" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + queryClient types.QueryClient + app *app.PassageApp +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.app = app.Setup(false) + suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "passage3d-1", Time: time.Now()}) + + airdropStartTime := time.Now() + suite.app.ClaimKeeper.CreateModuleAccount(suite.ctx, sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(10000000))) + + suite.app.ClaimKeeper.SetParams(suite.ctx, types.Params{ + AirdropEnabled: true, + AirdropStartTime: airdropStartTime, + DurationUntilDecay: types.DefaultDurationUntilDecay, + DurationOfDecay: types.DefaultDurationOfDecay, + ClaimDenom: types.DefaultClaimDenom, + }) + + querier := keeper.Querier{Keeper: suite.app.ClaimKeeper} + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, querier) + suite.queryClient = types.NewQueryClient(queryHelper) + + suite.ctx = suite.ctx.WithBlockTime(airdropStartTime) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/x/claim/keeper/msg_server.go b/x/claim/keeper/msg_server.go new file mode 100644 index 0000000..59d146e --- /dev/null +++ b/x/claim/keeper/msg_server.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// Claim sends the claim amount to user based on action type from airdrop +func (k msgServer) Claim(goCtx context.Context, msg *types.MsgClaim) (*types.MsgClaimResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + sender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + + params := k.GetParams(ctx) + if !params.IsAirdropEnabled(ctx.BlockTime()) { + return nil, types.ErrAirdropNotEnabled + } + + claimableCoinsForAction, err := k.Keeper.ClaimCoinsForAction(ctx, sender, types.Action_value[msg.ClaimAction]) + if err != nil { + return nil, err + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeyAction, msg.ClaimAction), + sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), + ), + }) + + return &types.MsgClaimResponse{ + ClaimedAmount: claimableCoinsForAction, + }, nil +} diff --git a/x/claim/keeper/params.go b/x/claim/keeper/params.go new file mode 100644 index 0000000..1245973 --- /dev/null +++ b/x/claim/keeper/params.go @@ -0,0 +1,18 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/envadiv/Passage3D/x/claim/types" +) + +// GetParams get params +// GetParams returns the total set of claim parameters. +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + k.paramstore.GetParamSet(ctx, ¶ms) + return params +} + +// SetParams sets claim parameters to the param space. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} diff --git a/x/claim/module.go b/x/claim/module.go new file mode 100644 index 0000000..b93d144 --- /dev/null +++ b/x/claim/module.go @@ -0,0 +1,149 @@ +package claim + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/envadiv/Passage3D/x/claim/client/cli" + "github.com/envadiv/Passage3D/x/claim/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/envadiv/Passage3D/x/claim/keeper" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the claim module. +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +func (a AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +func (a AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(amino) +} + +func (a AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +func (a AppModuleBasic) RegisterRESTRoutes(context client.Context, router *mux.Router) { +} + +func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + return + } +} + +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +func (a AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// InitGenesis performs the claim module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + jsonCodec.MustUnmarshalJSON(gs, &genState) + return InitGenesis(ctx, am.keeper, genState) +} + +// ExportGenesis returns the claim module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return jsonCodec.MustMarshalJSON(genState) +} + +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +func (am AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +func (am AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier { + return nil +} + +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +func (am AppModule) ConsensusVersion() uint64 { + return 1 +} + +func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + BeginBlocker(ctx, req, am.keeper) +} + +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + EndBlocker(ctx, am.keeper) + return []abci.ValidatorUpdate{} +} diff --git a/x/claim/types/airdrop_actions.go b/x/claim/types/airdrop_actions.go new file mode 100644 index 0000000..54f97de --- /dev/null +++ b/x/claim/types/airdrop_actions.go @@ -0,0 +1,16 @@ +package types + +const ( + // ActionInitialClaim defines a initial claim actions for airdrop. + ActionInitialClaim int32 = 0 + // DelegateActionStake defines Delegate Action Stake + InitialClaim = "ActionInitialClaim" +) + +var Action_name = map[int32]string{ + 0: "ActionInitialClaim", +} + +var Action_value = map[string]int32{ + "ActionInitialClaim": 0, +} diff --git a/x/claim/types/claim_record.pb.go b/x/claim/types/claim_record.pb.go new file mode 100644 index 0000000..e905559 --- /dev/null +++ b/x/claim/types/claim_record.pb.go @@ -0,0 +1,491 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: passage3d/claim/v1beta1/claim_record.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/x/bank/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// A Claim Records is the metadata of claim data per address +type ClaimRecord struct { + // address of claim user + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` + // claimable amount for claim actions + ClaimableAmount []types.Coin `protobuf:"bytes,2,rep,name=claimable_amount,json=claimableAmount,proto3" json:"claimable_amount" yaml:"claimable_amount"` + // true if action is completed + // index of bool in array refers to action enum # + ActionCompleted []bool `protobuf:"varint,4,rep,packed,name=action_completed,json=actionCompleted,proto3" json:"action_completed,omitempty" yaml:"action_completed"` +} + +func (m *ClaimRecord) Reset() { *m = ClaimRecord{} } +func (m *ClaimRecord) String() string { return proto.CompactTextString(m) } +func (*ClaimRecord) ProtoMessage() {} +func (*ClaimRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_322afa8dcf98ebcc, []int{0} +} +func (m *ClaimRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClaimRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClaimRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClaimRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClaimRecord.Merge(m, src) +} +func (m *ClaimRecord) XXX_Size() int { + return m.Size() +} +func (m *ClaimRecord) XXX_DiscardUnknown() { + xxx_messageInfo_ClaimRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_ClaimRecord proto.InternalMessageInfo + +func (m *ClaimRecord) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *ClaimRecord) GetClaimableAmount() []types.Coin { + if m != nil { + return m.ClaimableAmount + } + return nil +} + +func (m *ClaimRecord) GetActionCompleted() []bool { + if m != nil { + return m.ActionCompleted + } + return nil +} + +func init() { + proto.RegisterType((*ClaimRecord)(nil), "passage3d.claim.v1beta1.ClaimRecord") +} + +func init() { + proto.RegisterFile("passage3d/claim/v1beta1/claim_record.proto", fileDescriptor_322afa8dcf98ebcc) +} + +var fileDescriptor_322afa8dcf98ebcc = []byte{ + // 326 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0xcd, 0x6a, 0xc2, 0x40, + 0x14, 0x85, 0x93, 0x5a, 0xfa, 0x13, 0xa1, 0x4a, 0x28, 0x68, 0x2d, 0x4c, 0x6c, 0x56, 0x22, 0x65, + 0x82, 0x75, 0xd7, 0x5d, 0x63, 0xe9, 0x03, 0x64, 0xd9, 0x8d, 0x4c, 0x92, 0x4b, 0x3a, 0x34, 0x99, + 0x1b, 0x32, 0xa3, 0xd4, 0xb7, 0xe8, 0x63, 0xb9, 0x74, 0xd9, 0x95, 0x14, 0xdd, 0x75, 0xe9, 0x13, + 0x14, 0x33, 0x31, 0x82, 0xbb, 0x99, 0x73, 0x3e, 0xce, 0x3d, 0x33, 0xd7, 0x1a, 0xe6, 0x4c, 0x4a, + 0x96, 0xc0, 0x38, 0xf6, 0xa2, 0x94, 0xf1, 0xcc, 0x9b, 0x8f, 0x42, 0x50, 0x6c, 0xa4, 0x6f, 0xd3, + 0x02, 0x22, 0x2c, 0x62, 0x9a, 0x17, 0xa8, 0xd0, 0xee, 0xd4, 0x2c, 0x2d, 0x5d, 0x5a, 0xb1, 0xbd, + 0xdb, 0x04, 0x13, 0x2c, 0x19, 0x6f, 0x7f, 0xd2, 0x78, 0x8f, 0x44, 0x28, 0x33, 0x94, 0x5e, 0xc8, + 0x24, 0x1c, 0x63, 0x91, 0x8b, 0xca, 0x7f, 0xa8, 0x7d, 0xf1, 0x59, 0xfb, 0x09, 0x08, 0x90, 0x5c, + 0x6a, 0xc4, 0xfd, 0x33, 0xad, 0xe6, 0x64, 0x3f, 0x2a, 0x28, 0x7b, 0xd8, 0x8f, 0xd6, 0x25, 0x8b, + 0xe3, 0x02, 0xa4, 0xec, 0x9a, 0x7d, 0x73, 0x70, 0xed, 0xdb, 0xbb, 0xb5, 0x73, 0xb3, 0x60, 0x59, + 0xfa, 0xec, 0x56, 0x86, 0x1b, 0x1c, 0x10, 0x1b, 0xac, 0x76, 0xd9, 0x93, 0x85, 0x29, 0x4c, 0x59, + 0x86, 0x33, 0xa1, 0xba, 0x67, 0xfd, 0xc6, 0xa0, 0xf9, 0x74, 0x47, 0xf5, 0x6c, 0xba, 0xef, 0x76, + 0x78, 0x06, 0x9d, 0x20, 0x17, 0xbe, 0xb3, 0x5c, 0x3b, 0xc6, 0x6e, 0xed, 0x74, 0x74, 0xea, 0x69, + 0x80, 0x1b, 0xb4, 0x6a, 0xe9, 0xa5, 0x54, 0xec, 0x37, 0xab, 0xcd, 0x22, 0xc5, 0x51, 0x4c, 0x23, + 0xcc, 0xf2, 0x14, 0x14, 0xc4, 0xdd, 0xf3, 0x7e, 0x63, 0x70, 0xe5, 0xdf, 0x1f, 0x73, 0x4e, 0x09, + 0x37, 0x68, 0x69, 0x69, 0x72, 0x50, 0xfc, 0xd7, 0xe5, 0x86, 0x98, 0xab, 0x0d, 0x31, 0x7f, 0x37, + 0xc4, 0xfc, 0xde, 0x12, 0x63, 0xb5, 0x25, 0xc6, 0xcf, 0x96, 0x18, 0xef, 0xc3, 0x84, 0xab, 0x8f, + 0x59, 0x48, 0x23, 0xcc, 0x3c, 0x10, 0x73, 0x16, 0xf3, 0xb9, 0x77, 0xdc, 0xdb, 0x57, 0xb5, 0x39, + 0xb5, 0xc8, 0x41, 0x86, 0x17, 0xe5, 0xcf, 0x8d, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xb5, 0x58, + 0xdd, 0x41, 0xd9, 0x01, 0x00, 0x00, +} + +func (m *ClaimRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClaimRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClaimRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ActionCompleted) > 0 { + for iNdEx := len(m.ActionCompleted) - 1; iNdEx >= 0; iNdEx-- { + i-- + if m.ActionCompleted[iNdEx] { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + } + i = encodeVarintClaimRecord(dAtA, i, uint64(len(m.ActionCompleted))) + i-- + dAtA[i] = 0x22 + } + if len(m.ClaimableAmount) > 0 { + for iNdEx := len(m.ClaimableAmount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ClaimableAmount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintClaimRecord(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintClaimRecord(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintClaimRecord(dAtA []byte, offset int, v uint64) int { + offset -= sovClaimRecord(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ClaimRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovClaimRecord(uint64(l)) + } + if len(m.ClaimableAmount) > 0 { + for _, e := range m.ClaimableAmount { + l = e.Size() + n += 1 + l + sovClaimRecord(uint64(l)) + } + } + if len(m.ActionCompleted) > 0 { + n += 1 + sovClaimRecord(uint64(len(m.ActionCompleted))) + len(m.ActionCompleted)*1 + } + return n +} + +func sovClaimRecord(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozClaimRecord(x uint64) (n int) { + return sovClaimRecord(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ClaimRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClaimRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClaimRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthClaimRecord + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthClaimRecord + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimableAmount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthClaimRecord + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthClaimRecord + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClaimableAmount = append(m.ClaimableAmount, types.Coin{}) + if err := m.ClaimableAmount[len(m.ClaimableAmount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType == 0 { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ActionCompleted = append(m.ActionCompleted, bool(v != 0)) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthClaimRecord + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthClaimRecord + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + elementCount = packedLen + if elementCount != 0 && len(m.ActionCompleted) == 0 { + m.ActionCompleted = make([]bool, 0, elementCount) + } + for iNdEx < postIndex { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ActionCompleted = append(m.ActionCompleted, bool(v != 0)) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ActionCompleted", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipClaimRecord(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthClaimRecord + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipClaimRecord(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowClaimRecord + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthClaimRecord + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupClaimRecord + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthClaimRecord + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthClaimRecord = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowClaimRecord = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupClaimRecord = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/claim/types/codec.go b/x/claim/types/codec.go new file mode 100644 index 0000000..d91d549 --- /dev/null +++ b/x/claim/types/codec.go @@ -0,0 +1,32 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgClaim{}, "claim/Claim", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgClaim{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/claim/types/errors.go b/x/claim/types/errors.go new file mode 100644 index 0000000..69610af --- /dev/null +++ b/x/claim/types/errors.go @@ -0,0 +1,13 @@ +package types + +// DONTCOVER + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// x/claim module sentinel errors +var ( + ErrAirdropNotEnabled = sdkerrors.Register(ModuleName, 2, "airdrop not enabled") + ErrIncorrectModuleAccountBalance = sdkerrors.Register(ModuleName, 3, "claim module account balance != sum of all claim record InitialClaimableAmounts") +) diff --git a/x/claim/types/events.go b/x/claim/types/events.go new file mode 100644 index 0000000..2a498a3 --- /dev/null +++ b/x/claim/types/events.go @@ -0,0 +1,7 @@ +package types + +// claim module event types +const ( + EventTypeClaim = "claim" + AttributeValueCategory = ModuleName +) diff --git a/x/claim/types/expected_keepers.go b/x/claim/types/expected_keepers.go new file mode 100644 index 0000000..7c31ae1 --- /dev/null +++ b/x/claim/types/expected_keepers.go @@ -0,0 +1,9 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type StakingKeeper interface { + BondDenom(sdk.Context) string +} diff --git a/x/claim/types/genesis.go b/x/claim/types/genesis.go new file mode 100644 index 0000000..6957b47 --- /dev/null +++ b/x/claim/types/genesis.go @@ -0,0 +1,47 @@ +package types + +import ( + "fmt" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + ModuleAccountBalance: sdk.NewCoin(DefaultClaimDenom, sdk.ZeroInt()), + Params: Params{ + AirdropStartTime: time.Time{}, + DurationUntilDecay: DefaultDurationUntilDecay, // 2 month + DurationOfDecay: DefaultDurationOfDecay, // 4 months + ClaimDenom: DefaultClaimDenom, // upasg + }, + ClaimRecords: []ClaimRecord{}, + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + totalClaimable := sdk.Coins{} + + if err := gs.Params.Validate(); err != nil { + return err + } + + for _, claimRecord := range gs.ClaimRecords { + for _, ClaimableAmount := range claimRecord.ClaimableAmount { + totalClaimable = totalClaimable.Add(ClaimableAmount) + } + } + + if !totalClaimable.IsEqual(sdk.NewCoins(gs.ModuleAccountBalance)) { + return ErrIncorrectModuleAccountBalance + } + + if gs.Params.ClaimDenom != gs.ModuleAccountBalance.Denom { + return fmt.Errorf("denom for module and claim does not match") + } + return nil +} diff --git a/x/claim/types/genesis.pb.go b/x/claim/types/genesis.pb.go new file mode 100644 index 0000000..b40c418 --- /dev/null +++ b/x/claim/types/genesis.pb.go @@ -0,0 +1,451 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: passage3d/claim/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the claim module's genesis state. +type GenesisState struct { + // balance of the claim module's account + ModuleAccountBalance types.Coin `protobuf:"bytes,1,opt,name=module_account_balance,json=moduleAccountBalance,proto3" json:"module_account_balance" yaml:"module_account_balance"` + // params defines all the parameters of the module. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params" yaml:"params"` + // list of claim records, one for every airdrop recipient + ClaimRecords []ClaimRecord `protobuf:"bytes,3,rep,name=claim_records,json=claimRecords,proto3" json:"claim_records" yaml:"claim_records"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_3c24d42126f7b0be, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetModuleAccountBalance() types.Coin { + if m != nil { + return m.ModuleAccountBalance + } + return types.Coin{} +} + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetClaimRecords() []ClaimRecord { + if m != nil { + return m.ClaimRecords + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "passage3d.claim.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("passage3d/claim/v1beta1/genesis.proto", fileDescriptor_3c24d42126f7b0be) +} + +var fileDescriptor_3c24d42126f7b0be = []byte{ + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xc1, 0x4e, 0xc2, 0x30, + 0x18, 0xc7, 0x37, 0x48, 0x38, 0x0c, 0xb8, 0x2c, 0xa8, 0x48, 0xb4, 0x90, 0x05, 0x12, 0xc2, 0xa1, + 0x0d, 0x70, 0xf3, 0xe6, 0x30, 0xf1, 0x66, 0xcc, 0xbc, 0x79, 0x21, 0x5d, 0xd7, 0xcc, 0x25, 0xdb, + 0xba, 0xac, 0x65, 0x91, 0xb7, 0xf0, 0x8d, 0xbc, 0x72, 0xe4, 0xe8, 0x89, 0x18, 0x78, 0x03, 0x9f, + 0xc0, 0xac, 0xad, 0xa0, 0x89, 0xbb, 0xad, 0xfd, 0x7e, 0xfb, 0xfd, 0xbf, 0xaf, 0x9f, 0x35, 0xca, + 0x30, 0xe7, 0x38, 0xa4, 0xf3, 0x00, 0x91, 0x18, 0x47, 0x09, 0x2a, 0xa6, 0x3e, 0x15, 0x78, 0x8a, + 0x42, 0x9a, 0x52, 0x1e, 0x71, 0x98, 0xe5, 0x4c, 0x30, 0xfb, 0xe2, 0x88, 0x41, 0x89, 0x41, 0x8d, + 0xf5, 0x3a, 0x21, 0x0b, 0x99, 0x64, 0x50, 0xf9, 0xa5, 0xf0, 0x1e, 0x20, 0x8c, 0x27, 0x8c, 0x23, + 0x1f, 0x73, 0x7a, 0x34, 0x12, 0x16, 0xa5, 0xba, 0x3e, 0xac, 0x4a, 0xcd, 0x70, 0x8e, 0x13, 0x1d, + 0xda, 0x9b, 0x54, 0x51, 0xf2, 0xb4, 0xcc, 0x29, 0x61, 0x79, 0xa0, 0x58, 0xe7, 0xbd, 0x66, 0xb5, + 0xee, 0x55, 0xcb, 0x4f, 0x02, 0x0b, 0x6a, 0x17, 0xd6, 0x79, 0xc2, 0x82, 0x55, 0x4c, 0x97, 0x98, + 0x10, 0xb6, 0x4a, 0xc5, 0xd2, 0xc7, 0x31, 0x4e, 0x09, 0xed, 0x9a, 0x03, 0x73, 0xdc, 0x9c, 0x5d, + 0x42, 0xd5, 0x23, 0x2c, 0x7b, 0xfc, 0x19, 0x07, 0x2e, 0x58, 0x94, 0xba, 0xa3, 0xcd, 0xae, 0x6f, + 0x7c, 0xed, 0xfa, 0xd7, 0x6b, 0x9c, 0xc4, 0x37, 0xce, 0xff, 0x1a, 0xc7, 0xeb, 0xa8, 0xc2, 0xad, + 0xba, 0x77, 0xd5, 0xb5, 0xfd, 0x60, 0x35, 0xd4, 0x10, 0xdd, 0x9a, 0xcc, 0xe9, 0xc3, 0x8a, 0xa7, + 0x83, 0x8f, 0x12, 0x73, 0xcf, 0x74, 0x5a, 0x5b, 0xa5, 0xa9, 0x9f, 0x1d, 0x4f, 0x5b, 0xec, 0xd0, + 0x6a, 0xff, 0x1e, 0x97, 0x77, 0xeb, 0x83, 0xfa, 0xb8, 0x39, 0x1b, 0x56, 0x6a, 0x17, 0xe5, 0xc9, + 0x93, 0xb0, 0x7b, 0xa5, 0xdd, 0x1d, 0xe5, 0xfe, 0x23, 0x72, 0xbc, 0x16, 0x39, 0xa1, 0xdc, 0xbd, + 0xdb, 0xec, 0x81, 0xb9, 0xdd, 0x03, 0xf3, 0x73, 0x0f, 0xcc, 0xb7, 0x03, 0x30, 0xb6, 0x07, 0x60, + 0x7c, 0x1c, 0x80, 0xf1, 0x3c, 0x09, 0x23, 0xf1, 0xb2, 0xf2, 0x21, 0x61, 0x09, 0xa2, 0x69, 0x81, + 0x83, 0xa8, 0x40, 0xa7, 0xd5, 0xbc, 0xea, 0xe5, 0x88, 0x75, 0x46, 0xb9, 0xdf, 0x90, 0xeb, 0x98, + 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0x60, 0x7c, 0x4e, 0xe3, 0x58, 0x02, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClaimRecords) > 0 { + for iNdEx := len(m.ClaimRecords) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ClaimRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ModuleAccountBalance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ModuleAccountBalance.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.ClaimRecords) > 0 { + for _, e := range m.ClaimRecords { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccountBalance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ModuleAccountBalance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClaimRecords = append(m.ClaimRecords, ClaimRecord{}) + if err := m.ClaimRecords[len(m.ClaimRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/claim/types/keys.go b/x/claim/types/keys.go new file mode 100644 index 0000000..cc39678 --- /dev/null +++ b/x/claim/types/keys.go @@ -0,0 +1,29 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "claim" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + // ActionKey defines the store key to store user accomplished actions + ActionKey = "action" + + // ParamsKey defines the store key for claim module parameters + ParamsKey = "params" +) + +// KVStore keys +var ( + // ClaimRecordsStorePrefix defines the store prefix for the claim records + ClaimRecordsStorePrefix = []byte{0x01} +) + +// Actions diff --git a/x/claim/types/msg_initial_claim.go b/x/claim/types/msg_initial_claim.go new file mode 100644 index 0000000..0d199c6 --- /dev/null +++ b/x/claim/types/msg_initial_claim.go @@ -0,0 +1,52 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ sdk.Msg = &MsgClaim{} + +// msg types +const ( + TypeMsgClaim = "claim" +) + +func NewMsgClaim(sender, action string) *MsgClaim { + return &MsgClaim{ + Sender: sender, + ClaimAction: action, + } +} + +func (msg MsgClaim) Route() string { + return RouterKey +} + +func (msg MsgClaim) Type() string { + return TypeMsgClaim +} + +func (msg MsgClaim) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg MsgClaim) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +func (msg MsgClaim) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + } + if len(msg.ClaimAction) == 0 { + return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "empty action, action type is required") + } + return nil +} diff --git a/x/claim/types/msg_initial_claim_test.go b/x/claim/types/msg_initial_claim_test.go new file mode 100644 index 0000000..e132fda --- /dev/null +++ b/x/claim/types/msg_initial_claim_test.go @@ -0,0 +1,50 @@ +package types + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" +) + +// AccAddress returns a sample account address +func AccAddress() string { + pk := ed25519.GenPrivKey().PubKey() + addr := pk.Address() + return sdk.AccAddress(addr).String() +} + +func TestMsgClaim_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgClaim + err error + }{ + { + name: "invalid address", + msg: MsgClaim{ + Sender: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgClaim{ + Sender: AccAddress(), + ClaimAction: InitialClaim, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/claim/types/params.go b/x/claim/types/params.go new file mode 100644 index 0000000..ec34cef --- /dev/null +++ b/x/claim/types/params.go @@ -0,0 +1,122 @@ +package types + +import ( + "fmt" + "strings" + "time" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var ( + DefaultClaimDenom = "upasg" + DefaultDurationUntilDecay = time.Hour + DefaultDurationOfDecay = time.Hour * 5 +) + +// Parameter store keys +var ( + KeyEnabled = []byte("Enabled") + KeyStartTime = []byte("StartTime") + KeyClaimDenom = []byte("ClaimDenom") + KeyDurationUntilDecal = []byte("DurationUntilDecay") + KeyDurationOfDecay = []byte("DurationOfDecay") +) + +func NewParams(enabled bool, claimDenom string, startTime time.Time, durationUntilDecay, durationOfDecay time.Duration) Params { + return Params{ + AirdropEnabled: enabled, + ClaimDenom: claimDenom, + AirdropStartTime: startTime, + DurationUntilDecay: durationUntilDecay, + DurationOfDecay: durationOfDecay, + } +} + +// String implements the stringer interface for Params +func (p Params) String() string { + out, err := yaml.Marshal(p) + if err != nil { + return "" + } + return string(out) +} + +// ParamSetPairs - Implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyEnabled, &p.AirdropEnabled, validateEnabled), + paramtypes.NewParamSetPair(KeyClaimDenom, &p.ClaimDenom, validateDenom), + paramtypes.NewParamSetPair(KeyStartTime, &p.AirdropStartTime, validateTime), + paramtypes.NewParamSetPair(KeyDurationUntilDecal, &p.DurationUntilDecay, validateDuration), + paramtypes.NewParamSetPair(KeyDurationOfDecay, &p.DurationOfDecay, validateDuration), + } +} + +// Validate validates all params +func (p Params) Validate() error { + if err := validateEnabled(p.AirdropEnabled); err != nil { + return err + } + err := validateDenom(p.ClaimDenom) + return err +} + +func (p Params) IsAirdropEnabled(t time.Time) bool { + if !p.AirdropEnabled { + return false + } + if p.AirdropStartTime.IsZero() { + return false + } + if t.Before(p.AirdropStartTime) { + return false + } + return true +} + +// ParamKeyTable for staking module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +func validateEnabled(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} + +func validateDenom(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if strings.TrimSpace(v) == "" { + return fmt.Errorf("invalid denom: %s", v) + } + + return nil +} + +func validateTime(i interface{}) error { + _, ok := i.(time.Time) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} + +func validateDuration(i interface{}) error { + d, ok := i.(time.Duration) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if d < 1 { + return fmt.Errorf("duration must be greater than or equal to 1: %d", d) + } + return nil +} diff --git a/x/claim/types/params.pb.go b/x/claim/types/params.pb.go new file mode 100644 index 0000000..446db5b --- /dev/null +++ b/x/claim/types/params.pb.go @@ -0,0 +1,535 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: passage3d/claim/v1beta1/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the claim module's parameters. +type Params struct { + AirdropEnabled bool `protobuf:"varint,1,opt,name=airdrop_enabled,json=airdropEnabled,proto3" json:"airdrop_enabled,omitempty"` + // airdrop starting time + AirdropStartTime time.Time `protobuf:"bytes,2,opt,name=airdrop_start_time,json=airdropStartTime,proto3,stdtime" json:"airdrop_start_time" yaml:"airdrop_start_time"` + DurationUntilDecay time.Duration `protobuf:"bytes,3,opt,name=duration_until_decay,json=durationUntilDecay,proto3,stdduration" json:"duration_until_decay,omitempty" yaml:"duration_until_decay"` + DurationOfDecay time.Duration `protobuf:"bytes,4,opt,name=duration_of_decay,json=durationOfDecay,proto3,stdduration" json:"duration_of_decay,omitempty" yaml:"duration_of_decay"` + // denom of claimable asset + ClaimDenom string `protobuf:"bytes,5,opt,name=claim_denom,json=claimDenom,proto3" json:"claim_denom,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_b8f1f6d76eb4e4f0, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetAirdropEnabled() bool { + if m != nil { + return m.AirdropEnabled + } + return false +} + +func (m *Params) GetAirdropStartTime() time.Time { + if m != nil { + return m.AirdropStartTime + } + return time.Time{} +} + +func (m *Params) GetDurationUntilDecay() time.Duration { + if m != nil { + return m.DurationUntilDecay + } + return 0 +} + +func (m *Params) GetDurationOfDecay() time.Duration { + if m != nil { + return m.DurationOfDecay + } + return 0 +} + +func (m *Params) GetClaimDenom() string { + if m != nil { + return m.ClaimDenom + } + return "" +} + +func init() { + proto.RegisterType((*Params)(nil), "passage3d.claim.v1beta1.Params") +} + +func init() { + proto.RegisterFile("passage3d/claim/v1beta1/params.proto", fileDescriptor_b8f1f6d76eb4e4f0) +} + +var fileDescriptor_b8f1f6d76eb4e4f0 = []byte{ + // 424 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x41, 0x6b, 0xd4, 0x40, + 0x18, 0x86, 0x33, 0xb6, 0x16, 0x9d, 0x82, 0xd5, 0x50, 0x30, 0xdd, 0xc2, 0xcc, 0x12, 0x14, 0x17, + 0x91, 0x0c, 0xb5, 0xb7, 0x1e, 0xd7, 0x78, 0xf0, 0xa4, 0xac, 0x7a, 0xf1, 0x12, 0x26, 0x9b, 0xd9, + 0x38, 0x90, 0xc9, 0x84, 0x64, 0xb2, 0x98, 0xbf, 0xe0, 0xa9, 0x27, 0xe9, 0xd1, 0x9f, 0xd3, 0x63, + 0x8f, 0x9e, 0xa2, 0xec, 0xde, 0xbc, 0x08, 0xfb, 0x0b, 0x64, 0x26, 0x93, 0x15, 0x77, 0x17, 0x7a, + 0x4b, 0xde, 0xef, 0xf9, 0xf2, 0x3e, 0x81, 0x0f, 0x3e, 0x29, 0x68, 0x55, 0xd1, 0x94, 0x9d, 0x27, + 0x64, 0x9a, 0x51, 0x2e, 0xc8, 0xfc, 0x2c, 0x66, 0x8a, 0x9e, 0x91, 0x82, 0x96, 0x54, 0x54, 0x41, + 0x51, 0x4a, 0x25, 0xdd, 0xc7, 0x6b, 0x2a, 0x30, 0x54, 0x60, 0xa9, 0xc1, 0x71, 0x2a, 0x53, 0x69, + 0x18, 0xa2, 0x9f, 0x3a, 0x7c, 0x80, 0x53, 0x29, 0xd3, 0x8c, 0x11, 0xf3, 0x16, 0xd7, 0x33, 0xa2, + 0xb8, 0x60, 0x95, 0xa2, 0xa2, 0xb0, 0x00, 0xda, 0x04, 0x92, 0xba, 0xa4, 0x8a, 0xcb, 0xbc, 0x9b, + 0xfb, 0x7f, 0xf6, 0xe0, 0xc1, 0x3b, 0x23, 0xe0, 0x3e, 0x83, 0x47, 0x94, 0x97, 0x49, 0x29, 0x8b, + 0x88, 0xe5, 0x34, 0xce, 0x58, 0xe2, 0x81, 0x21, 0x18, 0xdd, 0x9b, 0x3c, 0xb0, 0xf1, 0xeb, 0x2e, + 0x75, 0x25, 0x74, 0x7b, 0xb0, 0x52, 0xb4, 0x54, 0x91, 0x2e, 0xf5, 0xee, 0x0c, 0xc1, 0xe8, 0xf0, + 0xe5, 0x20, 0xe8, 0x0a, 0x83, 0xbe, 0x30, 0xf8, 0xd0, 0x1b, 0x8d, 0x9f, 0x5e, 0xb7, 0xd8, 0x59, + 0xb5, 0xf8, 0xa4, 0xa1, 0x22, 0xbb, 0xf0, 0xb7, 0xbf, 0xe1, 0x5f, 0xfe, 0xc4, 0x60, 0xf2, 0xd0, + 0x0e, 0xde, 0xeb, 0x5c, 0x6f, 0xbb, 0xdf, 0x00, 0x3c, 0xee, 0xbd, 0xa3, 0x3a, 0x57, 0x3c, 0x8b, + 0x12, 0x36, 0xa5, 0x8d, 0xb7, 0x67, 0x3a, 0x4f, 0xb6, 0x3a, 0x43, 0x0b, 0x8f, 0xdf, 0xe8, 0xca, + 0xdf, 0x2d, 0x46, 0xbb, 0xd6, 0x5f, 0x48, 0xc1, 0x15, 0x13, 0x85, 0x6a, 0x56, 0x2d, 0x3e, 0xed, + 0xa4, 0x76, 0x71, 0xfe, 0x95, 0xd6, 0x72, 0xfb, 0xd1, 0x47, 0x3d, 0x09, 0xf5, 0xc0, 0xfd, 0x0a, + 0xe0, 0xa3, 0xf5, 0x86, 0x9c, 0x59, 0xab, 0xfd, 0xdb, 0xac, 0x5e, 0x59, 0xab, 0xd3, 0xad, 0xdd, + 0xff, 0x94, 0xbc, 0x0d, 0xa5, 0x1e, 0xea, 0x7c, 0x8e, 0xfa, 0xfc, 0xed, 0xac, 0x93, 0xc1, 0xf0, + 0xd0, 0x9c, 0x4c, 0x94, 0xb0, 0x5c, 0x0a, 0xef, 0xee, 0x10, 0x8c, 0xee, 0x4f, 0xa0, 0x89, 0x42, + 0x9d, 0x5c, 0xec, 0x5f, 0x7d, 0xc7, 0xce, 0x38, 0xbc, 0x5e, 0x20, 0x70, 0xb3, 0x40, 0xe0, 0xd7, + 0x02, 0x81, 0xcb, 0x25, 0x72, 0x6e, 0x96, 0xc8, 0xf9, 0xb1, 0x44, 0xce, 0xa7, 0xe7, 0x29, 0x57, + 0x9f, 0xeb, 0x38, 0x98, 0x4a, 0x41, 0x58, 0x3e, 0xa7, 0x09, 0x9f, 0x93, 0x7f, 0x47, 0xfb, 0xc5, + 0x9e, 0xad, 0x6a, 0x0a, 0x56, 0xc5, 0x07, 0xe6, 0xaf, 0xce, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, + 0x12, 0xa9, 0xa4, 0x91, 0xd6, 0x02, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClaimDenom) > 0 { + i -= len(m.ClaimDenom) + copy(dAtA[i:], m.ClaimDenom) + i = encodeVarintParams(dAtA, i, uint64(len(m.ClaimDenom))) + i-- + dAtA[i] = 0x2a + } + n1, err1 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.DurationOfDecay, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.DurationOfDecay):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + n2, err2 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.DurationUntilDecay, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.DurationUntilDecay):]) + if err2 != nil { + return 0, err2 + } + i -= n2 + i = encodeVarintParams(dAtA, i, uint64(n2)) + i-- + dAtA[i] = 0x1a + n3, err3 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.AirdropStartTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.AirdropStartTime):]) + if err3 != nil { + return 0, err3 + } + i -= n3 + i = encodeVarintParams(dAtA, i, uint64(n3)) + i-- + dAtA[i] = 0x12 + if m.AirdropEnabled { + i-- + if m.AirdropEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.AirdropEnabled { + n += 2 + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.AirdropStartTime) + n += 1 + l + sovParams(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.DurationUntilDecay) + n += 1 + l + sovParams(uint64(l)) + l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.DurationOfDecay) + n += 1 + l + sovParams(uint64(l)) + l = len(m.ClaimDenom) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AirdropEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.AirdropEnabled = bool(v != 0) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AirdropStartTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.AirdropStartTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DurationUntilDecay", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.DurationUntilDecay, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DurationOfDecay", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.DurationOfDecay, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClaimDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/claim/types/query.pb.go b/x/claim/types/query.pb.go new file mode 100644 index 0000000..5271eb8 --- /dev/null +++ b/x/claim/types/query.pb.go @@ -0,0 +1,2115 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: passage3d/claim/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryModuleAccountBalanceRequest is the request type for the Query/ModuleAccountBalance RPC method. +type QueryModuleAccountBalanceRequest struct { +} + +func (m *QueryModuleAccountBalanceRequest) Reset() { *m = QueryModuleAccountBalanceRequest{} } +func (m *QueryModuleAccountBalanceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountBalanceRequest) ProtoMessage() {} +func (*QueryModuleAccountBalanceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{0} +} +func (m *QueryModuleAccountBalanceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountBalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountBalanceRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryModuleAccountBalanceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountBalanceRequest.Merge(m, src) +} +func (m *QueryModuleAccountBalanceRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountBalanceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountBalanceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountBalanceRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryModuleAccountBalanceResponse struct { + // params defines the parameters of the module. + ModuleAccountBalance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=module_account_balance,json=moduleAccountBalance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"module_account_balance" yaml:"coins"` +} + +func (m *QueryModuleAccountBalanceResponse) Reset() { *m = QueryModuleAccountBalanceResponse{} } +func (m *QueryModuleAccountBalanceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountBalanceResponse) ProtoMessage() {} +func (*QueryModuleAccountBalanceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{1} +} +func (m *QueryModuleAccountBalanceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountBalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountBalanceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryModuleAccountBalanceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountBalanceResponse.Merge(m, src) +} +func (m *QueryModuleAccountBalanceResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountBalanceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountBalanceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountBalanceResponse proto.InternalMessageInfo + +func (m *QueryModuleAccountBalanceResponse) GetModuleAccountBalance() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.ModuleAccountBalance + } + return nil +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{2} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{3} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryClaimRecordRequest is the request type for the Query/ClaimRecord RPC method. +type QueryClaimRecordRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` +} + +func (m *QueryClaimRecordRequest) Reset() { *m = QueryClaimRecordRequest{} } +func (m *QueryClaimRecordRequest) String() string { return proto.CompactTextString(m) } +func (*QueryClaimRecordRequest) ProtoMessage() {} +func (*QueryClaimRecordRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{4} +} +func (m *QueryClaimRecordRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryClaimRecordRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryClaimRecordRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryClaimRecordRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryClaimRecordRequest.Merge(m, src) +} +func (m *QueryClaimRecordRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryClaimRecordRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryClaimRecordRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryClaimRecordRequest proto.InternalMessageInfo + +func (m *QueryClaimRecordRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +// QueryClaimRecordResponse is the response type for the Query/ClaimRecord RPC method. +type QueryClaimRecordResponse struct { + ClaimRecord ClaimRecord `protobuf:"bytes,1,opt,name=claim_record,json=claimRecord,proto3" json:"claim_record" yaml:"claim_record"` +} + +func (m *QueryClaimRecordResponse) Reset() { *m = QueryClaimRecordResponse{} } +func (m *QueryClaimRecordResponse) String() string { return proto.CompactTextString(m) } +func (*QueryClaimRecordResponse) ProtoMessage() {} +func (*QueryClaimRecordResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{5} +} +func (m *QueryClaimRecordResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryClaimRecordResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryClaimRecordResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryClaimRecordResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryClaimRecordResponse.Merge(m, src) +} +func (m *QueryClaimRecordResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryClaimRecordResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryClaimRecordResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryClaimRecordResponse proto.InternalMessageInfo + +func (m *QueryClaimRecordResponse) GetClaimRecord() ClaimRecord { + if m != nil { + return m.ClaimRecord + } + return ClaimRecord{} +} + +// QueryClaimableForActionRequest is the request type for the Query/ClaimRecord RPC method. +type QueryClaimableForActionRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` + Action string `protobuf:"bytes,2,opt,name=action,proto3" json:"action,omitempty" yaml:"action"` +} + +func (m *QueryClaimableForActionRequest) Reset() { *m = QueryClaimableForActionRequest{} } +func (m *QueryClaimableForActionRequest) String() string { return proto.CompactTextString(m) } +func (*QueryClaimableForActionRequest) ProtoMessage() {} +func (*QueryClaimableForActionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{6} +} +func (m *QueryClaimableForActionRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryClaimableForActionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryClaimableForActionRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryClaimableForActionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryClaimableForActionRequest.Merge(m, src) +} +func (m *QueryClaimableForActionRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryClaimableForActionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryClaimableForActionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryClaimableForActionRequest proto.InternalMessageInfo + +func (m *QueryClaimableForActionRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *QueryClaimableForActionRequest) GetAction() string { + if m != nil { + return m.Action + } + return "" +} + +// QueryClaimableForActionResponse is the response type for the Query/ClaimRecord RPC method. +type QueryClaimableForActionResponse struct { + Amount types.Coin `protobuf:"bytes,1,opt,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coin" json:"amount" yaml:"amount"` +} + +func (m *QueryClaimableForActionResponse) Reset() { *m = QueryClaimableForActionResponse{} } +func (m *QueryClaimableForActionResponse) String() string { return proto.CompactTextString(m) } +func (*QueryClaimableForActionResponse) ProtoMessage() {} +func (*QueryClaimableForActionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{7} +} +func (m *QueryClaimableForActionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryClaimableForActionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryClaimableForActionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryClaimableForActionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryClaimableForActionResponse.Merge(m, src) +} +func (m *QueryClaimableForActionResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryClaimableForActionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryClaimableForActionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryClaimableForActionResponse proto.InternalMessageInfo + +func (m *QueryClaimableForActionResponse) GetAmount() types.Coin { + if m != nil { + return m.Amount + } + return types.Coin{} +} + +// QueryTotalClaimableRequest is the request type for the Query/TotalClaimableRequest RPC method. +type QueryTotalClaimableRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` +} + +func (m *QueryTotalClaimableRequest) Reset() { *m = QueryTotalClaimableRequest{} } +func (m *QueryTotalClaimableRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTotalClaimableRequest) ProtoMessage() {} +func (*QueryTotalClaimableRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{8} +} +func (m *QueryTotalClaimableRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalClaimableRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalClaimableRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTotalClaimableRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalClaimableRequest.Merge(m, src) +} +func (m *QueryTotalClaimableRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalClaimableRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalClaimableRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalClaimableRequest proto.InternalMessageInfo + +func (m *QueryTotalClaimableRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +// QueryTotalClaimableResponse is the response type for the Query/TotalClaimableResponse RPC method. +type QueryTotalClaimableResponse struct { + Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins" yaml:"coins"` +} + +func (m *QueryTotalClaimableResponse) Reset() { *m = QueryTotalClaimableResponse{} } +func (m *QueryTotalClaimableResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTotalClaimableResponse) ProtoMessage() {} +func (*QueryTotalClaimableResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4fd63fd79faab761, []int{9} +} +func (m *QueryTotalClaimableResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalClaimableResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalClaimableResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTotalClaimableResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalClaimableResponse.Merge(m, src) +} +func (m *QueryTotalClaimableResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalClaimableResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalClaimableResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalClaimableResponse proto.InternalMessageInfo + +func (m *QueryTotalClaimableResponse) GetCoins() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Coins + } + return nil +} + +func init() { + proto.RegisterType((*QueryModuleAccountBalanceRequest)(nil), "passage3d.claim.v1beta1.QueryModuleAccountBalanceRequest") + proto.RegisterType((*QueryModuleAccountBalanceResponse)(nil), "passage3d.claim.v1beta1.QueryModuleAccountBalanceResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "passage3d.claim.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "passage3d.claim.v1beta1.QueryParamsResponse") + proto.RegisterType((*QueryClaimRecordRequest)(nil), "passage3d.claim.v1beta1.QueryClaimRecordRequest") + proto.RegisterType((*QueryClaimRecordResponse)(nil), "passage3d.claim.v1beta1.QueryClaimRecordResponse") + proto.RegisterType((*QueryClaimableForActionRequest)(nil), "passage3d.claim.v1beta1.QueryClaimableForActionRequest") + proto.RegisterType((*QueryClaimableForActionResponse)(nil), "passage3d.claim.v1beta1.QueryClaimableForActionResponse") + proto.RegisterType((*QueryTotalClaimableRequest)(nil), "passage3d.claim.v1beta1.QueryTotalClaimableRequest") + proto.RegisterType((*QueryTotalClaimableResponse)(nil), "passage3d.claim.v1beta1.QueryTotalClaimableResponse") +} + +func init() { + proto.RegisterFile("passage3d/claim/v1beta1/query.proto", fileDescriptor_4fd63fd79faab761) +} + +var fileDescriptor_4fd63fd79faab761 = []byte{ + // 752 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0x41, 0x4f, 0x13, 0x41, + 0x14, 0xee, 0xa0, 0x94, 0x38, 0x45, 0x12, 0x87, 0x46, 0xea, 0x62, 0x76, 0x61, 0x24, 0x01, 0x11, + 0x77, 0x6d, 0x21, 0x41, 0x49, 0x4c, 0xa0, 0x18, 0x35, 0x26, 0x26, 0xba, 0xe1, 0xe4, 0xa5, 0x99, + 0xee, 0x8e, 0xb5, 0xb1, 0xbb, 0x53, 0x76, 0xb6, 0xc4, 0x86, 0x90, 0x18, 0xcf, 0x1e, 0x30, 0x26, + 0x5e, 0xfc, 0x07, 0xfa, 0x03, 0xf8, 0x07, 0x86, 0x23, 0xc6, 0x8b, 0xa7, 0x6a, 0xc0, 0x5f, 0xc0, + 0x2f, 0x30, 0x3b, 0x33, 0x6d, 0x97, 0xd0, 0xad, 0x85, 0x83, 0xa7, 0xb6, 0x33, 0xdf, 0x7b, 0xef, + 0xfb, 0xde, 0xbc, 0xef, 0x15, 0xde, 0xa8, 0x13, 0xce, 0x49, 0x85, 0x2e, 0xba, 0x96, 0x53, 0x23, + 0x55, 0xcf, 0xda, 0xca, 0x97, 0x69, 0x48, 0xf2, 0xd6, 0x66, 0x83, 0x06, 0x4d, 0xb3, 0x1e, 0xb0, + 0x90, 0xa1, 0x89, 0x0e, 0xc8, 0x14, 0x20, 0x53, 0x81, 0xb4, 0x6c, 0x85, 0x55, 0x98, 0xc0, 0x58, + 0xd1, 0x37, 0x09, 0xd7, 0xae, 0x57, 0x18, 0xab, 0xd4, 0xa8, 0x45, 0xea, 0x55, 0x8b, 0xf8, 0x3e, + 0x0b, 0x49, 0x58, 0x65, 0x3e, 0x57, 0xb7, 0xba, 0xc3, 0xb8, 0xc7, 0xb8, 0x55, 0x26, 0x9c, 0x76, + 0xaa, 0x39, 0xac, 0xea, 0xab, 0xfb, 0x99, 0x24, 0x46, 0x75, 0x12, 0x10, 0xaf, 0x9d, 0x65, 0x3e, + 0x09, 0x25, 0x7e, 0x95, 0x02, 0xea, 0xb0, 0xc0, 0x95, 0x58, 0x8c, 0xe1, 0xd4, 0xf3, 0x48, 0xcd, + 0x53, 0xe6, 0x36, 0x6a, 0x74, 0xcd, 0x71, 0x58, 0xc3, 0x0f, 0x8b, 0xa4, 0x46, 0x7c, 0x87, 0xda, + 0x74, 0xb3, 0x41, 0x79, 0x88, 0xf7, 0x00, 0x9c, 0xee, 0x03, 0xe2, 0x75, 0xe6, 0x73, 0x8a, 0x3e, + 0x00, 0x78, 0xd5, 0x13, 0x80, 0x12, 0x91, 0x88, 0x52, 0x59, 0x42, 0x72, 0x60, 0xea, 0xc2, 0x5c, + 0xa6, 0x70, 0xcd, 0x94, 0xea, 0xcc, 0x48, 0x5d, 0xbb, 0x4d, 0xe6, 0x3a, 0xab, 0xfa, 0xc5, 0xd5, + 0xfd, 0x96, 0x91, 0x3a, 0x6e, 0x19, 0xa3, 0x4d, 0xe2, 0xd5, 0x56, 0x70, 0xa4, 0x98, 0xe3, 0x2f, + 0xbf, 0x8c, 0xb9, 0x4a, 0x35, 0x7c, 0xd5, 0x28, 0x9b, 0x0e, 0xf3, 0x2c, 0xd5, 0x1a, 0xf9, 0x71, + 0x9b, 0xbb, 0xaf, 0xad, 0xb0, 0x59, 0xa7, 0x5c, 0x24, 0xe0, 0x76, 0xd6, 0xeb, 0xc1, 0x0d, 0x67, + 0x21, 0x12, 0xc4, 0x9f, 0x89, 0xf6, 0xb4, 0xf5, 0x6c, 0xc0, 0xf1, 0x13, 0xa7, 0x4a, 0xc0, 0x7d, + 0x98, 0x96, 0x6d, 0xcc, 0x81, 0x29, 0x30, 0x97, 0x29, 0x18, 0x66, 0xc2, 0xd3, 0x9a, 0x32, 0xb0, + 0x78, 0x31, 0x62, 0x6d, 0xab, 0x20, 0xfc, 0x08, 0x4e, 0x88, 0xac, 0xeb, 0x11, 0xd4, 0x16, 0x3d, + 0x56, 0x05, 0xd1, 0x02, 0x1c, 0x21, 0xae, 0x1b, 0x50, 0x2e, 0x53, 0x5f, 0x2a, 0xa2, 0xe3, 0x96, + 0x31, 0x26, 0xb5, 0xaa, 0x0b, 0x6c, 0xb7, 0x21, 0xf8, 0x2d, 0x80, 0xb9, 0xd3, 0x99, 0x14, 0x49, + 0x17, 0x8e, 0xc6, 0x5f, 0x51, 0x51, 0x9d, 0x49, 0xa4, 0x1a, 0xcb, 0x51, 0x9c, 0x54, 0x5d, 0x1e, + 0x57, 0x5d, 0x8e, 0xe5, 0xc1, 0x76, 0xc6, 0xe9, 0x22, 0x71, 0x13, 0xea, 0x5d, 0x06, 0xa4, 0x5c, + 0xa3, 0x0f, 0x59, 0xb0, 0xe6, 0x44, 0x93, 0x7a, 0x2e, 0x49, 0xe8, 0x26, 0x4c, 0x13, 0x11, 0x9e, + 0x1b, 0x12, 0xe0, 0x2b, 0xc7, 0x2d, 0xe3, 0xb2, 0x02, 0x8b, 0x73, 0x6c, 0x2b, 0x00, 0xfe, 0x04, + 0xa0, 0x91, 0x58, 0x5b, 0x35, 0x81, 0xc3, 0x34, 0xf1, 0xa2, 0x77, 0x56, 0xf2, 0x07, 0x98, 0xac, + 0x76, 0x35, 0x11, 0x16, 0x8d, 0xd6, 0xec, 0x80, 0xa3, 0x65, 0xab, 0x52, 0xf8, 0x09, 0xd4, 0x04, + 0xaf, 0x0d, 0x16, 0x92, 0x5a, 0x87, 0xdc, 0xf9, 0x9e, 0x78, 0x17, 0xc0, 0xc9, 0x9e, 0xc9, 0x94, + 0xc0, 0x4d, 0x38, 0x2c, 0x3c, 0xf0, 0x3f, 0x9c, 0x23, 0x2b, 0x15, 0x3e, 0x8f, 0xc0, 0x61, 0x41, + 0x09, 0x7d, 0x03, 0x30, 0xdb, 0xcb, 0xe9, 0xe8, 0x5e, 0xe2, 0x94, 0xfd, 0x6b, 0x85, 0x68, 0x2b, + 0xe7, 0x09, 0x95, 0xcd, 0xc0, 0xcb, 0xef, 0x7e, 0xfc, 0xf9, 0x38, 0x94, 0x47, 0x96, 0x95, 0xb4, + 0xd7, 0x7a, 0xaf, 0x1d, 0xf4, 0x1e, 0xc0, 0xb4, 0xb4, 0x2a, 0xba, 0xd5, 0xbf, 0xfe, 0x89, 0xfd, + 0xa0, 0x2d, 0x0c, 0x06, 0x56, 0xf4, 0x66, 0x05, 0xbd, 0x69, 0x64, 0x58, 0xfd, 0x97, 0x33, 0xfa, + 0x0a, 0x60, 0x26, 0x66, 0x47, 0x74, 0xa7, 0x7f, 0x99, 0xd3, 0x7b, 0x44, 0xcb, 0x9f, 0x21, 0x62, + 0xe0, 0xe6, 0xc5, 0xd7, 0x80, 0xb5, 0xad, 0x26, 0x74, 0x07, 0x7d, 0x07, 0x10, 0x9d, 0xb6, 0x20, + 0x5a, 0x1e, 0x80, 0x42, 0xaf, 0x85, 0xa1, 0xdd, 0x3d, 0x7b, 0xa0, 0x92, 0xf0, 0x58, 0x48, 0x28, + 0xa2, 0xd5, 0xfe, 0x12, 0xa2, 0xe0, 0xd2, 0x4b, 0x16, 0x94, 0xe4, 0x22, 0xe9, 0x4a, 0xb1, 0xb6, + 0xe5, 0xc9, 0x0e, 0xda, 0x03, 0x70, 0xec, 0xa4, 0xe3, 0xd0, 0x62, 0x7f, 0x5a, 0x3d, 0xcd, 0xae, + 0x2d, 0x9d, 0x2d, 0x48, 0xe9, 0x58, 0x11, 0x3a, 0x96, 0x50, 0x21, 0x51, 0x47, 0x18, 0x05, 0x96, + 0x3a, 0x6a, 0xba, 0x12, 0x8a, 0x0f, 0xf6, 0x0f, 0x75, 0x70, 0x70, 0xa8, 0x83, 0xdf, 0x87, 0x3a, + 0xd8, 0x3d, 0xd2, 0x53, 0x07, 0x47, 0x7a, 0xea, 0xe7, 0x91, 0x9e, 0x7a, 0x31, 0x1f, 0x33, 0x3a, + 0xf5, 0xb7, 0x88, 0x5b, 0xdd, 0x8a, 0xe5, 0x7f, 0xa3, 0x2a, 0x08, 0xc3, 0x97, 0xd3, 0xe2, 0x3f, + 0x7f, 0xf1, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x82, 0x9e, 0x31, 0xd9, 0x08, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // ModuleAccountBalance RPC returns the claim module account balance + ModuleAccountBalance(ctx context.Context, in *QueryModuleAccountBalanceRequest, opts ...grpc.CallOption) (*QueryModuleAccountBalanceResponse, error) + // Params RPC returns claim module params + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // ClaimRecord RPC returns claim record for an address + ClaimRecord(ctx context.Context, in *QueryClaimRecordRequest, opts ...grpc.CallOption) (*QueryClaimRecordResponse, error) + // ClaimableForAction RPC returns claimable amount for an action of an address + ClaimableForAction(ctx context.Context, in *QueryClaimableForActionRequest, opts ...grpc.CallOption) (*QueryClaimableForActionResponse, error) + // TotalClaimable RPC returns total claimable amount for address + TotalClaimable(ctx context.Context, in *QueryTotalClaimableRequest, opts ...grpc.CallOption) (*QueryTotalClaimableResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) ModuleAccountBalance(ctx context.Context, in *QueryModuleAccountBalanceRequest, opts ...grpc.CallOption) (*QueryModuleAccountBalanceResponse, error) { + out := new(QueryModuleAccountBalanceResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Query/ModuleAccountBalance", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ClaimRecord(ctx context.Context, in *QueryClaimRecordRequest, opts ...grpc.CallOption) (*QueryClaimRecordResponse, error) { + out := new(QueryClaimRecordResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Query/ClaimRecord", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ClaimableForAction(ctx context.Context, in *QueryClaimableForActionRequest, opts ...grpc.CallOption) (*QueryClaimableForActionResponse, error) { + out := new(QueryClaimableForActionResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Query/ClaimableForAction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TotalClaimable(ctx context.Context, in *QueryTotalClaimableRequest, opts ...grpc.CallOption) (*QueryTotalClaimableResponse, error) { + out := new(QueryTotalClaimableResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Query/TotalClaimable", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // ModuleAccountBalance RPC returns the claim module account balance + ModuleAccountBalance(context.Context, *QueryModuleAccountBalanceRequest) (*QueryModuleAccountBalanceResponse, error) + // Params RPC returns claim module params + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // ClaimRecord RPC returns claim record for an address + ClaimRecord(context.Context, *QueryClaimRecordRequest) (*QueryClaimRecordResponse, error) + // ClaimableForAction RPC returns claimable amount for an action of an address + ClaimableForAction(context.Context, *QueryClaimableForActionRequest) (*QueryClaimableForActionResponse, error) + // TotalClaimable RPC returns total claimable amount for address + TotalClaimable(context.Context, *QueryTotalClaimableRequest) (*QueryTotalClaimableResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) ModuleAccountBalance(ctx context.Context, req *QueryModuleAccountBalanceRequest) (*QueryModuleAccountBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ModuleAccountBalance not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) ClaimRecord(ctx context.Context, req *QueryClaimRecordRequest) (*QueryClaimRecordResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ClaimRecord not implemented") +} +func (*UnimplementedQueryServer) ClaimableForAction(ctx context.Context, req *QueryClaimableForActionRequest) (*QueryClaimableForActionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ClaimableForAction not implemented") +} +func (*UnimplementedQueryServer) TotalClaimable(ctx context.Context, req *QueryTotalClaimableRequest) (*QueryTotalClaimableResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalClaimable not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_ModuleAccountBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryModuleAccountBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ModuleAccountBalance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Query/ModuleAccountBalance", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ModuleAccountBalance(ctx, req.(*QueryModuleAccountBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ClaimRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryClaimRecordRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ClaimRecord(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Query/ClaimRecord", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ClaimRecord(ctx, req.(*QueryClaimRecordRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ClaimableForAction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryClaimableForActionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ClaimableForAction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Query/ClaimableForAction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ClaimableForAction(ctx, req.(*QueryClaimableForActionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TotalClaimable_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTotalClaimableRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalClaimable(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Query/TotalClaimable", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalClaimable(ctx, req.(*QueryTotalClaimableRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "passage3d.claim.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ModuleAccountBalance", + Handler: _Query_ModuleAccountBalance_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "ClaimRecord", + Handler: _Query_ClaimRecord_Handler, + }, + { + MethodName: "ClaimableForAction", + Handler: _Query_ClaimableForAction_Handler, + }, + { + MethodName: "TotalClaimable", + Handler: _Query_TotalClaimable_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "passage3d/claim/v1beta1/query.proto", +} + +func (m *QueryModuleAccountBalanceRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryModuleAccountBalanceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountBalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryModuleAccountBalanceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryModuleAccountBalanceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountBalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ModuleAccountBalance) > 0 { + for iNdEx := len(m.ModuleAccountBalance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ModuleAccountBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryClaimRecordRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryClaimRecordRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryClaimRecordRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryClaimRecordResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryClaimRecordResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryClaimRecordResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ClaimRecord.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryClaimableForActionRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryClaimableForActionRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryClaimableForActionRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Action) > 0 { + i -= len(m.Action) + copy(dAtA[i:], m.Action) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Action))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryClaimableForActionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryClaimableForActionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryClaimableForActionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryTotalClaimableRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTotalClaimableRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalClaimableRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTotalClaimableResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTotalClaimableResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalClaimableResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Coins) > 0 { + for iNdEx := len(m.Coins) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Coins[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryModuleAccountBalanceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryModuleAccountBalanceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.ModuleAccountBalance) > 0 { + for _, e := range m.ModuleAccountBalance { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryClaimRecordRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryClaimRecordResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ClaimRecord.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryClaimableForActionRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.Action) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryClaimableForActionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryTotalClaimableRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalClaimableResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Coins) > 0 { + for _, e := range m.Coins { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryModuleAccountBalanceRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryModuleAccountBalanceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountBalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryModuleAccountBalanceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryModuleAccountBalanceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountBalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccountBalance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ModuleAccountBalance = append(m.ModuleAccountBalance, types.Coin{}) + if err := m.ModuleAccountBalance[len(m.ModuleAccountBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryClaimRecordRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryClaimRecordRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryClaimRecordRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryClaimRecordResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryClaimRecordResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryClaimRecordResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimRecord", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ClaimRecord.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryClaimableForActionRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryClaimableForActionRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryClaimableForActionRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Action", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Action = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryClaimableForActionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryClaimableForActionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryClaimableForActionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalClaimableRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTotalClaimableRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalClaimableRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalClaimableResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTotalClaimableResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalClaimableResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Coins = append(m.Coins, types.Coin{}) + if err := m.Coins[len(m.Coins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/claim/types/query.pb.gw.go b/x/claim/types/query.pb.gw.go new file mode 100644 index 0000000..d60bdf9 --- /dev/null +++ b/x/claim/types/query.pb.gw.go @@ -0,0 +1,526 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: passage3d/claim/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +func request_Query_ModuleAccountBalance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountBalanceRequest + var metadata runtime.ServerMetadata + + msg, err := client.ModuleAccountBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ModuleAccountBalance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountBalanceRequest + var metadata runtime.ServerMetadata + + msg, err := server.ModuleAccountBalance(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ClaimRecord_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryClaimRecordRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := client.ClaimRecord(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ClaimRecord_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryClaimRecordRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := server.ClaimRecord(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ClaimableForAction_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryClaimableForActionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + val, ok = pathParams["action"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "action") + } + + protoReq.Action, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "action", err) + } + + msg, err := client.ClaimableForAction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ClaimableForAction_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryClaimableForActionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + val, ok = pathParams["action"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "action") + } + + protoReq.Action, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "action", err) + } + + msg, err := server.ClaimableForAction(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_TotalClaimable_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalClaimableRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := client.TotalClaimable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TotalClaimable_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalClaimableRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := server.TotalClaimable(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_ModuleAccountBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ModuleAccountBalance_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ModuleAccountBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ClaimRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ClaimRecord_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ClaimRecord_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ClaimableForAction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ClaimableForAction_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ClaimableForAction_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalClaimable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TotalClaimable_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalClaimable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_ModuleAccountBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ModuleAccountBalance_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ModuleAccountBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ClaimRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ClaimRecord_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ClaimRecord_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ClaimableForAction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ClaimableForAction_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ClaimableForAction_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalClaimable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TotalClaimable_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalClaimable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_ModuleAccountBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"passage3d", "claim", "v1beta1", "module_account_balance"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"passage3d", "claim", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_ClaimRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"passage3d", "claim", "v1beta1", "claim_record", "address"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_ClaimableForAction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"passage3d", "claim", "v1beta1", "claimable_for_action", "address", "action"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_TotalClaimable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"passage3d", "claim", "v1beta1", "total_claimable", "address"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_ModuleAccountBalance_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_ClaimRecord_0 = runtime.ForwardResponseMessage + + forward_Query_ClaimableForAction_0 = runtime.ForwardResponseMessage + + forward_Query_TotalClaimable_0 = runtime.ForwardResponseMessage +) diff --git a/x/claim/types/tx.pb.go b/x/claim/types/tx.pb.go new file mode 100644 index 0000000..4d8e2e3 --- /dev/null +++ b/x/claim/types/tx.pb.go @@ -0,0 +1,641 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: passage3d/claim/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgInitialClaim defines request message for InitialClaim RPC request +type MsgClaim struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + ClaimAction string `protobuf:"bytes,2,opt,name=claim_action,json=claimAction,proto3" json:"claim_action,omitempty"` +} + +func (m *MsgClaim) Reset() { *m = MsgClaim{} } +func (m *MsgClaim) String() string { return proto.CompactTextString(m) } +func (*MsgClaim) ProtoMessage() {} +func (*MsgClaim) Descriptor() ([]byte, []int) { + return fileDescriptor_e631e60465986712, []int{0} +} +func (m *MsgClaim) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClaim) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClaim.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgClaim) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClaim.Merge(m, src) +} +func (m *MsgClaim) XXX_Size() int { + return m.Size() +} +func (m *MsgClaim) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClaim.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClaim proto.InternalMessageInfo + +func (m *MsgClaim) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgClaim) GetClaimAction() string { + if m != nil { + return m.ClaimAction + } + return "" +} + +// MsgInitialClaimResponse defines response for InitialClaim RPC request +type MsgClaimResponse struct { + // total initial claimable amount for the user + ClaimedAmount types.Coin `protobuf:"bytes,2,opt,name=claimed_amount,json=claimedAmount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"claimed_amount" yaml:"claimed_amount"` +} + +func (m *MsgClaimResponse) Reset() { *m = MsgClaimResponse{} } +func (m *MsgClaimResponse) String() string { return proto.CompactTextString(m) } +func (*MsgClaimResponse) ProtoMessage() {} +func (*MsgClaimResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e631e60465986712, []int{1} +} +func (m *MsgClaimResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgClaimResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgClaimResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgClaimResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgClaimResponse.Merge(m, src) +} +func (m *MsgClaimResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgClaimResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgClaimResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgClaimResponse proto.InternalMessageInfo + +func (m *MsgClaimResponse) GetClaimedAmount() types.Coin { + if m != nil { + return m.ClaimedAmount + } + return types.Coin{} +} + +func init() { + proto.RegisterType((*MsgClaim)(nil), "passage3d.claim.v1beta1.MsgClaim") + proto.RegisterType((*MsgClaimResponse)(nil), "passage3d.claim.v1beta1.MsgClaimResponse") +} + +func init() { proto.RegisterFile("passage3d/claim/v1beta1/tx.proto", fileDescriptor_e631e60465986712) } + +var fileDescriptor_e631e60465986712 = []byte{ + // 343 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x28, 0x48, 0x2c, 0x2e, + 0x4e, 0x4c, 0x4f, 0x35, 0x4e, 0xd1, 0x4f, 0xce, 0x49, 0xcc, 0xcc, 0xd5, 0x2f, 0x33, 0x4c, 0x4a, + 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0xab, + 0xd0, 0x03, 0xab, 0xd0, 0x83, 0xaa, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd1, 0x07, + 0xb1, 0x20, 0xca, 0xa5, 0xe4, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x93, 0x12, 0x8b, 0x53, + 0xe1, 0x86, 0x25, 0xe7, 0x67, 0xe6, 0x41, 0xe4, 0x95, 0x5c, 0xb9, 0x38, 0x7c, 0x8b, 0xd3, 0x9d, + 0x41, 0x26, 0x09, 0x89, 0x71, 0xb1, 0x15, 0xa7, 0xe6, 0xa5, 0xa4, 0x16, 0x49, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x41, 0x79, 0x42, 0x8a, 0x5c, 0x3c, 0x60, 0xab, 0xe2, 0x13, 0x93, 0x4b, 0x32, + 0xf3, 0xf3, 0x24, 0x98, 0xc0, 0xb2, 0xdc, 0x60, 0x31, 0x47, 0xb0, 0x90, 0xd2, 0x02, 0x46, 0x2e, + 0x01, 0x98, 0x39, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0xdd, 0x8c, 0x5c, 0x7c, + 0x60, 0x45, 0xa9, 0x29, 0xf1, 0x89, 0xb9, 0xf9, 0xa5, 0x79, 0x25, 0x60, 0xad, 0xdc, 0x46, 0x92, + 0x7a, 0x10, 0x57, 0xe9, 0x81, 0x5c, 0x05, 0xf3, 0x80, 0x9e, 0x73, 0x7e, 0x66, 0x9e, 0x93, 0xe7, + 0x89, 0x7b, 0xf2, 0x0c, 0x9f, 0xee, 0xc9, 0x8b, 0x56, 0x26, 0xe6, 0xe6, 0x58, 0x29, 0xa1, 0x6a, + 0x57, 0x5a, 0x75, 0x5f, 0x5e, 0x23, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, + 0x1f, 0xea, 0x37, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, 0x52, 0x59, 0x90, 0x5a, 0x0c, 0x36, + 0xa9, 0x38, 0x88, 0x17, 0xaa, 0xd9, 0x11, 0xac, 0xd7, 0x28, 0x86, 0x8b, 0xd9, 0xb7, 0x38, 0x5d, + 0x28, 0x94, 0x8b, 0x15, 0xe2, 0x5b, 0x45, 0x3d, 0x1c, 0x21, 0xa9, 0x07, 0xf3, 0x88, 0x94, 0x26, + 0x41, 0x25, 0x30, 0xbf, 0x3a, 0xb9, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, + 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, + 0x94, 0x16, 0x92, 0x83, 0x53, 0xf3, 0xca, 0x12, 0x53, 0x32, 0xcb, 0xf4, 0x11, 0xb1, 0x5c, 0x01, + 0x8d, 0x67, 0xb0, 0xc3, 0x93, 0xd8, 0xc0, 0x91, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xae, + 0x06, 0x57, 0xb2, 0x07, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // InitialClaim defines RPC service for claim + Claim(ctx context.Context, in *MsgClaim, opts ...grpc.CallOption) (*MsgClaimResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Claim(ctx context.Context, in *MsgClaim, opts ...grpc.CallOption) (*MsgClaimResponse, error) { + out := new(MsgClaimResponse) + err := c.cc.Invoke(ctx, "/passage3d.claim.v1beta1.Msg/Claim", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // InitialClaim defines RPC service for claim + Claim(context.Context, *MsgClaim) (*MsgClaimResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Claim(ctx context.Context, req *MsgClaim) (*MsgClaimResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Claim not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Claim_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgClaim) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Claim(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/passage3d.claim.v1beta1.Msg/Claim", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Claim(ctx, req.(*MsgClaim)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "passage3d.claim.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Claim", + Handler: _Msg_Claim_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "passage3d/claim/v1beta1/tx.proto", +} + +func (m *MsgClaim) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgClaim) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClaim) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ClaimAction) > 0 { + i -= len(m.ClaimAction) + copy(dAtA[i:], m.ClaimAction) + i = encodeVarintTx(dAtA, i, uint64(len(m.ClaimAction))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgClaimResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgClaimResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgClaimResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ClaimedAmount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgClaim) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ClaimAction) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgClaimResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ClaimedAmount.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgClaim) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgClaim: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClaim: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimAction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ClaimAction = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgClaimResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgClaimResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgClaimResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClaimedAmount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ClaimedAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)