diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..7f662a4f --- /dev/null +++ b/.clang-format @@ -0,0 +1,116 @@ +--- +Language: Proto +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +RawStringFormats: + - Delimiters: + - pb + Language: TextProto + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + diff --git a/.codecov.yml b/.codecov.yml index 758acd48..4eae1907 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -14,9 +14,13 @@ coverage: default: threshold: 1% # allow this much decrease on project app: - target: 80% - paths: "app/" - + target: 70% + flags: + - app + modules: + target: 70% + flags: + - modules changes: false comment: @@ -24,10 +28,24 @@ comment: behavior: default # update if exists else create new require_changes: true +flags: + app: + paths: + - "app/" + modules: + paths: + - "x/" + - "!x/**/client/" # ignore client package + ignore: + - "docs" - "*.md" - "*.rst" - - "cmd/" - - "contrib/" - - "docs/" - - "networks/" + - "**/*.pb.go" + - "types/*.pb.go" + - "tests/*" + - "tests/**/*" + - "x/**/*.pb.go" + - "x/**/test_common.go" + - "scripts/" + - "contrib" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 12492abc..5c4bb3bb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,18 +11,19 @@ jobs: golangci: name: golangci-lint runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | - .go - .mod - .sum + **/**.go + go.mod + go.sum - uses: golangci/golangci-lint-action@master with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.28.3 + version: v1.28 args: --timeout 10m github-token: ${{ secrets.github_token }} - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 50f03b37..b102eb02 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -33,7 +33,7 @@ jobs: run: echo "::add-path::$(go env GOPATH)/bin" shell: bash - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -45,17 +45,17 @@ jobs: with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - name: test nondeterminism run: | make test-sim-nondeterminism - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF test-sim-import-export: runs-on: ubuntu-latest needs: Build steps: - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -71,11 +71,11 @@ jobs: with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - name: test-sim-import-export run: | make test-sim-import-export - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF test-sim-after-import: runs-on: ubuntu-latest @@ -86,7 +86,7 @@ jobs: echo "::add-path::$(go env GOPATH)/bin" shell: bash - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -98,11 +98,11 @@ jobs: with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - name: test after import run: | make test-sim-after-import - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF test-sim-multi-seed-short: runs-on: ubuntu-latest @@ -112,7 +112,7 @@ jobs: run: echo "::add-path::$(go env GOPATH)/bin" shell: bash - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -124,8 +124,8 @@ jobs: with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - name: test-sim-multi-seed-short run: | make test-sim-multi-seed-short - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 079a3929..270e9bef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -27,7 +27,7 @@ jobs: - name: test & coverage report creation run: | go test ./... -mod=readonly -timeout 12m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - name: filter out DONTCOVER run: | excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')" @@ -38,12 +38,12 @@ jobs: echo "Excluding ${filename} from coverage report..." sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt done - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF - uses: codecov/codecov-action@v1 with: file: ./coverage.txt # optional fail_ci_if_error: true - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF integration-tests: runs-on: ubuntu-latest @@ -52,7 +52,7 @@ jobs: run: echo "::add-path::$(go env GOPATH)/bin" shell: bash - uses: actions/checkout@v2 - - uses: technote-space/get-diff-action@v1 + - uses: technote-space/get-diff-action@v4 with: SUFFIX_FILTER: | .go @@ -63,4 +63,4 @@ jobs: - name: Test CLI integration run: | make test-build - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF diff --git a/.golangci.yml b/.golangci.yml index c1770590..b079faec 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,10 +1,17 @@ +run: + tests: false +# # timeout for analysis, e.g. 30s, 5m, default is 1m +# timeout: 5m + linters: + # TODO: re-enable commented linters + disable-all: true enable: - bodyclose - deadcode - depguard - dogsled - - errcheck + # - errcheck - goconst - gocritic - gofmt @@ -15,8 +22,8 @@ linters: - govet - ineffassign - interfacer - - misspell - maligned + - misspell - nakedret - prealloc - scopelint @@ -26,16 +33,31 @@ linters: - typecheck - unconvert - unused - - varcheck + - unparam + # - wsl + - nolintlint issues: exclude-rules: - text: "Use of weak random number generator" linters: - gosec + - text: "comment on exported var" + linters: + - golint + - text: "don't use an underscore in package name" + linters: + - golint - text: "ST1003:" linters: - stylecheck + # FIXME: Disabled until golangci-lint updates stylecheck with this fix: + # https://github.com/dominikh/go-tools/issues/389 + - text: "ST1016:" + linters: + - stylecheck + max-issues-per-linter: 10000 + max-same-issues: 10000 linters-settings: dogsled: @@ -43,19 +65,8 @@ linters-settings: maligned: # print struct with more effective memory layout or not, false by default suggest-new: true - errcheck: - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: true - golint: - # minimal confidence for issues, default is 0.8 - min-confidence: 0 - prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. - simple: false - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: true # Report preallocation suggestions on for loops, false by default + nolintlint: + allow-unused: false + allow-leading-space: true + require-explanation: false + require-specific: false diff --git a/Makefile b/Makefile index bc74b783..839c3742 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ LEDGER_ENABLED ?= true SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') BUILDDIR ?= $(CURDIR)/build TEST_DOCKER_REPO=jackzampolin/sommtest +HTTPS_GIT := https://github.com/peggyjv/sommelier.git +DOCKER := $(shell which docker) +DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf export GO111MODULE = on @@ -211,19 +214,31 @@ test-docker-push: test-docker ### Protobuf ### ############################################################################### +proto-all: proto-format proto-lint proto-gen + proto-gen: - ./contrib/protocgen.sh + @echo "Generating Protobuf files" + $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen sh ./scripts/protocgen.sh + +proto-format: + @echo "Formatting Protobuf files" + $(DOCKER) run --rm -v $(CURDIR):/workspace \ + --workdir /workspace tendermintdev/docker-build-proto \ + find ./ -not -path "./third_party/*" -name *.proto -exec .clang-format -i {} \; + +proto-swagger-gen: + @./scripts/protoc-swagger-gen.sh proto-lint: - buf check lint --error-format=json + @$(DOCKER_BUF) check lint --error-format=json proto-check-breaking: - buf check breaking --against-input '.git#branch=master' + @$(DOCKER_BUF) check breaking --against-input $(HTTPS_GIT)#branch=master -TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.0-rc3/proto/tendermint +TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.0/proto/tendermint GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master -COSMOS_SDK_PROTO_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/master/proto/cosmos/base +COSMOS_SDK_PROTO_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.40.0-rc6/proto/cosmos/base TM_CRYPTO_TYPES = third_party/proto/tendermint/crypto TM_ABCI_TYPES = third_party/proto/tendermint/abci @@ -260,6 +275,7 @@ proto-update-deps: curl -sSL $(TM_URL)/types/types.proto > $(TM_TYPES)/types.proto curl -sSL $(TM_URL)/types/evidence.proto > $(TM_TYPES)/evidence.proto curl -sSL $(TM_URL)/types/params.proto > $(TM_TYPES)/params.proto + curl -sSL $(TM_URL)/types/validator.proto > $(TM_TYPES)/validator.proto mkdir -p $(TM_CRYPTO_TYPES) curl -sSL $(TM_URL)/crypto/proof.proto > $(TM_CRYPTO_TYPES)/proof.proto @@ -323,3 +339,5 @@ buf-stamp: tools-clean: rm -f proto-tools-stamp buf-stampmodule + +.PHONY: proto-all proto-gen proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps diff --git a/app/app.go b/app/app.go index d5567f95..74f81255 100644 --- a/app/app.go +++ b/app/app.go @@ -19,6 +19,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server/api" @@ -278,7 +279,7 @@ func NewSommelierApp( // Create IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper, + appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper, ) // register the proposal types @@ -557,11 +558,11 @@ func (app *SommelierApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config. rpc.RegisterRoutes(clientCtx, apiSvr.Router) authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) // Register new tx routes from grpc-gateway. - authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter) + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register legacy and grpc-gateway routes for all modules. ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) - ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCRouter) + ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // register swagger API from root so that other applications can override easily if apiConfig.Swagger { @@ -574,6 +575,11 @@ func (app *SommelierApp) RegisterTxService(clientCtx client.Context) { authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } +// RegisterTendermintService implements the application.RegisterTendermintService method +func (app *SommelierApp) RegisterTendermintService(clientCtx client.Context) { + tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) +} + // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { statikFS, err := fs.New() @@ -608,6 +614,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(oracletypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) return paramsKeeper } diff --git a/app/helpers/test_helpers.go b/app/helpers/test_helpers.go index 7c334cde..82a73860 100644 --- a/app/helpers/test_helpers.go +++ b/app/helpers/test_helpers.go @@ -4,7 +4,7 @@ import ( "math/rand" "time" - "github.com/tendermint/tendermint/crypto" + ccrypto "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +20,7 @@ const ( ) // GenTx generates a signed mock transaction. -func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums, seq []uint64, priv ...crypto.PrivKey) (sdk.Tx, error) { +func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums, seq []uint64, priv ...ccrypto.PrivKey) (sdk.Tx, error) { sigs := make([]signing.SignatureV2, len(priv)) // create a random length memo diff --git a/app/sim_bench_test.go b/app/sim_bench_test.go index 7ea33bda..e54f7faf 100644 --- a/app/sim_bench_test.go +++ b/app/sim_bench_test.go @@ -35,7 +35,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { b, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), @@ -80,7 +80,7 @@ func BenchmarkInvariants(b *testing.B) { b, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), diff --git a/app/sim_test.go b/app/sim_test.go index 7f00144e..91046ced 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -78,7 +78,7 @@ func TestFullAppSimulation(t *testing.T) { t, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), @@ -116,7 +116,7 @@ func TestAppImportExport(t *testing.T) { t, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), @@ -214,7 +214,7 @@ func TestAppSimulationAfterImport(t *testing.T) { t, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), @@ -262,7 +262,7 @@ func TestAppSimulationAfterImport(t *testing.T) { t, os.Stdout, newApp.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(newApp, newApp.AppCodec(), config), app.ModuleAccountAddrs(), @@ -313,7 +313,7 @@ func TestAppStateDeterminism(t *testing.T) { t, os.Stdout, app.BaseApp, - AppStateFn(app.AppCodec(), app.SimulationManager()), + simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 SimulationOperations(app, app.AppCodec(), config), app.ModuleAccountAddrs(), diff --git a/app/state.go b/app/state.go deleted file mode 100644 index 8ff8760b..00000000 --- a/app/state.go +++ /dev/null @@ -1,179 +0,0 @@ -package app - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "math/rand" - "time" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/cosmos/cosmos-sdk/codec" - simapparams "github.com/cosmos/cosmos-sdk/simapp/params" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - tmjson "github.com/tendermint/tendermint/libs/json" -) - -// AppStateFn returns the initial application state using a genesis or the simulation parameters. -// It panics if the user provides files for both of them. -// If a file is not given for the genesis or the sim params, it creates a randomized one. -func AppStateFn(cdc codec.JSONMarshaler, simManager *module.SimulationManager) simtypes.AppStateFn { - return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config, - ) (appState json.RawMessage, simAccs []simtypes.Account, chainID string, genesisTimestamp time.Time) { - - if FlagGenesisTimeValue == 0 { - genesisTimestamp = simtypes.RandTimestamp(r) - } else { - genesisTimestamp = time.Unix(FlagGenesisTimeValue, 0) - } - - chainID = config.ChainID - switch { - case config.ParamsFile != "" && config.GenesisFile != "": - panic("cannot provide both a genesis file and a params file") - - case config.GenesisFile != "": - // override the default chain-id from simapp to set it later to the config - genesisDoc, accounts := AppStateFromGenesisFileFn(r, cdc, config.GenesisFile) - - if FlagGenesisTimeValue == 0 { - // use genesis timestamp if no custom timestamp is provided (i.e no random timestamp) - genesisTimestamp = genesisDoc.GenesisTime - } - - appState = genesisDoc.AppState - chainID = genesisDoc.ChainID - simAccs = accounts - - case config.ParamsFile != "": - appParams := make(simtypes.AppParams) - bz, err := ioutil.ReadFile(config.ParamsFile) - if err != nil { - panic(err) - } - - err = json.Unmarshal(bz, &appParams) - if err != nil { - panic(err) - } - appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) - - default: - appParams := make(simtypes.AppParams) - appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) - } - - return appState, simAccs, chainID, genesisTimestamp - } -} - -// AppStateRandomizedFn creates calls each module's GenesisState generator function -// and creates the simulation params -func AppStateRandomizedFn( - simManager *module.SimulationManager, r *rand.Rand, cdc codec.JSONMarshaler, - accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, -) (json.RawMessage, []simtypes.Account) { - numAccs := int64(len(accs)) - genesisState := NewDefaultGenesisState() - - // generate a random amount of initial stake coins and a random initial - // number of bonded accounts - var initialStake, numInitiallyBonded int64 - appParams.GetOrGenerate( - cdc, simapparams.StakePerAccount, &initialStake, r, - func(r *rand.Rand) { initialStake = r.Int63n(1e12) }, - ) - appParams.GetOrGenerate( - cdc, simapparams.InitiallyBondedValidators, &numInitiallyBonded, r, - func(r *rand.Rand) { numInitiallyBonded = int64(r.Intn(300)) }, - ) - - if numInitiallyBonded > numAccs { - numInitiallyBonded = numAccs - } - - fmt.Printf( - `Selected randomly generated parameters for simulated genesis: -{ - stake_per_account: "%d", - initially_bonded_validators: "%d" -} -`, initialStake, numInitiallyBonded, - ) - - simState := &module.SimulationState{ - AppParams: appParams, - Cdc: cdc, - Rand: r, - GenState: genesisState, - Accounts: accs, - InitialStake: initialStake, - NumBonded: numInitiallyBonded, - GenTimestamp: genesisTimestamp, - } - - simManager.GenerateGenesisStates(simState) - - appState, err := json.Marshal(genesisState) - if err != nil { - panic(err) - } - - return appState, accs -} - -// AppStateFromGenesisFileFn util function to generate the genesis AppState -// from a genesis.json file. -func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONMarshaler, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) { - bytes, err := ioutil.ReadFile(genesisFile) - if err != nil { - panic(err) - } - - var genesis tmtypes.GenesisDoc - // NOTE: Tendermint uses a custom JSON decoder for GenesisDoc - err = tmjson.Unmarshal(bytes, &genesis) - if err != nil { - panic(err) - } - - var appState GenesisState - err = json.Unmarshal(genesis.AppState, &appState) - if err != nil { - panic(err) - } - - var authGenesis authtypes.GenesisState - if appState[authtypes.ModuleName] != nil { - cdc.MustUnmarshalJSON(appState[authtypes.ModuleName], &authGenesis) - } - - newAccs := make([]simtypes.Account, len(authGenesis.Accounts)) - for i, acc := range authGenesis.Accounts { - // Pick a random private key, since we don't know the actual key - // This should be fine as it's only used for mock Tendermint validators - // and these keys are never actually used to sign by mock Tendermint. - privkeySeed := make([]byte, 15) - if _, err := r.Read(privkeySeed); err != nil { - panic(err) - } - - privKey := secp256k1.GenPrivKeyFromSecret(privkeySeed) - - a, ok := acc.GetCachedValue().(authtypes.AccountI) - if !ok { - panic("expected account") - } - - // create simulator accounts - simAcc := simtypes.Account{PrivKey: privKey, PubKey: privKey.PubKey(), Address: a.GetAddress()} - newAccs[i] = simAcc - } - - return genesis, newAccs -} diff --git a/app/test_helpers.go b/app/test_helpers.go deleted file mode 100644 index 8f4b385f..00000000 --- a/app/test_helpers.go +++ /dev/null @@ -1,437 +0,0 @@ -package app - -import ( - "bytes" - "encoding/hex" - "encoding/json" - "fmt" - "strconv" - "testing" - "time" - - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtypes "github.com/tendermint/tendermint/types" - dbm "github.com/tendermint/tm-db" - - bam "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/simapp/helpers" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// DefaultConsensusParams defines the default Tendermint consensus params used in -// SimApp testing. -var DefaultConsensusParams = &abci.ConsensusParams{ - Block: &abci.BlockParams{ - MaxBytes: 200000, - MaxGas: 2000000, - }, - Evidence: &tmproto.EvidenceParams{ - MaxAgeNumBlocks: 302400, - MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration - MaxBytes: 10000, - }, - Validator: &tmproto.ValidatorParams{ - PubKeyTypes: []string{ - tmtypes.ABCIPubKeyTypeEd25519, - }, - }, -} - -// Setup initializes a new SimApp. A Nop logger is set in SimApp. -func Setup(isCheckTx bool) *SommelierApp { - db := dbm.NewMemDB() - app := NewSommelierApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}) - if !isCheckTx { - // init chain must be called to stop deliverState from being nil - genesisState := NewDefaultGenesisState() - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - // Initialize the chain - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) - } - - return app -} - -// SetupWithGenesisValSet initializes a new SimApp with a validator set and genesis accounts -// that also act as delegators. For simplicity, each validator is bonded with a delegation -// of one consensus engine unit (10^6) in the default token of the simapp from first genesis -// account. A Nop logger is set in SimApp. -func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SommelierApp { - db := dbm.NewMemDB() - app := NewSommelierApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{}) - genesisState := NewDefaultGenesisState() - - // set genesis accounts - authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) - - validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) - delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) - - bondAmt := sdk.NewInt(1000000) - - for _, val := range valSet.Validators { - // Currently validator requires tmcrypto.ed25519 keys, which don't support - // our Marshaling interfaces, so we need to pack them into our version of ed25519. - // There is ongoing work to add secp256k1 keys (https://github.com/cosmos/cosmos-sdk/pull/7604). - pk, err := ed25519.FromTmEd25519(val.PubKey) - require.NoError(t, err) - pkAny, err := codectypes.PackAny(pk) - require.NoError(t, err) - validator := stakingtypes.Validator{ - OperatorAddress: sdk.ValAddress(val.Address).String(), - ConsensusPubkey: pkAny, - Jailed: false, - Status: stakingtypes.Bonded, - Tokens: bondAmt, - DelegatorShares: sdk.OneDec(), - Description: stakingtypes.Description{}, - UnbondingHeight: int64(0), - UnbondingTime: time.Unix(0, 0).UTC(), - Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), - MinSelfDelegation: sdk.ZeroInt(), - } - validators = append(validators, validator) - delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec())) - - } - - // set validators and delegations - stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) - genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis) - - totalSupply := sdk.NewCoins() - for _, b := range balances { - // add genesis acc tokens and delegated tokens to total supply - totalSupply = totalSupply.Add(b.Coins.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt))...) - } - - // update total supply - bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) - genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - - // init chain will set the validator set and initialize the genesis accounts - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) - - // commit genesis changes - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - Height: app.LastBlockHeight() + 1, - AppHash: app.LastCommitID().Hash, - ValidatorsHash: valSet.Hash(), - NextValidatorsHash: valSet.Hash(), - }}) - - return app -} - -// SetupWithGenesisAccounts initializes a new SimApp with the provided genesis -// accounts and possible balances. -func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SommelierApp { - db := dbm.NewMemDB() - app := NewSommelierApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), simapp.EmptyAppOptions{}) - - // initialize the chain with the passed in genesis accounts - genesisState := NewDefaultGenesisState() - - authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) - - totalSupply := sdk.NewCoins() - for _, b := range balances { - totalSupply = totalSupply.Add(b.Coins...) - } - - bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) - genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - app.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) - - app.Commit() - app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) - - return app -} - -type GenerateAccountStrategy func(int) []sdk.AccAddress - -// createRandomAccounts is a strategy used by addTestAddrs() in order to generated addresses in random order. -func createRandomAccounts(accNum int) []sdk.AccAddress { - testAddrs := make([]sdk.AccAddress, accNum) - for i := 0; i < accNum; i++ { - pk := ed25519.GenPrivKey().PubKey() - testAddrs[i] = sdk.AccAddress(pk.Address()) - } - - return testAddrs -} - -// createIncrementalAccounts is a strategy used by addTestAddrs() in order to generated addresses in ascending order. -func createIncrementalAccounts(accNum int) []sdk.AccAddress { - var addresses []sdk.AccAddress - var buffer bytes.Buffer - - // start at 100 so we can make up to 999 test addresses with valid test addresses - for i := 100; i < (accNum + 100); i++ { - numString := strconv.Itoa(i) - buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") //base address string - - buffer.WriteString(numString) //adding on final two digits to make addresses unique - res, _ := sdk.AccAddressFromHex(buffer.String()) - bech := res.String() - addr, _ := TestAddr(buffer.String(), bech) - - addresses = append(addresses, addr) - buffer.Reset() - } - - return addresses -} - -// AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys. -func AddTestAddrsFromPubKeys(app *SommelierApp, ctx sdk.Context, pubKeys []crypto.PubKey, accAmt sdk.Int) { - initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt)) - - setTotalSupply(app, ctx, accAmt, len(pubKeys)) - - // fill all the addresses with some coins, set the loose pool tokens simultaneously - for _, pubKey := range pubKeys { - saveAccount(app, ctx, sdk.AccAddress(pubKey.Address()), initCoins) - } -} - -// setTotalSupply provides the total supply based on accAmt * totalAccounts. -func setTotalSupply(app *SommelierApp, ctx sdk.Context, accAmt sdk.Int, totalAccounts int) { - totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(totalAccounts)))) - prevSupply := app.BankKeeper.GetSupply(ctx) - app.BankKeeper.SetSupply(ctx, banktypes.NewSupply(prevSupply.GetTotal().Add(totalSupply...))) -} - -// AddTestAddrs constructs and returns accNum amount of accounts with an -// initial balance of accAmt in random order -func AddTestAddrs(app *SommelierApp, ctx sdk.Context, accNum int, accAmt sdk.Int) []sdk.AccAddress { - return addTestAddrs(app, ctx, accNum, accAmt, createRandomAccounts) -} - -// AddTestAddrs constructs and returns accNum amount of accounts with an -// initial balance of accAmt in random order -func AddTestAddrsIncremental(app *SommelierApp, ctx sdk.Context, accNum int, accAmt sdk.Int) []sdk.AccAddress { - return addTestAddrs(app, ctx, accNum, accAmt, createIncrementalAccounts) -} - -func addTestAddrs(app *SommelierApp, ctx sdk.Context, accNum int, accAmt sdk.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { - testAddrs := strategy(accNum) - - initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt)) - setTotalSupply(app, ctx, accAmt, accNum) - - // fill all the addresses with some coins, set the loose pool tokens simultaneously - for _, addr := range testAddrs { - saveAccount(app, ctx, addr, initCoins) - } - - return testAddrs -} - -// saveAccount saves the provided account into the simapp with balance based on initCoins. -func saveAccount(app *SommelierApp, ctx sdk.Context, addr sdk.AccAddress, initCoins sdk.Coins) { - acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr) - app.AccountKeeper.SetAccount(ctx, acc) - err := app.BankKeeper.AddCoins(ctx, addr, initCoins) - if err != nil { - panic(err) - } -} - -// ConvertAddrsToValAddrs converts the provided addresses to ValAddress. -func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress { - valAddrs := make([]sdk.ValAddress, len(addrs)) - - for i, addr := range addrs { - valAddrs[i] = sdk.ValAddress(addr) - } - - return valAddrs -} - -func TestAddr(addr string, bech string) (sdk.AccAddress, error) { - res, err := sdk.AccAddressFromHex(addr) - if err != nil { - return nil, err - } - bechexpected := res.String() - if bech != bechexpected { - return nil, fmt.Errorf("bech encoding doesn't match reference") - } - - bechres, err := sdk.AccAddressFromBech32(bech) - if err != nil { - return nil, err - } - if !bytes.Equal(bechres, res) { - return nil, err - } - - return res, nil -} - -// CheckBalance checks the balance of an account. -func CheckBalance(t *testing.T, app *SommelierApp, addr sdk.AccAddress, balances sdk.Coins) { - ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{}) - require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr))) -} - -// SignCheckDeliver checks a generated signed transaction and simulates a -// block commitment with the given transaction. A test assertion is made using -// the parameter 'expPass' against the result. A corresponding result is -// returned. -func SignCheckDeliver( - t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg, - chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, -) (sdk.GasInfo, *sdk.Result, error) { - - tx, err := helpers.GenTx( - txCfg, - msgs, - sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, - chainID, - accNums, - accSeqs, - priv..., - ) - require.NoError(t, err) - txBytes, err := txCfg.TxEncoder()(tx) - require.Nil(t, err) - - // Must simulate now as CheckTx doesn't run Msgs anymore - _, res, err := app.Simulate(txBytes) - - if expSimPass { - require.NoError(t, err) - require.NotNil(t, res) - } else { - require.Error(t, err) - require.Nil(t, res) - } - - // Simulate a sending a transaction and committing a block - app.BeginBlock(abci.RequestBeginBlock{Header: header}) - gInfo, res, err := app.Deliver(txCfg.TxEncoder(), tx) - - if expPass { - require.NoError(t, err) - require.NotNil(t, res) - } else { - require.Error(t, err) - require.Nil(t, res) - } - - app.EndBlock(abci.RequestEndBlock{}) - app.Commit() - - return gInfo, res, err -} - -// GenSequenceOfTxs generates a set of signed transactions of messages, such -// that they differ only by having the sequence numbers incremented between -// every transaction. -func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) { - txs := make([]sdk.Tx, numToGenerate) - var err error - for i := 0; i < numToGenerate; i++ { - txs[i], err = helpers.GenTx( - txGen, - msgs, - sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, - "", - accNums, - initSeqNums, - priv..., - ) - if err != nil { - break - } - incrementAllSequenceNumbers(initSeqNums) - } - - return txs, err -} - -func incrementAllSequenceNumbers(initSeqNums []uint64) { - for i := 0; i < len(initSeqNums); i++ { - initSeqNums[i]++ - } -} - -// CreateTestPubKeys returns a total of numPubKeys public keys in ascending order. -func CreateTestPubKeys(numPubKeys int) []crypto.PubKey { - var publicKeys []crypto.PubKey - var buffer bytes.Buffer - - // start at 10 to avoid changing 1 to 01, 2 to 02, etc - for i := 100; i < (numPubKeys + 100); i++ { - numString := strconv.Itoa(i) - buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") // base pubkey string - buffer.WriteString(numString) // adding on final two digits to make pubkeys unique - publicKeys = append(publicKeys, NewPubKeyFromHex(buffer.String())) - buffer.Reset() - } - - return publicKeys -} - -// NewPubKeyFromHex returns a PubKey from a hex string. -func NewPubKeyFromHex(pk string) (res crypto.PubKey) { - pkBytes, err := hex.DecodeString(pk) - if err != nil { - panic(err) - } - if len(pkBytes) != ed25519.PubKeySize { - panic(errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size")) - } - return &ed25519.PubKey{Key: pkBytes} -} diff --git a/buf.yaml b/buf.yaml index 8507c9cd..61b6c595 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,6 +1,9 @@ build: roots: - - . + - proto + - third_party/proto + excludes: + - third_party/proto/google/protobuf lint: use: - DEFAULT @@ -9,11 +12,19 @@ lint: except: - UNARY_RPC - COMMENT_FIELD - - PACKAGE_DIRECTORY_MATCH + - SERVICE_SUFFIX + - PACKAGE_VERSION_SUFFIX + - RPC_REQUEST_STANDARD_NAME ignore: - - third_party + - tendermint + - gogoproto + - cosmos_proto + - google breaking: use: - FILE ignore: - - third_party + - tendermint + - gogoproto + - cosmos_proto + - google diff --git a/cmd/sommelier/cmd/genaccounts.go b/cmd/sommelier/cmd/genaccounts.go index 315f9e21..61d4b066 100644 --- a/cmd/sommelier/cmd/genaccounts.go +++ b/cmd/sommelier/cmd/genaccounts.go @@ -51,13 +51,13 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa addr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { inBuf := bufio.NewReader(cmd.InOrStdin()) - keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend) - if err != nil { - return err - } + // keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend) + // if err != nil { + // return err + // } // attempt to lookup address from Keybase if no address was provided - kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf) + kb, err := keyring.New(sdk.KeyringServiceName(), "os", clientCtx.HomeDir, inBuf) if err != nil { return err } @@ -70,7 +70,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa addr = info.GetAddress() } - coins, err := sdk.ParseCoins(args[1]) + coins, err := sdk.ParseCoinsNormalized(args[1]) if err != nil { return fmt.Errorf("failed to parse coins: %w", err) } @@ -88,7 +88,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa return err } - vestingAmt, err := sdk.ParseCoins(vestingAmtStr) + vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr) if err != nil { return fmt.Errorf("failed to parse vesting amount: %w", err) } diff --git a/cmd/sommelier/cmd/root.go b/cmd/sommelier/cmd/root.go index f8d0d9b6..c7173887 100644 --- a/cmd/sommelier/cmd/root.go +++ b/cmd/sommelier/cmd/root.go @@ -89,7 +89,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), - genutilcli.ValidateGenesisCmd(app.ModuleBasics, encodingConfig.TxConfig), + genutilcli.ValidateGenesisCmd(app.ModuleBasics), AddGenesisAccountCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), diff --git a/cmd/sommelier/cmd/testnet.go b/cmd/sommelier/cmd/testnet.go index d17e57fb..d3d22c75 100644 --- a/cmd/sommelier/cmd/testnet.go +++ b/cmd/sommelier/cmd/testnet.go @@ -10,9 +10,9 @@ import ( "os" "path/filepath" + ccrypto "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/spf13/cobra" tmconfig "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/crypto" tmos "github.com/tendermint/tendermint/libs/os" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/types" @@ -116,7 +116,7 @@ func InitTestnet( } nodeIDs := make([]string, numValidators) - valPubKeys := make([]crypto.PubKey, numValidators) + valPubKeys := make([]ccrypto.PubKey, numValidators) simappConfig := srvconfig.DefaultConfig() simappConfig.MinGasPrices = minGasPrices @@ -230,7 +230,7 @@ func InitTestnet( WithKeybase(kb). WithTxConfig(clientCtx.TxConfig) - if err := tx.Sign(txFactory, nodeDirName, txBuilder); err != nil { + if err := tx.Sign(txFactory, nodeDirName, txBuilder, true); err != nil { return err } @@ -311,7 +311,7 @@ func initGenFiles( func collectGenFiles( clientCtx client.Context, nodeConfig *tmconfig.Config, chainID string, - nodeIDs []string, valPubKeys []crypto.PubKey, numValidators int, + nodeIDs []string, valPubKeys []ccrypto.PubKey, numValidators int, outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, ) error { diff --git a/contrib/protocgen.sh b/contrib/protocgen.sh deleted file mode 100755 index 3fef9b43..00000000 --- a/contrib/protocgen.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) -for dir in $proto_dirs; do - protoc \ - -I "proto" \ - -I "third_party/proto" \ - --gocosmos_out=plugins=interfacetype+grpc,\ -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 - protoc \ - -I "proto" \ - -I "third_party/proto" \ - --grpc-gateway_out=logtostderr=true:. \ - $(find "${dir}" -maxdepth 1 -name '*.proto') - -done - -# move proto files to the right places -cp -r github.com/peggyjv/sommelier/* ./ -rm -rf github.com diff --git a/go.mod b/go.mod index 0ab3b03e..7a3c1ed4 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,24 @@ module github.com/peggyjv/sommelier -go 1.14 +go 1.15 require ( - github.com/cosmos/cosmos-sdk v0.40.0-rc3 + github.com/cosmos/cosmos-sdk v0.40.0-rc6 github.com/gogo/protobuf v1.3.1 github.com/golang/protobuf v1.4.3 github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa // indirect github.com/gorilla/mux v1.8.0 - github.com/grpc-ecosystem/grpc-gateway v1.15.2 + github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.1 github.com/stretchr/testify v1.6.1 - github.com/tendermint/tendermint v0.34.0-rc6 - github.com/tendermint/tm-db v0.6.2 - google.golang.org/genproto v0.0.0-20201014134559-03b6142f0dc9 - google.golang.org/grpc v1.33.0 - gopkg.in/yaml.v2 v2.3.0 + github.com/tendermint/tendermint v0.34.0 + github.com/tendermint/tm-db v0.6.3 + google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d + google.golang.org/grpc v1.33.2 + gopkg.in/yaml.v2 v2.4.0 ) replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 diff --git a/go.sum b/go.sum index 8f9e2878..974ceefe 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-metrics v0.3.4 h1:Xqf+7f2Vhl9tsqDYmXhnXInUdcrtgpRNpIA15/uldSc= -github.com/armon/go-metrics v0.3.4/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= +github.com/armon/go-metrics v0.3.5 h1:uq4txK6NAUvLQ60rotN+K+JuTnf3XP4TdQmcs9ma5mk= +github.com/armon/go-metrics v0.3.5/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= @@ -113,13 +113,17 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.40.0-rc3 h1:sS9BZ82dOxXiZPZdfrzSniEAzLLN0oTP5lFVyjnq2x4= -github.com/cosmos/cosmos-sdk v0.40.0-rc3/go.mod h1:eKgbkQO4FEvC+a1+eyRuL7UgluGK1ad4PufPTpQc6ZA= +github.com/cosmos/cosmos-sdk v0.40.0-rc6 h1:Lrc/z9UTRlVCyw41g35iiAfRp1XWZkOtpYWj77H6m/M= +github.com/cosmos/cosmos-sdk v0.40.0-rc6/go.mod h1:oSCJHVWSjMK5Y0Rk9BIl+VAkh6vj+3w25Q/DDiM6ow4= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= +github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= +github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= -github.com/cosmos/iavl v0.15.0-rc4 h1:P1wmET7BueqCzfxsn+BzVkDWDLY9ij2JNwkbIdM7RG8= -github.com/cosmos/iavl v0.15.0-rc4/go.mod h1:5CsecJdh44Uj4vZ6WSPeWq84hNW5BwRI36ZsAbfJvRw= +github.com/cosmos/iavl v0.15.0-rc5 h1:AMKgaAjXwGANWv56NL4q4hV+a0puSkLYD6cCQAv3i44= +github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I= +github.com/cosmos/iavl v0.15.3 h1:xE9r6HW8GeKeoYJN4zefpljZ1oukVScP/7M8oj6SUts= +github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI= @@ -273,6 +277,7 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.2.1/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= @@ -280,8 +285,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY= github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= -github.com/grpc-ecosystem/grpc-gateway v1.15.2 h1:HC+hWRWf+v5zTMPyoaYTKIJih+4sd4XRWmj0qlG87Co= -github.com/grpc-ecosystem/grpc-gateway v1.15.2/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -354,6 +359,7 @@ github.com/kkdai/bstream v1.0.0 h1:Se5gHwgp2VT2uHfDrkbbgbgEvV9cimLELwrPJctSjg8= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -435,14 +441,14 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k= -github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= +github.com/otiai10/copy v1.4.2 h1:RTiz2sol3eoXPLF4o+YWqEybwfUa/Q2Nkc4ZIUs3fwI= +github.com/otiai10/copy v1.4.2/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= -github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc= -github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= +github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E= +github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -461,6 +467,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= @@ -492,6 +499,8 @@ github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lN github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= +github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM= +github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -517,6 +526,9 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.20.0 h1:38k9hgtUBdxFwE34yS8rTHmHBa4eN16E4DJlv177LNs= +github.com/rs/zerolog v1.20.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -540,8 +552,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/afero v1.3.4 h1:8q6vk3hthlpb2SouZcnBVKboxWQWMDNF38bwholZrJc= +github.com/spf13/afero v1.3.4/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= @@ -592,8 +604,12 @@ github.com/tendermint/tendermint v0.34.0-rc4 h1:fnPyDFz9QGAU6tjExoQ8ZY63eHkzdBg5 github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= github.com/tendermint/tendermint v0.34.0-rc6 h1:SVuKGvvE22KxfuK8QUHctUrmOWJsncZSYXIYtcnoKN0= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= +github.com/tendermint/tendermint v0.34.0 h1:eXCfMgoqVSzrjzOj6clI9GAejcHH0LvOlRjpCmMJksU= +github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= +github.com/tendermint/tm-db v0.6.3 h1:ZkhQcKnB8/2jr5EaZwGndN4owkPsGezW2fSisS9zGbg= +github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= @@ -632,6 +648,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -639,10 +656,14 @@ golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= +golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -693,6 +714,7 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrS golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc h1:zK/HqS5bZxDptfPJNq8v7vJfXtkU7r9TLIoSr1bXaP4= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 h1:YfxMZzv3PjGonQYNUaeU2+DhAdqOxerQ30JFB6WgAXo= golang.org/x/net v0.0.0-20200930145003-4acb6c075d10/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -730,6 +752,7 @@ golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -748,6 +771,8 @@ golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -774,6 +799,7 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -820,8 +846,11 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaR google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201014134559-03b6142f0dc9 h1:fG84H9C3EXfuDlzkG+VEPDYHHExklP6scH1QZ5gQTqU= -google.golang.org/genproto v0.0.0-20201014134559-03b6142f0dc9/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d h1:HV9Z9qMhQEsdlvxNFELgQ11RkMzO3CMkjEySjCtuLes= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -843,8 +872,9 @@ google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.0 h1:IBKSUNL2uBS2DkJBncPP+TwT0sp9tgA8A75NjHt6umg= -google.golang.org/grpc v1.33.0/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -887,6 +917,8 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/proto/oracle/v1/ballot.proto b/proto/oracle/v1/ballot.proto deleted file mode 100644 index 2a58dc45..00000000 --- a/proto/oracle/v1/ballot.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; -package oracle.v1; - -import "gogoproto/gogo.proto"; - -option go_package = "github.com/peggyjv/sommelier/x/oracle/types"; - -// // Claim is an interface that directs its rewards to an attached bank account. -message Claim { - int64 weight = 1; - string recipient = 2; -} - -// // Denom is the object to hold configurations of each denom -message Denom { - string name = 1; - string tobin_tax = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} \ No newline at end of file diff --git a/proto/oracle/v1/genesis.proto b/proto/oracle/v1/genesis.proto index ffd7960c..af243167 100644 --- a/proto/oracle/v1/genesis.proto +++ b/proto/oracle/v1/genesis.proto @@ -1,14 +1,14 @@ syntax = "proto3"; package oracle.v1; -import "oracle/v1/vote.proto"; -import "oracle/v1/ballot.proto"; +import "oracle/v1/oracle.proto"; import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; option go_package = "github.com/peggyjv/sommelier/x/oracle/types"; -// // GenesisState - all oracle state that must be provided at genesis +// GenesisState - all oracle state that must be provided at genesis message GenesisState { Params params = 1 [ (gogoproto.nullable) = false @@ -16,9 +16,9 @@ message GenesisState { map feeder_delegations = 2 [ (gogoproto.nullable) = false ]; - repeated ExchangeRateTuple exchange_rates = 3 [ - (gogoproto.nullable) = false, - (gogoproto.castrepeated) = "[]ExchangeRateTuple" + repeated cosmos.base.v1beta1.DecCoin exchange_rates = 3 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false ]; map miss_counters = 4 [ (gogoproto.nullable) = false @@ -31,35 +31,9 @@ message GenesisState { (gogoproto.nullable) = false, (gogoproto.castrepeated) = "[]AggregateExchangeRateVote" ]; - repeated ExchangeRateTuple tobin_taxes = 7 [ - (gogoproto.nullable) = false, - (gogoproto.castrepeated) = "[]ExchangeRateTuple" - ]; -} - -// Params oracle parameters -message Params { - int64 vote_period = 1; - string vote_threshold = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; - string reward_band = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; - int64 reward_distribution_window = 4; - repeated Denom whitelist = 5 [ - (gogoproto.nullable) = false, - (gogoproto.castrepeated) = "[]Denom" - ]; - string slash_fraction = 6 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + // NOTE: the amounts here indicate the tobin tax for a given USD/{denom} pair + repeated cosmos.base.v1beta1.DecCoin tobin_taxes = 7 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", (gogoproto.nullable) = false ]; - int64 slash_window = 7; - string min_valid_per_window = 8 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} \ No newline at end of file +} diff --git a/proto/oracle/v1/oracle.proto b/proto/oracle/v1/oracle.proto new file mode 100644 index 00000000..d78a463f --- /dev/null +++ b/proto/oracle/v1/oracle.proto @@ -0,0 +1,88 @@ +syntax = "proto3"; +package oracle.v1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "github.com/peggyjv/sommelier/x/oracle/types"; + +// Claim is an interface that directs its rewards to an attached bank account. +message Claim { + int64 weight = 1; + string recipient = 2; +} + +// ExchangeRatePrevote - struct to store a validator's prevote on the rate of Luna in the denom asset +message ExchangeRatePrevote { + bytes hash = 1; + string denom = 2; + string voter = 3; + int64 submit_block = 4 [(gogoproto.moretags) = "yaml:\"submit_block\""]; +} + +// ExchangeRateVote - struct to store a validator's vote on the rate of Luna in the denom asset +message ExchangeRateVote { + string exchange_rate = 1 [ + (gogoproto.moretags) = "yaml:\"exchange_rate\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string denom = 2; + string voter = 3; +} + +// AggregateExchangeRatePrevote - struct to store a validator's aggregate prevote on the rate of Luna in the denom asset +message AggregateExchangeRatePrevote { + bytes hash = 1; + string voter = 2; + int64 submit_block = 3 [(gogoproto.moretags) = "yaml:\"submit_block\""]; +} + +// AggregateExchangeRateVote - struct to store a validator's aggregate vote on the rate of Luna in the denom asset +message AggregateExchangeRateVote { + string voter = 1; + repeated cosmos.base.v1beta1.DecCoin exchange_rate_tuples = 2 [ + (gogoproto.moretags) = "yaml:\"exchange_rate_tuples\"", + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false + ]; +} + + +// Params oracle parameters +message Params { + int64 vote_period = 1 [ + (gogoproto.moretags) = "yaml:\"exchange_rate_tuples\"" + ]; + string vote_threshold = 2 [ + (gogoproto.moretags) = "yaml:\"vote_threshold\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string reward_band = 3 [ + (gogoproto.moretags) = "yaml:\"reward_band\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + int64 reward_distribution_window = 4 [ + (gogoproto.moretags) = "yaml:\"reward_distribution_window\"" + ]; + // NOTE: The amounts here indicate the tobin tax for each currency + repeated cosmos.base.v1beta1.DecCoin whitelist = 5 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins", + (gogoproto.nullable) = false + ]; + string slash_fraction = 6 [ + (gogoproto.moretags) = "yaml:\"slash_fraction\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + int64 slash_window = 7 [ + (gogoproto.moretags) = "yaml:\"slash_window\"" + ]; + string min_valid_per_window = 8 [ + (gogoproto.moretags) = "yaml:\"min_valid_per_window\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/proto/oracle/v1/query.proto b/proto/oracle/v1/query.proto index 1df5fe45..a03f7864 100644 --- a/proto/oracle/v1/query.proto +++ b/proto/oracle/v1/query.proto @@ -2,8 +2,7 @@ syntax = "proto3"; package oracle.v1; import "gogoproto/gogo.proto"; -import "oracle/v1/genesis.proto"; -import "oracle/v1/vote.proto"; +import "oracle/v1/oracle.proto"; import "google/api/annotations.proto"; import "cosmos/base/v1beta1/coin.proto"; diff --git a/proto/oracle/v1/msgs.proto b/proto/oracle/v1/tx.proto similarity index 92% rename from proto/oracle/v1/msgs.proto rename to proto/oracle/v1/tx.proto index cff7223f..a6d16622 100644 --- a/proto/oracle/v1/msgs.proto +++ b/proto/oracle/v1/tx.proto @@ -15,6 +15,7 @@ message MsgDelegateFeedConsent { string operator = 1; string delegate = 2; } + message MsgDelegateFeedConsentResponse {} // MsgAggregateExchangeRatePrevote - struct for aggregate prevoting on the ExchangeRateVote. @@ -25,13 +26,16 @@ message MsgAggregateExchangeRatePrevote { string feeder = 2; string validator = 3; } + message MsgAggregateExchangeRatePrevoteResponse {} // MsgAggregateExchangeRateVote - struct for voting on the exchange rates of Luna denominated in various Terra assets. message MsgAggregateExchangeRateVote { string salt = 1; + // NOTE: this exchange rates string is a DecCoins.String() string exchange_rates = 2; string feeder = 3; string validator = 4; } -message MsgAggregateExchangeRateVoteResponse {} \ No newline at end of file + +message MsgAggregateExchangeRateVoteResponse {} diff --git a/proto/oracle/v1/vote.proto b/proto/oracle/v1/vote.proto deleted file mode 100644 index 3ff569c1..00000000 --- a/proto/oracle/v1/vote.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; -package oracle.v1; - -import "gogoproto/gogo.proto"; - -option go_package = "github.com/peggyjv/sommelier/x/oracle/types"; - -// ExchangeRatePrevote - struct to store a validator's prevote on the rate of Luna in the denom asset -message ExchangeRatePrevote { - bytes hash = 1; - string denom = 2; - string voter = 3; - int64 submit_block = 4; -} - -// ExchangeRateVote - struct to store a validator's vote on the rate of Luna in the denom asset -message ExchangeRateVote { - string exchange_rate = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; - string denom = 2; - string voter = 3; -} - -// AggregateExchangeRatePrevote - struct to store a validator's aggregate prevote on the rate of Luna in the denom asset -message AggregateExchangeRatePrevote { - bytes hash = 1; - string voter = 2; - int64 submit_block = 3; -} - -// ExchangeRateTuple - struct to represent a exchange rate of Luna in the denom asset -message ExchangeRateTuple { - string denom = 1; - string exchange_rate = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} - -// AggregateExchangeRateVote - struct to store a validator's aggregate vote on the rate of Luna in the denom asset -message AggregateExchangeRateVote { - string voter = 1; - repeated ExchangeRateTuple exchange_rate_tuples = 2 [ - (gogoproto.nullable) = false, - (gogoproto.castrepeated) = "[]ExchangeRateTuple" - ]; -} \ No newline at end of file diff --git a/scripts/protoc-swagger-gen.sh b/scripts/protoc-swagger-gen.sh new file mode 100755 index 00000000..bf62cd31 --- /dev/null +++ b/scripts/protoc-swagger-gen.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -eo pipefail + +mkdir -p ./tmp-swagger-gen +proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) +for dir in $proto_dirs; do + + # generate swagger files (filter query files) + query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \)) + if [[ ! -z "$query_file" ]]; then + buf protoc \ + -I "proto" \ + -I "third_party/proto" \ + "$query_file" \ + --swagger_out=./tmp-swagger-gen \ + --swagger_opt=logtostderr=true --swagger_opt=fqn_for_swagger_name=true --swagger_opt=simple_operation_ids=true + fi +done + +# combine swagger files +# uses nodejs package `swagger-combine`. +# all the individual swagger files need to be configured in `config.json` for merging +swagger-combine ./client/docs/config.json -o ./client/docs/swagger-ui/swagger.yaml -f yaml --continueOnConflictingPaths true --includeDefinitions true + +# clean swagger files +rm -rf ./tmp-swagger-gen diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh new file mode 100755 index 00000000..0b156879 --- /dev/null +++ b/scripts/protocgen.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +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 sommelier folder." + return 1 + fi + + go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null +} + +protoc_gen_doc() { + go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc 2>/dev/null +} + +protoc_gen_gocosmos +protoc_gen_doc + +proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) +for dir in $proto_dirs; do + buf protoc \ + -I "proto" \ + -I "third_party/proto" \ + --gocosmos_out=plugins=interfacetype+grpc,\ +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:. \ + $(find "${dir}" -maxdepth 1 -name '*.proto') + +done + +# command to generate docs using protoc-gen-doc +buf protoc \ +-I "proto" \ +-I "third_party/proto" \ +--doc_out=./docs/core \ +--doc_opt=./docs/protodoc-markdown.tmpl,proto-docs.md \ +$(find "$(pwd)/proto" -maxdepth 5 -name '*.proto') +go mod tidy + +# move proto files to the right places +cp -r github.com/peggyjv/sommelier/* ./ +rm -rf github.com diff --git a/third_party/proto/tendermint/abci/types.proto b/third_party/proto/tendermint/abci/types.proto index c08cca2b..2cbcabb2 100644 --- a/third_party/proto/tendermint/abci/types.proto +++ b/third_party/proto/tendermint/abci/types.proto @@ -334,9 +334,9 @@ message TxResult { // Validator message Validator { - bytes address = 1; // The first 20 bytes of SHA256(public key) + bytes address = 1; // The first 20 bytes of SHA256(public key) // PubKey pub_key = 2 [(gogoproto.nullable)=false]; - int64 power = 3; // The voting power + int64 power = 3; // The voting power } // ValidatorUpdate @@ -351,14 +351,20 @@ message VoteInfo { bool signed_last_block = 2; } +enum EvidenceType { + UNKNOWN = 0; + DUPLICATE_VOTE = 1; + LIGHT_CLIENT_ATTACK = 2; +} + message Evidence { - string type = 1; + EvidenceType type = 1; // The offending validator - Validator validator = 2 [(gogoproto.nullable) = false]; - // The height when the offense occurred - int64 height = 3; + Validator validator = 2 [(gogoproto.nullable) = false]; + // The height when the offense occurred + int64 height = 3; // The corresponding time where the offense occurred - google.protobuf.Timestamp time = 4 [ + google.protobuf.Timestamp time = 4 [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ]; diff --git a/third_party/proto/tendermint/crypto/keys.proto b/third_party/proto/tendermint/crypto/keys.proto index e3a8ce93..16fd7adf 100644 --- a/third_party/proto/tendermint/crypto/keys.proto +++ b/third_party/proto/tendermint/crypto/keys.proto @@ -11,14 +11,7 @@ message PublicKey { option (gogoproto.equal) = true; oneof sum { - bytes ed25519 = 1; - } -} - -// PrivateKey defines the keys available for use with Tendermint Validators -// WARNING PrivateKey is used for internal purposes only -message PrivateKey { - oneof sum { - bytes ed25519 = 1; + bytes ed25519 = 1; + bytes secp256k1 = 2; } } diff --git a/third_party/proto/tendermint/types/evidence.proto b/third_party/proto/tendermint/types/evidence.proto index c2bb74ca..3b234571 100644 --- a/third_party/proto/tendermint/types/evidence.proto +++ b/third_party/proto/tendermint/types/evidence.proto @@ -6,63 +6,33 @@ option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; import "tendermint/types/types.proto"; -import "tendermint/crypto/keys.proto"; - -// DuplicateVoteEvidence contains evidence a validator signed two conflicting -// votes. -message DuplicateVoteEvidence { - Vote vote_a = 1; - Vote vote_b = 2; - - google.protobuf.Timestamp timestamp = 3 - [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; -} - -message PotentialAmnesiaEvidence { - Vote vote_a = 1; - Vote vote_b = 2; - - int64 height_stamp = 3; - google.protobuf.Timestamp timestamp = 4 - [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; -} - -message AmnesiaEvidence { - PotentialAmnesiaEvidence potential_amnesia_evidence = 1; - ProofOfLockChange polc = 2; -} - -message ConflictingHeadersEvidence { - SignedHeader h1 = 1; - SignedHeader h2 = 2; -} - -message LunaticValidatorEvidence { - Header header = 1; - Vote vote = 2; - string invalid_header_field = 3; - - google.protobuf.Timestamp timestamp = 4 - [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; -} +import "tendermint/types/validator.proto"; message Evidence { oneof sum { - DuplicateVoteEvidence duplicate_vote_evidence = 1; - ConflictingHeadersEvidence conflicting_headers_evidence = 2; - LunaticValidatorEvidence lunatic_validator_evidence = 3; - PotentialAmnesiaEvidence potential_amnesia_evidence = 4; - AmnesiaEvidence amnesia_evidence = 5; + DuplicateVoteEvidence duplicate_vote_evidence = 1; + LightClientAttackEvidence light_client_attack_evidence = 2; } } -// EvidenceData contains any evidence of malicious wrong-doing by validators -message EvidenceData { - repeated Evidence evidence = 1 [(gogoproto.nullable) = false]; - bytes hash = 2; +// DuplicateVoteEvidence contains evidence of a validator signed two conflicting votes. +message DuplicateVoteEvidence { + tendermint.types.Vote vote_a = 1; + tendermint.types.Vote vote_b = 2; + int64 total_voting_power = 3; + int64 validator_power = 4; + google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; +} + +// LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client. +message LightClientAttackEvidence { + tendermint.types.LightBlock conflicting_block = 1; + int64 common_height = 2; + repeated tendermint.types.Validator byzantine_validators = 3; + int64 total_voting_power = 4; + google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; } -message ProofOfLockChange { - repeated Vote votes = 1; - tendermint.crypto.PublicKey pub_key = 2; +message EvidenceList { + repeated Evidence evidence = 1 [(gogoproto.nullable) = false]; } diff --git a/third_party/proto/tendermint/types/params.proto b/third_party/proto/tendermint/types/params.proto index 33ed4f77..0de7d846 100644 --- a/third_party/proto/tendermint/types/params.proto +++ b/third_party/proto/tendermint/types/params.proto @@ -48,16 +48,10 @@ message EvidenceParams { google.protobuf.Duration max_age_duration = 2 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; - // This sets the maximum number of evidence that can be committed in a single block. - // and should fall comfortably under the max block bytes when we consider the size of - // each evidence (See MaxEvidenceBytes). The maximum number is MaxEvidencePerBlock. - // Default is 50 - uint32 max_num = 3; - - // Proof trial period dictates the time given for nodes accused of amnesia evidence, incorrectly - // voting twice in two different rounds to respond with their respective proofs. - // Default is half the max age in blocks: 50,000 - int64 proof_trial_period = 4; + // This sets the maximum size of total evidence in bytes that can be committed in a single block. + // and should fall comfortably under the max block bytes. + // Default is 1048576 or 1MB + int64 max_bytes = 3; } // ValidatorParams restrict the public key types validators can use. diff --git a/third_party/proto/tendermint/types/types.proto b/third_party/proto/tendermint/types/types.proto index 7ba7de8b..7f7ea74c 100644 --- a/third_party/proto/tendermint/types/types.proto +++ b/third_party/proto/tendermint/types/types.proto @@ -5,9 +5,9 @@ option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; -import "tendermint/libs/bits/types.proto"; import "tendermint/crypto/proof.proto"; import "tendermint/version/types.proto"; +import "tendermint/types/validator.proto"; // BlockIdFlag indicates which BlcokID the signature is for enum BlockIDFlag { @@ -25,13 +25,13 @@ enum SignedMsgType { option (gogoproto.goproto_enum_stringer) = true; option (gogoproto.goproto_enum_prefix) = false; - SIGNED_MSG_TYPE_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "UnknownType"]; + SIGNED_MSG_TYPE_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "UnknownType"]; // Votes SIGNED_MSG_TYPE_PREVOTE = 1 [(gogoproto.enumvalue_customname) = "PrevoteType"]; SIGNED_MSG_TYPE_PRECOMMIT = 2 [(gogoproto.enumvalue_customname) = "PrecommitType"]; // Proposals - SIGNED_MSG_TYPE_PROPOSAL = 32 [(gogoproto.enumvalue_customname) = "ProposalType"]; + SIGNED_MSG_TYPE_PROPOSAL = 32 [(gogoproto.enumvalue_customname) = "ProposalType"]; } // PartsetHeader @@ -87,8 +87,6 @@ message Data { // NOTE: not all txs here are valid. We're just agreeing on the order first. // This means that block.AppHash does not include these txs. repeated bytes txs = 1; - // Volatile - bytes hash = 2; } // Vote represents a prevote, precommit, or commit vote from validators for @@ -112,8 +110,6 @@ message Commit { int32 round = 2; BlockID block_id = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"]; repeated CommitSig signatures = 4 [(gogoproto.nullable) = false]; - bytes hash = 5; - tendermint.libs.bits.BitArray bit_array = 6; } // CommitSig is a part of the Vote included in a Commit. @@ -141,6 +137,11 @@ message SignedHeader { Commit commit = 2; } +message LightBlock { + SignedHeader signed_header = 1; + tendermint.types.ValidatorSet validator_set = 2; +} + message BlockMeta { BlockID block_id = 1 [(gogoproto.customname) = "BlockID", (gogoproto.nullable) = false]; int64 block_size = 2; diff --git a/third_party/proto/tendermint/types/validator.proto b/third_party/proto/tendermint/types/validator.proto new file mode 100644 index 00000000..49860b96 --- /dev/null +++ b/third_party/proto/tendermint/types/validator.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package tendermint.types; + +option go_package = "github.com/tendermint/tendermint/proto/tendermint/types"; + +import "gogoproto/gogo.proto"; +import "tendermint/crypto/keys.proto"; + +message ValidatorSet { + repeated Validator validators = 1; + Validator proposer = 2; + int64 total_voting_power = 3; +} + +message Validator { + bytes address = 1; + tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false]; + int64 voting_power = 3; + int64 proposer_priority = 4; +} + +message SimpleValidator { + tendermint.crypto.PublicKey pub_key = 1; + int64 voting_power = 2; +} diff --git a/x/oracle/abci.go b/x/oracle/abci.go index 9dbb9209..50a6a1e0 100644 --- a/x/oracle/abci.go +++ b/x/oracle/abci.go @@ -1,6 +1,8 @@ package oracle import ( + "sort" + "github.com/peggyjv/sommelier/x/oracle/keeper" "github.com/peggyjv/sommelier/x/oracle/types" @@ -20,9 +22,9 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { // Build valid votes counter and winner map over all validators in active set validVotesCounterMap := make(map[string]int) winnerMap := make(map[string]types.Claim) - k.StakingKeeper.IterateValidators(ctx, func(i int64, validator stakingtypes.ValidatorI) bool { + k.StakingKeeper.IterateValidators(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool { // Exclude not bonded validator or jailed validators from tallying - if validator.IsBonded() && !validator.IsJailed() { + if validator != nil && validator.IsBonded() && !validator.IsJailed() { // NOTE: we directly stringify byte to string to prevent unnecessary bech32fy works valAddr := validator.GetOperator() @@ -41,8 +43,8 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { }) // Clear all exchange rates - k.IterateLunaExchangeRates(ctx, func(denom string, _ sdk.Dec) (stop bool) { - k.DeleteLunaExchangeRate(ctx, denom) + k.IterateUSDExchangeRates(ctx, func(denom string, _ sdk.Dec) (stop bool) { + k.DeleteUSDExchangeRate(ctx, denom) return false }) @@ -51,7 +53,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { // NOTE: **Make abstain votes to have zero vote power** voteMap := k.OrganizeBallotByDenom(ctx) - if referenceTerra := pickReferenceTerra(ctx, k, voteTargets, voteMap); referenceTerra != "" { + if referenceTerra := k.PickReferenceTerra(ctx, voteTargets, voteMap); referenceTerra != "" { // make voteMap of Reference Terra to calculate cross exchange rates ballotRT := voteMap[referenceTerra] voteMapRT := ballotRT.ToMap() @@ -66,7 +68,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { } // Get weighted median of cross exchange rates - exchangeRate, ballotWinningClaims := tally(ctx, ballot, params.RewardBand) + exchangeRate, ballotWinningClaims := tally(ballot, params.RewardBand) // Update winnerMap, validVotesCounterMap using ballotWinningClaims of cross exchange rate ballot updateWinnerMap(ballotWinningClaims, validVotesCounterMap, winnerMap) @@ -77,7 +79,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { } // Set the exchange rate, emit ABCI event - k.SetLunaExchangeRateWithEvent(ctx, denom, exchangeRate) + k.SetUSDExchangeRateWithEvent(ctx, denom, exchangeRate) } } @@ -101,7 +103,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { // Do slash who did miss voting over threshold and // reset miss counters of all validators at the last block of slash window if IsPeriodLastBlock(ctx, params.SlashWindow) { - SlashAndResetMissCounters(ctx, k) + k.SlashAndResetMissCounters(ctx) } // Distribute rewards to ballot winners @@ -112,8 +114,6 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { // Update vote targets and tobin tax applyWhitelist(ctx, k, params.Whitelist, voteTargets) - - return } // clearBallots clears all tallied prevotes and votes from the store @@ -150,7 +150,7 @@ func clearBallots(ctx sdk.Context, k keeper.Keeper, votePeriod int64) { } // applyWhitelist update vote target denom list and set tobin tax with params whitelist -func applyWhitelist(ctx sdk.Context, k keeper.Keeper, whitelist types.DenomList, voteTargets map[string]sdk.Dec) { +func applyWhitelist(ctx sdk.Context, k keeper.Keeper, whitelist sdk.DecCoins, voteTargets map[string]sdk.Dec) { // check is there any update in whitelist params updateRequired := false @@ -158,7 +158,7 @@ func applyWhitelist(ctx sdk.Context, k keeper.Keeper, whitelist types.DenomList, updateRequired = true } else { for _, item := range whitelist { - if tobinTax, ok := voteTargets[item.Name]; !ok || !tobinTax.Equal(item.TobinTax) { + if tobinTax, ok := voteTargets[item.Denom]; !ok || !tobinTax.Equal(item.Amount) { updateRequired = true break } @@ -169,7 +169,7 @@ func applyWhitelist(ctx sdk.Context, k keeper.Keeper, whitelist types.DenomList, k.ClearTobinTaxes(ctx) for _, item := range whitelist { - k.SetTobinTax(ctx, item.Name, item.TobinTax) + k.SetTobinTax(ctx, item.Denom, item.Amount) } } } @@ -178,3 +178,52 @@ func applyWhitelist(ctx sdk.Context, k keeper.Keeper, whitelist types.DenomList, func IsPeriodLastBlock(ctx sdk.Context, blocksPerPeriod int64) bool { return (ctx.BlockHeight()+1)%blocksPerPeriod == 0 } + +// Calculates the median and returns it. Sets the set of voters to be rewarded, i.e. voted within +// a reasonable spread from the weighted median to the store +func tally(exchangeRateBallot types.ExchangeRateBallot, rewardBand sdk.Dec) (sdk.Dec, []types.Claim) { + if !sort.IsSorted(exchangeRateBallot) { + sort.Sort(exchangeRateBallot) + } + + weightedMedian := exchangeRateBallot.WeightedMedian() + standardDeviation := exchangeRateBallot.StandardDeviation() + rewardSpread := weightedMedian.Mul(rewardBand.QuoInt64(2)) + + if standardDeviation.GT(rewardSpread) { + rewardSpread = standardDeviation + } + + var ballotWinners []types.Claim + for _, vote := range exchangeRateBallot { + // Filter ballot winners & abstain voters + if (vote.ExchangeRate.GTE(weightedMedian.Sub(rewardSpread)) && + vote.ExchangeRate.LTE(weightedMedian.Add(rewardSpread))) || + !vote.ExchangeRate.IsPositive() { + + claim := types.Claim{ + Recipient: vote.Voter, + Weight: vote.Power, + } + // Abstain votes have zero vote power + ballotWinners = append(ballotWinners, claim) + } + } + + return weightedMedian, ballotWinners +} + +func updateWinnerMap(ballotWinningClaims []types.Claim, validVotesCounterMap map[string]int, winnerMap map[string]types.Claim) { + // Collect claims of ballot winners + for _, ballotWinningClaim := range ballotWinningClaims { + recipient := ballotWinningClaim.Recipient + + // Update claim + prevClaim := winnerMap[recipient] + prevClaim.Weight += ballotWinningClaim.Weight + winnerMap[recipient] = prevClaim + + // Increase valid votes counter + validVotesCounterMap[recipient]++ + } +} diff --git a/x/oracle/abci_test.go b/x/oracle/abci_test.go index 3c10e30d..6291c7f2 100644 --- a/x/oracle/abci_test.go +++ b/x/oracle/abci_test.go @@ -22,17 +22,17 @@ func TestOracleThreshold(t *testing.T) { hash := types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[0]) prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err := h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + _, err := h(input.Ctx.WithBlockHeight(0), prevoteMsg) require.NoError(t, err) // Vote and new Prevote voteMsg := types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.NoError(t, err) EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - _, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) + _, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) require.NotNil(t, err) // More than the threshold signs, msg succeeds @@ -40,32 +40,32 @@ func TestOracleThreshold(t *testing.T) { hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[0]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + h(input.Ctx.WithBlockHeight(0), prevoteMsg) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - h(input.Ctx.WithBlockHeight(1), &voteMsg) + h(input.Ctx.WithBlockHeight(1), voteMsg) salt = "2" hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[1]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[1]) - h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + h(input.Ctx.WithBlockHeight(0), prevoteMsg) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[1], keeper.ValAddrs[1]) - h(input.Ctx.WithBlockHeight(1), &voteMsg) + h(input.Ctx.WithBlockHeight(1), voteMsg) salt = "3" hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[2]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[2], keeper.ValAddrs[2]) - h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + h(input.Ctx.WithBlockHeight(0), prevoteMsg) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[2], keeper.ValAddrs[2]) - h(input.Ctx.WithBlockHeight(1), &voteMsg) + h(input.Ctx.WithBlockHeight(1), voteMsg) EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - rate, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) + rate, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) require.Nil(t, err) require.Equal(t, randomExchangeRate, rate) @@ -76,23 +76,23 @@ func TestOracleThreshold(t *testing.T) { hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[0]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + h(input.Ctx.WithBlockHeight(0), prevoteMsg) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - h(input.Ctx.WithBlockHeight(1), &voteMsg) + h(input.Ctx.WithBlockHeight(1), voteMsg) salt = "2" hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[1]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[1]) - h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + h(input.Ctx.WithBlockHeight(0), prevoteMsg) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[1], keeper.ValAddrs[1]) - h(input.Ctx.WithBlockHeight(1), &voteMsg) + h(input.Ctx.WithBlockHeight(1), voteMsg) EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - rate, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) + rate, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx.WithBlockHeight(1), types.MicroSDRDenom) require.NotNil(t, err) } @@ -106,56 +106,56 @@ func TestOracleMultiVote(t *testing.T) { hash := types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[0]) prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err := h(input.Ctx, &prevoteMsg) + _, err := h(input.Ctx, prevoteMsg) require.NoError(t, err) hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[1]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[1]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) hash = types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[2]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[2], keeper.ValAddrs[2]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) hash = types.GetAggregateVoteHash(salt, anotherExchangeRates.String(), keeper.ValAddrs[0]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) hash = types.GetAggregateVoteHash(salt, anotherExchangeRates.String(), keeper.ValAddrs[1]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[1]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) hash = types.GetAggregateVoteHash(salt, anotherExchangeRates.String(), keeper.ValAddrs[2]) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[2], keeper.ValAddrs[2]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) // Reveal ExchangeRate input.Ctx = input.Ctx.WithBlockHeight(1) voteMsg := types.NewMsgAggregateExchangeRateVote(salt, anotherExchangeRates.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &voteMsg) + _, err = h(input.Ctx, voteMsg) require.NoError(t, err) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, anotherExchangeRates.String(), keeper.Addrs[1], keeper.ValAddrs[1]) - _, err = h(input.Ctx, &voteMsg) + _, err = h(input.Ctx, voteMsg) require.NoError(t, err) voteMsg = types.NewMsgAggregateExchangeRateVote(salt, anotherExchangeRates.String(), keeper.Addrs[2], keeper.ValAddrs[2]) - _, err = h(input.Ctx, &voteMsg) + _, err = h(input.Ctx, voteMsg) require.NoError(t, err) EndBlocker(input.Ctx, input.OracleKeeper) - rate, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroSDRDenom) + rate, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroSDRDenom) require.Nil(t, err) require.Equal(t, rate, anotherRandomExchangeRate) } @@ -163,7 +163,7 @@ func TestOracleMultiVote(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroKRWDenom, randomExchangeRate) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroKRWDenom, randomExchangeRate) // Account 1, KRW makePrevoteAndVote(t, input, h, 0, types.MicroKRWDenom, randomExchangeRate, 0) @@ -171,7 +171,7 @@ func TestOracleDrop(t *testing.T) { // Immediately swap halt after an illiquid oracle vote EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroKRWDenom) + _, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroKRWDenom) require.NotNil(t, err) } @@ -196,7 +196,7 @@ func TestOracleTally(t *testing.T) { valAddrs[i], ) - _, err := h(input.Ctx.WithBlockHeight(0), &prevoteMsg) + _, err := h(input.Ctx.WithBlockHeight(0), prevoteMsg) require.NoError(t, err) voteMsg := types.NewMsgAggregateExchangeRateVote( @@ -206,7 +206,7 @@ func TestOracleTally(t *testing.T) { valAddrs[i], ) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.NoError(t, err) vote := types.NewVoteForTally(types.NewExchangeRateVote(decExchangeRate, types.MicroSDRDenom, valAddrs[i]), stakingAmt.QuoRaw(types.MicroUnit).Int64()) @@ -233,7 +233,7 @@ func TestOracleTally(t *testing.T) { } } - tallyMedian, ballotWinner := tally(input.Ctx, ballot, input.OracleKeeper.RewardBand(input.Ctx)) + tallyMedian, ballotWinner := tally(ballot, input.OracleKeeper.RewardBand(input.Ctx)) require.Equal(t, len(rewardees), len(ballotWinner)) require.Equal(t, tallyMedian.MulInt64(100).TruncateInt(), weightedMedian.MulInt64(100).TruncateInt()) @@ -253,13 +253,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroSDRDenom) + _, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroSDRDenom) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(params.VotePeriod - 1) EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroSDRDenom) + _, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroSDRDenom) require.NoError(t, err) } @@ -294,7 +294,7 @@ func TestOracleRewardDistribution(t *testing.T) { func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, types.DefaultTobinTax}} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets @@ -424,14 +424,14 @@ func TestOracleExchangeRateVal5(t *testing.T) { krwExchangeRate := sdk.NewDecWithPrec(505000, int64(6)).MulInt64(types.MicroUnit) krwExchangeRateWithErr := sdk.NewDecWithPrec(500000, int64(6)).MulInt64(types.MicroUnit) - usdExchangeRate := sdk.NewDecWithPrec(505, int64(6)).MulInt64(types.MicroUnit) - usdExchangeRateWithErr := sdk.NewDecWithPrec(500, int64(6)).MulInt64(types.MicroUnit) + lunaExchangeRate := sdk.NewDecWithPrec(505, int64(6)).MulInt64(types.MicroUnit) + lunaExchangeRateWithErr := sdk.NewDecWithPrec(500, int64(6)).MulInt64(types.MicroUnit) // KRW has been chosen as referenceTerra by highest voting power // Account 1, KRW, USD val1 := sdk.NewDecCoins( sdk.NewDecCoinFromDec(types.MicroKRWDenom, krwExchangeRate), - sdk.NewDecCoinFromDec(types.MicroUSDDenom, usdExchangeRate), + sdk.NewDecCoinFromDec(types.MicroSDRDenom, lunaExchangeRate), ) makeAggregatePrevoteAndVote(t, input, h, 0, val1, 0) @@ -444,7 +444,7 @@ func TestOracleExchangeRateVal5(t *testing.T) { // Account 4, KRW, USD val4 := sdk.NewDecCoins( sdk.NewDecCoinFromDec(types.MicroKRWDenom, krwExchangeRateWithErr), - sdk.NewDecCoinFromDec(types.MicroUSDDenom, usdExchangeRateWithErr), + sdk.NewDecCoinFromDec(types.MicroSDRDenom, lunaExchangeRateWithErr), ) makeAggregatePrevoteAndVote(t, input, h, 0, val4, 3) @@ -453,23 +453,23 @@ func TestOracleExchangeRateVal5(t *testing.T) { rewardAmt := sdk.NewInt(100000000) moduleAcc := input.AccKeeper.GetModuleAccount(input.Ctx.WithBlockHeight(1), types.ModuleName) - require.NoError(t, input.BankKeeper.SetBalances(input.Ctx, moduleAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(types.MicroLunaDenom, rewardAmt)))) + require.NoError(t, input.BankKeeper.SetBalances(input.Ctx, moduleAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(types.MicroSDRDenom, rewardAmt)))) input.AccKeeper.SetModuleAccount(input.Ctx.WithBlockHeight(1), moduleAcc) EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - krw, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroKRWDenom) + krw, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroKRWDenom) require.NoError(t, err) - usd, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroUSDDenom) + usd, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroSDRDenom) require.NoError(t, err) // legacy version case - require.NotEqual(t, usdExchangeRateWithErr, usd) + require.NotEqual(t, lunaExchangeRateWithErr, usd) // new version case require.Equal(t, krwExchangeRate, krw) - require.Equal(t, usdExchangeRate, usd) + require.Equal(t, lunaExchangeRate, usd) rewardDistributedWindow := input.OracleKeeper.RewardDistributionWindow(input.Ctx) expectedRewardAmt := sdk.NewDecFromInt(rewardAmt.QuoRaw(8).MulRaw(2)).QuoInt64(rewardDistributedWindow).TruncateInt() @@ -489,7 +489,7 @@ func TestOracleExchangeRateVal5(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{sdk.NewDecCoinFromDec(types.MicroKRWDenom, types.DefaultTobinTax)} input.OracleKeeper.SetParams(input.Ctx, params) input.OracleKeeper.SetTobinTax(input.Ctx, types.MicroKRWDenom, types.DefaultTobinTax) @@ -570,7 +570,7 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, types.DefaultTobinTax}} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets @@ -591,7 +591,7 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, types.DefaultTobinTax}} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets @@ -624,7 +624,7 @@ func TestAbstainSlashing(t *testing.T) { func TestVoteTargets(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}, {Name: types.MicroSDRDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, types.DefaultTobinTax}, {types.MicroSDRDenom, types.DefaultTobinTax}} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets @@ -652,7 +652,7 @@ func TestVoteTargets(t *testing.T) { require.Equal(t, types.DefaultTobinTax, sdrTobinTax) // delete SDR - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, types.DefaultTobinTax}} input.OracleKeeper.SetParams(input.Ctx, params) // KRW, missing @@ -673,7 +673,7 @@ func TestVoteTargets(t *testing.T) { require.Error(t, err) // change KRW tobin tax - params.Whitelist = types.DenomList{{Name: types.MicroKRWDenom, TobinTax: sdk.ZeroDec()}} + params.Whitelist = sdk.DecCoins{{types.MicroKRWDenom, sdk.ZeroDec()}} input.OracleKeeper.SetParams(input.Ctx, params) // KRW, no missing @@ -702,7 +702,7 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { makePrevoteAndVote(t, input, h, 0, types.MicroKRWDenom, sdk.ZeroDec(), 0) EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroKRWDenom) + _, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroKRWDenom) require.Error(t, err) } @@ -713,11 +713,11 @@ func makePrevoteAndVote(t *testing.T, input keeper.TestInput, h sdk.Handler, hei hash := types.GetAggregateVoteHash(salt, exchangeRates.String(), keeper.ValAddrs[idx]) prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[idx], keeper.ValAddrs[idx]) - _, err := h(input.Ctx.WithBlockHeight(height), &prevoteMsg) + _, err := h(input.Ctx.WithBlockHeight(height), prevoteMsg) require.NoError(t, err) voteMsg := types.NewMsgAggregateExchangeRateVote(salt, exchangeRates.String(), keeper.Addrs[idx], keeper.ValAddrs[idx]) - _, err = h(input.Ctx.WithBlockHeight(height+1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(height+1), voteMsg) require.NoError(t, err) } @@ -727,10 +727,10 @@ func makeAggregatePrevoteAndVote(t *testing.T, input keeper.TestInput, h sdk.Han hash := types.GetAggregateVoteHash(salt, rates.String(), keeper.ValAddrs[idx]) prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[idx], keeper.ValAddrs[idx]) - _, err := h(input.Ctx.WithBlockHeight(height), &prevoteMsg) + _, err := h(input.Ctx.WithBlockHeight(height), prevoteMsg) require.NoError(t, err) voteMsg := types.NewMsgAggregateExchangeRateVote(salt, rates.String(), keeper.Addrs[idx], keeper.ValAddrs[idx]) - _, err = h(input.Ctx.WithBlockHeight(height+1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(height+1), voteMsg) require.NoError(t, err) } diff --git a/x/oracle/client/cli/query.go b/x/oracle/client/cli/query.go index 651eb4ce..48ab3ef3 100644 --- a/x/oracle/client/cli/query.go +++ b/x/oracle/client/cli/query.go @@ -1,13 +1,13 @@ package cli import ( - "encoding/json" - "fmt" + "context" "strings" "github.com/peggyjv/sommelier/x/oracle/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" ) @@ -43,7 +43,7 @@ func GetCmdQueryExchangeRates() *cobra.Command { cmd := &cobra.Command{ Use: "exchange-rates [denom]", Args: cobra.RangeArgs(0, 1), - Short: "Query the current Luna exchange rate w.r.t an asset", + Short: "Query the current Luna exchange rate w.r.t an asset", // TODO: update "Luna" Long: strings.TrimSpace(` Query the current exchange rate of Luna with an asset. You can find the current list of active denoms by running @@ -55,38 +55,45 @@ Or, can filter with denom $ sommelier query oracle exchange-rates ukrw `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) + if len(args) == 0 { - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryExchangeRates), nil) - if err != nil { - return err + // pageReq, err := client.ReadPageRequest(cmd.Flags()) + // if err != nil { + // return err + // } + + req := &types.QueryExchangeRatesRequest{ + // Pagination: pageReq, } - rates, err := sdk.ParseDecCoins(string(res)) + res, err := queryClient.ExchangeRates(context.Background(), req) if err != nil { return err } - return clientCtx.PrintOutput(&types.QueryExchangeRatesResponse{Rates: rates}) + + return clientCtx.PrintProto(res) } - bz, err := json.Marshal(types.NewQueryExchangeRateParams(args[0])) - if err != nil { - return err + req := &types.QueryExchangeRateRequest{ + Denom: args[0], } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryExchangeRate), bz) + + res, err := queryClient.ExchangeRate(context.Background(), req) if err != nil { return err } - fmt.Println(res) - return nil + return clientCtx.PrintProto(res) }, } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "exchange rates") return cmd } @@ -95,28 +102,39 @@ func GetCmdQueryActives() *cobra.Command { cmd := &cobra.Command{ Use: "actives", Args: cobra.NoArgs, - Short: "Query the active list of Terra assets recognized by the oracle", + Short: "Query the active list of Sommelier assets recognized by the oracle", Long: strings.TrimSpace(` -Query the active list of Terra assets recognized by the types. +Query the active list of Sommelier assets recognized by the types. $ sommelier query oracle actives `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryActives), nil) + // pageReq, err := client.ReadPageRequest(cmd.Flags()) + // if err != nil { + // return err + // } + + req := &types.QueryActivesRequest{ + // Pagination: pageReq, + } + + res, err := queryClient.Actives(context.Background(), req) if err != nil { return err } - fmt.Println(res) - return nil + + return clientCtx.PrintProto(res) }, } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "actives") return cmd } @@ -125,19 +143,22 @@ func GetCmdQueryParams() *cobra.Command { cmd := &cobra.Command{ Use: "params", Args: cobra.NoArgs, - Short: "Query the current Oracle params", + Short: "Query the current oracle module parameters", RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters), nil) + + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryParametersRequest{} + res, err := queryClient.Parameters(context.Background(), req) if err != nil { return err } - fmt.Println(res) - return nil + + return clientCtx.PrintProto(res) }, } @@ -156,8 +177,7 @@ Query the account the validator's oracle voting right is delegated to. $ sommelier query oracle feeder terravaloper... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -167,18 +187,18 @@ $ sommelier query oracle feeder terravaloper... return err } - bz, err := json.Marshal(types.NewQueryFeederDelegationParams(validator)) - if err != nil { - return err + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryFeederDelegationRequest{ + Validator: validator.String(), } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFeederDelegation), bz) + res, err := queryClient.FeederDelegation(context.Background(), req) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.PrintProto(res) }, } @@ -197,8 +217,7 @@ Query the # of vote periods missed in this oracle slash window. $ sommelier query oracle miss terravaloper... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -209,18 +228,18 @@ $ sommelier query oracle miss terravaloper... return err } - bz, err := json.Marshal(types.NewQueryMissCounterParams(validator)) - if err != nil { - return err + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryMissCounterRequest{ + Validator: validator.String(), } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryMissCounter), bz) + res, err := queryClient.MissCounter(context.Background(), req) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.PrintProto(res) }, } @@ -239,8 +258,7 @@ Query outstanding oracle aggregate prevote, filtered by voter address. $ sommelier query oracle aggregate-prevote terravaloper... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -251,19 +269,18 @@ $ sommelier query oracle aggregate-prevote terravaloper... return err } - bz, err := json.Marshal(types.NewQueryAggregatePrevoteParams(validator)) - if err != nil { - return err + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryAggregatePrevoteRequest{ + Validator: validator.String(), } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAggregatePrevote), bz) + res, err := queryClient.AggregatePrevote(context.Background(), req) if err != nil { return err } - var aggregatePrevote types.AggregateExchangeRatePrevote - clientCtx.JSONMarshaler.MustUnmarshalJSON(res, &aggregatePrevote) - return clientCtx.PrintOutput(&aggregatePrevote) + return clientCtx.PrintProto(res) }, } @@ -282,8 +299,7 @@ Query outstanding oracle aggregate vote, filtered by voter address. $ sommelier query oracle aggregate-vote terravaloper... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } @@ -294,19 +310,18 @@ $ sommelier query oracle aggregate-vote terravaloper... return err } - bz, err := json.Marshal(types.NewQueryAggregateVoteParams(validator)) - if err != nil { - return err + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryAggregateVoteRequest{ + Validator: validator.String(), } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAggregateVote), bz) + res, err := queryClient.AggregateVote(context.Background(), req) if err != nil { return err } - var aggregateVote types.AggregateExchangeRateVote - clientCtx.JSONMarshaler.MustUnmarshalJSON(res, &aggregateVote) - return clientCtx.PrintOutput(&aggregateVote) + return clientCtx.PrintProto(res) }, } @@ -320,22 +335,33 @@ func GetCmdQueryVoteTargets() *cobra.Command { Args: cobra.NoArgs, Short: "Query the current Oracle vote targets", RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryVoteTargets), nil) + // pageReq, err := client.ReadPageRequest(cmd.Flags()) + // if err != nil { + // return err + // } + + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryVoteTargetsRequest{ + // Pagination: pageReq, + } + + res, err := queryClient.VoteTargets(context.Background(), req) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.PrintProto(res) }, } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "vote targets") return cmd } @@ -357,38 +383,41 @@ $ sommelier query oracle tobin-taxes ukrw Or, can `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } + queryClient := types.NewQueryClient(clientCtx) + if len(args) == 0 { - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTobinTaxes), nil) - if err != nil { - return err + // pageReq, err := client.ReadPageRequest(cmd.Flags()) + // if err != nil { + // return err + // } + + req := &types.QueryTobinTaxesRequest{ + // Pagination: pageReq, } - out, err := sdk.ParseDecCoins(string(res)) + res, err := queryClient.TobinTaxes(context.Background(), req) if err != nil { return err } - return clientCtx.PrintOutput(&types.QueryTobinTaxesResponse{Rates: out}) + return clientCtx.PrintProto(res) } - bz, err := json.Marshal(types.NewQueryTobinTaxParams(args[0])) - if err != nil { - return err + req := &types.QueryTobinTaxRequest{ + Denom: args[0], } - res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTobinTax), bz) + res, err := queryClient.TobinTax(context.Background(), req) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.PrintProto(res) }, } diff --git a/x/oracle/client/cli/tx.go b/x/oracle/client/cli/tx.go index 88709d68..a232f852 100644 --- a/x/oracle/client/cli/tx.go +++ b/x/oracle/client/cli/tx.go @@ -50,8 +50,7 @@ $ sommelier tx oracle set-feeder terra1... where "terra1..." is the address you want to delegate your voting rights to. `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } @@ -74,7 +73,7 @@ where "terra1..." is the address you want to delegate your voting rights to. return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } @@ -101,8 +100,7 @@ If voting from a voting delegate, set "validator" to the address of the validato $ sommelier tx oracle aggregate-prevote 1234 8888.0ukrw,1.243uusd,0.99usdr terravaloper1... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } @@ -136,7 +134,7 @@ $ sommelier tx oracle aggregate-prevote 1234 8888.0ukrw,1.243uusd,0.99usdr terra return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } @@ -162,8 +160,7 @@ If voting from a voting delegate, set "validator" to the address of the validato $ sommelier tx oracle aggregate-vote 1234 8888.0ukrw,1.243uusd,0.99usdr terravaloper1.... `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags()) + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } @@ -195,7 +192,7 @@ $ sommelier tx oracle aggregate-vote 1234 8888.0ukrw,1.243uusd,0.99usdr terraval return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } diff --git a/x/oracle/client/rest/query.go b/x/oracle/client/rest/query.go deleted file mode 100644 index 94e77762..00000000 --- a/x/oracle/client/rest/query.go +++ /dev/null @@ -1,469 +0,0 @@ -package rest - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/peggyjv/sommelier/x/oracle/types" - - "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/gorilla/mux" -) - -func registerQueryRoute(cliCtx client.Context, r *mux.Router) { - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/prevotes", RestDenom), queryPrevotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/prevotes/{%s}", RestDenom, RestVoter), queryPrevotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/votes", RestDenom), queryVotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/votes/{%s}", RestDenom, RestVoter), queryVotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/exchange_rate", RestDenom), queryExchangeRateHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/denoms/{%s}/tobin_tax", RestDenom), queryTobinTaxHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc("/oracle/denoms/actives", queryActivesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc("/oracle/denoms/exchange_rates", queryExchangeRatesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc("/oracle/denoms/vote_targets", queryVoteTargetsHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc("/oracle/denoms/tobin_taxes", queryTobinTaxesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/prevotes", RestVoter), queryVoterPrevotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/votes", RestVoter), queryVoterVotesHandlerFunction(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/feeder", RestVoter), queryFeederDelegationHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/miss", RestVoter), queryMissHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/aggregate_prevote", RestVoter), queryAggregatePrevoteHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/aggregate_vote", RestVoter), queryAggregateVoteHandlerFn(cliCtx)).Methods("GET") - r.HandleFunc("/oracle/parameters", queryParamsHandlerFn(cliCtx)).Methods("GET") -} - -func queryVotesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - denom := vars[RestDenom] - - voter := vars[RestVoter] - - var voterAddress sdk.ValAddress - params := types.NewQueryVotesParams(voterAddress, denom) - - if len(voter) != 0 { - voterAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - params.Voter = voterAddress - } - - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryVotes), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryPrevotesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - denom := vars[RestDenom] - - voter := vars[RestVoter] - - var voterAddress sdk.ValAddress - params := types.NewQueryPrevotesParams(voterAddress, denom) - - if len(voter) != 0 { - - voterAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - params.Voter = voterAddress - } - - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryPrevotes), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryExchangeRateHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - denom := vars[RestDenom] - - params := types.NewQueryExchangeRateParams(denom) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryExchangeRate), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryExchangeRatesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryExchangeRates), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryActivesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryActives), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryVoterPrevotesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - voterAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryPrevotesParams(voterAddress, "") - - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryPrevotes), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryVoterVotesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - voterAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryVotesParams(voterAddress, "") - - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryVotes), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryParamsHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryFeederDelegationHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - validator, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryFeederDelegationParams(validator) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryFeederDelegation), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryMissHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - validator, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryMissCounterParams(validator) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryMissCounter), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryAggregatePrevoteHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - validator, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryAggregatePrevoteParams(validator) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAggregatePrevote), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryAggregateVoteHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - voter := vars[RestVoter] - - validator, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - params := types.NewQueryAggregateVoteParams(validator) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAggregateVote), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryVoteTargetsHandlerFn(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryVoteTargets), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryTobinTaxesHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTobinTaxes), nil) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} - -func queryTobinTaxHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r) - if !ok { - return - } - - vars := mux.Vars(r) - denom := vars[RestDenom] - - params := types.NewQueryTobinTaxParams(denom) - bz, err := json.Marshal(params) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTobinTax), bz) - if err != nil { - rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) - } -} diff --git a/x/oracle/client/rest/rest.go b/x/oracle/client/rest/rest.go deleted file mode 100644 index ab4f0449..00000000 --- a/x/oracle/client/rest/rest.go +++ /dev/null @@ -1,18 +0,0 @@ -package rest - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/gorilla/mux" -) - -//nolint -const ( - RestDenom = "denom" - RestVoter = "voter" -) - -// RegisterRoutes registers oracle-related REST handlers to a router -func RegisterRoutes(cliCtx client.Context, r *mux.Router) { - resgisterTxRoute(cliCtx, r) - registerQueryRoute(cliCtx, r) -} diff --git a/x/oracle/client/rest/tx.go b/x/oracle/client/rest/tx.go deleted file mode 100644 index 85fa918a..00000000 --- a/x/oracle/client/rest/tx.go +++ /dev/null @@ -1,204 +0,0 @@ -package rest - -import ( - "fmt" - "net/http" - - "github.com/peggyjv/sommelier/x/oracle/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/rest" - - "github.com/gorilla/mux" -) - -func resgisterTxRoute(cliCtx client.Context, r *mux.Router) { - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/feeder", RestVoter), submitDelegateHandlerFunction(cliCtx)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/aggregate_prevote", RestVoter), submitAggregatePrevoteHandlerFunction(cliCtx)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/oracle/voters/{%s}/aggregate_vote", RestVoter), submitAggregateVoteHandlerFunction(cliCtx)).Methods("POST") -} - -// DelegateReq is request body to set feeder of validator -type DelegateReq struct { - BaseReq rest.BaseReq `json:"base_req"` - Feeder string `json:"feeder"` -} - -func submitDelegateHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - voter := vars[RestVoter] - - // Get voter validator address - valAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - var req DelegateReq - if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { - return - } - - req.BaseReq = req.BaseReq.Sanitize() - - if !req.BaseReq.ValidateBasic(w) { - return - } - - fromAddress, err := sdk.AccAddressFromBech32(req.BaseReq.From) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - // Bytes comparison, so do not require type conversion - if !valAddress.Equals(fromAddress) { - err := fmt.Errorf("[%v] can not change [%v] delegation", fromAddress, valAddress) - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - feeder, err := sdk.AccAddressFromBech32(req.Feeder) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - // create the message - msg := types.NewMsgDelegateFeedConsent(valAddress, feeder) - err = msg.ValidateBasic() - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, &msg) - } -} - -// AggregatePrevoteReq ... -type AggregatePrevoteReq struct { - BaseReq rest.BaseReq `json:"base_req"` - - Hash string `json:"hash"` - ExchangeRates string `json:"exchange_rates"` - Salt string `json:"salt"` -} - -func submitAggregatePrevoteHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - voter := vars[RestVoter] - - valAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - var req AggregatePrevoteReq - if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { - return - } - - req.BaseReq = req.BaseReq.Sanitize() - - if !req.BaseReq.ValidateBasic(w) { - return - } - - fromAddress, err := sdk.AccAddressFromBech32(req.BaseReq.From) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - var hash types.AggregateVoteHash - - // If hash is not given, then retrieve hash from exchange_rate and salt - if len(req.Hash) == 0 && (len(req.ExchangeRates) > 0 && len(req.Salt) > 0) { - _, err := types.ParseExchangeRateTuples(req.ExchangeRates) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - hash = types.GetAggregateVoteHash(req.Salt, req.ExchangeRates, valAddress) - } else { - hash, err = types.AggregateVoteHashFromHexString(req.Hash) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - } - - // create the message - msg := types.NewMsgAggregateExchangeRatePrevote(hash, fromAddress, valAddress) - err = msg.ValidateBasic() - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, &msg) - } -} - -// AggregateVoteReq ... -type AggregateVoteReq struct { - BaseReq rest.BaseReq `json:"base_req"` - - ExchangeRates string `json:"exchange_rates"` - Salt string `json:"salt"` -} - -func submitAggregateVoteHandlerFunction(cliCtx client.Context) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - voter := vars[RestVoter] - - valAddress, err := sdk.ValAddressFromBech32(voter) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - var req AggregateVoteReq - if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { - return - } - - req.BaseReq = req.BaseReq.Sanitize() - - if !req.BaseReq.ValidateBasic(w) { - return - } - - fromAddress, err := sdk.AccAddressFromBech32(req.BaseReq.From) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - // Check validation of tuples - _, err = types.ParseExchangeRateTuples(req.ExchangeRates) - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - // create the message - msg := types.NewMsgAggregateExchangeRateVote(req.Salt, req.ExchangeRates, fromAddress, valAddress) - err = msg.ValidateBasic() - if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) - return - } - - tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, &msg) - } -} diff --git a/x/oracle/genesis.go b/x/oracle/genesis.go index bc90ece9..d93c7e81 100644 --- a/x/oracle/genesis.go +++ b/x/oracle/genesis.go @@ -24,7 +24,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data types.GenesisState) } for _, rate := range data.ExchangeRates { - keeper.SetLunaExchangeRate(ctx, rate.Denom, rate.ExchangeRate) + keeper.SetUSDExchangeRate(ctx, rate.Denom, rate.Amount) } for operatorBechAddr, missCounter := range data.MissCounters { @@ -45,11 +45,11 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data types.GenesisState) if len(data.TobinTaxes) > 0 { for _, tt := range data.TobinTaxes { - keeper.SetTobinTax(ctx, tt.Denom, tt.ExchangeRate) + keeper.SetTobinTax(ctx, tt.Denom, tt.Amount) } } else { for _, item := range data.Params.Whitelist { - keeper.SetTobinTax(ctx, item.Name, item.TobinTax) + keeper.SetTobinTax(ctx, item.Denom, item.Amount) } } @@ -74,9 +74,9 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data types.GenesisSta return false }) - rates := make([]types.ExchangeRateTuple, 0) - keeper.IterateLunaExchangeRates(ctx, func(denom string, rate sdk.Dec) (stop bool) { - rates = append(rates, types.ExchangeRateTuple{ExchangeRate: rate, Denom: denom}) + rates := make(sdk.DecCoins, 0) + keeper.IterateUSDExchangeRates(ctx, func(denom string, rate sdk.Dec) (stop bool) { + rates = append(rates, sdk.DecCoin{Amount: rate, Denom: denom}) return false }) @@ -98,9 +98,9 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data types.GenesisSta return false }) - tobinTaxes := make([]types.ExchangeRateTuple, 0) + tobinTaxes := make(sdk.DecCoins, 0) keeper.IterateTobinTaxes(ctx, func(denom string, tobinTax sdk.Dec) (stop bool) { - tobinTaxes = append(tobinTaxes, types.ExchangeRateTuple{ExchangeRate: tobinTax, Denom: denom}) + tobinTaxes = append(tobinTaxes, sdk.DecCoin{Amount: tobinTax, Denom: denom}) return false }) diff --git a/x/oracle/genesis_test.go b/x/oracle/genesis_test.go index d1ce3500..a1ce3f69 100644 --- a/x/oracle/genesis_test.go +++ b/x/oracle/genesis_test.go @@ -15,9 +15,9 @@ func TestExportInitGenesis(t *testing.T) { input, _ := setup(t) input.OracleKeeper.SetOracleDelegate(input.Ctx, keeper.ValAddrs[0], keeper.Addrs[1]) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, "denom", sdk.NewDec(123)) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, "denom", sdk.NewDec(123)) input.OracleKeeper.AddAggregateExchangeRatePrevote(input.Ctx, types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{123}, keeper.ValAddrs[0], int64(2))) - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{Denom: "foo", ExchangeRate: sdk.NewDec(123)}}, keeper.ValAddrs[0])) + input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(sdk.DecCoins{{"foo", sdk.NewDec(123)}}, keeper.ValAddrs[0])) input.OracleKeeper.SetTobinTax(input.Ctx, "denom", sdk.NewDecWithPrec(123, 3)) input.OracleKeeper.SetTobinTax(input.Ctx, "denom2", sdk.NewDecWithPrec(123, 3)) genesis := ExportGenesis(input.Ctx, input.OracleKeeper) diff --git a/x/oracle/handler_test.go b/x/oracle/handler_test.go index e809b1f3..dd913992 100644 --- a/x/oracle/handler_test.go +++ b/x/oracle/handler_test.go @@ -25,12 +25,12 @@ func TestOracleFilters(t *testing.T) { er := sdk.DecCoins{sdk.NewDecCoinFromDec(types.MicroSDRDenom, randomExchangeRate)} hash := types.GetAggregateVoteHash(salt, er.String(), keeper.ValAddrs[0]) prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) // // Case 3: Normal MsgExchangeRateVote submission goes through keeper.keeper.Addrs voteMsg := types.NewMsgAggregateExchangeRateVote(salt, er.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.NoError(t, err) // Case 4: a non-validator sending an oracle message fails @@ -39,7 +39,7 @@ func TestOracleFilters(t *testing.T) { hash = types.GetAggregateVoteHash(salt, er.String(), sdk.ValAddress(addr)) prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, addr, keeper.ValAddrs[3]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.Error(t, err) } @@ -57,47 +57,47 @@ func TestFeederDelegation(t *testing.T) { // Case 2: Normal Prevote - without delegation prevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) // Case 2.1: Normal Prevote - with delegation fails prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.Error(t, err) // Case 2.2: Normal Vote - without delegation voteMsg := types.NewMsgAggregateExchangeRateVote(salt, er.String(), keeper.Addrs[0], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.NoError(t, err) // Case 2.3: Normal Vote - with delegation fails voteMsg = types.NewMsgAggregateExchangeRateVote(salt, er.String(), keeper.Addrs[1], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.Error(t, err) // Case 3: Normal MsgDelegateFeedConsent succeeds msg := types.NewMsgDelegateFeedConsent(keeper.ValAddrs[0], keeper.Addrs[1]) - _, err = h(input.Ctx, &msg) + _, err = h(input.Ctx, msg) require.NoError(t, err) // Case 4.1: Normal Prevote - without delegation fails prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[2], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.Error(t, err) // Case 4.2: Normal Prevote - with delegation succeeds prevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &prevoteMsg) + _, err = h(input.Ctx, prevoteMsg) require.NoError(t, err) // Case 4.3: Normal Vote - without delegation fails voteMsg = types.NewMsgAggregateExchangeRateVote(salt, er.String(), keeper.Addrs[2], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.Error(t, err) // Case 4.4: Normal Vote - with delegation succeeds voteMsg = types.NewMsgAggregateExchangeRateVote(salt, er.String(), keeper.Addrs[1], keeper.ValAddrs[0]) - _, err = h(input.Ctx.WithBlockHeight(1), &voteMsg) + _, err = h(input.Ctx.WithBlockHeight(1), voteMsg) require.NoError(t, err) } @@ -113,50 +113,50 @@ func TestAggregatePrevoteVote(t *testing.T) { hash := types.GetAggregateVoteHash(salt, exchangeRatesStr, keeper.ValAddrs[0]) aggregateExchangeRatePrevoteMsg := types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[0], keeper.ValAddrs[0]) - _, err := h(input.Ctx, &aggregateExchangeRatePrevoteMsg) + _, err := h(input.Ctx, aggregateExchangeRatePrevoteMsg) require.NoError(t, err) // Unauthorized feeder aggregateExchangeRatePrevoteMsg = types.NewMsgAggregateExchangeRatePrevote(hash, keeper.Addrs[1], keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRatePrevoteMsg) + _, err = h(input.Ctx, aggregateExchangeRatePrevoteMsg) require.Error(t, err) // Invalid reveal period - aggregateExchangeRateVoteMsg := types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg := types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Invalid reveal period input.Ctx = input.Ctx.WithBlockHeight(2) - aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Other exchange rate with valid real period input.Ctx = input.Ctx.WithBlockHeight(1) - aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, otherExchangeRateStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, otherExchangeRateStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Invalid exchange rate with valid real period input.Ctx = input.Ctx.WithBlockHeight(1) - aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, invalidExchangeRateStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, invalidExchangeRateStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Unauthorized feeder aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, invalidExchangeRateStr, sdk.AccAddress(keeper.Addrs[1]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Unintended denom vote - aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, unintendedExchageRateStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, unintendedExchageRateStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.Error(t, err) // Valid exchange rate reveal submission input.Ctx = input.Ctx.WithBlockHeight(1) - aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, sdk.AccAddress(keeper.Addrs[0]), keeper.ValAddrs[0]) - _, err = h(input.Ctx, &aggregateExchangeRateVoteMsg) + aggregateExchangeRateVoteMsg = types.NewMsgAggregateExchangeRateVote(salt, exchangeRatesStr, keeper.Addrs[0], keeper.ValAddrs[0]) + _, err = h(input.Ctx, aggregateExchangeRateVoteMsg) require.NoError(t, err) } diff --git a/x/oracle/keeper/ballot.go b/x/oracle/keeper/ballot.go index 7cadb227..d37f0dee 100644 --- a/x/oracle/keeper/ballot.go +++ b/x/oracle/keeper/ballot.go @@ -26,14 +26,14 @@ func (k Keeper) OrganizeBallotByDenom(ctx sdk.Context) (votes map[string]types.E power := validator.GetConsensusPower() for _, tuple := range vote.ExchangeRateTuples { tmpPower := power - if !tuple.ExchangeRate.IsPositive() { + if !tuple.Amount.IsPositive() { // Make the power of abstain vote zero tmpPower = 0 } votes[tuple.Denom] = append(votes[tuple.Denom], types.NewVoteForTally( - types.NewExchangeRateVote(tuple.ExchangeRate, tuple.Denom, voter), + types.NewExchangeRateVote(tuple.Amount, tuple.Denom, voter), tmpPower, ), ) diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index 8bf9f12d..67665493 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -104,10 +104,10 @@ func TestOrganizeAggregate(t *testing.T) { } for i := range sdrBallot { - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Denom: sdrBallot[i].Denom, ExchangeRate: sdrBallot[i].ExchangeRate}, - {Denom: krwBallot[i].Denom, ExchangeRate: krwBallot[i].ExchangeRate}, - }, ValAddrs[i])) + input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(sdk.NewDecCoins( + sdk.NewDecCoinFromDec(sdrBallot[i].Denom, sdrBallot[i].ExchangeRate), + sdk.NewDecCoinFromDec(krwBallot[i].Denom, krwBallot[i].ExchangeRate), + ), ValAddrs[i])) } // organize votes by denom @@ -169,10 +169,10 @@ func TestDuplicateVote(t *testing.T) { input.OracleKeeper.AddExchangeRateVote(input.Ctx, vote.ExchangeRateVote) } - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Denom: sdrBallot[i].Denom, ExchangeRate: sdrBallot[i].ExchangeRate}, - {Denom: krwBallot[i].Denom, ExchangeRate: krwBallot[i].ExchangeRate}, - }, ValAddrs[i])) + input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, types.NewAggregateExchangeRateVote(sdk.NewDecCoins( + sdk.NewDecCoinFromDec(sdrBallot[i].Denom, sdrBallot[i].ExchangeRate), + sdk.NewDecCoinFromDec(krwBallot[i].Denom, krwBallot[i].ExchangeRate), + ), ValAddrs[i])) } // organize votes by denom diff --git a/x/oracle/keeper/grpc_query.go b/x/oracle/keeper/grpc_query.go index b7ea5e36..e03135ef 100644 --- a/x/oracle/keeper/grpc_query.go +++ b/x/oracle/keeper/grpc_query.go @@ -12,7 +12,7 @@ var _ types.QueryServer = Keeper{} // ExchangeRate returns the current exchange rate for a given denom func (k Keeper) ExchangeRate(c context.Context, req *types.QueryExchangeRateRequest) (*types.QueryExchangeRateResponse, error) { - rate, err := k.GetLunaExchangeRate(sdk.UnwrapSDKContext(c), req.Denom) + rate, err := k.GetUSDExchangeRate(sdk.UnwrapSDKContext(c), req.Denom) if err != nil { return nil, sdkerrors.Wrap(types.ErrUnknowDenom, req.Denom) } @@ -23,7 +23,7 @@ func (k Keeper) ExchangeRate(c context.Context, req *types.QueryExchangeRateRequ // ExchangeRates returns all the exchange rates tracked by the system func (k Keeper) ExchangeRates(c context.Context, req *types.QueryExchangeRatesRequest) (*types.QueryExchangeRatesResponse, error) { var rates sdk.DecCoins - k.IterateLunaExchangeRates(sdk.UnwrapSDKContext(c), func(denom string, rate sdk.Dec) (stop bool) { + k.IterateUSDExchangeRates(sdk.UnwrapSDKContext(c), func(denom string, rate sdk.Dec) (stop bool) { rates = append(rates, sdk.NewDecCoinFromDec(denom, rate)) return false }) @@ -33,7 +33,7 @@ func (k Keeper) ExchangeRates(c context.Context, req *types.QueryExchangeRatesRe // Actives returns the active denoms func (k Keeper) Actives(c context.Context, req *types.QueryActivesRequest) (*types.QueryActivesResponse, error) { denoms := []string{} - k.IterateLunaExchangeRates(sdk.UnwrapSDKContext(c), func(denom string, rate sdk.Dec) (stop bool) { + k.IterateUSDExchangeRates(sdk.UnwrapSDKContext(c), func(denom string, rate sdk.Dec) (stop bool) { denoms = append(denoms, denom) return false }) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 78ae14f6..7ed61bf5 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -72,14 +72,14 @@ func (k Keeper) GetExchangeRatePrevote(ctx sdk.Context, denom string, voter sdk. err = sdkerrors.Wrap(types.ErrNoPrevote, fmt.Sprintf("(%s, %s)", voter, denom)) return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &prevote) + k.cdc.MustUnmarshalBinaryBare(b, &prevote) return } // AddExchangeRatePrevote adds an oracle prevote to the store func (k Keeper) AddExchangeRatePrevote(ctx sdk.Context, prevote types.ExchangeRatePrevote) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&prevote) + bz := k.cdc.MustMarshalBinaryBare(&prevote) voter, err := sdk.ValAddressFromBech32(prevote.Voter) if err != nil { panic(err) @@ -104,21 +104,7 @@ func (k Keeper) IterateExchangeRatePrevotes(ctx sdk.Context, handler func(prevot defer iter.Close() for ; iter.Valid(); iter.Next() { var prevote types.ExchangeRatePrevote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &prevote) - if handler(prevote) { - break - } - } -} - -// iterateExchangeRatePrevotesWithPrefix iterates over prevotes in the store with given prefix -func (k Keeper) iterateExchangeRatePrevotesWithPrefix(ctx sdk.Context, prefix []byte, handler func(vote types.ExchangeRatePrevote) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iter := sdk.KVStorePrefixIterator(store, prefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - var prevote types.ExchangeRatePrevote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &prevote) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &prevote) if handler(prevote) { break } @@ -135,7 +121,7 @@ func (k Keeper) IterateExchangeRateVotes(ctx sdk.Context, handler func(vote type defer iter.Close() for ; iter.Valid(); iter.Next() { var vote types.ExchangeRateVote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &vote) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &vote) if handler(vote) { break } @@ -149,7 +135,7 @@ func (k Keeper) iterateExchangeRateVotesWithPrefix(ctx sdk.Context, prefix []byt defer iter.Close() for ; iter.Valid(); iter.Next() { var vote types.ExchangeRateVote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &vote) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &vote) if handler(vote) { break } @@ -164,14 +150,14 @@ func (k Keeper) getExchangeRateVote(ctx sdk.Context, denom string, voter sdk.Val err = sdkerrors.Wrap(types.ErrNoVote, fmt.Sprintf("(%s, %s)", voter, denom)) return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &vote) + k.cdc.MustUnmarshalBinaryBare(b, &vote) return } // AddExchangeRateVote adds an oracle vote to the store func (k Keeper) AddExchangeRateVote(ctx sdk.Context, vote types.ExchangeRateVote) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&vote) + bz := k.cdc.MustMarshalBinaryBare(&vote) voter, err := sdk.ValAddressFromBech32(vote.Voter) if err != nil { panic(err) @@ -192,9 +178,9 @@ func (k Keeper) DeleteExchangeRateVote(ctx sdk.Context, vote types.ExchangeRateV //----------------------------------- // ExchangeRate logic -// GetLunaExchangeRate gets the consensus exchange rate of Luna denominated in the denom asset from the store. -func (k Keeper) GetLunaExchangeRate(ctx sdk.Context, denom string) (exchangeRate sdk.Dec, err error) { - if denom == types.MicroLunaDenom { +// GetUSDExchangeRate gets the consensus exchange rate of USD denominated in the denom asset from the store. +func (k Keeper) GetUSDExchangeRate(ctx sdk.Context, denom string) (exchangeRate sdk.Dec, err error) { + if denom == types.MicroUSDDenom { return sdk.OneDec(), nil } @@ -211,8 +197,8 @@ func (k Keeper) GetLunaExchangeRate(ctx sdk.Context, denom string) (exchangeRate return } -// SetLunaExchangeRate sets the consensus exchange rate of Luna denominated in the denom asset to the store. -func (k Keeper) SetLunaExchangeRate(ctx sdk.Context, denom string, exchangeRate sdk.Dec) { +// SetUSDExchangeRate sets the consensus exchange rate of USD denominated in the denom asset to the store. +func (k Keeper) SetUSDExchangeRate(ctx sdk.Context, denom string, exchangeRate sdk.Dec) { store := ctx.KVStore(k.storeKey) // TODO: review echange rate marshal/unmarshal bz, err := exchangeRate.Marshal() @@ -222,9 +208,9 @@ func (k Keeper) SetLunaExchangeRate(ctx sdk.Context, denom string, exchangeRate store.Set(types.GetExchangeRateKey(denom), bz) } -// SetLunaExchangeRateWithEvent sets the consensus exchange rate of Luna denominated in the denom asset to the store with ABCI event -func (k Keeper) SetLunaExchangeRateWithEvent(ctx sdk.Context, denom string, exchangeRate sdk.Dec) { - k.SetLunaExchangeRate(ctx, denom, exchangeRate) +// SetUSDExchangeRateWithEvent sets the consensus exchange rate of USD denominated in the denom asset to the store with ABCI event +func (k Keeper) SetUSDExchangeRateWithEvent(ctx sdk.Context, denom string, exchangeRate sdk.Dec) { + k.SetUSDExchangeRate(ctx, denom, exchangeRate) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeExchangeRateUpdate, sdk.NewAttribute(types.AttributeKeyDenom, denom), @@ -233,14 +219,14 @@ func (k Keeper) SetLunaExchangeRateWithEvent(ctx sdk.Context, denom string, exch ) } -// DeleteLunaExchangeRate deletes the consensus exchange rate of Luna denominated in the denom asset from the store. -func (k Keeper) DeleteLunaExchangeRate(ctx sdk.Context, denom string) { +// DeleteUSDExchangeRate deletes the consensus exchange rate of usd denominated in the denom asset from the store. +func (k Keeper) DeleteUSDExchangeRate(ctx sdk.Context, denom string) { store := ctx.KVStore(k.storeKey) store.Delete(types.GetExchangeRateKey(denom)) } -// IterateLunaExchangeRates iterates over luna rates in the store -func (k Keeper) IterateLunaExchangeRates(ctx sdk.Context, handler func(denom string, exchangeRate sdk.Dec) (stop bool)) { +// IterateUSDExchangeRates iterates over usd rates in the store +func (k Keeper) IterateUSDExchangeRates(ctx sdk.Context, handler func(denom string, exchangeRate sdk.Dec) (stop bool)) { store := ctx.KVStore(k.storeKey) iter := sdk.KVStorePrefixIterator(store, types.ExchangeRateKey) defer iter.Close() @@ -362,14 +348,14 @@ func (k Keeper) GetAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAd err = sdkerrors.Wrap(types.ErrNoAggregatePrevote, voter.String()) return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &aggregatePrevote) + k.cdc.MustUnmarshalBinaryBare(b, &aggregatePrevote) return } // AddAggregateExchangeRatePrevote adds an oracle aggregate prevote to the store func (k Keeper) AddAggregateExchangeRatePrevote(ctx sdk.Context, aggregatePrevote types.AggregateExchangeRatePrevote) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&aggregatePrevote) + bz := k.cdc.MustMarshalBinaryBare(&aggregatePrevote) voter, err := sdk.ValAddressFromBech32(aggregatePrevote.Voter) if err != nil { panic(err) @@ -394,7 +380,7 @@ func (k Keeper) IterateAggregateExchangeRatePrevotes(ctx sdk.Context, handler fu defer iter.Close() for ; iter.Valid(); iter.Next() { var aggregatePrevote types.AggregateExchangeRatePrevote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &aggregatePrevote) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &aggregatePrevote) if handler(aggregatePrevote) { break } @@ -412,14 +398,14 @@ func (k Keeper) GetAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddre err = sdkerrors.Wrap(types.ErrNoAggregateVote, voter.String()) return } - k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &aggregateVote) + k.cdc.MustUnmarshalBinaryBare(b, &aggregateVote) return } // AddAggregateExchangeRateVote adds an oracle aggregate prevote to the store func (k Keeper) AddAggregateExchangeRateVote(ctx sdk.Context, aggregateVote types.AggregateExchangeRateVote) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(&aggregateVote) + bz := k.cdc.MustMarshalBinaryBare(&aggregateVote) voter, err := sdk.ValAddressFromBech32(aggregateVote.Voter) if err != nil { panic(err) @@ -444,7 +430,7 @@ func (k Keeper) IterateAggregateExchangeRateVotes(ctx sdk.Context, handler func( defer iter.Close() for ; iter.Valid(); iter.Next() { var aggregateVote types.AggregateExchangeRateVote - k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &aggregateVote) + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &aggregateVote) if handler(aggregateVote) { break } diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 1c8917bb..aab83b01 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -105,27 +105,27 @@ func TestExchangeRate(t *testing.T) { lunaExchangeRate := sdk.NewDecWithPrec(3282384, int64(OracleDecPrecision)).MulInt64(types.MicroUnit) // Set & get rates - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroCNYDenom, cnyExchangeRate) - rate, err := input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroCNYDenom) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroCNYDenom, cnyExchangeRate) + rate, err := input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroCNYDenom) require.NoError(t, err) require.Equal(t, cnyExchangeRate, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroGBPDenom, gbpExchangeRate) - rate, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroGBPDenom) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroGBPDenom, gbpExchangeRate) + rate, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroGBPDenom) require.NoError(t, err) require.Equal(t, gbpExchangeRate, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroKRWDenom, krwExchangeRate) - rate, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroKRWDenom) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroKRWDenom, krwExchangeRate) + rate, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroKRWDenom) require.NoError(t, err) require.Equal(t, krwExchangeRate, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroLunaDenom, lunaExchangeRate) - rate, _ = input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroLunaDenom) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroUSDDenom, lunaExchangeRate) + rate, _ = input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroUSDDenom) require.Equal(t, sdk.OneDec(), rate) - input.OracleKeeper.DeleteLunaExchangeRate(input.Ctx, types.MicroKRWDenom) - _, err = input.OracleKeeper.GetLunaExchangeRate(input.Ctx, types.MicroKRWDenom) + input.OracleKeeper.DeleteUSDExchangeRate(input.Ctx, types.MicroKRWDenom) + _, err = input.OracleKeeper.GetUSDExchangeRate(input.Ctx, types.MicroKRWDenom) require.Error(t, err) numExchangeRates := 0 @@ -133,12 +133,12 @@ func TestExchangeRate(t *testing.T) { numExchangeRates = numExchangeRates + 1 return false } - input.OracleKeeper.IterateLunaExchangeRates(input.Ctx, handler) + input.OracleKeeper.IterateUSDExchangeRates(input.Ctx, handler) require.True(t, numExchangeRates == 3) } -func TestIterateLunaExchangeRates(t *testing.T) { +func TestIterateUSDExchangeRates(t *testing.T) { input := CreateTestInput(t) cnyExchangeRate := sdk.NewDecWithPrec(839, int64(OracleDecPrecision)).MulInt64(types.MicroUnit) @@ -147,12 +147,12 @@ func TestIterateLunaExchangeRates(t *testing.T) { lunaExchangeRate := sdk.NewDecWithPrec(3282384, int64(OracleDecPrecision)).MulInt64(types.MicroUnit) // Set & get rates - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroCNYDenom, cnyExchangeRate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroGBPDenom, gbpExchangeRate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroKRWDenom, krwExchangeRate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroLunaDenom, lunaExchangeRate) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroCNYDenom, cnyExchangeRate) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroGBPDenom, gbpExchangeRate) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroKRWDenom, krwExchangeRate) + input.OracleKeeper.SetUSDExchangeRate(input.Ctx, types.MicroLunaDenom, lunaExchangeRate) - input.OracleKeeper.IterateLunaExchangeRates(input.Ctx, func(denom string, rate sdk.Dec) (stop bool) { + input.OracleKeeper.IterateUSDExchangeRates(input.Ctx, func(denom string, rate sdk.Dec) (stop bool) { switch denom { case types.MicroCNYDenom: require.Equal(t, cnyExchangeRate, rate) @@ -200,10 +200,10 @@ func TestParams(t *testing.T) { slashFraction := sdk.NewDecWithPrec(1, 2) slashWindow := int64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) - whitelist := types.DenomList{ - {Name: types.MicroSDRDenom, TobinTax: types.DefaultTobinTax}, - {Name: types.MicroKRWDenom, TobinTax: types.DefaultTobinTax}, - } + whitelist := sdk.NewDecCoins( + sdk.NewDecCoinFromDec(types.MicroSDRDenom, types.DefaultTobinTax), + sdk.NewDecCoinFromDec(types.MicroKRWDenom, types.DefaultTobinTax), + ) // Should really test validateParams, but skipping because obvious newParams := types.Params{ @@ -343,10 +343,10 @@ func TestAggregatePrevoteIterate(t *testing.T) { func TestAggregateVoteAddDelete(t *testing.T) { input := CreateTestInput(t) - aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Denom: "foo", ExchangeRate: sdk.NewDec(-1)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(0)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(1)}, + aggregateVote := types.NewAggregateExchangeRateVote(sdk.DecCoins{ + sdk.DecCoin{"foo", sdk.NewDec(-1)}, + sdk.NewDecCoinFromDec("foo", sdk.NewDec(0)), + sdk.NewDecCoinFromDec("foo", sdk.NewDec(1)), }, sdk.ValAddress(Addrs[0])) input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, aggregateVote) @@ -362,17 +362,17 @@ func TestAggregateVoteAddDelete(t *testing.T) { func TestAggregateVoteIterate(t *testing.T) { input := CreateTestInput(t) - aggregateVote1 := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Denom: "foo", ExchangeRate: sdk.NewDec(-1)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(0)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(1)}, + aggregateVote1 := types.NewAggregateExchangeRateVote(sdk.DecCoins{ + sdk.DecCoin{"foo", sdk.NewDec(-1)}, + sdk.NewDecCoinFromDec("foo", sdk.NewDec(0)), + sdk.NewDecCoinFromDec("foo", sdk.NewDec(1)), }, sdk.ValAddress(Addrs[0])) input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, aggregateVote1) - aggregateVote2 := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Denom: "foo", ExchangeRate: sdk.NewDec(-1)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(0)}, - {Denom: "foo", ExchangeRate: sdk.NewDec(1)}, + aggregateVote2 := types.NewAggregateExchangeRateVote(sdk.DecCoins{ + sdk.DecCoin{"foo", sdk.NewDec(-1)}, + sdk.NewDecCoinFromDec("foo", sdk.NewDec(0)), + sdk.NewDecCoinFromDec("foo", sdk.NewDec(1)), }, sdk.ValAddress(Addrs[1])) input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, aggregateVote2) diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index b8f905fb..e2884248 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -129,7 +129,7 @@ func (m msgServer) AggregateExchangeRateVote(c context.Context, msg *types.MsgAg return nil, sdkerrors.Wrap(types.ErrNoAggregatePrevote, msg.Validator) } - // Check a msg is submitted porper period + // Check a msg is submitted proper period if (ctx.BlockHeight()/params.VotePeriod)-(aggregatePrevote.SubmitBlock/params.VotePeriod) != 1 { return nil, types.ErrRevealPeriodMissMatch } @@ -174,5 +174,5 @@ func (m msgServer) AggregateExchangeRateVote(c context.Context, msg *types.MsgAg ), }) - return nil, nil + return &types.MsgAggregateExchangeRateVoteResponse{}, nil } diff --git a/x/oracle/keeper/params.go b/x/oracle/keeper/params.go index f6a87b37..fbbfc5b8 100644 --- a/x/oracle/keeper/params.go +++ b/x/oracle/keeper/params.go @@ -30,7 +30,7 @@ func (k Keeper) RewardDistributionWindow(ctx sdk.Context) (res int64) { } // Whitelist returns the denom list that can be activated -func (k Keeper) Whitelist(ctx sdk.Context) (res types.DenomList) { +func (k Keeper) Whitelist(ctx sdk.Context) (res sdk.DecCoins) { k.paramSpace.Get(ctx, types.ParamStoreKeyWhitelist, &res) return } diff --git a/x/oracle/keeper/querier.go b/x/oracle/keeper/querier.go deleted file mode 100644 index 9ff3d737..00000000 --- a/x/oracle/keeper/querier.go +++ /dev/null @@ -1,166 +0,0 @@ -package keeper - -import ( - "encoding/json" - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/peggyjv/sommelier/x/oracle/types" -) - -// NewQuerier is the module level router for state queries -func NewQuerier(keeper Keeper) sdk.Querier { - return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) { - switch path[0] { - case types.QueryExchangeRate: - return queryExchangeRate(ctx, req, keeper) - case types.QueryExchangeRates: - return queryExchangeRates(ctx, keeper) - case types.QueryActives: - return queryActives(ctx, keeper) - case types.QueryParameters: - return queryParameters(ctx, keeper) - case types.QueryFeederDelegation: - return queryFeederDelegation(ctx, req, keeper) - case types.QueryMissCounter: - return queryMissCounter(ctx, req, keeper) - case types.QueryAggregatePrevote: - return queryAggregatePrevote(ctx, req, keeper) - case types.QueryAggregateVote: - return queryAggregateVote(ctx, req, keeper) - case types.QueryVoteTargets: - return queryVoteTargets(ctx, keeper) - case types.QueryTobinTax: - return queryTobinTax(ctx, req, keeper) - case types.QueryTobinTaxes: - return queryTobinTaxes(ctx, keeper) - default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) - } - } -} - -func queryExchangeRate(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryExchangeRateParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - rate, err := keeper.GetLunaExchangeRate(ctx, params.Denom) - if err != nil { - return nil, sdkerrors.Wrap(types.ErrUnknowDenom, params.Denom) - } - return []byte(rate.String()), nil -} - -func queryExchangeRates(ctx sdk.Context, keeper Keeper) ([]byte, error) { - var rates sdk.DecCoins - keeper.IterateLunaExchangeRates(ctx, func(denom string, rate sdk.Dec) (stop bool) { - rates = append(rates, sdk.NewDecCoinFromDec(denom, rate)) - return false - }) - return []byte(rates.String()), nil -} - -func queryActives(ctx sdk.Context, keeper Keeper) ([]byte, error) { - var denoms []string - keeper.IterateLunaExchangeRates(ctx, func(denom string, rate sdk.Dec) (stop bool) { - denoms = append(denoms, denom) - return false - }) - bz, err := json.MarshalIndent(denoms, "", " ") - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - return bz, nil -} - -// TODO: investigate param returns -func queryParameters(ctx sdk.Context, keeper Keeper) ([]byte, error) { - bz, err := json.Marshal(keeper.GetParams(ctx)) - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - return bz, nil -} - -func queryFeederDelegation(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryFeederDelegationParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - return []byte(keeper.GetOracleDelegate(ctx, params.Validator).String()), nil -} - -func queryMissCounter(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryMissCounterParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - return []byte(fmt.Sprint(keeper.GetMissCounter(ctx, params.Validator))), nil -} - -func queryAggregatePrevote(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryAggregatePrevoteParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - aggregateExchangeRatePrevote, err := keeper.GetAggregateExchangeRatePrevote(ctx, params.Validator) - if err != nil { - return nil, err - } - bz, err := json.MarshalIndent(aggregateExchangeRatePrevote, "", " ") - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - return bz, nil -} - -// TODO: make this print { "voter": "cosmos1u94xef3cp9thkcpxecuvhtpwnmg8mhlja8hzkd", "rates": "92992.1103umon/foo,3014.893umosn/foosd" } -func queryAggregateVote(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryAggregateVoteParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - vote, err := keeper.GetAggregateExchangeRateVote(ctx, params.Validator) - if err != nil { - return nil, err - } - bz, err := json.MarshalIndent(vote, "", " ") - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - return bz, nil -} - -func queryVoteTargets(ctx sdk.Context, keeper Keeper) ([]byte, error) { - bz, err := json.MarshalIndent(keeper.GetVoteTargets(ctx), "", " ") - if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) - } - return bz, nil -} - -func queryTobinTax(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) ([]byte, error) { - var params types.QueryTobinTaxParams - if err := json.Unmarshal(req.Data, ¶ms); err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) - } - tobinTax, err := keeper.GetTobinTax(ctx, params.Denom) - if err != nil { - return nil, err - } - return []byte(tobinTax.String()), nil -} - -func queryTobinTaxes(ctx sdk.Context, keeper Keeper) ([]byte, error) { - var denoms sdk.DecCoins - keeper.IterateTobinTaxes(ctx, func(denom string, tobinTax sdk.Dec) (stop bool) { - denoms = append(denoms, sdk.NewDecCoinFromDec(denom, tobinTax)) - return false - }) - return []byte(denoms.String()), nil -} diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go deleted file mode 100644 index 48a1595c..00000000 --- a/x/oracle/keeper/querier_test.go +++ /dev/null @@ -1,276 +0,0 @@ -package keeper - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/peggyjv/sommelier/x/oracle/types" -) - -func TestNewQuerier(t *testing.T) { - input := CreateTestInput(t) - - querier := NewQuerier(input.OracleKeeper) - - query := abci.RequestQuery{ - Path: "", - Data: []byte{}, - } - - _, err := querier(input.Ctx, []string{types.QueryParameters}, query) - require.NoError(t, err) -} - -func TestQueryParams(t *testing.T) { - input := CreateTestInput(t) - - var params types.Params - - res, errRes := queryParameters(input.Ctx, input.OracleKeeper) - require.NoError(t, errRes) - - err := json.Unmarshal(res, ¶ms) - require.NoError(t, err) - require.Equal(t, input.OracleKeeper.GetParams(input.Ctx), params) -} - -func TestQueryExchangeRate(t *testing.T) { - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - rate := sdk.NewDec(1700) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroSDRDenom, rate) - - // denom query params - queryParams := types.NewQueryExchangeRateParams(types.MicroSDRDenom) - bz, err := json.Marshal(queryParams) - require.NoError(t, err) - - res, err := querier(input.Ctx, []string{types.QueryExchangeRate}, abci.RequestQuery{Path: "", Data: bz}) - require.NoError(t, err) - require.Equal(t, rate.String(), string(res)) -} - -func TestQueryExchangeRates(t *testing.T) { - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - rate := sdk.NewDec(1700) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroSDRDenom, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroUSDDenom, rate) - - res, err := querier(input.Ctx, []string{types.QueryExchangeRates}, abci.RequestQuery{}) - require.NoError(t, err) - - rrate, err := sdk.ParseDecCoins(string(res)) - require.NoError(t, err) - require.Equal(t, sdk.DecCoins{ - sdk.NewDecCoinFromDec(types.MicroSDRDenom, rate), - sdk.NewDecCoinFromDec(types.MicroUSDDenom, rate), - }, rrate) -} - -func TestQueryActives(t *testing.T) { - cdc := codec.NewLegacyAmino() - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - rate := sdk.NewDec(1700) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroSDRDenom, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroKRWDenom, rate) - input.OracleKeeper.SetLunaExchangeRate(input.Ctx, types.MicroUSDDenom, rate) - - res, err := querier(input.Ctx, []string{types.QueryActives}, abci.RequestQuery{}) - require.NoError(t, err) - - targetDenoms := []string{ - types.MicroKRWDenom, - types.MicroSDRDenom, - types.MicroUSDDenom, - } - - var denoms []string - err2 := cdc.UnmarshalJSON(res, &denoms) - require.NoError(t, err2) - require.Equal(t, targetDenoms, denoms) -} - -func TestQueryFeederDelegation(t *testing.T) { - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - input.OracleKeeper.SetOracleDelegate(input.Ctx, ValAddrs[0], Addrs[1]) - bz, err := json.Marshal(types.NewQueryFeederDelegationParams(ValAddrs[0])) - require.NoError(t, err) - res, err := querier(input.Ctx, []string{types.QueryFeederDelegation}, abci.RequestQuery{Path: "", Data: bz}) - require.NoError(t, err) - require.Equal(t, Addrs[1].String(), string(res)) -} - -func TestQueryAggregatePrevote(t *testing.T) { - cdc := codec.NewLegacyAmino() - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - prevote1 := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{}, ValAddrs[0], 0) - input.OracleKeeper.AddAggregateExchangeRatePrevote(input.Ctx, prevote1) - prevote2 := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{}, ValAddrs[1], 0) - input.OracleKeeper.AddAggregateExchangeRatePrevote(input.Ctx, prevote2) - prevote3 := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{}, ValAddrs[2], 0) - input.OracleKeeper.AddAggregateExchangeRatePrevote(input.Ctx, prevote3) - - // validator 0 address params - queryParams := types.NewQueryAggregatePrevoteParams(ValAddrs[0]) - bz, err := cdc.MarshalJSON(queryParams) - require.NoError(t, err) - - req := abci.RequestQuery{ - Path: "", - Data: bz, - } - - res, err := querier(input.Ctx, []string{types.QueryAggregatePrevote}, req) - require.NoError(t, err) - - var prevote types.AggregateExchangeRatePrevote - err = json.Unmarshal(res, &prevote) - require.NoError(t, err) - require.Equal(t, prevote1.Voter, prevote.Voter) - require.Equal(t, prevote1.SubmitBlock, prevote.SubmitBlock) - require.Equal(t, len(prevote1.Hash), len(prevote.Hash)) - - // validator 1 address params - queryParams = types.NewQueryAggregatePrevoteParams(ValAddrs[1]) - bz, err = cdc.MarshalJSON(queryParams) - require.NoError(t, err) - - req = abci.RequestQuery{ - Path: "", - Data: bz, - } - - res, err = querier(input.Ctx, []string{types.QueryAggregatePrevote}, req) - require.NoError(t, err) - - err = cdc.UnmarshalJSON(res, &prevote) - require.NoError(t, err) - require.Equal(t, prevote2.Voter, prevote.Voter) - require.Equal(t, prevote2.SubmitBlock, prevote.SubmitBlock) - require.Equal(t, len(prevote2.Hash), len(prevote.Hash)) -} - -func TestQueryAggregateVote(t *testing.T) { - cdc := codec.NewLegacyAmino() - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - vote1 := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{"", sdk.OneDec()}}, ValAddrs[0]) - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, vote1) - vote2 := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{"", sdk.OneDec()}}, ValAddrs[1]) - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, vote2) - vote3 := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{"", sdk.OneDec()}}, ValAddrs[2]) - input.OracleKeeper.AddAggregateExchangeRateVote(input.Ctx, vote3) - - // validator 0 address params - queryParams := types.NewQueryAggregateVoteParams(ValAddrs[0]) - bz, err := cdc.MarshalJSON(queryParams) - require.NoError(t, err) - - req := abci.RequestQuery{ - Path: "", - Data: bz, - } - - res, err := querier(input.Ctx, []string{types.QueryAggregateVote}, req) - require.NoError(t, err) - - var vote types.AggregateExchangeRateVote - err = cdc.UnmarshalJSON(res, &vote) - require.NoError(t, err) - require.Equal(t, vote1, vote) - - // validator 1 address params - queryParams = types.NewQueryAggregateVoteParams(ValAddrs[1]) - bz, err = cdc.MarshalJSON(queryParams) - require.NoError(t, err) - - req = abci.RequestQuery{ - Path: "", - Data: bz, - } - - res, err = querier(input.Ctx, []string{types.QueryAggregateVote}, req) - require.NoError(t, err) - - err = cdc.UnmarshalJSON(res, &vote) - require.NoError(t, err) - require.Equal(t, vote2, vote) -} - -func TestQueryVoteTargets(t *testing.T) { - cdc := codec.NewLegacyAmino() - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - // clear tobin taxes - input.OracleKeeper.ClearTobinTaxes(input.Ctx) - - voteTargets := []string{"denom", "denom2", "denom3"} - for _, target := range voteTargets { - input.OracleKeeper.SetTobinTax(input.Ctx, target, sdk.OneDec()) - } - - req := abci.RequestQuery{ - Path: "", - Data: nil, - } - - res, err := querier(input.Ctx, []string{types.QueryVoteTargets}, req) - require.NoError(t, err) - - var voteTargetsRes []string - err2 := cdc.UnmarshalJSON(res, &voteTargetsRes) - require.NoError(t, err2) - require.Equal(t, voteTargets, voteTargetsRes) -} - -func TestQueryTobinTaxes(t *testing.T) { - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - input.OracleKeeper.ClearTobinTaxes(input.Ctx) - tobinTaxes := sdk.DecCoins{ - sdk.NewDecCoinFromDec(types.MicroKRWDenom, sdk.OneDec()), - sdk.NewDecCoinFromDec(types.MicroSDRDenom, sdk.NewDecWithPrec(123, 2)), - } - for _, item := range tobinTaxes { - input.OracleKeeper.SetTobinTax(input.Ctx, item.Denom, item.Amount) - } - - res, err := querier(input.Ctx, []string{types.QueryTobinTaxes}, abci.RequestQuery{Path: "", Data: nil}) - require.NoError(t, err) - - tobinTaxesRes, err := sdk.ParseDecCoins(string(res)) - require.NoError(t, err) - require.Equal(t, tobinTaxes, tobinTaxesRes) -} - -func TestQueryTobinTax(t *testing.T) { - cdc := codec.NewLegacyAmino() - input := CreateTestInput(t) - querier := NewQuerier(input.OracleKeeper) - - denom := types.Denom{types.MicroKRWDenom, sdk.OneDec()} - input.OracleKeeper.SetTobinTax(input.Ctx, denom.Name, denom.TobinTax) - - queryParams := types.NewQueryTobinTaxParams(types.MicroKRWDenom) - bz, err := cdc.MarshalJSON(queryParams) - require.NoError(t, err) - - res, err := querier(input.Ctx, []string{types.QueryTobinTax}, abci.RequestQuery{Path: "", Data: bz}) - require.NoError(t, err) - require.Equal(t, denom.TobinTax.String(), string(res)) -} diff --git a/x/oracle/slash_test.go b/x/oracle/keeper/slash_test.go similarity index 53% rename from x/oracle/slash_test.go rename to x/oracle/keeper/slash_test.go index cd1cfadd..09e0815a 100644 --- a/x/oracle/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -1,60 +1,59 @@ -package oracle +package keeper import ( "testing" "github.com/stretchr/testify/require" - "github.com/peggyjv/sommelier/x/oracle/keeper" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func TestSlashAndResetMissCounters(t *testing.T) { - input, _ := setup(t) + stakingAmt := sdk.TokensFromConsensusPower(10) + input := CreateTestInput(t) votePeriodsPerWindow := sdk.NewDec(input.OracleKeeper.SlashWindow(input.Ctx)).QuoInt64(input.OracleKeeper.VotePeriod(input.Ctx)).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) minValidVotes := input.OracleKeeper.MinValidPerWindow(input.Ctx).MulInt64(votePeriodsPerWindow).TruncateInt64() // Case 1, no slash - input.OracleKeeper.SetMissCounter(input.Ctx, keeper.ValAddrs[0], votePeriodsPerWindow-minValidVotes) - SlashAndResetMissCounters(input.Ctx, input.OracleKeeper) + input.OracleKeeper.SetMissCounter(input.Ctx, ValAddrs[0], votePeriodsPerWindow-minValidVotes) + input.OracleKeeper.SlashAndResetMissCounters(input.Ctx) staking.EndBlocker(input.Ctx, input.StakingKeeper) - validator, _ := input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + validator, _ := input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) require.Equal(t, stakingAmt, validator.GetBondedTokens()) // Case 2, slash - input.OracleKeeper.SetMissCounter(input.Ctx, keeper.ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) - SlashAndResetMissCounters(input.Ctx, input.OracleKeeper) - validator, _ = input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + input.OracleKeeper.SetMissCounter(input.Ctx, ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) + input.OracleKeeper.SlashAndResetMissCounters(input.Ctx) + validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) require.Equal(t, stakingAmt.Sub(slashFraction.MulInt(stakingAmt).TruncateInt()), validator.GetBondedTokens()) require.True(t, validator.IsJailed()) // Case 3, slash unbonded validator - validator, _ = input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) validator.Status = stakingtypes.Unbonded validator.Jailed = false validator.Tokens = stakingAmt input.StakingKeeper.SetValidator(input.Ctx, validator) - input.OracleKeeper.SetMissCounter(input.Ctx, keeper.ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) - SlashAndResetMissCounters(input.Ctx, input.OracleKeeper) - validator, _ = input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + input.OracleKeeper.SetMissCounter(input.Ctx, ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) + input.OracleKeeper.SlashAndResetMissCounters(input.Ctx) + validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) require.Equal(t, stakingAmt, validator.Tokens) require.False(t, validator.IsJailed()) // Case 4, slash jailed validator - validator, _ = input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) validator.Status = stakingtypes.Bonded validator.Jailed = true validator.Tokens = stakingAmt input.StakingKeeper.SetValidator(input.Ctx, validator) - input.OracleKeeper.SetMissCounter(input.Ctx, keeper.ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) - SlashAndResetMissCounters(input.Ctx, input.OracleKeeper) - validator, _ = input.StakingKeeper.GetValidator(input.Ctx, keeper.ValAddrs[0]) + input.OracleKeeper.SetMissCounter(input.Ctx, ValAddrs[0], votePeriodsPerWindow-minValidVotes+1) + input.OracleKeeper.SlashAndResetMissCounters(input.Ctx) + validator, _ = input.StakingKeeper.GetValidator(input.Ctx, ValAddrs[0]) require.Equal(t, stakingAmt, validator.Tokens) } diff --git a/x/oracle/slashing.go b/x/oracle/keeper/slashing.go similarity index 65% rename from x/oracle/slashing.go rename to x/oracle/keeper/slashing.go index f6678bbe..cf47ae0a 100644 --- a/x/oracle/slashing.go +++ b/x/oracle/keeper/slashing.go @@ -1,18 +1,15 @@ -package oracle +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/peggyjv/sommelier/x/oracle/keeper" ) -// SlashAndResetMissCounters do salsh any operator who over criteria & clear all operators miss counter to zero -func SlashAndResetMissCounters(ctx sdk.Context, k keeper.Keeper) { +// SlashAndResetMissCounters do slash any operator who over criteria & clear all operators miss counter to zero +func (k Keeper) SlashAndResetMissCounters(ctx sdk.Context) { height := ctx.BlockHeight() distributionHeight := height - sdk.ValidatorUpdateDelay - 1 votePeriodsPerWindow := sdk.NewDec(k.SlashWindow(ctx)).QuoInt64(k.VotePeriod(ctx)).TruncateInt64() - minValidPerWindow := k.MinValidPerWindow(ctx) - slashFraction := k.SlashFraction(ctx) k.IterateMissCounters(ctx, func(operator sdk.ValAddress, missCounter int64) bool { // Calculate valid vote rate; (SlashWindow - MissCounter)/SlashWindow @@ -21,18 +18,19 @@ func SlashAndResetMissCounters(ctx sdk.Context, k keeper.Keeper) { QuoInt64(votePeriodsPerWindow) // Penalize the validator whose the valid vote rate is smaller than min threshold - if validVoteRate.LT(minValidPerWindow) { + if validVoteRate.LT(k.MinValidPerWindow(ctx)) { validator := k.StakingKeeper.Validator(ctx, operator) - if validator.IsBonded() && !validator.IsJailed() { + if validator != nil && validator.IsBonded() && !validator.IsJailed() { cons, err := validator.GetConsAddr() if err != nil { panic(err) } k.StakingKeeper.Slash( ctx, cons, - distributionHeight, validator.GetConsensusPower(), slashFraction, + distributionHeight, validator.GetConsensusPower(), k.SlashFraction(ctx), ) - k.StakingKeeper.Jail(ctx, cons) + // TODO: Reenable jailing + // k.StakingKeeper.Jail(ctx, cons) } } diff --git a/x/oracle/keeper/tally.go b/x/oracle/keeper/tally.go new file mode 100644 index 00000000..1fb5fe62 --- /dev/null +++ b/x/oracle/keeper/tally.go @@ -0,0 +1,53 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/peggyjv/sommelier/x/oracle/types" +) + +// ballot for the asset is passing the threshold amount of voting power +func (k Keeper) BallotIsPassing(ctx sdk.Context, ballot types.ExchangeRateBallot) (sdk.Int, bool) { + totalBondedPower := sdk.TokensToConsensusPower(k.StakingKeeper.TotalBondedTokens(ctx)) + voteThreshold := k.VoteThreshold(ctx) + thresholdVotes := voteThreshold.MulInt64(totalBondedPower).RoundInt() + ballotPower := sdk.NewInt(ballot.Power()) + return ballotPower, !ballotPower.IsZero() && ballotPower.GTE(thresholdVotes) +} + +// choose Reference Terra with the highest voter turnout +// If the voting power of the two denominations is the same, +// select reference Terra in alphabetical order. +func (k Keeper) PickReferenceTerra(ctx sdk.Context, voteTargets map[string]sdk.Dec, voteMap map[string]types.ExchangeRateBallot) string { + largestBallotPower := int64(0) + referenceTerra := "" + + for denom, ballot := range voteMap { + // If denom is not in the voteTargets, or the ballot for it has failed, then skip + // and remove it from voteMap for iteration efficiency + if _, exists := voteTargets[denom]; !exists { + delete(voteMap, denom) + continue + } + + ballotPower := int64(0) + + // If the ballot is not passed, remove it from the voteTargets array + // to prevent slashing validators who did valid vote. + if power, ok := k.BallotIsPassing(ctx, ballot); ok { + ballotPower = power.Int64() + } else { + delete(voteTargets, denom) + delete(voteMap, denom) + continue + } + + if ballotPower > largestBallotPower || largestBallotPower == 0 { + referenceTerra = denom + largestBallotPower = ballotPower + } else if largestBallotPower == ballotPower && referenceTerra > denom { + referenceTerra = denom + } + } + + return referenceTerra +} diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go index af93037b..849e8b83 100644 --- a/x/oracle/keeper/test_utils.go +++ b/x/oracle/keeper/test_utils.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/tendermint/tendermint/crypto" + crypto "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -90,7 +90,6 @@ type TestInput struct { func newTestCodec() *codec.LegacyAmino { cdc := codec.NewLegacyAmino() - types.RegisterLegacyAminoCodec(cdc) authtypes.RegisterLegacyAminoCodec(cdc) banktypes.RegisterLegacyAminoCodec(cdc) sdk.RegisterLegacyAminoCodec(cdc) @@ -245,7 +244,7 @@ func CreateTestInput(t *testing.T) TestInput { keeper.SetParams(ctx, defaults) for _, denom := range defaults.Whitelist { - keeper.SetTobinTax(ctx, denom.Name, denom.TobinTax) + keeper.SetTobinTax(ctx, denom.Denom, denom.Amount) } stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(distrKeeper.Hooks())) diff --git a/x/oracle/module.go b/x/oracle/module.go index e28762c5..e573c3eb 100644 --- a/x/oracle/module.go +++ b/x/oracle/module.go @@ -11,12 +11,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" sim "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/peggyjv/sommelier/x/oracle/client/cli" - "github.com/peggyjv/sommelier/x/oracle/client/rest" "github.com/peggyjv/sommelier/x/oracle/keeper" "github.com/peggyjv/sommelier/x/oracle/simulation" "github.com/peggyjv/sommelier/x/oracle/types" @@ -38,10 +35,8 @@ func (AppModuleBasic) Name() string { return types.ModuleName } -// RegisterLegacyAminoCodec registers the oracle module's types for the given codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterLegacyAminoCodec(cdc) -} +// RegisterLegacyAminoCodec doesn't support amino +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // DefaultGenesis returns default genesis state as raw bytes for the oracle // module. @@ -52,16 +47,15 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { // ValidateGenesis performs genesis state validation for the oracle module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, _ client.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState - if err := cdc.UnmarshalJSON(bz, &data); err != nil { + var gs types.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { return err } - return types.ValidateGenesis(data) + return gs.Validate() } -// RegisterRESTRoutes registers the REST routes for the oracle module. -func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr) +// RegisterRESTRoutes doesn't support legacy REST routes. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { } // GetTxCmd returns the root tx command for the oracle module. @@ -80,7 +74,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) } -// RegisterInterfaces implements app bmodule basic +// RegisterInterfaces implements app module basic func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } @@ -91,13 +85,13 @@ func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry type AppModule struct { AppModuleBasic keeper keeper.Keeper - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper cdc codec.Marshaler } // NewAppModule creates a new AppModule object -func NewAppModule(keeper keeper.Keeper, accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, cdc codec.Marshaler) AppModule { +func NewAppModule(keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, cdc codec.Marshaler) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, @@ -119,9 +113,9 @@ func (am AppModule) Route() sdk.Route { return sdk.NewRoute(types.RouterKey, New // QuerierRoute returns the oracle module's querier route name. func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQuerierHandler returns the oracle module sdk.Querier. +// LegacyQuerierHandler returns a nil Querier. func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { - return keeper.NewQuerier(am.keeper) + return nil } // RegisterServices registers module services. diff --git a/x/oracle/simulation/decoder.go b/x/oracle/simulation/decoder.go index 3e2c475e..15b20d25 100644 --- a/x/oracle/simulation/decoder.go +++ b/x/oracle/simulation/decoder.go @@ -18,8 +18,8 @@ func DecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.ExchangeRateKey): var exchangeRateA, exchangeRateB sdk.Dec - exchangeRateA.Unmarshal(kvA.Value) - exchangeRateB.Unmarshal(kvB.Value) + _ = exchangeRateA.Unmarshal(kvA.Value) + _ = exchangeRateB.Unmarshal(kvB.Value) return fmt.Sprintf("%v\n%v", exchangeRateA, exchangeRateB) case bytes.Equal(kvA.Key[:1], types.FeederDelegationKey): addressA, _ := sdk.AccAddressFromBech32(string(kvA.Value)) @@ -31,18 +31,18 @@ func DecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("%v\n%v", counterA, counterB) case bytes.Equal(kvA.Key[:1], types.AggregateExchangeRatePrevoteKey): var prevoteA, prevoteB types.AggregateExchangeRatePrevote - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &prevoteA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &prevoteB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &prevoteA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &prevoteB) return fmt.Sprintf("%v\n%v", prevoteA, prevoteB) case bytes.Equal(kvA.Key[:1], types.AggregateExchangeRateVoteKey): var voteA, voteB types.AggregateExchangeRateVote - cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &voteA) - cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &voteB) + cdc.MustUnmarshalBinaryBare(kvA.Value, &voteA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &voteB) return fmt.Sprintf("%v\n%v", voteA, voteB) case bytes.Equal(kvA.Key[:1], types.TobinTaxKey): var tobinTaxA, tobinTaxB sdk.Dec - tobinTaxA.Unmarshal(kvA.Value) - tobinTaxB.Unmarshal(kvB.Value) + _ = tobinTaxA.Unmarshal(kvA.Value) + _ = tobinTaxB.Unmarshal(kvB.Value) return fmt.Sprintf("%v\n%v", tobinTaxA, tobinTaxB) default: panic(fmt.Sprintf("invalid oracle key prefix %X", kvA.Key[:1])) diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index 83d72fb9..d5063458 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -31,7 +31,6 @@ func makeTestCodec() (cdc *codec.LegacyAmino) { cdc = codec.NewLegacyAmino() sdk.RegisterLegacyAminoCodec(cdc) ccodec.RegisterCrypto(cdc) - types.RegisterLegacyAminoCodec(cdc) return } @@ -54,9 +53,9 @@ func TestDecodeDistributionStore(t *testing.T) { missCounter := 123 aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) - aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {types.MicroKRWDenom, sdk.NewDecWithPrec(1234, 1)}, - {types.MicroKRWDenom, sdk.NewDecWithPrec(4321, 1)}, + aggregateVote := types.NewAggregateExchangeRateVote(sdk.DecCoins{ + {Denom: types.MicroKRWDenom, Amount: sdk.NewDecWithPrec(1234, 1)}, + {Denom: types.MicroKRWDenom, Amount: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) tobinTax := sdk.NewDecWithPrec(2, 2) @@ -68,13 +67,13 @@ func TestDecodeDistributionStore(t *testing.T) { require.NoError(t, err) kvPairs := []tmkv.Pair{ - {types.ExchangeRateKey, marEr}, - {types.FeederDelegationKey, []byte(feederAddr.String())}, - {types.MissCounterKey, missCounterBz}, - {types.AggregateExchangeRatePrevoteKey, cdc.MustMarshalBinaryLengthPrefixed(&aggregatePrevote)}, - {types.AggregateExchangeRateVoteKey, cdc.MustMarshalBinaryLengthPrefixed(&aggregateVote)}, - {types.TobinTaxKey, marTt}, - {[]byte{0x99}, []byte{0x99}}, + {Key: types.ExchangeRateKey, Value: marEr}, + {Key: types.FeederDelegationKey, Value: []byte(feederAddr.String())}, + {Key: types.MissCounterKey, Value: missCounterBz}, + {Key: types.AggregateExchangeRatePrevoteKey, Value: cdc.MustMarshalBinaryBare(&aggregatePrevote)}, + {Key: types.AggregateExchangeRateVoteKey, Value: cdc.MustMarshalBinaryBare(&aggregateVote)}, + {Key: types.TobinTaxKey, Value: marTt}, + {Key: []byte{0x99}, Value: []byte{0x99}}, } tests := []struct { diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 5dbcdd08..96d1b41c 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/peggyjv/sommelier/x/oracle/types" - core "github.com/peggyjv/sommelier/x/oracle/types" ) // Simulation parameter constants @@ -110,21 +109,21 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, RewardDistributionWindow: rewardDistributionWindow, - Whitelist: []types.Denom{ - {core.MicroKRWDenom, types.DefaultTobinTax}, - {core.MicroSDRDenom, types.DefaultTobinTax}, - {core.MicroUSDDenom, types.DefaultTobinTax}, - {core.MicroMNTDenom, sdk.NewDecWithPrec(2, 2)}}, + Whitelist: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(types.MicroKRWDenom, types.DefaultTobinTax), + sdk.NewDecCoinFromDec(types.MicroSDRDenom, types.DefaultTobinTax), + sdk.NewDecCoinFromDec(types.MicroUSDDenom, types.DefaultTobinTax), + sdk.NewDecCoinFromDec(types.MicroMNTDenom, sdk.NewDecWithPrec(2, 2))), SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, - []types.ExchangeRateTuple{}, + sdk.DecCoins{}, map[string]string{}, map[string]int64{}, []types.AggregateExchangeRatePrevote{}, []types.AggregateExchangeRateVote{}, - []types.ExchangeRateTuple{}, + sdk.DecCoins{}, ) fmt.Printf("Selected randomly generated oracle parameters:\n%s\n", simState.Cdc.MustMarshalJSON(&oracleGenesis)) diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 9551a9e5..8d67966a 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -12,8 +12,6 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/peggyjv/sommelier/x/oracle/keeper" @@ -38,8 +36,8 @@ var ( func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONMarshaler, - ak authkeeper.AccountKeeper, - bk bankkeeper.Keeper, + ak types.AccountKeeper, + bk types.BankKeeper, k keeper.Keeper) simulation.WeightedOperations { var ( weightMsgAggregateExchangeRatePrevote int @@ -82,7 +80,7 @@ func WeightedOperations( // SimulateMsgAggregateExchangeRatePrevote generates a MsgExchangeRatePrevote with random values. // nolint: funlen -func SimulateMsgAggregateExchangeRatePrevote(ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgAggregateExchangeRatePrevote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -114,7 +112,7 @@ func SimulateMsgAggregateExchangeRatePrevote(ak authkeeper.AccountKeeper, bk ban tx, err := helpers.GenTx( txcfg, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, @@ -133,13 +131,13 @@ func SimulateMsgAggregateExchangeRatePrevote(ak authkeeper.AccountKeeper, bk ban voteHashMap[denom+address.String()] = price - return simtypes.NewOperationMsg(&msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, ""), nil, nil } } // SimulateMsgExchangeRateVote generates a MsgExchangeRateVote with random values. // nolint: funlen -func SimulateMsgExchangeRateVote(ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgExchangeRateVote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -181,12 +179,12 @@ func SimulateMsgExchangeRateVote(ak authkeeper.AccountKeeper, bk bankkeeper.Keep return simtypes.NoOpMsg(types.ModuleName, "", ""), nil, err } - er := &types.ExchangeRateTuple{Denom: denom, ExchangeRate: price} + er := &sdk.DecCoin{Denom: denom, Amount: price} msg := types.NewMsgAggregateExchangeRateVote(salt, er.String(), feederAddr, address) tx, err := helpers.GenTx( txcfg, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, @@ -203,13 +201,13 @@ func SimulateMsgExchangeRateVote(ak authkeeper.AccountKeeper, bk bankkeeper.Keep return simtypes.NoOpMsg(types.ModuleName, "", ""), nil, err } - return simtypes.NewOperationMsg(&msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, ""), nil, nil } } // SimulateMsgDelegateFeedConsent generates a MsgDelegateFeedConsent with random values. // nolint: funlen -func SimulateMsgDelegateFeedConsent(ak authkeeper.AccountKeeper, bk bankkeeper.Keeper, k keeper.Keeper) simtypes.Operation { +func SimulateMsgDelegateFeedConsent(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { @@ -243,7 +241,7 @@ func SimulateMsgDelegateFeedConsent(ak authkeeper.AccountKeeper, bk bankkeeper.K tx, err := helpers.GenTx( txcfg, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, chainID, @@ -260,6 +258,6 @@ func SimulateMsgDelegateFeedConsent(ak authkeeper.AccountKeeper, bk bankkeeper.K return simtypes.NoOpMsg(types.ModuleName, "", ""), nil, err } - return simtypes.NewOperationMsg(&msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, ""), nil, nil } } diff --git a/x/oracle/tally.go b/x/oracle/tally.go deleted file mode 100644 index f43a614b..00000000 --- a/x/oracle/tally.go +++ /dev/null @@ -1,106 +0,0 @@ -package oracle - -import ( - "sort" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/peggyjv/sommelier/x/oracle/keeper" - "github.com/peggyjv/sommelier/x/oracle/types" -) - -// Calculates the median and returns it. Sets the set of voters to be rewarded, i.e. voted within -// a reasonable spread from the weighted median to the store -func tally(ctx sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec) (weightedMedian sdk.Dec, ballotWinners []types.Claim) { - if !sort.IsSorted(pb) { - sort.Sort(pb) - } - - weightedMedian = pb.WeightedMedian() - standardDeviation := pb.StandardDeviation() - rewardSpread := weightedMedian.Mul(rewardBand.QuoInt64(2)) - - if standardDeviation.GT(rewardSpread) { - rewardSpread = standardDeviation - } - - for _, vote := range pb { - // Filter ballot winners & abstain voters - if (vote.ExchangeRate.GTE(weightedMedian.Sub(rewardSpread)) && - vote.ExchangeRate.LTE(weightedMedian.Add(rewardSpread))) || - !vote.ExchangeRate.IsPositive() { - - // Abstain votes have zero vote power - ballotWinners = append(ballotWinners, types.Claim{ - Recipient: vote.Voter, - Weight: vote.Power, - }) - } - - } - - return -} - -func updateWinnerMap(ballotWinningClaims []types.Claim, validVotesCounterMap map[string]int, winnerMap map[string]types.Claim) { - // Collect claims of ballot winners - for _, ballotWinningClaim := range ballotWinningClaims { - - // NOTE: we directly stringify byte to string to prevent unnecessary bech32fy works - key := string(ballotWinningClaim.Recipient) - - // Update claim - prevClaim := winnerMap[key] - prevClaim.Weight += ballotWinningClaim.Weight - winnerMap[key] = prevClaim - - // Increase valid votes counter - validVotesCounterMap[key]++ - } -} - -// ballot for the asset is passing the threshold amount of voting power -func ballotIsPassing(ctx sdk.Context, ballot types.ExchangeRateBallot, k keeper.Keeper) (sdk.Int, bool) { - totalBondedPower := sdk.TokensToConsensusPower(k.StakingKeeper.TotalBondedTokens(ctx)) - voteThreshold := k.VoteThreshold(ctx) - thresholdVotes := voteThreshold.MulInt64(totalBondedPower).RoundInt() - ballotPower := sdk.NewInt(ballot.Power()) - return ballotPower, !ballotPower.IsZero() && ballotPower.GTE(thresholdVotes) -} - -// choose Reference Terra with the highest voter turnout -// If the voting power of the two denominations is the same, -// select reference Terra in alphabetical order. -func pickReferenceTerra(ctx sdk.Context, k keeper.Keeper, voteTargets map[string]sdk.Dec, voteMap map[string]types.ExchangeRateBallot) string { - largestBallotPower := int64(0) - referenceTerra := "" - - for denom, ballot := range voteMap { - // If denom is not in the voteTargets, or the ballot for it has failed, then skip - // and remove it from voteMap for iteration efficiency - if _, exists := voteTargets[denom]; !exists { - delete(voteMap, denom) - continue - } - - ballotPower := int64(0) - - // If the ballot is not passed, remove it from the voteTargets array - // to prevent slashing validators who did valid vote. - if power, ok := ballotIsPassing(ctx, ballot, k); ok { - ballotPower = power.Int64() - } else { - delete(voteTargets, denom) - delete(voteMap, denom) - continue - } - - if ballotPower > largestBallotPower || largestBallotPower == 0 { - referenceTerra = denom - largestBallotPower = ballotPower - } else if largestBallotPower == ballotPower && referenceTerra > denom { - referenceTerra = denom - } - } - - return referenceTerra -} diff --git a/x/oracle/types/ballot.go b/x/oracle/types/ballot.go index 16d0fae8..cb975484 100644 --- a/x/oracle/types/ballot.go +++ b/x/oracle/types/ballot.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// VoteForTally is a convinience wrapper to reduct redundant lookup cost +// VoteForTally is a convenience wrapper to reduct redundant lookup cost type VoteForTally struct { ExchangeRateVote Power int64 @@ -23,7 +23,7 @@ func NewVoteForTally(vote ExchangeRateVote, power int64) VoteForTally { } } -// ExchangeRateBallot is a convinience wrapper around a ExchangeRateVote slice +// ExchangeRateBallot is a convenience wrapper around a ExchangeRateVote slice type ExchangeRateBallot []VoteForTally // ToMap return organized exchange rate map by validator @@ -31,7 +31,7 @@ func (pb ExchangeRateBallot) ToMap() map[string]sdk.Dec { exchangeRateMap := make(map[string]sdk.Dec) for _, vote := range pb { if vote.ExchangeRate.IsPositive() { - exchangeRateMap[string(vote.Voter)] = vote.ExchangeRate + exchangeRateMap[vote.Voter] = vote.ExchangeRate } } @@ -43,10 +43,10 @@ func (pb ExchangeRateBallot) ToCrossRate(bases map[string]sdk.Dec) (cb ExchangeR for i := range pb { vote := pb[i] - if exchangeRateRT, ok := bases[string(vote.Voter)]; ok && vote.ExchangeRate.IsPositive() { + if exchangeRateRT, ok := bases[vote.Voter]; ok && vote.ExchangeRate.IsPositive() { vote.ExchangeRate = exchangeRateRT.Quo(vote.ExchangeRate) } else { - // If we can't get reference terra exhcnage rate, we just convert the vote as abstain vote + // If we can't get reference terra exchnage rate, we just convert the vote as abstain vote vote.ExchangeRate = sdk.ZeroDec() vote.Power = 0 } diff --git a/x/oracle/types/ballot.pb.go b/x/oracle/types/ballot.pb.go deleted file mode 100644 index ea67314c..00000000 --- a/x/oracle/types/ballot.pb.go +++ /dev/null @@ -1,583 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: oracle/v1/ballot.proto - -package types - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_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 - -// // Claim is an interface that directs its rewards to an attached bank account. -type Claim struct { - Weight int64 `protobuf:"varint,1,opt,name=weight,proto3" json:"weight,omitempty"` - Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` -} - -func (m *Claim) Reset() { *m = Claim{} } -func (m *Claim) String() string { return proto.CompactTextString(m) } -func (*Claim) ProtoMessage() {} -func (*Claim) Descriptor() ([]byte, []int) { - return fileDescriptor_8fee13d30f6b7edd, []int{0} -} -func (m *Claim) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Claim) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Claim.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 *Claim) XXX_Merge(src proto.Message) { - xxx_messageInfo_Claim.Merge(m, src) -} -func (m *Claim) XXX_Size() int { - return m.Size() -} -func (m *Claim) XXX_DiscardUnknown() { - xxx_messageInfo_Claim.DiscardUnknown(m) -} - -var xxx_messageInfo_Claim proto.InternalMessageInfo - -func (m *Claim) GetWeight() int64 { - if m != nil { - return m.Weight - } - return 0 -} - -func (m *Claim) GetRecipient() string { - if m != nil { - return m.Recipient - } - return "" -} - -// // Denom is the object to hold configurations of each denom -type Denom struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - TobinTax github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=tobin_tax,json=tobinTax,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"tobin_tax"` -} - -func (m *Denom) Reset() { *m = Denom{} } -func (m *Denom) String() string { return proto.CompactTextString(m) } -func (*Denom) ProtoMessage() {} -func (*Denom) Descriptor() ([]byte, []int) { - return fileDescriptor_8fee13d30f6b7edd, []int{1} -} -func (m *Denom) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Denom) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Denom.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 *Denom) XXX_Merge(src proto.Message) { - xxx_messageInfo_Denom.Merge(m, src) -} -func (m *Denom) XXX_Size() int { - return m.Size() -} -func (m *Denom) XXX_DiscardUnknown() { - xxx_messageInfo_Denom.DiscardUnknown(m) -} - -var xxx_messageInfo_Denom proto.InternalMessageInfo - -func (m *Denom) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func init() { - proto.RegisterType((*Claim)(nil), "oracle.v1.Claim") - proto.RegisterType((*Denom)(nil), "oracle.v1.Denom") -} - -func init() { proto.RegisterFile("oracle/v1/ballot.proto", fileDescriptor_8fee13d30f6b7edd) } - -var fileDescriptor_8fee13d30f6b7edd = []byte{ - // 266 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4b, 0xfb, 0x30, - 0x14, 0xc7, 0x9b, 0xdf, 0xcf, 0x0d, 0x9b, 0x63, 0x90, 0x31, 0x44, 0xb2, 0xb1, 0x83, 0x0c, 0xc4, - 0x86, 0xe1, 0xd9, 0xcb, 0x9c, 0x27, 0x6f, 0xc5, 0x93, 0x17, 0x49, 0xeb, 0x23, 0x8d, 0x36, 0x7d, - 0xa5, 0x89, 0xb5, 0xfb, 0x2f, 0xfc, 0xb3, 0x76, 0xdc, 0x51, 0x3c, 0x0c, 0x69, 0xff, 0x11, 0x31, - 0x2d, 0xe8, 0x29, 0xdf, 0x7c, 0x78, 0xdf, 0x0f, 0xbc, 0x47, 0x27, 0x58, 0xc9, 0x34, 0x07, 0x51, - 0xaf, 0x44, 0x22, 0xf3, 0x1c, 0x5d, 0x54, 0x56, 0xe8, 0x90, 0x85, 0x3d, 0x8f, 0xea, 0xd5, 0xe9, - 0x89, 0x42, 0x85, 0x9e, 0x8a, 0x9f, 0xd4, 0x0f, 0x2c, 0xae, 0xe9, 0xe8, 0x26, 0x97, 0xda, 0xb0, - 0x09, 0x1d, 0xbf, 0x81, 0x56, 0x99, 0x9b, 0x92, 0x39, 0x59, 0xfe, 0x8f, 0x87, 0x1f, 0x3b, 0xa3, - 0x61, 0x05, 0xa9, 0x2e, 0x35, 0x14, 0x6e, 0xfa, 0x6f, 0x4e, 0x96, 0x61, 0xfc, 0x0b, 0x16, 0x19, - 0x1d, 0x6d, 0xa0, 0x40, 0xc3, 0x18, 0x3d, 0x2a, 0xa4, 0x01, 0x5f, 0x0e, 0x63, 0x9f, 0xd9, 0x1d, - 0x0d, 0x1d, 0x26, 0xba, 0x78, 0x74, 0xb2, 0xe9, 0xab, 0xeb, 0x68, 0x77, 0x98, 0x05, 0x9f, 0x87, - 0xd9, 0xb9, 0xd2, 0x2e, 0x7b, 0x4d, 0xa2, 0x14, 0x8d, 0x48, 0xd1, 0x1a, 0xb4, 0xc3, 0x73, 0x69, - 0x9f, 0x5e, 0x84, 0xdb, 0x96, 0x60, 0xa3, 0x0d, 0xa4, 0xf1, 0xb1, 0x17, 0xdc, 0xcb, 0x66, 0x7d, - 0xbb, 0x6b, 0x39, 0xd9, 0xb7, 0x9c, 0x7c, 0xb5, 0x9c, 0xbc, 0x77, 0x3c, 0xd8, 0x77, 0x3c, 0xf8, - 0xe8, 0x78, 0xf0, 0x70, 0xf1, 0xc7, 0x55, 0x82, 0x52, 0xdb, 0xe7, 0x5a, 0x58, 0x34, 0x06, 0x72, - 0x0d, 0x95, 0x68, 0xc4, 0x70, 0x1a, 0x2f, 0x4d, 0xc6, 0x7e, 0xed, 0xab, 0xef, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xaf, 0xcf, 0x43, 0x8d, 0x31, 0x01, 0x00, 0x00, -} - -func (m *Claim) 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 *Claim) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Claim) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Recipient) > 0 { - i -= len(m.Recipient) - copy(dAtA[i:], m.Recipient) - i = encodeVarintBallot(dAtA, i, uint64(len(m.Recipient))) - i-- - dAtA[i] = 0x12 - } - if m.Weight != 0 { - i = encodeVarintBallot(dAtA, i, uint64(m.Weight)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *Denom) 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 *Denom) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Denom) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.TobinTax.Size() - i -= size - if _, err := m.TobinTax.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintBallot(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintBallot(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintBallot(dAtA []byte, offset int, v uint64) int { - offset -= sovBallot(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Claim) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Weight != 0 { - n += 1 + sovBallot(uint64(m.Weight)) - } - l = len(m.Recipient) - if l > 0 { - n += 1 + l + sovBallot(uint64(l)) - } - return n -} - -func (m *Denom) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovBallot(uint64(l)) - } - l = m.TobinTax.Size() - n += 1 + l + sovBallot(uint64(l)) - return n -} - -func sovBallot(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozBallot(x uint64) (n int) { - return sovBallot(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Claim) 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 ErrIntOverflowBallot - } - 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: Claim: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Claim: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Weight", wireType) - } - m.Weight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBallot - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Weight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBallot - } - 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 ErrInvalidLengthBallot - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthBallot - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Recipient = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipBallot(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthBallot - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthBallot - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Denom) 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 ErrIntOverflowBallot - } - 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: Denom: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Denom: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBallot - } - 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 ErrInvalidLengthBallot - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthBallot - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TobinTax", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowBallot - } - 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 ErrInvalidLengthBallot - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthBallot - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.TobinTax.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipBallot(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthBallot - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthBallot - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipBallot(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, ErrIntOverflowBallot - } - 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, ErrIntOverflowBallot - } - 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, ErrIntOverflowBallot - } - 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, ErrInvalidLengthBallot - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupBallot - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthBallot - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthBallot = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowBallot = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupBallot = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/oracle/types/codec.go b/x/oracle/types/codec.go index 5a242f56..fddfb7d2 100644 --- a/x/oracle/types/codec.go +++ b/x/oracle/types/codec.go @@ -1,30 +1,18 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" ) -// ModuleCdc module codec -var ModuleCdc = codec.NewLegacyAmino() - -// RegisterLegacyAminoCodec registers concrete types on codec codec -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(MsgDelegateFeedConsent{}, "oracle/MsgDelegateFeedConsent", nil) - cdc.RegisterConcrete(MsgAggregateExchangeRatePrevote{}, "oracle/MsgAggregateExchangeRatePrevote", nil) - cdc.RegisterConcrete(MsgAggregateExchangeRateVote{}, "oracle/MsgAggregateExchangeRateVote", nil) -} - -// RegisterInterfaces registers the x/staking interfaces types with the interface registry +// RegisterInterfaces registers the x/oracle interfaces types with the interface registry func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgDelegateFeedConsent{}, &MsgAggregateExchangeRatePrevote{}, &MsgAggregateExchangeRateVote{}, ) -} -func init() { - RegisterLegacyAminoCodec(ModuleCdc) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/oracle/types/denom.go b/x/oracle/types/denom.go deleted file mode 100644 index ed69838d..00000000 --- a/x/oracle/types/denom.go +++ /dev/null @@ -1,4 +0,0 @@ -package types - -// DenomList is array of Denom -type DenomList []Denom diff --git a/x/oracle/types/errors.go b/x/oracle/types/errors.go index 23896804..b22df1e6 100644 --- a/x/oracle/types/errors.go +++ b/x/oracle/types/errors.go @@ -9,7 +9,6 @@ import ( // Oracle Errors var ( - ErrUnknowDenom = sdkerrors.Register(ModuleName, 1, "unknown denom") ErrInvalidExchangeRate = sdkerrors.Register(ModuleName, 2, "invalid exchange rate") ErrNoPrevote = sdkerrors.Register(ModuleName, 3, "no prevote") ErrNoVote = sdkerrors.Register(ModuleName, 4, "no vote") @@ -22,4 +21,5 @@ var ( ErrNoAggregatePrevote = sdkerrors.Register(ModuleName, 11, "no aggregate prevote") ErrNoAggregateVote = sdkerrors.Register(ModuleName, 12, "no aggregate vote") ErrNoTobinTax = sdkerrors.Register(ModuleName, 13, "no tobin tax") + ErrUnknowDenom = sdkerrors.Register(ModuleName, 14, "unknown denom") ) diff --git a/x/oracle/types/expected_keeper.go b/x/oracle/types/expected_keeper.go index 8839b93b..2f385f23 100644 --- a/x/oracle/types/expected_keeper.go +++ b/x/oracle/types/expected_keeper.go @@ -23,6 +23,7 @@ type DistributionKeeper interface { // AccountKeeper is the expected account keeper type AccountKeeper interface { + GetAccount(ctx sdk.Context, address sdk.AccAddress) authtypes.AccountI GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI SetModuleAccount(sdk.Context, authtypes.ModuleAccountI) @@ -32,6 +33,7 @@ type AccountKeeper interface { type BankKeeper interface { GetSupply(ctx sdk.Context) (supply bankexported.SupplyI) SetSupply(ctx sdk.Context, supply bankexported.SupplyI) + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error } diff --git a/x/oracle/types/genesis.go b/x/oracle/types/genesis.go index dee7e2a7..c668c68f 100644 --- a/x/oracle/types/genesis.go +++ b/x/oracle/types/genesis.go @@ -1,16 +1,18 @@ package types import ( - "bytes" + sdk "github.com/cosmos/cosmos-sdk/types" ) // NewGenesisState creates a new GenesisState object func NewGenesisState( - params Params, rates []ExchangeRateTuple, - feederDelegations map[string]string, missCounters map[string]int64, + params Params, + rates sdk.DecCoins, + feederDelegations map[string]string, + missCounters map[string]int64, aggregateExchangeRatePrevotes []AggregateExchangeRatePrevote, aggregateExchangeRateVotes []AggregateExchangeRateVote, - TobinTaxes []ExchangeRateTuple, + TobinTaxes sdk.DecCoins, ) GenesisState { return GenesisState{ @@ -28,29 +30,16 @@ func NewGenesisState( func DefaultGenesisState() GenesisState { return GenesisState{ Params: DefaultParams(), - ExchangeRates: make([]ExchangeRateTuple, 0), + ExchangeRates: make(sdk.DecCoins, 0), FeederDelegations: make(map[string]string), MissCounters: make(map[string]int64), AggregateExchangeRatePrevotes: []AggregateExchangeRatePrevote{}, AggregateExchangeRateVotes: []AggregateExchangeRateVote{}, - TobinTaxes: make([]ExchangeRateTuple, 0), + TobinTaxes: make(sdk.DecCoins, 0), } } -// ValidateGenesis validates the oracle genesis parameters -func ValidateGenesis(data GenesisState) error { - return data.Params.ValidateBasic() -} - -// Equal checks whether 2 GenesisState structs are equivalent. -func (data GenesisState) Equal(data2 GenesisState) bool { - b1 := ModuleCdc.MustMarshalBinaryBare(data) - b2 := ModuleCdc.MustMarshalBinaryBare(data2) - return bytes.Equal(b1, b2) -} - -// IsEmpty returns if a GenesisState is empty or has data in it -func (data GenesisState) IsEmpty() bool { - emptyGenState := GenesisState{} - return data.Equal(emptyGenState) +// Validate validates the oracle genesis state fields. +func (gs GenesisState) Validate() error { + return gs.Params.ValidateBasic() } diff --git a/x/oracle/types/genesis.pb.go b/x/oracle/types/genesis.pb.go index f5d51bd4..58188cdc 100644 --- a/x/oracle/types/genesis.pb.go +++ b/x/oracle/types/genesis.pb.go @@ -6,6 +6,7 @@ package types import ( 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" proto "github.com/gogo/protobuf/proto" io "io" @@ -24,15 +25,16 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// // GenesisState - all oracle state that must be provided at genesis +// GenesisState - all oracle state that must be provided at genesis type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - FeederDelegations map[string]string `protobuf:"bytes,2,rep,name=feeder_delegations,json=feederDelegations,proto3" json:"feeder_delegations" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - ExchangeRates []ExchangeRateTuple `protobuf:"bytes,3,rep,name=exchange_rates,json=exchangeRates,proto3,castrepeated=[]ExchangeRateTuple" json:"exchange_rates"` - MissCounters map[string]int64 `protobuf:"bytes,4,rep,name=miss_counters,json=missCounters,proto3" json:"miss_counters" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - AggregateExchangeRatePrevotes []AggregateExchangeRatePrevote `protobuf:"bytes,5,rep,name=aggregate_exchange_rate_prevotes,json=aggregateExchangeRatePrevotes,proto3,castrepeated=[]AggregateExchangeRatePrevote" json:"aggregate_exchange_rate_prevotes"` - AggregateExchangeRateVotes []AggregateExchangeRateVote `protobuf:"bytes,6,rep,name=aggregate_exchange_rate_votes,json=aggregateExchangeRateVotes,proto3,castrepeated=[]AggregateExchangeRateVote" json:"aggregate_exchange_rate_votes"` - TobinTaxes []ExchangeRateTuple `protobuf:"bytes,7,rep,name=tobin_taxes,json=tobinTaxes,proto3,castrepeated=[]ExchangeRateTuple" json:"tobin_taxes"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + FeederDelegations map[string]string `protobuf:"bytes,2,rep,name=feeder_delegations,json=feederDelegations,proto3" json:"feeder_delegations" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + ExchangeRates github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=exchange_rates,json=exchangeRates,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"exchange_rates"` + MissCounters map[string]int64 `protobuf:"bytes,4,rep,name=miss_counters,json=missCounters,proto3" json:"miss_counters" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + AggregateExchangeRatePrevotes []AggregateExchangeRatePrevote `protobuf:"bytes,5,rep,name=aggregate_exchange_rate_prevotes,json=aggregateExchangeRatePrevotes,proto3,castrepeated=[]AggregateExchangeRatePrevote" json:"aggregate_exchange_rate_prevotes"` + AggregateExchangeRateVotes []AggregateExchangeRateVote `protobuf:"bytes,6,rep,name=aggregate_exchange_rate_votes,json=aggregateExchangeRateVotes,proto3,castrepeated=[]AggregateExchangeRateVote" json:"aggregate_exchange_rate_votes"` + // NOTE: the amounts here indicate the tobin tax for a given USD/{denom} pair + TobinTaxes github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,7,rep,name=tobin_taxes,json=tobinTaxes,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"tobin_taxes"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -82,7 +84,7 @@ func (m *GenesisState) GetFeederDelegations() map[string]string { return nil } -func (m *GenesisState) GetExchangeRates() []ExchangeRateTuple { +func (m *GenesisState) GetExchangeRates() github_com_cosmos_cosmos_sdk_types.DecCoins { if m != nil { return m.ExchangeRates } @@ -110,143 +112,56 @@ func (m *GenesisState) GetAggregateExchangeRateVotes() []AggregateExchangeRateVo return nil } -func (m *GenesisState) GetTobinTaxes() []ExchangeRateTuple { +func (m *GenesisState) GetTobinTaxes() github_com_cosmos_cosmos_sdk_types.DecCoins { if m != nil { return m.TobinTaxes } return nil } -// Params oracle parameters -type Params struct { - VotePeriod int64 `protobuf:"varint,1,opt,name=vote_period,json=votePeriod,proto3" json:"vote_period,omitempty"` - VoteThreshold github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=vote_threshold,json=voteThreshold,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"vote_threshold"` - RewardBand github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=reward_band,json=rewardBand,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_band"` - RewardDistributionWindow int64 `protobuf:"varint,4,opt,name=reward_distribution_window,json=rewardDistributionWindow,proto3" json:"reward_distribution_window,omitempty"` - Whitelist []Denom `protobuf:"bytes,5,rep,name=whitelist,proto3,castrepeated=[]Denom" json:"whitelist"` - SlashFraction github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=slash_fraction,json=slashFraction,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"slash_fraction"` - SlashWindow int64 `protobuf:"varint,7,opt,name=slash_window,json=slashWindow,proto3" json:"slash_window,omitempty"` - MinValidPerWindow github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=min_valid_per_window,json=minValidPerWindow,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"min_valid_per_window"` -} - -func (m *Params) Reset() { *m = Params{} } -func (m *Params) String() string { return proto.CompactTextString(m) } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_14b982a0a6345d1d, []int{1} -} -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) GetVotePeriod() int64 { - if m != nil { - return m.VotePeriod - } - return 0 -} - -func (m *Params) GetRewardDistributionWindow() int64 { - if m != nil { - return m.RewardDistributionWindow - } - return 0 -} - -func (m *Params) GetWhitelist() []Denom { - if m != nil { - return m.Whitelist - } - return nil -} - -func (m *Params) GetSlashWindow() int64 { - if m != nil { - return m.SlashWindow - } - return 0 -} - func init() { proto.RegisterType((*GenesisState)(nil), "oracle.v1.GenesisState") proto.RegisterMapType((map[string]string)(nil), "oracle.v1.GenesisState.FeederDelegationsEntry") proto.RegisterMapType((map[string]int64)(nil), "oracle.v1.GenesisState.MissCountersEntry") - proto.RegisterType((*Params)(nil), "oracle.v1.Params") } func init() { proto.RegisterFile("oracle/v1/genesis.proto", fileDescriptor_14b982a0a6345d1d) } var fileDescriptor_14b982a0a6345d1d = []byte{ - // 724 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x41, 0x4f, 0xdb, 0x48, - 0x14, 0x8e, 0x49, 0x08, 0xcb, 0x04, 0x58, 0x32, 0x1b, 0xb1, 0x56, 0x58, 0x12, 0x96, 0x5d, 0xb1, - 0xac, 0x56, 0x6b, 0x0b, 0xf6, 0xb2, 0x5a, 0xad, 0x84, 0x9a, 0x06, 0x7a, 0xaa, 0x1a, 0xb9, 0x29, - 0x95, 0x40, 0xc8, 0x9d, 0xd8, 0x0f, 0x67, 0x8a, 0xed, 0x89, 0x66, 0x26, 0x09, 0xf9, 0x0f, 0x3d, - 0xf4, 0xd8, 0xdf, 0xd0, 0xfe, 0x11, 0x8e, 0x1c, 0xab, 0x1e, 0x68, 0x05, 0xa7, 0xfe, 0x8b, 0x6a, - 0xc6, 0xa6, 0x71, 0x4b, 0x03, 0x12, 0x3d, 0x65, 0xf2, 0xbd, 0xef, 0x7d, 0xdf, 0xf7, 0xe6, 0xd9, - 0x09, 0xfa, 0x99, 0x71, 0xe2, 0x85, 0x60, 0x0f, 0x36, 0xed, 0x00, 0x62, 0x10, 0x54, 0x58, 0x3d, - 0xce, 0x24, 0xc3, 0xb3, 0x49, 0xc1, 0x1a, 0x6c, 0x56, 0x2b, 0x63, 0xce, 0x80, 0x49, 0x48, 0x08, - 0xd5, 0xa5, 0x31, 0xda, 0x21, 0x61, 0xc8, 0x64, 0x8a, 0x57, 0x02, 0x16, 0x30, 0x7d, 0xb4, 0xd5, - 0x29, 0x41, 0xd7, 0x3e, 0x16, 0xd1, 0xdc, 0x83, 0xc4, 0xe0, 0xb1, 0x24, 0x12, 0xb0, 0x8d, 0x8a, - 0x3d, 0xc2, 0x49, 0x24, 0x4c, 0x63, 0xd5, 0xd8, 0x28, 0x6d, 0x95, 0xad, 0xcf, 0x86, 0x56, 0x4b, - 0x17, 0x1a, 0x85, 0xd3, 0xf3, 0x7a, 0xce, 0x49, 0x69, 0xd8, 0x43, 0xf8, 0x08, 0xc0, 0x07, 0xee, - 0xfa, 0x10, 0x42, 0x40, 0x24, 0x65, 0xb1, 0x30, 0xa7, 0x56, 0xf3, 0x1b, 0xa5, 0x2d, 0x2b, 0xd3, - 0x9c, 0x75, 0xb1, 0x76, 0x75, 0x47, 0x73, 0xdc, 0xb0, 0x13, 0x4b, 0x3e, 0x4a, 0x95, 0xcb, 0x47, - 0x5f, 0x57, 0xf1, 0x33, 0xb4, 0x00, 0x27, 0x5e, 0x97, 0xc4, 0x01, 0xb8, 0x9c, 0x48, 0x10, 0x66, - 0x5e, 0x1b, 0xfc, 0x92, 0x31, 0xd8, 0x49, 0x09, 0x0e, 0x91, 0xd0, 0xee, 0xf7, 0x42, 0x68, 0x2c, - 0x2b, 0xb9, 0xd7, 0xef, 0xeb, 0x3f, 0x1d, 0x1c, 0x5e, 0x2b, 0x3a, 0xf3, 0x90, 0x81, 0x04, 0x6e, - 0xa3, 0xf9, 0x88, 0x0a, 0xe1, 0x7a, 0xac, 0x1f, 0x4b, 0xe0, 0xc2, 0x2c, 0x68, 0x83, 0x3f, 0x27, - 0x4d, 0xf0, 0x90, 0x0a, 0x71, 0x3f, 0xe5, 0x66, 0xc3, 0xcf, 0x45, 0x99, 0x02, 0x7e, 0x65, 0xa0, - 0x55, 0x12, 0x04, 0x5c, 0x0d, 0x02, 0xee, 0x17, 0x23, 0xb8, 0x3d, 0x0e, 0x6a, 0x6d, 0xc2, 0x9c, - 0xd6, 0x4e, 0x7f, 0x64, 0x9c, 0xee, 0x5d, 0xb5, 0x64, 0x63, 0xb7, 0x12, 0x7e, 0x63, 0x3d, 0x9d, - 0xaa, 0x76, 0x70, 0x78, 0x13, 0xcf, 0x59, 0x21, 0x37, 0x54, 0x05, 0x7e, 0x61, 0xa0, 0x95, 0x49, - 0xd1, 0x92, 0x5c, 0x45, 0x9d, 0xeb, 0xf7, 0xdb, 0x72, 0xed, 0xa9, 0x50, 0xbf, 0xa5, 0xa1, 0x96, - 0x27, 0x84, 0x52, 0x24, 0xa7, 0x4a, 0x26, 0x95, 0x04, 0xde, 0x47, 0x25, 0xc9, 0x3a, 0x34, 0x76, - 0x25, 0x39, 0x01, 0x61, 0xce, 0x7c, 0xef, 0x7a, 0x91, 0x56, 0x6b, 0x2b, 0xb1, 0x6a, 0x13, 0x2d, - 0x7d, 0xfb, 0x81, 0xc3, 0x8b, 0x28, 0x7f, 0x0c, 0x23, 0xfd, 0xa8, 0xcf, 0x3a, 0xea, 0x88, 0x2b, - 0x68, 0x7a, 0x40, 0xc2, 0x3e, 0x98, 0x53, 0x1a, 0x4b, 0xbe, 0xfc, 0x37, 0xf5, 0xaf, 0x51, 0xdd, - 0x46, 0xe5, 0x6b, 0x4b, 0xbf, 0x4d, 0x20, 0x9f, 0x11, 0x58, 0x7b, 0x53, 0x40, 0xc5, 0xe4, 0x15, - 0xc2, 0x75, 0x54, 0x52, 0x77, 0xec, 0xf6, 0x80, 0x53, 0xe6, 0xeb, 0xf6, 0xbc, 0x83, 0x14, 0xd4, - 0xd2, 0x08, 0x7e, 0x82, 0x16, 0x34, 0x41, 0x76, 0x39, 0x88, 0x2e, 0x0b, 0xfd, 0x24, 0x4f, 0xc3, - 0x52, 0x33, 0xbf, 0x3b, 0xaf, 0xaf, 0x07, 0x54, 0x76, 0xfb, 0x1d, 0xcb, 0x63, 0x91, 0xed, 0x31, - 0x11, 0x31, 0x91, 0x7e, 0xfc, 0x2d, 0xfc, 0x63, 0x5b, 0x8e, 0x7a, 0x20, 0xac, 0x26, 0x78, 0xce, - 0xbc, 0x52, 0x69, 0x5f, 0x89, 0xe0, 0x47, 0xa8, 0xc4, 0x61, 0x48, 0xb8, 0xef, 0x76, 0x48, 0xec, - 0x9b, 0xf9, 0x3b, 0x69, 0xa2, 0x44, 0xa2, 0x41, 0x62, 0x1f, 0xff, 0x8f, 0xaa, 0xa9, 0xa0, 0x4f, - 0x85, 0xe4, 0xb4, 0xd3, 0x57, 0xb7, 0xeb, 0x0e, 0x69, 0xec, 0xb3, 0xa1, 0x59, 0xd0, 0x73, 0x99, - 0x09, 0xa3, 0x99, 0x21, 0x3c, 0xd5, 0x75, 0xbc, 0x8d, 0x66, 0x87, 0x5d, 0x2a, 0x21, 0xa4, 0x42, - 0xa6, 0xaf, 0xc1, 0x62, 0x66, 0xe5, 0x4d, 0x88, 0x59, 0xd4, 0xf8, 0x31, 0x5d, 0xf3, 0xcc, 0xc1, - 0xa1, 0x06, 0x9c, 0x71, 0x8f, 0xba, 0x26, 0x11, 0x12, 0xd1, 0x75, 0x8f, 0x38, 0xf1, 0x94, 0xb0, - 0x59, 0xbc, 0xdb, 0x35, 0x69, 0x95, 0xdd, 0x54, 0x04, 0xff, 0x8a, 0xe6, 0x12, 0xd9, 0x74, 0x8e, - 0x19, 0x3d, 0x47, 0x49, 0x63, 0x69, 0x74, 0x17, 0x55, 0x22, 0x1a, 0xbb, 0x03, 0x12, 0x52, 0x5f, - 0xad, 0xf1, 0x8a, 0xfa, 0xc3, 0x9d, 0xfc, 0xcb, 0x11, 0x8d, 0xf7, 0x94, 0x54, 0x0b, 0x78, 0x62, - 0xd0, 0xd8, 0x39, 0xbd, 0xa8, 0x19, 0x67, 0x17, 0x35, 0xe3, 0xc3, 0x45, 0xcd, 0x78, 0x79, 0x59, - 0xcb, 0x9d, 0x5d, 0xd6, 0x72, 0x6f, 0x2f, 0x6b, 0xb9, 0xfd, 0xbf, 0x32, 0xa2, 0x3d, 0x08, 0x82, - 0xd1, 0xf3, 0x81, 0x2d, 0x58, 0x14, 0x41, 0x48, 0x81, 0xdb, 0x27, 0x76, 0xfa, 0x07, 0xa0, 0xd5, - 0x3b, 0x45, 0xfd, 0x3b, 0xff, 0xcf, 0xa7, 0x00, 0x00, 0x00, 0xff, 0xff, 0xcc, 0xce, 0x80, 0xf3, - 0x51, 0x06, 0x00, 0x00, + // 526 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6f, 0xd3, 0x30, + 0x1c, 0x6d, 0xd6, 0xad, 0xd3, 0xdc, 0x0d, 0x51, 0x6b, 0x1a, 0x51, 0x61, 0x59, 0x05, 0x08, 0x86, + 0x10, 0x8e, 0xba, 0x5d, 0x10, 0x17, 0x44, 0xd7, 0xc2, 0x09, 0x69, 0x0a, 0x13, 0x07, 0x10, 0x8a, + 0xdc, 0xf4, 0xb7, 0x2c, 0xac, 0x89, 0x2b, 0xff, 0xdc, 0xaa, 0xfd, 0x0e, 0x1c, 0x38, 0xc2, 0x57, + 0xe0, 0x93, 0xec, 0xb8, 0x23, 0x27, 0x40, 0xed, 0x17, 0x41, 0x76, 0x5c, 0x16, 0xfe, 0x74, 0x3b, + 0x71, 0xaa, 0xeb, 0xf7, 0xde, 0xef, 0xbd, 0x97, 0xd8, 0x21, 0x37, 0x84, 0xe4, 0x51, 0x1f, 0xfc, + 0x51, 0xd3, 0x8f, 0x21, 0x03, 0x4c, 0x90, 0x0d, 0xa4, 0x50, 0x82, 0xae, 0xe5, 0x00, 0x1b, 0x35, + 0xeb, 0x5b, 0x17, 0x1c, 0xbb, 0x69, 0x28, 0xf5, 0xcd, 0x58, 0xc4, 0xc2, 0x2c, 0x7d, 0xbd, 0xb2, + 0xbb, 0x5e, 0x24, 0x30, 0x15, 0xe8, 0x77, 0x39, 0x6a, 0x49, 0x17, 0x14, 0x6f, 0xfa, 0x91, 0x48, + 0xb2, 0x1c, 0xbf, 0xfd, 0x79, 0x95, 0xac, 0xbf, 0xc8, 0xad, 0x5e, 0x29, 0xae, 0x80, 0xfa, 0xa4, + 0x32, 0xe0, 0x92, 0xa7, 0xe8, 0x3a, 0x0d, 0x67, 0xb7, 0xba, 0x57, 0x63, 0xbf, 0xac, 0xd9, 0xa1, + 0x01, 0x5a, 0xcb, 0x67, 0xdf, 0x76, 0x4a, 0x81, 0xa5, 0xd1, 0x88, 0xd0, 0x63, 0x80, 0x1e, 0xc8, + 0xb0, 0x07, 0x7d, 0x88, 0xb9, 0x4a, 0x44, 0x86, 0xee, 0x52, 0xa3, 0xbc, 0x5b, 0xdd, 0x63, 0x05, + 0x71, 0xd1, 0x85, 0x3d, 0x37, 0x8a, 0xf6, 0x85, 0xa0, 0x93, 0x29, 0x39, 0xb1, 0x93, 0x6b, 0xc7, + 0x7f, 0xa2, 0x74, 0x4c, 0xae, 0xc1, 0x38, 0x3a, 0xe1, 0x59, 0x0c, 0xa1, 0xe4, 0x0a, 0xd0, 0x2d, + 0x1b, 0x83, 0x5b, 0x2c, 0xef, 0xc7, 0x74, 0x3f, 0x66, 0xfb, 0xb1, 0x36, 0x44, 0x07, 0x22, 0xc9, + 0x5a, 0xfb, 0x7a, 0xdc, 0x97, 0xef, 0x3b, 0x0f, 0xe3, 0x44, 0x9d, 0x0c, 0xbb, 0x2c, 0x12, 0xa9, + 0x6f, 0x9f, 0x47, 0xfe, 0xf3, 0x08, 0x7b, 0xa7, 0xbe, 0x9a, 0x0c, 0x00, 0xe7, 0x1a, 0x0c, 0x36, + 0xe6, 0x46, 0x81, 0xf6, 0xa1, 0x47, 0x64, 0x23, 0x4d, 0x10, 0xc3, 0x48, 0x0c, 0x33, 0x05, 0x12, + 0xdd, 0x65, 0x63, 0xfc, 0x60, 0x51, 0xb3, 0x97, 0x09, 0xe2, 0x81, 0xe5, 0x16, 0x4b, 0xad, 0xa7, + 0x05, 0x80, 0x7e, 0x72, 0x48, 0x83, 0xc7, 0xb1, 0xd4, 0x05, 0x21, 0xfc, 0xad, 0x5a, 0x38, 0x90, + 0x30, 0x12, 0xba, 0xe2, 0x8a, 0x71, 0xba, 0x5f, 0x70, 0x7a, 0x36, 0x97, 0x74, 0x0a, 0x19, 0x0f, + 0x73, 0x7e, 0xeb, 0x9e, 0x6d, 0xeb, 0xbd, 0x7d, 0x77, 0x19, 0x2f, 0xd8, 0xe6, 0x97, 0xa0, 0x48, + 0x3f, 0x38, 0x64, 0x7b, 0x51, 0xb4, 0x3c, 0x57, 0xc5, 0xe4, 0xba, 0x7b, 0x55, 0xae, 0xd7, 0x3a, + 0xd4, 0x1d, 0x1b, 0xea, 0xe6, 0x82, 0x50, 0x9a, 0x14, 0xd4, 0xf9, 0x22, 0x08, 0xa9, 0x24, 0x55, + 0x25, 0xba, 0x49, 0x16, 0x2a, 0x3e, 0x06, 0x74, 0x57, 0xff, 0xd7, 0x6b, 0x27, 0xc6, 0xe5, 0x48, + 0x9b, 0xd4, 0xdb, 0x64, 0xeb, 0xdf, 0x07, 0x94, 0x5e, 0x27, 0xe5, 0x53, 0x98, 0x98, 0xab, 0xb1, + 0x16, 0xe8, 0x25, 0xdd, 0x24, 0x2b, 0x23, 0xde, 0x1f, 0x82, 0xbb, 0x64, 0xf6, 0xf2, 0x3f, 0x4f, + 0x96, 0x1e, 0x3b, 0xf5, 0xa7, 0xa4, 0xf6, 0xd7, 0x61, 0xb8, 0x6a, 0x40, 0xb9, 0x30, 0xa0, 0xd5, + 0x39, 0x9b, 0x7a, 0xce, 0xf9, 0xd4, 0x73, 0x7e, 0x4c, 0x3d, 0xe7, 0xe3, 0xcc, 0x2b, 0x9d, 0xcf, + 0xbc, 0xd2, 0xd7, 0x99, 0x57, 0x7a, 0x53, 0x6c, 0x36, 0x80, 0x38, 0x9e, 0xbc, 0x1f, 0xf9, 0x28, + 0xd2, 0x14, 0xfa, 0x09, 0x48, 0x7f, 0x6c, 0x3f, 0x0c, 0x79, 0xc5, 0x6e, 0xc5, 0xdc, 0xf4, 0xfd, + 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2b, 0x46, 0xe8, 0x30, 0x5d, 0x04, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -374,98 +289,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -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 - { - size := m.MinValidPerWindow.Size() - i -= size - if _, err := m.MinValidPerWindow.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x42 - if m.SlashWindow != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.SlashWindow)) - i-- - dAtA[i] = 0x38 - } - { - size := m.SlashFraction.Size() - i -= size - if _, err := m.SlashFraction.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - if len(m.Whitelist) > 0 { - for iNdEx := len(m.Whitelist) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Whitelist[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - } - if m.RewardDistributionWindow != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.RewardDistributionWindow)) - i-- - dAtA[i] = 0x20 - } - { - size := m.RewardBand.Size() - i -= size - if _, err := m.RewardBand.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - { - size := m.VoteThreshold.Size() - i -= size - if _, err := m.VoteThreshold.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.VotePeriod != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.VotePeriod)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -528,38 +351,6 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.VotePeriod != 0 { - n += 1 + sovGenesis(uint64(m.VotePeriod)) - } - l = m.VoteThreshold.Size() - n += 1 + l + sovGenesis(uint64(l)) - l = m.RewardBand.Size() - n += 1 + l + sovGenesis(uint64(l)) - if m.RewardDistributionWindow != 0 { - n += 1 + sovGenesis(uint64(m.RewardDistributionWindow)) - } - if len(m.Whitelist) > 0 { - for _, e := range m.Whitelist { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - l = m.SlashFraction.Size() - n += 1 + l + sovGenesis(uint64(l)) - if m.SlashWindow != 0 { - n += 1 + sovGenesis(uint64(m.SlashWindow)) - } - l = m.MinValidPerWindow.Size() - n += 1 + l + sovGenesis(uint64(l)) - return n -} - func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -784,7 +575,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ExchangeRates = append(m.ExchangeRates, ExchangeRateTuple{}) + m.ExchangeRates = append(m.ExchangeRates, types.DecCoin{}) if err := m.ExchangeRates[len(m.ExchangeRates)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -999,7 +790,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.TobinTaxes = append(m.TobinTaxes, ExchangeRateTuple{}) + m.TobinTaxes = append(m.TobinTaxes, types.DecCoin{}) if err := m.TobinTaxes[len(m.TobinTaxes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1028,286 +819,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -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 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: 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 VotePeriod", wireType) - } - m.VotePeriod = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.VotePeriod |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field VoteThreshold", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.VoteThreshold.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardBand", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.RewardBand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardDistributionWindow", wireType) - } - m.RewardDistributionWindow = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RewardDistributionWindow |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Whitelist", 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.Whitelist = append(m.Whitelist, Denom{}) - if err := m.Whitelist[len(m.Whitelist)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SlashFraction", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.SlashFraction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SlashWindow", wireType) - } - m.SlashWindow = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SlashWindow |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinValidPerWindow", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - 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 ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinValidPerWindow.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 { - return ErrInvalidLengthGenesis - } - if (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 diff --git a/x/oracle/types/genesis_test.go b/x/oracle/types/genesis_test.go index 4e714cda..6352253d 100644 --- a/x/oracle/types/genesis_test.go +++ b/x/oracle/types/genesis_test.go @@ -8,17 +8,5 @@ import ( func TestGenesisValidation(t *testing.T) { genState := DefaultGenesisState() - require.NoError(t, ValidateGenesis(genState)) -} - -func TestGenesisEqual(t *testing.T) { - genState1 := DefaultGenesisState() - genState2 := DefaultGenesisState() - - require.True(t, genState1.Equal(genState2)) -} - -func TestGenesisEmpty(t *testing.T) { - genState := GenesisState{} - require.True(t, genState.IsEmpty()) + require.NoError(t, genState.Validate()) } diff --git a/x/oracle/types/msgs.go b/x/oracle/types/msgs.go index 6f46b758..b4939336 100644 --- a/x/oracle/types/msgs.go +++ b/x/oracle/types/msgs.go @@ -16,8 +16,8 @@ var ( //------------------------------------------------- // NewMsgDelegateFeedConsent creates a MsgDelegateFeedConsent instance -func NewMsgDelegateFeedConsent(operatorAddress sdk.ValAddress, feederAddress sdk.AccAddress) MsgDelegateFeedConsent { - return MsgDelegateFeedConsent{ +func NewMsgDelegateFeedConsent(operatorAddress sdk.ValAddress, feederAddress sdk.AccAddress) *MsgDelegateFeedConsent { + return &MsgDelegateFeedConsent{ Operator: operatorAddress.String(), Delegate: feederAddress.String(), } @@ -31,12 +31,15 @@ func (msg MsgDelegateFeedConsent) Type() string { return "delegatefeeder" } // GetSignBytes implements sdk.Msg func (msg MsgDelegateFeedConsent) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + panic("oracle messages do not support amino") } // GetSigners implements sdk.Msg func (msg MsgDelegateFeedConsent) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.Operator) + addr, err := sdk.AccAddressFromBech32(msg.Operator) + if err != nil { + return nil + } return []sdk.AccAddress{addr} } @@ -56,8 +59,8 @@ func (msg MsgDelegateFeedConsent) ValidateBasic() error { } // NewMsgAggregateExchangeRatePrevote returns MsgAggregateExchangeRatePrevote instance -func NewMsgAggregateExchangeRatePrevote(hash AggregateVoteHash, feeder sdk.AccAddress, validator sdk.ValAddress) MsgAggregateExchangeRatePrevote { - return MsgAggregateExchangeRatePrevote{ +func NewMsgAggregateExchangeRatePrevote(hash AggregateVoteHash, feeder sdk.AccAddress, validator sdk.ValAddress) *MsgAggregateExchangeRatePrevote { + return &MsgAggregateExchangeRatePrevote{ Hash: hash, Feeder: feeder.String(), Validator: validator.String(), @@ -72,12 +75,15 @@ func (msg MsgAggregateExchangeRatePrevote) Type() string { return "aggregateexch // GetSignBytes implements sdk.Msg func (msg MsgAggregateExchangeRatePrevote) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + panic("oracle messages do not support amino") } // GetSigners implements sdk.Msg func (msg MsgAggregateExchangeRatePrevote) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.Feeder) + addr, err := sdk.AccAddressFromBech32(msg.Feeder) + if err != nil { + return nil + } return []sdk.AccAddress{addr} } @@ -103,8 +109,8 @@ func (msg MsgAggregateExchangeRatePrevote) ValidateBasic() error { } // NewMsgAggregateExchangeRateVote returns MsgAggregateExchangeRateVote instance -func NewMsgAggregateExchangeRateVote(salt string, exchangeRates string, feeder sdk.AccAddress, validator sdk.ValAddress) MsgAggregateExchangeRateVote { - return MsgAggregateExchangeRateVote{ +func NewMsgAggregateExchangeRateVote(salt string, exchangeRates string, feeder sdk.AccAddress, validator sdk.ValAddress) *MsgAggregateExchangeRateVote { + return &MsgAggregateExchangeRateVote{ Salt: salt, ExchangeRates: exchangeRates, Feeder: feeder.String(), @@ -120,18 +126,20 @@ func (msg MsgAggregateExchangeRateVote) Type() string { return "aggregateexchang // GetSignBytes implements sdk.Msg func (msg MsgAggregateExchangeRateVote) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + panic("oracle messages do not support amino") } // GetSigners implements sdk.Msg func (msg MsgAggregateExchangeRateVote) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(msg.Feeder) + addr, err := sdk.AccAddressFromBech32(msg.Feeder) + if err != nil { + return nil + } return []sdk.AccAddress{addr} } // ValidateBasic implements sdk.Msg func (msg MsgAggregateExchangeRateVote) ValidateBasic() error { - feeder, err := sdk.AccAddressFromBech32(msg.Feeder) if err != nil || feeder.Empty() { return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "must give valid feeder address") @@ -155,7 +163,7 @@ func (msg MsgAggregateExchangeRateVote) ValidateBasic() error { for _, tuple := range exchangeRateTuples { // Check overflow bit length - if tuple.ExchangeRate.BigInt().BitLen() > 100+sdk.DecimalPrecisionBits { + if tuple.Amount.BigInt().BitLen() > 100+sdk.DecimalPrecisionBits { return sdkerrors.Wrap(ErrInvalidExchangeRate, "overflow") } } diff --git a/x/oracle/types/msgs.pb.gw.go b/x/oracle/types/msgs.pb.gw.go deleted file mode 100644 index b3847824..00000000 --- a/x/oracle/types/msgs.pb.gw.go +++ /dev/null @@ -1,326 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: oracle/v1/msgs.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 - -var ( - filter_Msg_DelegateFeedConsent_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Msg_DelegateFeedConsent_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgDelegateFeedConsent - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_DelegateFeedConsent_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DelegateFeedConsent(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Msg_DelegateFeedConsent_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgDelegateFeedConsent - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_DelegateFeedConsent_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.DelegateFeedConsent(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Msg_AggregateExchangeRatePrevote_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Msg_AggregateExchangeRatePrevote_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgAggregateExchangeRatePrevote - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_AggregateExchangeRatePrevote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AggregateExchangeRatePrevote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Msg_AggregateExchangeRatePrevote_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgAggregateExchangeRatePrevote - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_AggregateExchangeRatePrevote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.AggregateExchangeRatePrevote(ctx, &protoReq) - return msg, metadata, err - -} - -var ( - filter_Msg_AggregateExchangeRateVote_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Msg_AggregateExchangeRateVote_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgAggregateExchangeRateVote - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_AggregateExchangeRateVote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AggregateExchangeRateVote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Msg_AggregateExchangeRateVote_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgAggregateExchangeRateVote - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_AggregateExchangeRateVote_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.AggregateExchangeRateVote(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". -// UnaryRPC :call MsgServer 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 RegisterMsgHandlerFromEndpoint instead. -func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { - - mux.Handle("POST", pattern_Msg_DelegateFeedConsent_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_Msg_DelegateFeedConsent_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_DelegateFeedConsent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Msg_AggregateExchangeRatePrevote_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_Msg_AggregateExchangeRatePrevote_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_AggregateExchangeRatePrevote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Msg_AggregateExchangeRateVote_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_Msg_AggregateExchangeRateVote_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_AggregateExchangeRateVote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterMsgHandlerFromEndpoint is same as RegisterMsgHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterMsgHandlerFromEndpoint(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 RegisterMsgHandler(ctx, mux, conn) -} - -// RegisterMsgHandler registers the http handlers for service Msg to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterMsgHandlerClient(ctx, mux, NewMsgClient(conn)) -} - -// RegisterMsgHandlerClient registers the http handlers for service Msg -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MsgClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MsgClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "MsgClient" to call the correct interceptors. -func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { - - mux.Handle("POST", pattern_Msg_DelegateFeedConsent_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_Msg_DelegateFeedConsent_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_DelegateFeedConsent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Msg_AggregateExchangeRatePrevote_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_Msg_AggregateExchangeRatePrevote_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_AggregateExchangeRatePrevote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Msg_AggregateExchangeRateVote_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_Msg_AggregateExchangeRateVote_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Msg_AggregateExchangeRateVote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Msg_DelegateFeedConsent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"oracle", "v1", "delegate_feed_consent"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Msg_AggregateExchangeRatePrevote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"oracle", "v1", "aggregate_exchange_rate_prevote"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Msg_AggregateExchangeRateVote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"oracle", "v1", "aggregate_exchange_rate_vote"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Msg_DelegateFeedConsent_0 = runtime.ForwardResponseMessage - - forward_Msg_AggregateExchangeRatePrevote_0 = runtime.ForwardResponseMessage - - forward_Msg_AggregateExchangeRateVote_0 = runtime.ForwardResponseMessage -) diff --git a/x/oracle/types/vote.pb.go b/x/oracle/types/oracle.pb.go similarity index 53% rename from x/oracle/types/vote.pb.go rename to x/oracle/types/oracle.pb.go index 21213b1a..7f0803ae 100644 --- a/x/oracle/types/vote.pb.go +++ b/x/oracle/types/oracle.pb.go @@ -1,11 +1,12 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: oracle/v1/vote.proto +// source: oracle/v1/oracle.proto package types import ( 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" proto "github.com/gogo/protobuf/proto" io "io" @@ -24,19 +25,72 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// Claim is an interface that directs its rewards to an attached bank account. +type Claim struct { + Weight int64 `protobuf:"varint,1,opt,name=weight,proto3" json:"weight,omitempty"` + Recipient string `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` +} + +func (m *Claim) Reset() { *m = Claim{} } +func (m *Claim) String() string { return proto.CompactTextString(m) } +func (*Claim) ProtoMessage() {} +func (*Claim) Descriptor() ([]byte, []int) { + return fileDescriptor_652b57db11528d07, []int{0} +} +func (m *Claim) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Claim) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Claim.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 *Claim) XXX_Merge(src proto.Message) { + xxx_messageInfo_Claim.Merge(m, src) +} +func (m *Claim) XXX_Size() int { + return m.Size() +} +func (m *Claim) XXX_DiscardUnknown() { + xxx_messageInfo_Claim.DiscardUnknown(m) +} + +var xxx_messageInfo_Claim proto.InternalMessageInfo + +func (m *Claim) GetWeight() int64 { + if m != nil { + return m.Weight + } + return 0 +} + +func (m *Claim) GetRecipient() string { + if m != nil { + return m.Recipient + } + return "" +} + // ExchangeRatePrevote - struct to store a validator's prevote on the rate of Luna in the denom asset type ExchangeRatePrevote struct { Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` Voter string `protobuf:"bytes,3,opt,name=voter,proto3" json:"voter,omitempty"` - SubmitBlock int64 `protobuf:"varint,4,opt,name=submit_block,json=submitBlock,proto3" json:"submit_block,omitempty"` + SubmitBlock int64 `protobuf:"varint,4,opt,name=submit_block,json=submitBlock,proto3" json:"submit_block,omitempty" yaml:"submit_block"` } func (m *ExchangeRatePrevote) Reset() { *m = ExchangeRatePrevote{} } func (m *ExchangeRatePrevote) String() string { return proto.CompactTextString(m) } func (*ExchangeRatePrevote) ProtoMessage() {} func (*ExchangeRatePrevote) Descriptor() ([]byte, []int) { - return fileDescriptor_92bdd9e640ece7e2, []int{0} + return fileDescriptor_652b57db11528d07, []int{1} } func (m *ExchangeRatePrevote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -95,7 +149,7 @@ func (m *ExchangeRatePrevote) GetSubmitBlock() int64 { // ExchangeRateVote - struct to store a validator's vote on the rate of Luna in the denom asset type ExchangeRateVote struct { - ExchangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=exchange_rate,json=exchangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchange_rate"` + ExchangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=exchange_rate,json=exchangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchange_rate" yaml:"exchange_rate"` Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"` Voter string `protobuf:"bytes,3,opt,name=voter,proto3" json:"voter,omitempty"` } @@ -104,7 +158,7 @@ func (m *ExchangeRateVote) Reset() { *m = ExchangeRateVote{} } func (m *ExchangeRateVote) String() string { return proto.CompactTextString(m) } func (*ExchangeRateVote) ProtoMessage() {} func (*ExchangeRateVote) Descriptor() ([]byte, []int) { - return fileDescriptor_92bdd9e640ece7e2, []int{1} + return fileDescriptor_652b57db11528d07, []int{2} } func (m *ExchangeRateVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -151,14 +205,14 @@ func (m *ExchangeRateVote) GetVoter() string { type AggregateExchangeRatePrevote struct { Hash []byte `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` Voter string `protobuf:"bytes,2,opt,name=voter,proto3" json:"voter,omitempty"` - SubmitBlock int64 `protobuf:"varint,3,opt,name=submit_block,json=submitBlock,proto3" json:"submit_block,omitempty"` + SubmitBlock int64 `protobuf:"varint,3,opt,name=submit_block,json=submitBlock,proto3" json:"submit_block,omitempty" yaml:"submit_block"` } func (m *AggregateExchangeRatePrevote) Reset() { *m = AggregateExchangeRatePrevote{} } func (m *AggregateExchangeRatePrevote) String() string { return proto.CompactTextString(m) } func (*AggregateExchangeRatePrevote) ProtoMessage() {} func (*AggregateExchangeRatePrevote) Descriptor() ([]byte, []int) { - return fileDescriptor_92bdd9e640ece7e2, []int{2} + return fileDescriptor_652b57db11528d07, []int{3} } func (m *AggregateExchangeRatePrevote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -208,24 +262,24 @@ func (m *AggregateExchangeRatePrevote) GetSubmitBlock() int64 { return 0 } -// ExchangeRateTuple - struct to represent a exchange rate of Luna in the denom asset -type ExchangeRateTuple struct { - Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` - ExchangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exchange_rate,json=exchangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exchange_rate"` +// AggregateExchangeRateVote - struct to store a validator's aggregate vote on the rate of Luna in the denom asset +type AggregateExchangeRateVote struct { + Voter string `protobuf:"bytes,1,opt,name=voter,proto3" json:"voter,omitempty"` + ExchangeRateTuples github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=exchange_rate_tuples,json=exchangeRateTuples,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"exchange_rate_tuples" yaml:"exchange_rate_tuples"` } -func (m *ExchangeRateTuple) Reset() { *m = ExchangeRateTuple{} } -func (m *ExchangeRateTuple) String() string { return proto.CompactTextString(m) } -func (*ExchangeRateTuple) ProtoMessage() {} -func (*ExchangeRateTuple) Descriptor() ([]byte, []int) { - return fileDescriptor_92bdd9e640ece7e2, []int{3} +func (m *AggregateExchangeRateVote) Reset() { *m = AggregateExchangeRateVote{} } +func (m *AggregateExchangeRateVote) String() string { return proto.CompactTextString(m) } +func (*AggregateExchangeRateVote) ProtoMessage() {} +func (*AggregateExchangeRateVote) Descriptor() ([]byte, []int) { + return fileDescriptor_652b57db11528d07, []int{4} } -func (m *ExchangeRateTuple) XXX_Unmarshal(b []byte) error { +func (m *AggregateExchangeRateVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ExchangeRateTuple) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *AggregateExchangeRateVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ExchangeRateTuple.Marshal(b, m, deterministic) + return xxx_messageInfo_AggregateExchangeRateVote.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -235,43 +289,57 @@ func (m *ExchangeRateTuple) XXX_Marshal(b []byte, deterministic bool) ([]byte, e return b[:n], nil } } -func (m *ExchangeRateTuple) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExchangeRateTuple.Merge(m, src) +func (m *AggregateExchangeRateVote) XXX_Merge(src proto.Message) { + xxx_messageInfo_AggregateExchangeRateVote.Merge(m, src) } -func (m *ExchangeRateTuple) XXX_Size() int { +func (m *AggregateExchangeRateVote) XXX_Size() int { return m.Size() } -func (m *ExchangeRateTuple) XXX_DiscardUnknown() { - xxx_messageInfo_ExchangeRateTuple.DiscardUnknown(m) +func (m *AggregateExchangeRateVote) XXX_DiscardUnknown() { + xxx_messageInfo_AggregateExchangeRateVote.DiscardUnknown(m) } -var xxx_messageInfo_ExchangeRateTuple proto.InternalMessageInfo +var xxx_messageInfo_AggregateExchangeRateVote proto.InternalMessageInfo -func (m *ExchangeRateTuple) GetDenom() string { +func (m *AggregateExchangeRateVote) GetVoter() string { if m != nil { - return m.Denom + return m.Voter } return "" } -// AggregateExchangeRateVote - struct to store a validator's aggregate vote on the rate of Luna in the denom asset -type AggregateExchangeRateVote struct { - Voter string `protobuf:"bytes,1,opt,name=voter,proto3" json:"voter,omitempty"` - ExchangeRateTuples []ExchangeRateTuple `protobuf:"bytes,2,rep,name=exchange_rate_tuples,json=exchangeRateTuples,proto3,castrepeated=[]ExchangeRateTuple" json:"exchange_rate_tuples"` +func (m *AggregateExchangeRateVote) GetExchangeRateTuples() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.ExchangeRateTuples + } + return nil } -func (m *AggregateExchangeRateVote) Reset() { *m = AggregateExchangeRateVote{} } -func (m *AggregateExchangeRateVote) String() string { return proto.CompactTextString(m) } -func (*AggregateExchangeRateVote) ProtoMessage() {} -func (*AggregateExchangeRateVote) Descriptor() ([]byte, []int) { - return fileDescriptor_92bdd9e640ece7e2, []int{4} +// Params oracle parameters +type Params struct { + VotePeriod int64 `protobuf:"varint,1,opt,name=vote_period,json=votePeriod,proto3" json:"vote_period,omitempty" yaml:"exchange_rate_tuples"` + VoteThreshold github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=vote_threshold,json=voteThreshold,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"vote_threshold" yaml:"vote_threshold"` + RewardBand github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=reward_band,json=rewardBand,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_band" yaml:"reward_band"` + RewardDistributionWindow int64 `protobuf:"varint,4,opt,name=reward_distribution_window,json=rewardDistributionWindow,proto3" json:"reward_distribution_window,omitempty" yaml:"reward_distribution_window"` + // NOTE: The amounts here indicate the tobin tax for each currency + Whitelist github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,5,rep,name=whitelist,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"whitelist"` + SlashFraction github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=slash_fraction,json=slashFraction,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"slash_fraction" yaml:"slash_fraction"` + SlashWindow int64 `protobuf:"varint,7,opt,name=slash_window,json=slashWindow,proto3" json:"slash_window,omitempty" yaml:"slash_window"` + MinValidPerWindow github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,opt,name=min_valid_per_window,json=minValidPerWindow,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"min_valid_per_window" yaml:"min_valid_per_window"` } -func (m *AggregateExchangeRateVote) XXX_Unmarshal(b []byte) error { + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_652b57db11528d07, []int{5} +} +func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *AggregateExchangeRateVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_AggregateExchangeRateVote.Marshal(b, m, deterministic) + return xxx_messageInfo_Params.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -281,69 +349,139 @@ func (m *AggregateExchangeRateVote) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *AggregateExchangeRateVote) XXX_Merge(src proto.Message) { - xxx_messageInfo_AggregateExchangeRateVote.Merge(m, src) +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) } -func (m *AggregateExchangeRateVote) XXX_Size() int { +func (m *Params) XXX_Size() int { return m.Size() } -func (m *AggregateExchangeRateVote) XXX_DiscardUnknown() { - xxx_messageInfo_AggregateExchangeRateVote.DiscardUnknown(m) +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) } -var xxx_messageInfo_AggregateExchangeRateVote proto.InternalMessageInfo +var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *AggregateExchangeRateVote) GetVoter() string { +func (m *Params) GetVotePeriod() int64 { if m != nil { - return m.Voter + return m.VotePeriod } - return "" + return 0 } -func (m *AggregateExchangeRateVote) GetExchangeRateTuples() []ExchangeRateTuple { +func (m *Params) GetRewardDistributionWindow() int64 { if m != nil { - return m.ExchangeRateTuples + return m.RewardDistributionWindow + } + return 0 +} + +func (m *Params) GetWhitelist() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Whitelist } return nil } +func (m *Params) GetSlashWindow() int64 { + if m != nil { + return m.SlashWindow + } + return 0 +} + func init() { + proto.RegisterType((*Claim)(nil), "oracle.v1.Claim") proto.RegisterType((*ExchangeRatePrevote)(nil), "oracle.v1.ExchangeRatePrevote") proto.RegisterType((*ExchangeRateVote)(nil), "oracle.v1.ExchangeRateVote") proto.RegisterType((*AggregateExchangeRatePrevote)(nil), "oracle.v1.AggregateExchangeRatePrevote") - proto.RegisterType((*ExchangeRateTuple)(nil), "oracle.v1.ExchangeRateTuple") proto.RegisterType((*AggregateExchangeRateVote)(nil), "oracle.v1.AggregateExchangeRateVote") + proto.RegisterType((*Params)(nil), "oracle.v1.Params") } -func init() { proto.RegisterFile("oracle/v1/vote.proto", fileDescriptor_92bdd9e640ece7e2) } - -var fileDescriptor_92bdd9e640ece7e2 = []byte{ - // 399 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0x41, 0xee, 0x93, 0x40, - 0x14, 0xc6, 0x19, 0xa8, 0x26, 0x9d, 0xd6, 0x44, 0x29, 0x0b, 0xd4, 0x86, 0x22, 0x0b, 0x43, 0x62, - 0x64, 0x52, 0x3d, 0x81, 0xc4, 0xee, 0x0d, 0x1a, 0x17, 0x1a, 0xd3, 0x00, 0x7d, 0x19, 0x2a, 0xd0, - 0x21, 0xcc, 0x94, 0xb4, 0x1b, 0xcf, 0x60, 0xe2, 0xde, 0x03, 0x78, 0x92, 0x2e, 0xbb, 0x34, 0x2e, - 0xaa, 0x69, 0x2f, 0x62, 0x06, 0x9a, 0x06, 0xc5, 0x98, 0x34, 0xff, 0x15, 0x33, 0x3f, 0x98, 0xf7, - 0xbe, 0xef, 0xe3, 0x0d, 0x36, 0x58, 0x19, 0xc6, 0x19, 0x90, 0x6a, 0x4a, 0x2a, 0x26, 0xc0, 0x2b, - 0x4a, 0x26, 0x98, 0xde, 0x6f, 0xa8, 0x57, 0x4d, 0x1f, 0x18, 0x94, 0x51, 0x56, 0x53, 0x22, 0x57, - 0xcd, 0x07, 0xce, 0x06, 0x8f, 0x66, 0x9b, 0x38, 0x09, 0x57, 0x14, 0x82, 0x50, 0xc0, 0xab, 0x12, - 0xe4, 0x69, 0x5d, 0xc7, 0xbd, 0x24, 0xe4, 0x89, 0x89, 0x6c, 0xe4, 0x0e, 0x83, 0x7a, 0xad, 0x1b, - 0xf8, 0xd6, 0x02, 0x56, 0x2c, 0x37, 0x55, 0x1b, 0xb9, 0xfd, 0xa0, 0xd9, 0x48, 0x2a, 0x4f, 0x94, - 0xa6, 0xd6, 0xd0, 0x7a, 0xa3, 0x3f, 0xc2, 0x43, 0xbe, 0x8e, 0xf2, 0xa5, 0x98, 0x47, 0x19, 0x8b, - 0x53, 0xb3, 0x67, 0x23, 0x57, 0x0b, 0x06, 0x0d, 0xf3, 0x25, 0x72, 0xbe, 0x20, 0x7c, 0xb7, 0xdd, - 0xfa, 0xad, 0xec, 0xfb, 0x1a, 0xdf, 0x81, 0x33, 0x9b, 0x97, 0xa1, 0x80, 0x5a, 0x40, 0xdf, 0xf7, - 0x76, 0x87, 0x89, 0xf2, 0xe3, 0x30, 0x79, 0x4c, 0x97, 0x22, 0x59, 0x47, 0x5e, 0xcc, 0x72, 0x12, - 0x33, 0x9e, 0x33, 0x7e, 0x7e, 0x3c, 0xe5, 0x8b, 0x94, 0x88, 0x6d, 0x01, 0xdc, 0x7b, 0x09, 0x71, - 0x30, 0x84, 0x56, 0xe1, 0x6b, 0x84, 0x3b, 0x29, 0x1e, 0xbf, 0xa0, 0xb4, 0x04, 0x1a, 0x0a, 0xb8, - 0x22, 0x98, 0xa6, 0x92, 0xfa, 0xbf, 0x08, 0xb4, 0x6e, 0x04, 0x9f, 0xf0, 0xbd, 0x76, 0x8f, 0x37, - 0xeb, 0x22, 0x6b, 0xa9, 0x45, 0x6d, 0xb5, 0x9d, 0x60, 0xd4, 0x9b, 0x07, 0xe3, 0x7c, 0x45, 0xf8, - 0xfe, 0x3f, 0xdd, 0xd6, 0xff, 0xe2, 0x62, 0x0b, 0xb5, 0x6d, 0xa5, 0xd8, 0xf8, 0x43, 0xc8, 0x5c, - 0x48, 0xd5, 0xdc, 0x54, 0x6d, 0xcd, 0x1d, 0x3c, 0x1b, 0x7b, 0x97, 0x81, 0xf3, 0x3a, 0xd6, 0xfc, - 0x87, 0x52, 0xed, 0xb7, 0x9f, 0x93, 0xd1, 0xfb, 0x0f, 0x9d, 0x97, 0x81, 0x0e, 0x7f, 0x23, 0xee, - 0xcf, 0x76, 0x47, 0x0b, 0xed, 0x8f, 0x16, 0xfa, 0x75, 0xb4, 0xd0, 0xe7, 0x93, 0xa5, 0xec, 0x4f, - 0x96, 0xf2, 0xfd, 0x64, 0x29, 0xef, 0x9e, 0xb4, 0x0c, 0x17, 0x40, 0xe9, 0xf6, 0x63, 0x45, 0x38, - 0xcb, 0x73, 0xc8, 0x96, 0x50, 0x92, 0x0d, 0x39, 0xdf, 0x86, 0xda, 0x79, 0x74, 0xbb, 0x9e, 0xf5, - 0xe7, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xbc, 0xa6, 0x70, 0xc9, 0x24, 0x03, 0x00, 0x00, +func init() { proto.RegisterFile("oracle/v1/oracle.proto", fileDescriptor_652b57db11528d07) } + +var fileDescriptor_652b57db11528d07 = []byte{ + // 711 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcd, 0x6e, 0xd3, 0x4a, + 0x18, 0x8d, 0x9b, 0x36, 0xf7, 0x66, 0xd2, 0x5e, 0xdd, 0xeb, 0xe6, 0x16, 0x53, 0xaa, 0xb8, 0x58, + 0x02, 0x55, 0x42, 0xc4, 0x2a, 0xdd, 0x55, 0x42, 0x02, 0xf7, 0x87, 0x15, 0x52, 0x64, 0x55, 0x45, + 0x62, 0x63, 0x8d, 0xed, 0xc1, 0x1e, 0x6a, 0x7b, 0xa2, 0x99, 0x49, 0xd2, 0x6e, 0x58, 0xf1, 0x00, + 0xf0, 0x0a, 0xb0, 0x83, 0x17, 0xe9, 0xb2, 0x2b, 0x84, 0x58, 0x04, 0xd4, 0xbe, 0x41, 0x9e, 0x00, + 0xcd, 0x4f, 0xa9, 0x23, 0x22, 0xa8, 0xc5, 0x2a, 0x73, 0xbe, 0x6f, 0xe6, 0x9c, 0x93, 0x33, 0xdf, + 0xc8, 0x60, 0x85, 0x50, 0x18, 0x65, 0xc8, 0x1d, 0x6e, 0xba, 0x6a, 0xd5, 0xed, 0x53, 0xc2, 0x89, + 0xd9, 0xd4, 0x68, 0xb8, 0xb9, 0xda, 0x4e, 0x48, 0x42, 0x64, 0xd5, 0x15, 0x2b, 0xb5, 0x61, 0xb5, + 0x13, 0x11, 0x96, 0x13, 0xe6, 0x86, 0x90, 0x89, 0xd3, 0x21, 0xe2, 0x70, 0xd3, 0x8d, 0x08, 0x2e, + 0x54, 0xdf, 0x79, 0x08, 0x16, 0x76, 0x32, 0x88, 0x73, 0x73, 0x05, 0x34, 0x46, 0x08, 0x27, 0x29, + 0xb7, 0x8c, 0x75, 0x63, 0xa3, 0xee, 0x6b, 0x64, 0xae, 0x81, 0x26, 0x45, 0x11, 0xee, 0x63, 0x54, + 0x70, 0x6b, 0x6e, 0xdd, 0xd8, 0x68, 0xfa, 0x57, 0x05, 0xe7, 0xad, 0x01, 0x96, 0xf7, 0x8e, 0xa3, + 0x14, 0x16, 0x09, 0xf2, 0x21, 0x47, 0x3d, 0x8a, 0x86, 0x84, 0x23, 0xd3, 0x04, 0xf3, 0x29, 0x64, + 0xa9, 0xe4, 0x5a, 0xf4, 0xe5, 0xda, 0x6c, 0x83, 0x85, 0x18, 0x15, 0x24, 0xd7, 0x2c, 0x0a, 0x88, + 0xaa, 0x38, 0x41, 0xad, 0xba, 0xaa, 0x4a, 0x60, 0x6e, 0x83, 0x45, 0x36, 0x08, 0x73, 0xcc, 0x83, + 0x30, 0x23, 0xd1, 0x91, 0x35, 0x2f, 0x3c, 0x79, 0x37, 0x26, 0x63, 0x7b, 0xf9, 0x04, 0xe6, 0xd9, + 0xb6, 0x53, 0xee, 0x3a, 0x7e, 0x4b, 0x41, 0x4f, 0xa2, 0x8f, 0x06, 0xf8, 0xb7, 0xec, 0xe9, 0x50, + 0x18, 0x3a, 0x02, 0x4b, 0x48, 0xd7, 0x02, 0x0a, 0x39, 0x92, 0xce, 0x9a, 0xde, 0xfe, 0xe9, 0xd8, + 0xae, 0x7d, 0x19, 0xdb, 0x77, 0x13, 0xcc, 0xd3, 0x41, 0xd8, 0x8d, 0x48, 0xee, 0xea, 0xc4, 0xd4, + 0xcf, 0x7d, 0x16, 0x1f, 0xb9, 0xfc, 0xa4, 0x8f, 0x58, 0x77, 0x17, 0x45, 0x93, 0xb1, 0xdd, 0x56, + 0xfa, 0x53, 0x64, 0x8e, 0xbf, 0x88, 0x4a, 0x82, 0x55, 0xfe, 0xa9, 0xf3, 0xda, 0x00, 0x6b, 0x8f, + 0x93, 0x84, 0xa2, 0x04, 0x72, 0x54, 0x21, 0x4a, 0x45, 0x35, 0xf7, 0xab, 0xd0, 0xea, 0x15, 0x42, + 0xfb, 0x64, 0x80, 0x9b, 0x33, 0x6d, 0xc8, 0xf4, 0x7e, 0xe8, 0x19, 0x65, 0xbd, 0x77, 0x06, 0x68, + 0x4f, 0xe5, 0x10, 0xf0, 0x41, 0x3f, 0x43, 0xcc, 0x9a, 0x5b, 0xaf, 0x6f, 0xb4, 0x1e, 0xac, 0x75, + 0x55, 0x84, 0x5d, 0x31, 0x7b, 0x5d, 0x3d, 0x7b, 0x22, 0xc5, 0x1d, 0x82, 0x0b, 0xcf, 0x17, 0xc9, + 0x4f, 0xc6, 0xf6, 0xad, 0x19, 0x79, 0x6a, 0x1e, 0xe7, 0xc3, 0x57, 0xfb, 0xde, 0xf5, 0x2e, 0x46, + 0x50, 0x32, 0xdf, 0x2c, 0xdf, 0xc2, 0x81, 0xe2, 0x78, 0xdf, 0x00, 0x8d, 0x1e, 0xa4, 0x30, 0x67, + 0xe6, 0x23, 0xd0, 0x12, 0xc6, 0x83, 0x3e, 0xa2, 0x98, 0xc4, 0x6a, 0xce, 0x3d, 0xfb, 0x37, 0x1e, + 0x7c, 0x20, 0xce, 0xf4, 0xe4, 0x11, 0xb3, 0x00, 0xff, 0x48, 0x06, 0x9e, 0x52, 0xc4, 0x52, 0x92, + 0xc5, 0xea, 0x02, 0xbc, 0x27, 0x95, 0xc7, 0xe8, 0x7f, 0x25, 0x39, 0xcd, 0xe6, 0xf8, 0x4b, 0xa2, + 0x70, 0x70, 0x89, 0x4d, 0x04, 0x5a, 0x14, 0x8d, 0x20, 0x8d, 0x83, 0x10, 0x16, 0xb1, 0x1a, 0x1c, + 0x6f, 0xb7, 0xb2, 0x98, 0xa9, 0xc4, 0x4a, 0x54, 0x8e, 0x0f, 0x14, 0xf2, 0x60, 0x11, 0x9b, 0x11, + 0x58, 0xd5, 0xbd, 0x18, 0x33, 0x4e, 0x71, 0x38, 0xe0, 0x98, 0x14, 0xc1, 0x08, 0x17, 0x31, 0x19, + 0xe9, 0xb7, 0x77, 0x67, 0x32, 0xb6, 0x6f, 0x4f, 0xf1, 0xcc, 0xd8, 0xeb, 0xf8, 0x96, 0x6a, 0xee, + 0x96, 0x7a, 0xcf, 0x64, 0xcb, 0x24, 0xa0, 0x39, 0x4a, 0x31, 0x47, 0x19, 0x66, 0xdc, 0x5a, 0xb8, + 0xc6, 0x84, 0x6c, 0x89, 0xff, 0x59, 0x75, 0x04, 0xae, 0x34, 0xc4, 0x65, 0xb1, 0x0c, 0xb2, 0x34, + 0x78, 0x41, 0x61, 0x24, 0x8c, 0x58, 0x8d, 0x3f, 0xbb, 0xac, 0x69, 0x36, 0xc7, 0x5f, 0x92, 0x85, + 0x7d, 0x8d, 0xe5, 0xf3, 0x93, 0x3b, 0x74, 0x6e, 0x7f, 0xfd, 0xf4, 0xfc, 0x4a, 0x5d, 0xf1, 0xfc, + 0x04, 0xd4, 0xe1, 0xbc, 0x02, 0xed, 0x1c, 0x17, 0xc1, 0x10, 0x66, 0x38, 0x16, 0xf3, 0x79, 0xc9, + 0xf1, 0xb7, 0x74, 0xfc, 0xb4, 0xb2, 0x63, 0x3d, 0xd1, 0xb3, 0x38, 0x1d, 0xff, 0xbf, 0x1c, 0x17, + 0x87, 0xa2, 0xda, 0x43, 0x54, 0xe9, 0x7b, 0x7b, 0xa7, 0xe7, 0x1d, 0xe3, 0xec, 0xbc, 0x63, 0x7c, + 0x3b, 0xef, 0x18, 0x6f, 0x2e, 0x3a, 0xb5, 0xb3, 0x8b, 0x4e, 0xed, 0xf3, 0x45, 0xa7, 0xf6, 0xbc, + 0x9c, 0x7e, 0x1f, 0x25, 0xc9, 0xc9, 0xcb, 0xa1, 0xcb, 0x48, 0x9e, 0xa3, 0x0c, 0x23, 0xea, 0x1e, + 0xeb, 0xcf, 0x91, 0x12, 0x0f, 0x1b, 0xf2, 0xa3, 0xb2, 0xf5, 0x3d, 0x00, 0x00, 0xff, 0xff, 0x1a, + 0xb6, 0xcb, 0x80, 0xaf, 0x06, 0x00, 0x00, +} + +func (m *Claim) 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 *Claim) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Claim) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Recipient) > 0 { + i -= len(m.Recipient) + copy(dAtA[i:], m.Recipient) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Recipient))) + i-- + dAtA[i] = 0x12 + } + if m.Weight != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.Weight)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil } func (m *ExchangeRatePrevote) Marshal() (dAtA []byte, err error) { @@ -367,28 +505,28 @@ func (m *ExchangeRatePrevote) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if m.SubmitBlock != 0 { - i = encodeVarintVote(dAtA, i, uint64(m.SubmitBlock)) + i = encodeVarintOracle(dAtA, i, uint64(m.SubmitBlock)) i-- dAtA[i] = 0x20 } if len(m.Voter) > 0 { i -= len(m.Voter) copy(dAtA[i:], m.Voter) - i = encodeVarintVote(dAtA, i, uint64(len(m.Voter))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Voter))) i-- dAtA[i] = 0x1a } if len(m.Denom) > 0 { i -= len(m.Denom) copy(dAtA[i:], m.Denom) - i = encodeVarintVote(dAtA, i, uint64(len(m.Denom))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Denom))) i-- dAtA[i] = 0x12 } if len(m.Hash) > 0 { i -= len(m.Hash) copy(dAtA[i:], m.Hash) - i = encodeVarintVote(dAtA, i, uint64(len(m.Hash))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Hash))) i-- dAtA[i] = 0xa } @@ -418,14 +556,14 @@ func (m *ExchangeRateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.Voter) > 0 { i -= len(m.Voter) copy(dAtA[i:], m.Voter) - i = encodeVarintVote(dAtA, i, uint64(len(m.Voter))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Voter))) i-- dAtA[i] = 0x1a } if len(m.Denom) > 0 { i -= len(m.Denom) copy(dAtA[i:], m.Denom) - i = encodeVarintVote(dAtA, i, uint64(len(m.Denom))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Denom))) i-- dAtA[i] = 0x12 } @@ -435,7 +573,7 @@ func (m *ExchangeRateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { if _, err := m.ExchangeRate.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i = encodeVarintVote(dAtA, i, uint64(size)) + i = encodeVarintOracle(dAtA, i, uint64(size)) } i-- dAtA[i] = 0xa @@ -463,28 +601,28 @@ func (m *AggregateExchangeRatePrevote) MarshalToSizedBuffer(dAtA []byte) (int, e var l int _ = l if m.SubmitBlock != 0 { - i = encodeVarintVote(dAtA, i, uint64(m.SubmitBlock)) + i = encodeVarintOracle(dAtA, i, uint64(m.SubmitBlock)) i-- dAtA[i] = 0x18 } if len(m.Voter) > 0 { i -= len(m.Voter) copy(dAtA[i:], m.Voter) - i = encodeVarintVote(dAtA, i, uint64(len(m.Voter))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Voter))) i-- dAtA[i] = 0x12 } if len(m.Hash) > 0 { i -= len(m.Hash) copy(dAtA[i:], m.Hash) - i = encodeVarintVote(dAtA, i, uint64(len(m.Hash))) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Hash))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *ExchangeRateTuple) Marshal() (dAtA []byte, err error) { +func (m *AggregateExchangeRateVote) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -494,37 +632,41 @@ func (m *ExchangeRateTuple) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ExchangeRateTuple) MarshalTo(dAtA []byte) (int, error) { +func (m *AggregateExchangeRateVote) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ExchangeRateTuple) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *AggregateExchangeRateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size := m.ExchangeRate.Size() - i -= size - if _, err := m.ExchangeRate.MarshalTo(dAtA[i:]); err != nil { - return 0, err + if len(m.ExchangeRateTuples) > 0 { + for iNdEx := len(m.ExchangeRateTuples) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ExchangeRateTuples[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - i = encodeVarintVote(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x12 - if len(m.Denom) > 0 { - i -= len(m.Denom) - copy(dAtA[i:], m.Denom) - i = encodeVarintVote(dAtA, i, uint64(len(m.Denom))) + if len(m.Voter) > 0 { + i -= len(m.Voter) + copy(dAtA[i:], m.Voter) + i = encodeVarintOracle(dAtA, i, uint64(len(m.Voter))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *AggregateExchangeRateVote) Marshal() (dAtA []byte, err error) { +func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -534,42 +676,90 @@ func (m *AggregateExchangeRateVote) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *AggregateExchangeRateVote) MarshalTo(dAtA []byte) (int, error) { +func (m *Params) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *AggregateExchangeRateVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.ExchangeRateTuples) > 0 { - for iNdEx := len(m.ExchangeRateTuples) - 1; iNdEx >= 0; iNdEx-- { + { + size := m.MinValidPerWindow.Size() + i -= size + if _, err := m.MinValidPerWindow.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if m.SlashWindow != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.SlashWindow)) + i-- + dAtA[i] = 0x38 + } + { + size := m.SlashFraction.Size() + i -= size + if _, err := m.SlashFraction.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.Whitelist) > 0 { + for iNdEx := len(m.Whitelist) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.ExchangeRateTuples[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Whitelist[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } i -= size - i = encodeVarintVote(dAtA, i, uint64(size)) + i = encodeVarintOracle(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x2a } } - if len(m.Voter) > 0 { - i -= len(m.Voter) - copy(dAtA[i:], m.Voter) - i = encodeVarintVote(dAtA, i, uint64(len(m.Voter))) + if m.RewardDistributionWindow != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.RewardDistributionWindow)) i-- - dAtA[i] = 0xa + dAtA[i] = 0x20 + } + { + size := m.RewardBand.Size() + i -= size + if _, err := m.RewardBand.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.VoteThreshold.Size() + i -= size + if _, err := m.VoteThreshold.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintOracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.VotePeriod != 0 { + i = encodeVarintOracle(dAtA, i, uint64(m.VotePeriod)) + i-- + dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func encodeVarintVote(dAtA []byte, offset int, v uint64) int { - offset -= sovVote(v) +func encodeVarintOracle(dAtA []byte, offset int, v uint64) int { + offset -= sovOracle(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -579,6 +769,22 @@ func encodeVarintVote(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Claim) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Weight != 0 { + n += 1 + sovOracle(uint64(m.Weight)) + } + l = len(m.Recipient) + if l > 0 { + n += 1 + l + sovOracle(uint64(l)) + } + return n +} + func (m *ExchangeRatePrevote) Size() (n int) { if m == nil { return 0 @@ -587,18 +793,18 @@ func (m *ExchangeRatePrevote) Size() (n int) { _ = l l = len(m.Hash) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } l = len(m.Denom) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } l = len(m.Voter) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } if m.SubmitBlock != 0 { - n += 1 + sovVote(uint64(m.SubmitBlock)) + n += 1 + sovOracle(uint64(m.SubmitBlock)) } return n } @@ -610,14 +816,14 @@ func (m *ExchangeRateVote) Size() (n int) { var l int _ = l l = m.ExchangeRate.Size() - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) l = len(m.Denom) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } l = len(m.Voter) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } return n } @@ -630,57 +836,178 @@ func (m *AggregateExchangeRatePrevote) Size() (n int) { _ = l l = len(m.Hash) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } l = len(m.Voter) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } if m.SubmitBlock != 0 { - n += 1 + sovVote(uint64(m.SubmitBlock)) + n += 1 + sovOracle(uint64(m.SubmitBlock)) } return n } -func (m *ExchangeRateTuple) Size() (n int) { +func (m *AggregateExchangeRateVote) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Denom) + l = len(m.Voter) if l > 0 { - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) + } + if len(m.ExchangeRateTuples) > 0 { + for _, e := range m.ExchangeRateTuples { + l = e.Size() + n += 1 + l + sovOracle(uint64(l)) + } } - l = m.ExchangeRate.Size() - n += 1 + l + sovVote(uint64(l)) return n } -func (m *AggregateExchangeRateVote) Size() (n int) { +func (m *Params) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.Voter) - if l > 0 { - n += 1 + l + sovVote(uint64(l)) - } - if len(m.ExchangeRateTuples) > 0 { - for _, e := range m.ExchangeRateTuples { + if m.VotePeriod != 0 { + n += 1 + sovOracle(uint64(m.VotePeriod)) + } + l = m.VoteThreshold.Size() + n += 1 + l + sovOracle(uint64(l)) + l = m.RewardBand.Size() + n += 1 + l + sovOracle(uint64(l)) + if m.RewardDistributionWindow != 0 { + n += 1 + sovOracle(uint64(m.RewardDistributionWindow)) + } + if len(m.Whitelist) > 0 { + for _, e := range m.Whitelist { l = e.Size() - n += 1 + l + sovVote(uint64(l)) + n += 1 + l + sovOracle(uint64(l)) } } + l = m.SlashFraction.Size() + n += 1 + l + sovOracle(uint64(l)) + if m.SlashWindow != 0 { + n += 1 + sovOracle(uint64(m.SlashWindow)) + } + l = m.MinValidPerWindow.Size() + n += 1 + l + sovOracle(uint64(l)) return n } -func sovVote(x uint64) (n int) { +func sovOracle(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozVote(x uint64) (n int) { - return sovVote(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozOracle(x uint64) (n int) { + return sovOracle(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Claim) 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 ErrIntOverflowOracle + } + 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: Claim: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Claim: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Weight", wireType) + } + m.Weight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Weight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Recipient", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Recipient = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipOracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthOracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -690,7 +1017,7 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -718,7 +1045,7 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -731,11 +1058,11 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -752,7 +1079,7 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -766,11 +1093,11 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -784,7 +1111,7 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -798,11 +1125,11 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -816,7 +1143,7 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { m.SubmitBlock = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -830,15 +1157,15 @@ func (m *ExchangeRatePrevote) Unmarshal(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skipVote(dAtA[iNdEx:]) + skippy, err := skipOracle(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -860,7 +1187,7 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -888,7 +1215,7 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -902,11 +1229,11 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -922,7 +1249,7 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -936,11 +1263,11 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -954,7 +1281,7 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -968,11 +1295,11 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -981,15 +1308,15 @@ func (m *ExchangeRateVote) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipVote(dAtA[iNdEx:]) + skippy, err := skipOracle(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1011,7 +1338,7 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1039,7 +1366,7 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1052,11 +1379,11 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -1073,7 +1400,7 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1087,11 +1414,11 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF @@ -1105,7 +1432,7 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { m.SubmitBlock = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1119,15 +1446,15 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } default: iNdEx = preIndex - skippy, err := skipVote(dAtA[iNdEx:]) + skippy, err := skipOracle(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1141,7 +1468,7 @@ func (m *AggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } return nil } -func (m *ExchangeRateTuple) Unmarshal(dAtA []byte) error { +func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1149,7 +1476,7 @@ func (m *ExchangeRateTuple) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1164,20 +1491,20 @@ func (m *ExchangeRateTuple) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ExchangeRateTuple: wiretype end group for non-group") + return fmt.Errorf("proto: AggregateExchangeRateVote: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ExchangeRateTuple: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: AggregateExchangeRateVote: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Voter", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1191,62 +1518,62 @@ func (m *ExchangeRateTuple) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - m.Denom = string(dAtA[iNdEx:postIndex]) + m.Voter = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRate", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRateTuples", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthVote + if msglen < 0 { + return ErrInvalidLengthOracle } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.ExchangeRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ExchangeRateTuples = append(m.ExchangeRateTuples, types.DecCoin{}) + if err := m.ExchangeRateTuples[len(m.ExchangeRateTuples)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipVote(dAtA[iNdEx:]) + skippy, err := skipOracle(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1260,7 +1587,7 @@ func (m *ExchangeRateTuple) Unmarshal(dAtA []byte) error { } return nil } -func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { +func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1268,7 +1595,7 @@ func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1283,20 +1610,39 @@ func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: AggregateExchangeRateVote: wiretype end group for non-group") + return fmt.Errorf("proto: Params: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: AggregateExchangeRateVote: illegal tag %d (wire type %d)", fieldNum, wire) + 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 VotePeriod", wireType) + } + m.VotePeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotePeriod |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Voter", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field VoteThreshold", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1310,25 +1656,80 @@ func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - m.Voter = string(dAtA[iNdEx:postIndex]) + if err := m.VoteThreshold.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 2: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ExchangeRateTuples", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardBand", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RewardBand.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardDistributionWindow", wireType) + } + m.RewardDistributionWindow = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RewardDistributionWindow |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Whitelist", wireType) } var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowVote + return ErrIntOverflowOracle } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1341,31 +1742,118 @@ func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } } if msglen < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } postIndex := iNdEx + msglen if postIndex < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if postIndex > l { return io.ErrUnexpectedEOF } - m.ExchangeRateTuples = append(m.ExchangeRateTuples, ExchangeRateTuple{}) - if err := m.ExchangeRateTuples[len(m.ExchangeRateTuples)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Whitelist = append(m.Whitelist, types.DecCoin{}) + if err := m.Whitelist[len(m.Whitelist)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SlashFraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SlashFraction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SlashWindow", wireType) + } + m.SlashWindow = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SlashWindow |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinValidPerWindow", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowOracle + } + 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 ErrInvalidLengthOracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthOracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinValidPerWindow.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipVote(dAtA[iNdEx:]) + skippy, err := skipOracle(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthVote + return ErrInvalidLengthOracle } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1379,7 +1867,7 @@ func (m *AggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } return nil } -func skipVote(dAtA []byte) (n int, err error) { +func skipOracle(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -1387,7 +1875,7 @@ func skipVote(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowVote + return 0, ErrIntOverflowOracle } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1404,7 +1892,7 @@ func skipVote(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowVote + return 0, ErrIntOverflowOracle } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1420,7 +1908,7 @@ func skipVote(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowVote + return 0, ErrIntOverflowOracle } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1433,14 +1921,14 @@ func skipVote(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthVote + return 0, ErrInvalidLengthOracle } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupVote + return 0, ErrUnexpectedEndOfGroupOracle } depth-- case 5: @@ -1449,7 +1937,7 @@ func skipVote(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthVote + return 0, ErrInvalidLengthOracle } if depth == 0 { return iNdEx, nil @@ -1459,7 +1947,7 @@ func skipVote(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthVote = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowVote = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupVote = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthOracle = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowOracle = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupOracle = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 460f784e..473d78a8 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -53,11 +53,12 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultTobinTax = sdk.NewDecWithPrec(25, 4) // 0.25% - DefaultWhitelist = DenomList{ - {Name: MicroKRWDenom, TobinTax: DefaultTobinTax}, - {Name: MicroSDRDenom, TobinTax: DefaultTobinTax}, - {Name: MicroUSDDenom, TobinTax: DefaultTobinTax}, - {Name: MicroMNTDenom, TobinTax: DefaultTobinTax.MulInt64(8)}} + // TODO: need a better default whitelist + DefaultWhitelist = sdk.NewDecCoins( + sdk.NewDecCoinFromDec(MicroKRWDenom, DefaultTobinTax), + sdk.NewDecCoinFromDec(MicroSDRDenom, DefaultTobinTax), + sdk.NewDecCoinFromDec(MicroUSDDenom, DefaultTobinTax), + sdk.NewDecCoinFromDec(MicroMNTDenom, DefaultTobinTax.MulInt64(8))) DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% ) @@ -99,42 +100,35 @@ func ParamKeyTable() paramtypes.KeyTable { // ValidateBasic performs basic validation on oracle parameters. func (p Params) ValidateBasic() error { - if p.VotePeriod <= 0 { - return fmt.Errorf("oracle parameter VotePeriod must be > 0, is %d", p.VotePeriod) - } - if p.VoteThreshold.LTE(sdk.NewDecWithPrec(33, 2)) { - return fmt.Errorf("oracle parameter VoteTheshold must be greater than 33 percent") + if err := validateVotePeriod(p.VotePeriod); err != nil { + return err } - if p.RewardBand.IsNegative() || p.RewardBand.GT(sdk.OneDec()) { - return fmt.Errorf("oracle parameter RewardBand must be between [0, 1]") + if err := validateVoteThreshold(p.VoteThreshold); err != nil { + return err } - if p.RewardDistributionWindow < p.VotePeriod { - return fmt.Errorf("oracle parameter RewardDistributionWindow must be greater than or equal with votes period") + if err := validateRewardBand(p.RewardBand); err != nil { + return err } - if p.SlashFraction.GT(sdk.OneDec()) || p.SlashFraction.IsNegative() { - return fmt.Errorf("oracle parameter SlashRraction must be between [0, 1]") + if err := validateSlashFraction(p.SlashFraction); err != nil { + return err } - if p.SlashWindow < p.VotePeriod { - return fmt.Errorf("oracle parameter SlashWindow must be greater than or equal with votes period") + if err := validateMinValidPerWindow(p.MinValidPerWindow); err != nil { + return err } - if p.MinValidPerWindow.GT(sdk.NewDecWithPrec(5, 1)) || p.MinValidPerWindow.IsNegative() { - return fmt.Errorf("oracle parameter MinValidPerWindow must be between [0, 0.5]") + if p.RewardDistributionWindow < p.VotePeriod { + return fmt.Errorf("oracle RewardDistributionWindow parameter must be ≥ VotePeriod parameter") } - for _, denom := range p.Whitelist { - if denom.TobinTax.LT(sdk.ZeroDec()) || denom.TobinTax.GT(sdk.OneDec()) { - return fmt.Errorf("oracle parameter Whitelist Denom must have TobinTax between [0, 1]") - } - if len(denom.Name) == 0 { - return fmt.Errorf("oracle parameter Whitelist Denom must have name") - } + if p.SlashWindow < p.VotePeriod { + return fmt.Errorf("oracle SlashWindow parameter must be ≥ VotePeriod parameter") } - return nil + + return validateWhitelist(p.Whitelist) } func validateVotePeriod(i interface{}) error { @@ -156,12 +150,8 @@ func validateVoteThreshold(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } - if v.LT(sdk.NewDecWithPrec(33, 2)) { - return fmt.Errorf("vote threshold must be bigger than 33%%: %s", v) - } - - if v.GT(sdk.OneDec()) { - return fmt.Errorf("vote threshold too large: %s", v) + if v.LT(sdk.NewDecWithPrec(33, 2)) || v.GT(sdk.OneDec()) { + return fmt.Errorf("reward band must be between [0.33, 1], got %s", v) } return nil @@ -173,12 +163,8 @@ func validateRewardBand(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } - if v.IsNegative() { - return fmt.Errorf("reward band must be positive: %s", v) - } - - if v.GT(sdk.OneDec()) { - return fmt.Errorf("reward band is too large: %s", v) + if v.IsNegative() || v.GT(sdk.OneDec()) { + return fmt.Errorf("reward band must be between [0, 1], got %s", v) } return nil @@ -198,21 +184,18 @@ func validateRewardDistributionWindow(i interface{}) error { } func validateWhitelist(i interface{}) error { - v, ok := i.([]Denom) + v, ok := i.(sdk.DecCoins) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } for _, d := range v { - if d.TobinTax.LT(sdk.ZeroDec()) || d.TobinTax.GT(sdk.OneDec()) { - return fmt.Errorf("oracle parameter Whitelist Denom must have TobinTax between [0, 1]") - } - if len(d.Name) == 0 { - return fmt.Errorf("oracle parameter Whitelist Denom must have name") + if d.Amount.LT(sdk.ZeroDec()) || d.Amount.GT(sdk.OneDec()) { + return fmt.Errorf("whitelist denom must have TobinTax between [0, 1]") } } - return nil + return v.Validate() } func validateSlashFraction(i interface{}) error { @@ -221,12 +204,8 @@ func validateSlashFraction(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } - if v.IsNegative() { - return fmt.Errorf("slash fraction must be positive: %s", v) - } - - if v.GT(sdk.OneDec()) { - return fmt.Errorf("slash fraction is too large: %s", v) + if v.GT(sdk.OneDec()) || v.IsNegative() { + return fmt.Errorf("slash fraction must be between [0, 1], got %s", v) } return nil @@ -251,12 +230,8 @@ func validateMinValidPerWindow(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } - if v.IsNegative() { - return fmt.Errorf("min valid per window must be positive: %s", v) - } - - if v.GT(sdk.NewDecWithPrec(5, 1)) { - return fmt.Errorf("min valid per window is too large: %s", v) + if v.GT(sdk.NewDecWithPrec(5, 1)) || v.IsNegative() { + return fmt.Errorf("min valid perWindow must be between [0, 0.5], got %s", v) } return nil diff --git a/x/oracle/types/params_test.go b/x/oracle/types/params_test.go index 7400c50b..db2d6553 100644 --- a/x/oracle/types/params_test.go +++ b/x/oracle/types/params_test.go @@ -56,13 +56,13 @@ func TestParamsEqual(t *testing.T) { // non-positive tobin tax p8 := DefaultParams() - p8.Whitelist[0].TobinTax = sdk.NewDec(-1) + p8.Whitelist[0].Amount = sdk.NewDec(-1) err = p8.ValidateBasic() require.Error(t, err) // empty name p9 := DefaultParams() - p9.Whitelist[0].Name = "" + p9.Whitelist[0].Denom = "" err = p9.ValidateBasic() require.Error(t, err) diff --git a/x/oracle/types/querier.go b/x/oracle/types/querier.go deleted file mode 100644 index b8297926..00000000 --- a/x/oracle/types/querier.go +++ /dev/null @@ -1,112 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// Defines the prefix of each query path -const ( - QueryParameters = "parameters" - QueryExchangeRate = "exchangeRate" - QueryExchangeRates = "exchangeRates" - QueryActives = "actives" - QueryPrevotes = "prevotes" - QueryVotes = "votes" - QueryFeederDelegation = "feederDelegation" - QueryMissCounter = "missCounter" - QueryAggregatePrevote = "aggregatePrevote" - QueryAggregateVote = "aggregateVote" - QueryVoteTargets = "voteTargets" - QueryTobinTax = "tobinTax" - QueryTobinTaxes = "tobinTaxes" -) - -// QueryExchangeRateParams defines the params for the following queries: -// - 'custom/oracle/exchange_rate' -type QueryExchangeRateParams struct { - Denom string `json:"denom"` -} - -// NewQueryExchangeRateParams returns params for exchange_rate query -func NewQueryExchangeRateParams(denom string) QueryExchangeRateParams { - return QueryExchangeRateParams{denom} -} - -// QueryPrevotesParams defines the params for the following queries: -// - 'custom/oracle/prevotes' -type QueryPrevotesParams struct { - Voter sdk.ValAddress `json:"voter"` - Denom string `json:"denom"` -} - -// NewQueryPrevotesParams returns params for exchange_rate prevotes query -func NewQueryPrevotesParams(voter sdk.ValAddress, denom string) QueryPrevotesParams { - return QueryPrevotesParams{voter, denom} -} - -// QueryVotesParams defines the params for the following queries: -// - 'custom/oracle/votes' -type QueryVotesParams struct { - Voter sdk.ValAddress `json:"voter"` - Denom string `json:"denom"` -} - -// NewQueryVotesParams returns params for exchange_rate votes query -func NewQueryVotesParams(voter sdk.ValAddress, denom string) QueryVotesParams { - return QueryVotesParams{voter, denom} -} - -// QueryFeederDelegationParams defeins the params for the following queries: -// - 'custom/oracle/feederDelegation' -type QueryFeederDelegationParams struct { - Validator sdk.ValAddress `json:"validator"` -} - -// NewQueryFeederDelegationParams returns params for feeder delegation query -func NewQueryFeederDelegationParams(validator sdk.ValAddress) QueryFeederDelegationParams { - return QueryFeederDelegationParams{validator} -} - -// QueryMissCounterParams defines the params for the following queries: -// - 'custom/oracle/missCounter' -type QueryMissCounterParams struct { - Validator sdk.ValAddress `json:"validator"` -} - -// NewQueryMissCounterParams returns params for feeder delegation query -func NewQueryMissCounterParams(validator sdk.ValAddress) QueryMissCounterParams { - return QueryMissCounterParams{validator} -} - -// QueryAggregatePrevoteParams defines the params for the following queries: -// - 'custom/oracle/aggregatePrevote' -type QueryAggregatePrevoteParams struct { - Validator sdk.ValAddress `json:"validator"` -} - -// NewQueryAggregatePrevoteParams returns params for feeder delegation query -func NewQueryAggregatePrevoteParams(validator sdk.ValAddress) QueryAggregatePrevoteParams { - return QueryAggregatePrevoteParams{validator} -} - -// QueryAggregateVoteParams defines the params for the following queries: -// - 'custom/oracle/aggregateVote' -type QueryAggregateVoteParams struct { - Validator sdk.ValAddress `json:"validator"` -} - -// NewQueryAggregateVoteParams returns params for feeder delegation query -func NewQueryAggregateVoteParams(validator sdk.ValAddress) QueryAggregateVoteParams { - return QueryAggregateVoteParams{validator} -} - -// QueryTobinTaxParams defines the params for the following queries: -// - 'custom/oracle/tobinTax' -type QueryTobinTaxParams struct { - Denom string `json:"denom"` -} - -// NewQueryTobinTaxParams returns params for tobin tax query -func NewQueryTobinTaxParams(denom string) QueryTobinTaxParams { - return QueryTobinTaxParams{denom} -} diff --git a/x/oracle/types/query.pb.go b/x/oracle/types/query.pb.go index 8943fbe3..7f1ccce0 100644 --- a/x/oracle/types/query.pb.go +++ b/x/oracle/types/query.pb.go @@ -973,70 +973,70 @@ func init() { func init() { proto.RegisterFile("oracle/v1/query.proto", fileDescriptor_34238c8dfdfcd7ec) } var fileDescriptor_34238c8dfdfcd7ec = []byte{ - // 1003 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0xce, 0xe6, 0x97, 0x4c, 0xa8, 0x04, 0x83, 0x93, 0x38, 0x5b, 0x77, 0xed, 0x4e, 0x12, 0x62, - 0x51, 0xba, 0xdb, 0xa4, 0x48, 0xa8, 0x12, 0x42, 0xaa, 0xdb, 0x82, 0x84, 0x84, 0x54, 0xac, 0xa8, - 0x17, 0x80, 0x64, 0x8d, 0xed, 0xe9, 0x66, 0xc1, 0xde, 0x71, 0x77, 0x26, 0x26, 0x51, 0x55, 0x21, - 0x15, 0x71, 0xc5, 0x0d, 0x12, 0x42, 0xbc, 0x03, 0x4f, 0xd2, 0xcb, 0x4a, 0xdc, 0x20, 0x2e, 0x0a, - 0x4a, 0x78, 0x10, 0x34, 0xb3, 0x67, 0xff, 0x3c, 0x6b, 0x27, 0x17, 0xa8, 0x57, 0xc9, 0xcc, 0xf9, - 0xf9, 0xbe, 0x33, 0xe7, 0x9c, 0xcf, 0x8b, 0xd6, 0x79, 0x44, 0x7b, 0x03, 0xe6, 0x8d, 0xf7, 0xbd, - 0x27, 0xc7, 0x2c, 0x3a, 0x75, 0x47, 0x11, 0x97, 0x1c, 0xaf, 0xc6, 0xd7, 0xee, 0x78, 0xdf, 0xae, - 0xf8, 0xdc, 0xe7, 0xfa, 0xd6, 0x53, 0xff, 0xc5, 0x0e, 0xf6, 0x66, 0x16, 0xe7, 0xb3, 0x90, 0x89, - 0x40, 0x80, 0xa1, 0x92, 0x19, 0xc6, 0x5c, 0x32, 0xb8, 0xad, 0xf9, 0x9c, 0xfb, 0x03, 0xe6, 0xd1, - 0x51, 0xe0, 0xd1, 0x30, 0xe4, 0x92, 0xca, 0x80, 0x87, 0x49, 0x8c, 0xd3, 0xe3, 0x62, 0xc8, 0x85, - 0xd7, 0xa5, 0x42, 0x05, 0x76, 0x99, 0xa4, 0xfb, 0x5e, 0x8f, 0x07, 0x61, 0x6c, 0x27, 0xb7, 0x50, - 0xf5, 0x0b, 0x45, 0xee, 0xc1, 0x49, 0xef, 0x88, 0x86, 0x3e, 0x6b, 0x53, 0xc9, 0xda, 0xec, 0xc9, - 0x31, 0x13, 0x12, 0x57, 0xd0, 0x52, 0x9f, 0x85, 0x7c, 0x58, 0xb5, 0x1a, 0x56, 0x73, 0xb5, 0x1d, - 0x1f, 0x48, 0x07, 0x6d, 0x95, 0x44, 0x88, 0x11, 0x0f, 0x05, 0xc3, 0x2d, 0xb4, 0x18, 0x51, 0xc9, - 0xaa, 0xf3, 0x2a, 0xa2, 0xe5, 0xbe, 0x78, 0x55, 0x9f, 0xfb, 0xeb, 0x55, 0xfd, 0x5d, 0x3f, 0x90, - 0x47, 0xc7, 0x5d, 0xb7, 0xc7, 0x87, 0x1e, 0xf0, 0x89, 0xff, 0xdc, 0x14, 0xfd, 0x6f, 0x3d, 0x79, - 0x3a, 0x62, 0xc2, 0xbd, 0xcf, 0x7a, 0x6d, 0x1d, 0x4b, 0xae, 0x96, 0x00, 0x08, 0xe0, 0x44, 0x7e, - 0xb4, 0x90, 0x5d, 0x66, 0x05, 0x7c, 0x1f, 0x2d, 0xa9, 0x1c, 0xa2, 0x3a, 0xdf, 0x58, 0x68, 0xae, - 0x1d, 0xd4, 0xdc, 0x18, 0xc7, 0x55, 0xe5, 0xbb, 0x50, 0xbe, 0x82, 0xba, 0xc7, 0x83, 0xb0, 0x75, - 0x5b, 0xd1, 0xfb, 0xfd, 0xef, 0xfa, 0x8d, 0xcb, 0xd1, 0x53, 0x31, 0xa2, 0x1d, 0xe7, 0x27, 0xeb, - 0xe8, 0x1d, 0x4d, 0xe3, 0x6e, 0x4f, 0x06, 0xe3, 0x8c, 0x9e, 0x8b, 0x2a, 0xc5, 0x6b, 0xe0, 0xb5, - 0x81, 0x96, 0xf5, 0xeb, 0x89, 0xaa, 0xd5, 0x58, 0x68, 0xae, 0xb6, 0xe1, 0x44, 0xaa, 0x68, 0x43, - 0xfb, 0x3f, 0xa4, 0x11, 0x1d, 0x32, 0xc9, 0xa2, 0x34, 0xd3, 0x67, 0x68, 0xd3, 0xb0, 0x40, 0x32, - 0x0f, 0x2d, 0x8f, 0xd4, 0xad, 0xd0, 0x8d, 0x59, 0x3b, 0x78, 0xdb, 0x4d, 0x47, 0xca, 0xd5, 0xee, - 0xa2, 0xb5, 0xa8, 0x4a, 0x6b, 0x83, 0x1b, 0xf9, 0x08, 0xd5, 0x74, 0xae, 0x4f, 0x18, 0xeb, 0xb3, - 0xe8, 0x3e, 0x1b, 0x30, 0x5f, 0x0f, 0x49, 0xd2, 0xe8, 0x1a, 0x5a, 0x1d, 0xd3, 0x41, 0xd0, 0xa7, - 0x92, 0x47, 0xd0, 0xec, 0xec, 0x82, 0xdc, 0x41, 0xd7, 0xa6, 0x44, 0x03, 0x9f, 0x2a, 0x5a, 0xa1, - 0xfd, 0x7e, 0xc4, 0x84, 0x80, 0xe0, 0xe4, 0x48, 0x3e, 0x84, 0x22, 0x3e, 0x0f, 0x84, 0xb8, 0xc7, - 0x8f, 0x43, 0xc9, 0xa2, 0xcb, 0x61, 0x7e, 0x00, 0x63, 0x59, 0x08, 0xcc, 0xe0, 0x7a, 0xf1, 0x95, - 0x8e, 0x5b, 0x68, 0x27, 0xc7, 0xb4, 0xce, 0xbb, 0xbe, 0x1f, 0x29, 0x92, 0xec, 0x61, 0xc4, 0xd4, - 0xa6, 0x5c, 0x0e, 0xf3, 0x08, 0xea, 0x34, 0xa3, 0x01, 0xf8, 0x53, 0xb4, 0x32, 0x8a, 0xaf, 0xe0, - 0xe1, 0xf7, 0x72, 0x0f, 0x9f, 0x46, 0xe5, 0x07, 0x13, 0x32, 0x40, 0x3b, 0x92, 0x68, 0x72, 0x07, - 0x26, 0x3c, 0x8d, 0x79, 0x74, 0x69, 0x92, 0x5f, 0xc3, 0xf8, 0x4f, 0x84, 0x02, 0xc3, 0x8f, 0xd1, - 0x62, 0x8e, 0xde, 0xce, 0x45, 0xf4, 0x1e, 0x65, 0xdc, 0x74, 0x1c, 0xd9, 0x82, 0x7e, 0x29, 0xc3, - 0x21, 0x8d, 0x7c, 0x26, 0xd3, 0x79, 0x4c, 0x3a, 0x52, 0x30, 0x65, 0x1d, 0x91, 0xf1, 0x15, 0x8c, - 0x77, 0x72, 0x24, 0xef, 0xc3, 0x3e, 0x1c, 0xf2, 0x6e, 0x10, 0x1e, 0xd2, 0x93, 0xd9, 0xd2, 0xf2, - 0x15, 0x5a, 0x9f, 0xf0, 0xfe, 0x1f, 0x65, 0x25, 0x59, 0xb5, 0x24, 0x79, 0xb6, 0xb4, 0xcf, 0x2d, - 0x28, 0x3b, 0x6f, 0x7a, 0xcd, 0x82, 0x72, 0xf0, 0xeb, 0x1a, 0x5a, 0xd2, 0x24, 0xf0, 0x0f, 0x16, - 0x7a, 0x33, 0xdf, 0x25, 0xbc, 0x9d, 0xeb, 0xe3, 0x34, 0xb1, 0xb6, 0x77, 0x66, 0x3b, 0xc5, 0xe5, - 0x90, 0xe6, 0xf3, 0x3f, 0xfe, 0xfd, 0x65, 0x9e, 0xe0, 0x86, 0x97, 0xfd, 0x96, 0x30, 0x70, 0xec, - 0x28, 0x22, 0xde, 0x53, 0xdd, 0x8a, 0x67, 0xf8, 0x7b, 0x74, 0xa5, 0x20, 0xb1, 0x78, 0x26, 0x40, - 0xf2, 0x96, 0xf6, 0xee, 0x05, 0x5e, 0xc0, 0xe3, 0xba, 0xe6, 0x71, 0x15, 0x6f, 0x4d, 0xe3, 0x21, - 0xf0, 0x63, 0xb4, 0x02, 0x2a, 0x8a, 0x9d, 0xc9, 0xa4, 0x45, 0xd5, 0xb5, 0xeb, 0x53, 0xed, 0x00, - 0x67, 0x6b, 0xb8, 0x0a, 0xc6, 0x39, 0x38, 0x0a, 0xc9, 0x23, 0x84, 0x32, 0x8d, 0xc5, 0xd7, 0x27, - 0x53, 0x19, 0xca, 0x6c, 0x93, 0x59, 0x2e, 0x00, 0x78, 0x4d, 0x03, 0x6e, 0xe2, 0xf5, 0x1c, 0xe0, - 0x28, 0x43, 0xf9, 0xcd, 0x42, 0x6f, 0x4d, 0xca, 0x29, 0xde, 0x9b, 0xcc, 0x3b, 0x45, 0xae, 0xed, - 0xe6, 0xc5, 0x8e, 0x40, 0xe3, 0x96, 0xa6, 0xf1, 0x1e, 0x6e, 0xe6, 0x68, 0x3c, 0xd6, 0xce, 0x9d, - 0x7e, 0xea, 0xed, 0x3d, 0x4d, 0xe5, 0xe5, 0x99, 0x1a, 0xbe, 0xb5, 0x9c, 0xe8, 0x62, 0xa3, 0x58, - 0x53, 0xca, 0xed, 0xed, 0x99, 0x3e, 0x40, 0xe5, 0x86, 0xa6, 0xb2, 0x8b, 0xb7, 0x73, 0x54, 0x86, - 0x81, 0x10, 0x1d, 0x10, 0xef, 0x02, 0x0b, 0xf5, 0x3e, 0x93, 0x32, 0x6c, 0xbe, 0xcf, 0x14, 0x99, - 0x37, 0xdf, 0x67, 0x9a, 0xa2, 0x97, 0xbe, 0x0f, 0x4d, 0x9c, 0x3b, 0x20, 0xd7, 0x05, 0x66, 0x3f, - 0x59, 0xe8, 0x4a, 0x41, 0x7b, 0xcd, 0xbd, 0x28, 0x53, 0x75, 0x73, 0x2f, 0x4a, 0x05, 0x9c, 0xdc, - 0xd4, 0x84, 0xf6, 0xf0, 0x6e, 0x29, 0x21, 0x83, 0xcd, 0x77, 0x68, 0x2d, 0xa7, 0xc7, 0x66, 0xb3, - 0x4c, 0x1d, 0x37, 0x9b, 0x55, 0x22, 0xe8, 0xa4, 0xae, 0x69, 0x6c, 0xe1, 0x4d, 0xaf, 0xf8, 0xc9, - 0xd9, 0x01, 0x5d, 0xc7, 0x02, 0xbd, 0x91, 0x88, 0x25, 0x36, 0xb6, 0x6f, 0x42, 0xec, 0xed, 0xc6, - 0x74, 0x07, 0xc0, 0xdb, 0xd1, 0x78, 0x0e, 0xae, 0xe5, 0xf0, 0xa4, 0x72, 0xea, 0x48, 0x7a, 0x92, - 0x4a, 0x92, 0x40, 0x28, 0x53, 0x68, 0x73, 0x53, 0x0d, 0x61, 0x37, 0x37, 0xd5, 0x14, 0x78, 0xe2, - 0x68, 0xe8, 0x2a, 0xde, 0x28, 0x83, 0x66, 0xa2, 0xf5, 0xe0, 0xc5, 0x99, 0x63, 0xbd, 0x3c, 0x73, - 0xac, 0x7f, 0xce, 0x1c, 0xeb, 0xe7, 0x73, 0x67, 0xee, 0xe5, 0xb9, 0x33, 0xf7, 0xe7, 0xb9, 0x33, - 0xf7, 0x65, 0x5e, 0xe5, 0x47, 0xcc, 0xf7, 0x4f, 0xbf, 0x19, 0x7b, 0x82, 0x0f, 0x87, 0x6c, 0x10, - 0xb0, 0xc8, 0x3b, 0x49, 0xf2, 0x69, 0xb9, 0xef, 0x2e, 0xeb, 0xcf, 0xed, 0xdb, 0xff, 0x05, 0x00, - 0x00, 0xff, 0xff, 0xc7, 0x0e, 0xf5, 0x4d, 0x15, 0x0c, 0x00, 0x00, + // 996 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x5d, 0x6f, 0x1b, 0x45, + 0x14, 0xcd, 0xe6, 0x93, 0x8c, 0xa9, 0x04, 0x43, 0x3e, 0x9c, 0xad, 0xbb, 0x76, 0x27, 0x09, 0xb1, + 0x28, 0xdd, 0x6d, 0x52, 0x24, 0x54, 0x09, 0x21, 0xd5, 0x6d, 0x41, 0x42, 0x42, 0x2a, 0x56, 0xd4, + 0x07, 0x40, 0xb2, 0xc6, 0xf6, 0x74, 0xb3, 0x60, 0xef, 0xb8, 0x3b, 0x13, 0x93, 0xa8, 0xaa, 0x90, + 0x8a, 0x78, 0xe2, 0x05, 0x09, 0x21, 0xfe, 0x03, 0xbf, 0xa4, 0x8f, 0x95, 0x78, 0x41, 0x3c, 0x14, + 0x94, 0xf0, 0x43, 0xd0, 0xcc, 0xde, 0xfd, 0xb0, 0x67, 0xd7, 0xc9, 0x03, 0xea, 0x53, 0xb2, 0x77, + 0xce, 0xbd, 0xe7, 0xdc, 0xb9, 0x77, 0x4e, 0x82, 0xd6, 0x79, 0x44, 0x7b, 0x03, 0xe6, 0x8d, 0xf7, + 0xbd, 0x27, 0xc7, 0x2c, 0x3a, 0x75, 0x47, 0x11, 0x97, 0x1c, 0xaf, 0xc6, 0x61, 0x77, 0xbc, 0x6f, + 0xaf, 0xf9, 0xdc, 0xe7, 0x3a, 0xea, 0xa9, 0xdf, 0x62, 0x80, 0xbd, 0x91, 0xe5, 0x01, 0x34, 0x8e, + 0xd7, 0x7c, 0xce, 0xfd, 0x01, 0xf3, 0xe8, 0x28, 0xf0, 0x68, 0x18, 0x72, 0x49, 0x65, 0xc0, 0x43, + 0x01, 0xa7, 0x4e, 0x8f, 0x8b, 0x21, 0x17, 0x5e, 0x97, 0x0a, 0x95, 0xda, 0x65, 0x92, 0xee, 0x7b, + 0x3d, 0x1e, 0x84, 0xf1, 0x39, 0xb9, 0x85, 0xaa, 0x5f, 0x28, 0x15, 0x0f, 0x4e, 0x7a, 0x47, 0x34, + 0xf4, 0x59, 0x9b, 0x4a, 0xd6, 0x66, 0x4f, 0x8e, 0x99, 0x90, 0x78, 0x0d, 0x2d, 0xf5, 0x59, 0xc8, + 0x87, 0x55, 0xab, 0x61, 0x35, 0x57, 0xdb, 0xf1, 0x07, 0xe9, 0xa0, 0xad, 0x82, 0x0c, 0x31, 0xe2, + 0xa1, 0x60, 0xb8, 0x85, 0x16, 0x23, 0x2a, 0x59, 0x75, 0x5e, 0x65, 0xb4, 0xdc, 0x17, 0xaf, 0xea, + 0x73, 0x7f, 0xbd, 0xaa, 0xbf, 0xeb, 0x07, 0xf2, 0xe8, 0xb8, 0xeb, 0xf6, 0xf8, 0xd0, 0x03, 0x3d, + 0xf1, 0x8f, 0x9b, 0xa2, 0xff, 0xad, 0x27, 0x4f, 0x47, 0x4c, 0xb8, 0xf7, 0x59, 0xaf, 0xad, 0x73, + 0xc9, 0xd5, 0x02, 0x02, 0x01, 0x9a, 0xc8, 0x8f, 0x16, 0xb2, 0x8b, 0x4e, 0x81, 0xdf, 0x47, 0x4b, + 0xaa, 0x86, 0xa8, 0xce, 0x37, 0x16, 0x9a, 0x95, 0x83, 0x9a, 0x1b, 0xf3, 0xb8, 0xaa, 0x7d, 0x17, + 0xda, 0x57, 0x54, 0xf7, 0x78, 0x10, 0xb6, 0x6e, 0x2b, 0x79, 0xbf, 0xff, 0x5d, 0xbf, 0x71, 0x39, + 0x79, 0x2a, 0x47, 0xb4, 0xe3, 0xfa, 0x64, 0x1d, 0xbd, 0xa3, 0x65, 0xdc, 0xed, 0xc9, 0x60, 0x9c, + 0xc9, 0x73, 0xd1, 0xda, 0x64, 0x18, 0x74, 0x6d, 0xa0, 0x65, 0x7d, 0x7b, 0xa2, 0x6a, 0x35, 0x16, + 0x9a, 0xab, 0x6d, 0xf8, 0x22, 0x55, 0xb4, 0xa1, 0xf1, 0x0f, 0x69, 0x44, 0x87, 0x4c, 0xb2, 0x28, + 0xad, 0xf4, 0x19, 0xda, 0x34, 0x4e, 0xa0, 0x98, 0x87, 0x96, 0x47, 0x2a, 0x2a, 0xf4, 0x60, 0x2a, + 0x07, 0x6f, 0xbb, 0xe9, 0xee, 0xb8, 0x1a, 0x2e, 0x5a, 0x8b, 0xaa, 0xb5, 0x36, 0xc0, 0xc8, 0x47, + 0xa8, 0xa6, 0x6b, 0x7d, 0xc2, 0x58, 0x9f, 0x45, 0xf7, 0xd9, 0x80, 0xf9, 0x7a, 0x49, 0x92, 0x41, + 0xd7, 0xd0, 0xea, 0x98, 0x0e, 0x82, 0x3e, 0x95, 0x3c, 0x82, 0x61, 0x67, 0x01, 0x72, 0x07, 0x5d, + 0x2b, 0xc9, 0x06, 0x3d, 0x55, 0xb4, 0x42, 0xfb, 0xfd, 0x88, 0x09, 0x01, 0xc9, 0xc9, 0x27, 0xf9, + 0x10, 0x9a, 0xf8, 0x3c, 0x10, 0xe2, 0x1e, 0x3f, 0x0e, 0x25, 0x8b, 0x2e, 0xc7, 0xf9, 0x01, 0xac, + 0xe5, 0x44, 0x62, 0x46, 0xd7, 0x8b, 0x43, 0x3a, 0x6f, 0xa1, 0x9d, 0x7c, 0xa6, 0x7d, 0xde, 0xf5, + 0xfd, 0x48, 0x89, 0x64, 0x0f, 0x23, 0x36, 0xe6, 0xd9, 0x42, 0xcf, 0xe6, 0x3c, 0x82, 0x3e, 0xcd, + 0x6c, 0x20, 0xfe, 0x14, 0xad, 0x8c, 0xe2, 0x10, 0x5c, 0xfc, 0x5e, 0xee, 0xe2, 0xd3, 0xac, 0xfc, + 0x62, 0x42, 0x05, 0x18, 0x47, 0x92, 0x4d, 0xee, 0xc0, 0x86, 0xa7, 0x39, 0x8f, 0x2e, 0x2d, 0xf2, + 0x6b, 0x58, 0xff, 0xa9, 0x54, 0x50, 0xf8, 0x31, 0x5a, 0xcc, 0xc9, 0xdb, 0xb9, 0x48, 0xde, 0xa3, + 0x4c, 0x9b, 0xce, 0x23, 0x5b, 0x30, 0x2f, 0x75, 0x70, 0x48, 0x23, 0x9f, 0xc9, 0x74, 0x1f, 0x93, + 0x89, 0x4c, 0x1c, 0x65, 0x13, 0x91, 0x71, 0x08, 0xd6, 0x3b, 0xf9, 0x24, 0xef, 0xc3, 0x7b, 0x38, + 0xe4, 0xdd, 0x20, 0x3c, 0xa4, 0x27, 0xb3, 0xad, 0xe5, 0x2b, 0xb4, 0x3e, 0x85, 0xfe, 0x1f, 0x6d, + 0x25, 0x79, 0x6a, 0x49, 0xf1, 0xec, 0xd1, 0x3e, 0xb7, 0xa0, 0xed, 0xfc, 0xd1, 0x6b, 0x36, 0x94, + 0x83, 0x5f, 0x2b, 0x68, 0x49, 0x8b, 0xc0, 0x3f, 0x58, 0xe8, 0xcd, 0xfc, 0x94, 0xf0, 0x76, 0x6e, + 0x8e, 0x65, 0x66, 0x6d, 0xef, 0xcc, 0x06, 0xc5, 0xed, 0x90, 0xe6, 0xf3, 0x3f, 0xfe, 0xfd, 0x65, + 0x9e, 0xe0, 0x86, 0x97, 0xfd, 0x35, 0x61, 0x00, 0xec, 0x28, 0x21, 0xde, 0x53, 0x3d, 0x8a, 0x67, + 0xf8, 0x7b, 0x74, 0x65, 0xc2, 0x62, 0xf1, 0x4c, 0x82, 0xe4, 0x2e, 0xed, 0xdd, 0x0b, 0x50, 0xa0, + 0xe3, 0xba, 0xd6, 0x71, 0x15, 0x6f, 0x95, 0xe9, 0x10, 0xf8, 0x31, 0x5a, 0x01, 0x17, 0xc5, 0xce, + 0x74, 0xd1, 0x49, 0xd7, 0xb5, 0xeb, 0xa5, 0xe7, 0x40, 0x67, 0x6b, 0xba, 0x35, 0x8c, 0x73, 0x74, + 0x14, 0x8a, 0x47, 0x08, 0x65, 0x1e, 0x8b, 0xaf, 0x4f, 0x97, 0x32, 0x9c, 0xd9, 0x26, 0xb3, 0x20, + 0x40, 0x78, 0x4d, 0x13, 0x6e, 0xe2, 0xf5, 0x1c, 0xe1, 0x28, 0x63, 0xf9, 0xcd, 0x42, 0x6f, 0x4d, + 0xdb, 0x29, 0xde, 0x9b, 0xae, 0x5b, 0x62, 0xd7, 0x76, 0xf3, 0x62, 0x20, 0xc8, 0xb8, 0xa5, 0x65, + 0xbc, 0x87, 0x9b, 0x39, 0x19, 0x8f, 0x35, 0xb8, 0xd3, 0x4f, 0xd1, 0xde, 0xd3, 0xd4, 0x5e, 0x9e, + 0xa9, 0xe5, 0xab, 0xe4, 0x4c, 0x17, 0x1b, 0xcd, 0x9a, 0x56, 0x6e, 0x6f, 0xcf, 0xc4, 0x80, 0x94, + 0x1b, 0x5a, 0xca, 0x2e, 0xde, 0xce, 0x49, 0x19, 0x06, 0x42, 0x74, 0xc0, 0xbc, 0x27, 0x54, 0xa8, + 0xfb, 0x99, 0xb6, 0x61, 0xf3, 0x7e, 0x4a, 0x6c, 0xde, 0xbc, 0x9f, 0x32, 0x47, 0x2f, 0xbc, 0x1f, + 0x9a, 0x80, 0x3b, 0x60, 0xd7, 0x13, 0xca, 0x7e, 0xb2, 0xd0, 0x95, 0x09, 0xef, 0x35, 0xdf, 0x45, + 0x91, 0xab, 0x9b, 0xef, 0xa2, 0xd0, 0xc0, 0xc9, 0x4d, 0x2d, 0x68, 0x0f, 0xef, 0x16, 0x0a, 0x32, + 0xd4, 0x7c, 0x87, 0x2a, 0x39, 0x3f, 0x36, 0x87, 0x65, 0xfa, 0xb8, 0x39, 0xac, 0x02, 0x43, 0x27, + 0x75, 0x2d, 0x63, 0x0b, 0x6f, 0xe6, 0x64, 0x28, 0xf2, 0x0e, 0xf8, 0x3a, 0x16, 0xe8, 0x8d, 0xc4, + 0x2c, 0xb1, 0xf1, 0xfa, 0xa6, 0xcc, 0xde, 0x6e, 0x94, 0x03, 0x80, 0x6f, 0x47, 0xf3, 0x39, 0xb8, + 0x96, 0xe3, 0x93, 0x0a, 0xd4, 0x91, 0xf4, 0x24, 0xb5, 0x24, 0x81, 0x50, 0xe6, 0xd0, 0xe6, 0x4b, + 0x35, 0x8c, 0xdd, 0x7c, 0xa9, 0xa6, 0xc1, 0x13, 0x47, 0x53, 0x57, 0xf1, 0x46, 0x11, 0x35, 0x13, + 0xad, 0x07, 0x2f, 0xce, 0x1c, 0xeb, 0xe5, 0x99, 0x63, 0xfd, 0x73, 0xe6, 0x58, 0x3f, 0x9f, 0x3b, + 0x73, 0x2f, 0xcf, 0x9d, 0xb9, 0x3f, 0xcf, 0x9d, 0xb9, 0x2f, 0xf3, 0x2e, 0x3f, 0x62, 0xbe, 0x7f, + 0xfa, 0xcd, 0xd8, 0x13, 0x7c, 0x38, 0x64, 0x83, 0x80, 0x45, 0xde, 0x49, 0x52, 0x4f, 0xdb, 0x7d, + 0x77, 0x59, 0xff, 0xbb, 0x7d, 0xfb, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xbf, 0x18, 0x97, + 0xfe, 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/oracle/types/query.pb.gw.go b/x/oracle/types/query.pb.gw.go index 1f83e872..cf636785 100644 --- a/x/oracle/types/query.pb.gw.go +++ b/x/oracle/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_ExchangeRate_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryExchangeRateRequest @@ -448,12 +450,14 @@ func local_request_Query_TobinTaxes_0(ctx context.Context, marshaler runtime.Mar // 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. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_ExchangeRate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -461,6 +465,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_ExchangeRate_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -474,6 +479,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_ExchangeRates_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -481,6 +488,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_ExchangeRates_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -494,6 +502,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Actives_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -501,6 +511,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Actives_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -514,6 +525,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Parameters_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -521,6 +534,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Parameters_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -534,6 +548,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_FeederDelegation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -541,6 +557,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_FeederDelegation_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -554,6 +571,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_MissCounter_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -561,6 +580,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_MissCounter_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -574,6 +594,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_AggregatePrevote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -581,6 +603,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_AggregatePrevote_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -594,6 +617,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_AggregateVote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -601,6 +626,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_AggregateVote_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -614,6 +640,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_VoteTargets_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -621,6 +649,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_VoteTargets_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -634,6 +663,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_TobinTax_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -641,6 +672,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_TobinTax_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -654,6 +686,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_TobinTaxes_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -661,6 +695,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_TobinTaxes_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/oracle/types/test_utils.go b/x/oracle/types/test_utils.go index 886bdeed..7806926b 100644 --- a/x/oracle/types/test_utils.go +++ b/x/oracle/types/test_utils.go @@ -6,10 +6,11 @@ import ( "math/rand" "time" + ccrypto "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/proto/tendermint/crypto" ) const oracleDecPrecision = 6 @@ -101,12 +102,12 @@ func (MockValidator) IsBonded() bool { return t func (MockValidator) IsUnbonded() bool { return false } func (MockValidator) IsUnbonding() bool { return false } func (v MockValidator) GetOperator() sdk.ValAddress { return v.operator } -func (MockValidator) GetConsPubKey() crypto.PubKey { return nil } +func (MockValidator) ConsPubKey() (ccrypto.PubKey, error) { return nil, nil } func (MockValidator) GetConsAddr() (sdk.ConsAddress, error) { return nil, nil } func (v MockValidator) GetTokens() sdk.Int { return sdk.TokensFromConsensusPower(v.power) } func (v MockValidator) GetBondedTokens() sdk.Int { return sdk.TokensFromConsensusPower(v.power) } func (v MockValidator) GetConsensusPower() int64 { return v.power } -func (v MockValidator) TmConsPubKey() (crypto.PubKey, error) { return nil, nil } +func (v MockValidator) TmConsPublicKey() (crypto.PublicKey, error) { return crypto.PublicKey{}, nil } func (v MockValidator) GetCommission() sdk.Dec { return sdk.ZeroDec() } func (v MockValidator) GetMinSelfDelegation() sdk.Int { return sdk.OneInt() } func (v MockValidator) GetDelegatorShares() sdk.Dec { return sdk.NewDec(v.power) } diff --git a/x/oracle/types/msgs.pb.go b/x/oracle/types/tx.pb.go similarity index 85% rename from x/oracle/types/msgs.pb.go rename to x/oracle/types/tx.pb.go index 73ebf520..556db14f 100644 --- a/x/oracle/types/msgs.pb.go +++ b/x/oracle/types/tx.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: oracle/v1/msgs.proto +// source: oracle/v1/tx.proto package types @@ -37,7 +37,7 @@ func (m *MsgDelegateFeedConsent) Reset() { *m = MsgDelegateFeedConsent{} func (m *MsgDelegateFeedConsent) String() string { return proto.CompactTextString(m) } func (*MsgDelegateFeedConsent) ProtoMessage() {} func (*MsgDelegateFeedConsent) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{0} + return fileDescriptor_31571edce0094a5d, []int{0} } func (m *MsgDelegateFeedConsent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -80,7 +80,6 @@ func (m *MsgDelegateFeedConsent) GetDelegate() string { return "" } -// TODO: return data type MsgDelegateFeedConsentResponse struct { } @@ -88,7 +87,7 @@ func (m *MsgDelegateFeedConsentResponse) Reset() { *m = MsgDelegateFeedC func (m *MsgDelegateFeedConsentResponse) String() string { return proto.CompactTextString(m) } func (*MsgDelegateFeedConsentResponse) ProtoMessage() {} func (*MsgDelegateFeedConsentResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{1} + return fileDescriptor_31571edce0094a5d, []int{1} } func (m *MsgDelegateFeedConsentResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -130,7 +129,7 @@ func (m *MsgAggregateExchangeRatePrevote) Reset() { *m = MsgAggregateExc func (m *MsgAggregateExchangeRatePrevote) String() string { return proto.CompactTextString(m) } func (*MsgAggregateExchangeRatePrevote) ProtoMessage() {} func (*MsgAggregateExchangeRatePrevote) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{2} + return fileDescriptor_31571edce0094a5d, []int{2} } func (m *MsgAggregateExchangeRatePrevote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -180,7 +179,6 @@ func (m *MsgAggregateExchangeRatePrevote) GetValidator() string { return "" } -// TODO: return data type MsgAggregateExchangeRatePrevoteResponse struct { } @@ -190,7 +188,7 @@ func (m *MsgAggregateExchangeRatePrevoteResponse) Reset() { func (m *MsgAggregateExchangeRatePrevoteResponse) String() string { return proto.CompactTextString(m) } func (*MsgAggregateExchangeRatePrevoteResponse) ProtoMessage() {} func (*MsgAggregateExchangeRatePrevoteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{3} + return fileDescriptor_31571edce0094a5d, []int{3} } func (m *MsgAggregateExchangeRatePrevoteResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -221,7 +219,8 @@ var xxx_messageInfo_MsgAggregateExchangeRatePrevoteResponse proto.InternalMessag // MsgAggregateExchangeRateVote - struct for voting on the exchange rates of Luna denominated in various Terra assets. type MsgAggregateExchangeRateVote struct { - Salt string `protobuf:"bytes,1,opt,name=salt,proto3" json:"salt,omitempty"` + Salt string `protobuf:"bytes,1,opt,name=salt,proto3" json:"salt,omitempty"` + // NOTE: this exchange rates string is a DecCoins.String() ExchangeRates string `protobuf:"bytes,2,opt,name=exchange_rates,json=exchangeRates,proto3" json:"exchange_rates,omitempty"` Feeder string `protobuf:"bytes,3,opt,name=feeder,proto3" json:"feeder,omitempty"` Validator string `protobuf:"bytes,4,opt,name=validator,proto3" json:"validator,omitempty"` @@ -231,7 +230,7 @@ func (m *MsgAggregateExchangeRateVote) Reset() { *m = MsgAggregateExchan func (m *MsgAggregateExchangeRateVote) String() string { return proto.CompactTextString(m) } func (*MsgAggregateExchangeRateVote) ProtoMessage() {} func (*MsgAggregateExchangeRateVote) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{4} + return fileDescriptor_31571edce0094a5d, []int{4} } func (m *MsgAggregateExchangeRateVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -288,7 +287,6 @@ func (m *MsgAggregateExchangeRateVote) GetValidator() string { return "" } -// TODO: return data type MsgAggregateExchangeRateVoteResponse struct { } @@ -296,7 +294,7 @@ func (m *MsgAggregateExchangeRateVoteResponse) Reset() { *m = MsgAggrega func (m *MsgAggregateExchangeRateVoteResponse) String() string { return proto.CompactTextString(m) } func (*MsgAggregateExchangeRateVoteResponse) ProtoMessage() {} func (*MsgAggregateExchangeRateVoteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_6dda9defd295d067, []int{5} + return fileDescriptor_31571edce0094a5d, []int{5} } func (m *MsgAggregateExchangeRateVoteResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -334,35 +332,35 @@ func init() { proto.RegisterType((*MsgAggregateExchangeRateVoteResponse)(nil), "oracle.v1.MsgAggregateExchangeRateVoteResponse") } -func init() { proto.RegisterFile("oracle/v1/msgs.proto", fileDescriptor_6dda9defd295d067) } - -var fileDescriptor_6dda9defd295d067 = []byte{ - // 391 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x8e, 0xda, 0x30, - 0x10, 0xc6, 0x09, 0x20, 0x54, 0x46, 0x6d, 0x0f, 0x6e, 0x85, 0x68, 0x84, 0x52, 0x1a, 0xb5, 0xa5, - 0xb4, 0x52, 0x22, 0xe8, 0x13, 0xf4, 0x0f, 0xbd, 0x21, 0xa1, 0x1c, 0x7a, 0xe8, 0xa5, 0x32, 0xc9, - 0xd4, 0xa1, 0x4d, 0x70, 0x64, 0x9b, 0x08, 0x2e, 0x7d, 0x85, 0xdd, 0xc7, 0xda, 0x23, 0xc7, 0x3d, - 0xee, 0xc2, 0x8b, 0xac, 0x08, 0x4e, 0x96, 0x5d, 0xf1, 0xef, 0x36, 0xe3, 0xf9, 0x3c, 0xdf, 0x4f, - 0xfe, 0x64, 0x78, 0xc9, 0x05, 0xf5, 0x23, 0x74, 0xd3, 0x9e, 0x1b, 0x4b, 0x26, 0x9d, 0x44, 0x70, - 0xc5, 0x49, 0x7d, 0x7b, 0xea, 0xa4, 0x3d, 0x7b, 0x04, 0x8d, 0xa1, 0x64, 0xdf, 0x31, 0x42, 0x46, - 0x15, 0xfe, 0x40, 0x0c, 0xbe, 0xf1, 0xa9, 0xc4, 0xa9, 0x22, 0x26, 0x3c, 0xe1, 0x09, 0x0a, 0xaa, - 0xb8, 0x68, 0x1a, 0x6d, 0xe3, 0x43, 0xdd, 0x2b, 0xfa, 0xcd, 0x2c, 0xd0, 0x57, 0x9a, 0xe5, 0xed, - 0x2c, 0xef, 0xed, 0x36, 0x58, 0xfb, 0x37, 0x7a, 0x28, 0x93, 0x4d, 0x65, 0xff, 0x83, 0xd7, 0x43, - 0xc9, 0xbe, 0x30, 0x26, 0x32, 0xc9, 0x60, 0xee, 0x87, 0x74, 0xca, 0xd0, 0xa3, 0x0a, 0x47, 0x02, - 0x53, 0xae, 0x90, 0x10, 0xa8, 0x86, 0x54, 0x86, 0x99, 0xf1, 0x53, 0x2f, 0xab, 0x49, 0x03, 0x6a, - 0x7f, 0x10, 0x03, 0x14, 0xda, 0x52, 0x77, 0xa4, 0x05, 0xf5, 0x94, 0x46, 0x93, 0x20, 0x23, 0xad, - 0x64, 0xa3, 0xfb, 0x03, 0xbb, 0x0b, 0x9d, 0x13, 0x66, 0x05, 0xd7, 0x85, 0x01, 0xad, 0x43, 0xda, - 0x9f, 0x9a, 0x4a, 0xd2, 0x48, 0xe9, 0xe7, 0xc8, 0x6a, 0xf2, 0x0e, 0x9e, 0xa3, 0xd6, 0xfd, 0x16, - 0x54, 0xa1, 0xd4, 0x74, 0xcf, 0x70, 0xe7, 0xb6, 0xdc, 0x81, 0xaf, 0x1c, 0x86, 0xaf, 0x3e, 0x86, - 0x7f, 0x0f, 0x6f, 0x8f, 0x01, 0xe5, 0xe4, 0xfd, 0xdb, 0x32, 0x54, 0x86, 0x92, 0x11, 0x1f, 0x5e, - 0xec, 0x8b, 0xf2, 0x8d, 0x53, 0x04, 0xee, 0xec, 0xcf, 0xc6, 0xec, 0x9e, 0x94, 0xe4, 0x66, 0xe4, - 0x3f, 0xb4, 0x8e, 0x66, 0xf7, 0xf1, 0xe1, 0xaa, 0x63, 0x5a, 0xb3, 0x7f, 0xbe, 0xb6, 0xf0, 0x9f, - 0xc1, 0xab, 0xc3, 0x11, 0x75, 0xce, 0x58, 0xb8, 0x11, 0x9a, 0xee, 0x99, 0xc2, 0xdc, 0xf6, 0xeb, - 0xe0, 0x6a, 0x65, 0x19, 0xcb, 0x95, 0x65, 0xdc, 0xac, 0x2c, 0xe3, 0x72, 0x6d, 0x95, 0x96, 0x6b, - 0xab, 0x74, 0xbd, 0xb6, 0x4a, 0xbf, 0x3e, 0xb1, 0x89, 0x0a, 0x67, 0x63, 0xc7, 0xe7, 0xb1, 0x9b, - 0x20, 0x63, 0x8b, 0xbf, 0xa9, 0x2b, 0x79, 0x1c, 0x63, 0x34, 0x41, 0xe1, 0xce, 0x5d, 0xfd, 0x07, - 0xd5, 0x22, 0x41, 0x39, 0xae, 0x65, 0x5f, 0xf0, 0xf3, 0x5d, 0x00, 0x00, 0x00, 0xff, 0xff, 0x96, - 0x94, 0x2e, 0x03, 0x9a, 0x03, 0x00, 0x00, +func init() { proto.RegisterFile("oracle/v1/tx.proto", fileDescriptor_31571edce0094a5d) } + +var fileDescriptor_31571edce0094a5d = []byte{ + // 389 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x6e, 0xda, 0x40, + 0x10, 0xc6, 0x31, 0x20, 0x54, 0x46, 0x6d, 0x0f, 0x5b, 0x09, 0x51, 0x0b, 0xb9, 0xd4, 0x6a, 0x4b, + 0x69, 0x25, 0x5b, 0xd0, 0x27, 0xe8, 0x1f, 0x7a, 0x43, 0x42, 0x3e, 0xf4, 0xd0, 0x4b, 0xb4, 0xd8, + 0x93, 0x35, 0x89, 0x61, 0xad, 0xdd, 0xc5, 0x82, 0x4b, 0x5e, 0x21, 0x79, 0xac, 0x1c, 0x39, 0xe6, + 0x98, 0xc0, 0x8b, 0x44, 0x98, 0xb5, 0x43, 0x22, 0xfe, 0xdd, 0x66, 0x76, 0xbe, 0x9d, 0xef, 0xa7, + 0xfd, 0xb4, 0x40, 0xb8, 0xa0, 0x7e, 0x84, 0x6e, 0xd2, 0x71, 0xd5, 0xcc, 0x89, 0x05, 0x57, 0x9c, + 0x54, 0x37, 0x67, 0x4e, 0xd2, 0xb1, 0x07, 0x50, 0xeb, 0x4b, 0xf6, 0x07, 0x23, 0x64, 0x54, 0xe1, + 0x5f, 0xc4, 0xe0, 0x37, 0x9f, 0x48, 0x9c, 0x28, 0x62, 0xc2, 0x2b, 0x1e, 0xa3, 0xa0, 0x8a, 0x8b, + 0xba, 0xd1, 0x34, 0xbe, 0x56, 0xbd, 0xbc, 0x5f, 0xcf, 0x02, 0x7d, 0xa5, 0x5e, 0xdc, 0xcc, 0xb2, + 0xde, 0x6e, 0x82, 0xb5, 0x7b, 0xa3, 0x87, 0x32, 0x5e, 0x57, 0xf6, 0x25, 0x7c, 0xe8, 0x4b, 0xf6, + 0x93, 0x31, 0x91, 0x4a, 0x7a, 0x33, 0x3f, 0xa4, 0x13, 0x86, 0x1e, 0x55, 0x38, 0x10, 0x98, 0x70, + 0x85, 0x84, 0x40, 0x39, 0xa4, 0x32, 0x4c, 0x8d, 0x5f, 0x7b, 0x69, 0x4d, 0x6a, 0x50, 0x39, 0x47, + 0x0c, 0x50, 0x68, 0x4b, 0xdd, 0x91, 0x06, 0x54, 0x13, 0x1a, 0x8d, 0x82, 0x94, 0xb4, 0x94, 0x8e, + 0x9e, 0x0e, 0xec, 0x36, 0xb4, 0x8e, 0x98, 0xe5, 0x5c, 0xd7, 0x06, 0x34, 0xf6, 0x69, 0xff, 0x69, + 0x2a, 0x49, 0x23, 0xa5, 0x9f, 0x23, 0xad, 0xc9, 0x67, 0x78, 0x8b, 0x5a, 0x77, 0x26, 0xa8, 0x42, + 0xa9, 0xe9, 0xde, 0xe0, 0xd6, 0x6d, 0xb9, 0x05, 0x5f, 0xda, 0x0f, 0x5f, 0x7e, 0x09, 0xff, 0x05, + 0x3e, 0x1d, 0x02, 0xca, 0xc8, 0xbb, 0x0f, 0x45, 0x28, 0xf5, 0x25, 0x23, 0x3e, 0xbc, 0xdb, 0x15, + 0xe5, 0x47, 0x27, 0x0f, 0xdc, 0xd9, 0x9d, 0x8d, 0xd9, 0x3e, 0x2a, 0xc9, 0xcc, 0xc8, 0x15, 0x34, + 0x0e, 0x66, 0xf7, 0xed, 0xf9, 0xaa, 0x43, 0x5a, 0xb3, 0x7b, 0xba, 0x36, 0xf7, 0x9f, 0xc2, 0xfb, + 0xfd, 0x11, 0xb5, 0x4e, 0x58, 0xb8, 0x16, 0x9a, 0xee, 0x89, 0xc2, 0xcc, 0xf6, 0x57, 0xef, 0x76, + 0x69, 0x19, 0x8b, 0xa5, 0x65, 0xdc, 0x2f, 0x2d, 0xe3, 0x66, 0x65, 0x15, 0x16, 0x2b, 0xab, 0x70, + 0xb7, 0xb2, 0x0a, 0xff, 0xbf, 0xb3, 0x91, 0x0a, 0xa7, 0x43, 0xc7, 0xe7, 0x63, 0x37, 0x46, 0xc6, + 0xe6, 0x17, 0x89, 0x2b, 0xf9, 0x78, 0x8c, 0xd1, 0x08, 0x85, 0x3b, 0x73, 0xf5, 0x0f, 0x54, 0xf3, + 0x18, 0xe5, 0xb0, 0x92, 0x7e, 0xc1, 0x1f, 0x8f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x09, 0x14, 0x7a, + 0x54, 0x98, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -514,7 +512,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "oracle/v1/msgs.proto", + Metadata: "oracle/v1/tx.proto", } func (m *MsgDelegateFeedConsent) Marshal() (dAtA []byte, err error) { @@ -540,14 +538,14 @@ func (m *MsgDelegateFeedConsent) MarshalToSizedBuffer(dAtA []byte) (int, error) if len(m.Delegate) > 0 { i -= len(m.Delegate) copy(dAtA[i:], m.Delegate) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Delegate))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Delegate))) i-- dAtA[i] = 0x12 } if len(m.Operator) > 0 { i -= len(m.Operator) copy(dAtA[i:], m.Operator) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Operator))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Operator))) i-- dAtA[i] = 0xa } @@ -600,21 +598,21 @@ func (m *MsgAggregateExchangeRatePrevote) MarshalToSizedBuffer(dAtA []byte) (int if len(m.Validator) > 0 { i -= len(m.Validator) copy(dAtA[i:], m.Validator) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Validator))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validator))) i-- dAtA[i] = 0x1a } if len(m.Feeder) > 0 { i -= len(m.Feeder) copy(dAtA[i:], m.Feeder) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Feeder))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Feeder))) i-- dAtA[i] = 0x12 } if len(m.Hash) > 0 { i -= len(m.Hash) copy(dAtA[i:], m.Hash) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Hash))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Hash))) i-- dAtA[i] = 0xa } @@ -667,28 +665,28 @@ func (m *MsgAggregateExchangeRateVote) MarshalToSizedBuffer(dAtA []byte) (int, e if len(m.Validator) > 0 { i -= len(m.Validator) copy(dAtA[i:], m.Validator) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Validator))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validator))) i-- dAtA[i] = 0x22 } if len(m.Feeder) > 0 { i -= len(m.Feeder) copy(dAtA[i:], m.Feeder) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Feeder))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Feeder))) i-- dAtA[i] = 0x1a } if len(m.ExchangeRates) > 0 { i -= len(m.ExchangeRates) copy(dAtA[i:], m.ExchangeRates) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.ExchangeRates))) + i = encodeVarintTx(dAtA, i, uint64(len(m.ExchangeRates))) i-- dAtA[i] = 0x12 } if len(m.Salt) > 0 { i -= len(m.Salt) copy(dAtA[i:], m.Salt) - i = encodeVarintMsgs(dAtA, i, uint64(len(m.Salt))) + i = encodeVarintTx(dAtA, i, uint64(len(m.Salt))) i-- dAtA[i] = 0xa } @@ -718,8 +716,8 @@ func (m *MsgAggregateExchangeRateVoteResponse) MarshalToSizedBuffer(dAtA []byte) return len(dAtA) - i, nil } -func encodeVarintMsgs(dAtA []byte, offset int, v uint64) int { - offset -= sovMsgs(v) +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -737,11 +735,11 @@ func (m *MsgDelegateFeedConsent) Size() (n int) { _ = l l = len(m.Operator) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Delegate) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } return n } @@ -763,15 +761,15 @@ func (m *MsgAggregateExchangeRatePrevote) Size() (n int) { _ = l l = len(m.Hash) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Feeder) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Validator) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } return n } @@ -793,19 +791,19 @@ func (m *MsgAggregateExchangeRateVote) Size() (n int) { _ = l l = len(m.Salt) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.ExchangeRates) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Feeder) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } l = len(m.Validator) if l > 0 { - n += 1 + l + sovMsgs(uint64(l)) + n += 1 + l + sovTx(uint64(l)) } return n } @@ -819,11 +817,11 @@ func (m *MsgAggregateExchangeRateVoteResponse) Size() (n int) { return n } -func sovMsgs(x uint64) (n int) { +func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozMsgs(x uint64) (n int) { - return sovMsgs(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -833,7 +831,7 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -861,7 +859,7 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -875,11 +873,11 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -893,7 +891,7 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -907,11 +905,11 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -920,15 +918,15 @@ func (m *MsgDelegateFeedConsent) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -950,7 +948,7 @@ func (m *MsgDelegateFeedConsentResponse) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -973,15 +971,15 @@ func (m *MsgDelegateFeedConsentResponse) Unmarshal(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1003,7 +1001,7 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1031,7 +1029,7 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1044,11 +1042,11 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } } if byteLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + byteLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1065,7 +1063,7 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1079,11 +1077,11 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1097,7 +1095,7 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1111,11 +1109,11 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1124,15 +1122,15 @@ func (m *MsgAggregateExchangeRatePrevote) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1154,7 +1152,7 @@ func (m *MsgAggregateExchangeRatePrevoteResponse) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1177,15 +1175,15 @@ func (m *MsgAggregateExchangeRatePrevoteResponse) Unmarshal(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1207,7 +1205,7 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1235,7 +1233,7 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1249,11 +1247,11 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1267,7 +1265,7 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1281,11 +1279,11 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1299,7 +1297,7 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1313,11 +1311,11 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1331,7 +1329,7 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1345,11 +1343,11 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF @@ -1358,15 +1356,15 @@ func (m *MsgAggregateExchangeRateVote) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1388,7 +1386,7 @@ func (m *MsgAggregateExchangeRateVoteResponse) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowMsgs + return ErrIntOverflowTx } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -1411,15 +1409,15 @@ func (m *MsgAggregateExchangeRateVoteResponse) Unmarshal(dAtA []byte) error { switch fieldNum { default: iNdEx = preIndex - skippy, err := skipMsgs(dAtA[iNdEx:]) + skippy, err := skipTx(dAtA[iNdEx:]) if err != nil { return err } if skippy < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMsgs + return ErrInvalidLengthTx } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -1433,7 +1431,7 @@ func (m *MsgAggregateExchangeRateVoteResponse) Unmarshal(dAtA []byte) error { } return nil } -func skipMsgs(dAtA []byte) (n int, err error) { +func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -1441,7 +1439,7 @@ func skipMsgs(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowMsgs + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1458,7 +1456,7 @@ func skipMsgs(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowMsgs + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1474,7 +1472,7 @@ func skipMsgs(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowMsgs + return 0, ErrIntOverflowTx } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -1487,14 +1485,14 @@ func skipMsgs(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthMsgs + return 0, ErrInvalidLengthTx } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupMsgs + return 0, ErrUnexpectedEndOfGroupTx } depth-- case 5: @@ -1503,7 +1501,7 @@ func skipMsgs(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthMsgs + return 0, ErrInvalidLengthTx } if depth == 0 { return iNdEx, nil @@ -1513,7 +1511,7 @@ func skipMsgs(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthMsgs = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowMsgs = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupMsgs = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/oracle/types/vote.go b/x/oracle/types/vote.go index 9af90541..7baf88c0 100644 --- a/x/oracle/types/vote.go +++ b/x/oracle/types/vote.go @@ -27,50 +27,33 @@ func NewAggregateExchangeRatePrevote(hash AggregateVoteHash, voter sdk.ValAddres } } -// ExchangeRateTuples - array of ExchangeRateTuple -type ExchangeRateTuples []ExchangeRateTuple - -// String implements fmt.Stringer interface -func (tuples ExchangeRateTuples) String() (out string) { - for _, tuple := range tuples { - out += tuple.String() + "\n" - } - return strings.TrimSpace(out) -} - // ParseExchangeRateTuples ExchangeRateTuple parser -func ParseExchangeRateTuples(tuplesStr string) (ExchangeRateTuples, error) { +func ParseExchangeRateTuples(tuplesStr string) (sdk.DecCoins, error) { tuplesStr = strings.TrimSpace(tuplesStr) if len(tuplesStr) == 0 { return nil, nil } tupleStrs := strings.Split(tuplesStr, ",") - tuples := make(ExchangeRateTuples, len(tupleStrs)) + tuples := make(sdk.DecCoins, len(tupleStrs)) duplicateCheckMap := make(map[string]bool) + for i, tupleStr := range tupleStrs { decCoin, err := sdk.ParseDecCoin(tupleStr) if err != nil { return nil, err } - - tuples[i] = ExchangeRateTuple{ - Denom: decCoin.Denom, - ExchangeRate: decCoin.Amount, - } - + tuples[i] = decCoin if _, ok := duplicateCheckMap[decCoin.Denom]; ok { return nil, fmt.Errorf("duplicated denom %s", decCoin.Denom) } - duplicateCheckMap[decCoin.Denom] = true } - return tuples, nil } // NewAggregateExchangeRateVote creates a AggregateExchangeRateVote instance -func NewAggregateExchangeRateVote(tuples ExchangeRateTuples, voter sdk.ValAddress) AggregateExchangeRateVote { +func NewAggregateExchangeRateVote(tuples sdk.DecCoins, voter sdk.ValAddress) AggregateExchangeRateVote { return AggregateExchangeRateVote{ ExchangeRateTuples: tuples, Voter: voter.String(),