Merge branch 'master' into adr_gov_split_vote
This commit is contained in:
commit
e34a986a7e
|
@ -91,7 +91,8 @@ PenaltyExcessCharacter: 1000000
|
|||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
RawStringFormats:
|
||||
- Delimiter: pb
|
||||
- Delimiters:
|
||||
- pb
|
||||
Language: TextProto
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
|
|
|
@ -7,8 +7,6 @@ coverage:
|
|||
precision: 2
|
||||
round: down
|
||||
range: 70...100
|
||||
notify:
|
||||
after_n_builds: 4
|
||||
|
||||
status:
|
||||
# Learn more at https://docs.codecov.io/docs/commit-status
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
name: Nightly Builds
|
||||
# Nightly Builds rebuilds the simapp docker image Monday - Friday at midnight
|
||||
name: Build & Push
|
||||
# Build & Push builds the simapp docker image on every push to master and
|
||||
# and pushes the image to https://hub.docker.com/r/interchainio/simapp/tags
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * 1-5" # deploy at midnight Monday - Friday
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
- "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
@ -12,9 +16,27 @@ jobs:
|
|||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
|
||||
|
||||
- name: Prepare
|
||||
id: prep
|
||||
run: |
|
||||
DOCKER_IMAGE=interchainio/simapp
|
||||
VERSION=noop
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
||||
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
|
||||
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
|
||||
VERSION=latest
|
||||
fi
|
||||
fi
|
||||
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
||||
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}"
|
||||
fi
|
||||
echo ::set-output name=version::${VERSION}
|
||||
echo ::set-output name=tags::${TAGS}
|
||||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
@ -28,5 +50,5 @@ jobs:
|
|||
- name: Publish to Docker Hub
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
push: true
|
||||
tags: interchainio/simapp:nightly-${{ steps.date.outputs.date }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.prep.outputs.tags }}
|
||||
|
|
|
@ -7,6 +7,6 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: gaurav-nelson/github-action-markdown-link-check@1.0.7
|
||||
- uses: gaurav-nelson/github-action-markdown-link-check@1.0.8
|
||||
with:
|
||||
folder-path: "docs"
|
||||
|
|
|
@ -57,46 +57,41 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- name: Create a file with all the pkgs
|
||||
run: go list ./... > pkgs.txt
|
||||
- name: Split pkgs into 4 files
|
||||
run: split -n l/4 --additional-suffix=.txt ./pkgs.txt
|
||||
run: split -d -n l/4 pkgs.txt pkgs.txt.part.
|
||||
# cache multiple
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-aa"
|
||||
path: ./xaa.txt
|
||||
name: "${{ github.sha }}-00"
|
||||
path: ./pkgs.txt.part.00
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ab"
|
||||
path: ./xab.txt
|
||||
name: "${{ github.sha }}-01"
|
||||
path: ./pkgs.txt.part.01
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ac"
|
||||
path: ./xac.txt
|
||||
name: "${{ github.sha }}-02"
|
||||
path: ./pkgs.txt.part.02
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ad"
|
||||
path: ./xad.txt
|
||||
name: "${{ github.sha }}-03"
|
||||
path: ./pkgs.txt.part.03
|
||||
|
||||
test-coverage-run-1:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 15
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
part: ["00", "01", "02", "03"]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
|
@ -104,11 +99,46 @@ jobs:
|
|||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-aa"
|
||||
name: "${{ github.sha }}-${{ matrix.part }}"
|
||||
if: env.GIT_DIFF
|
||||
- name: test & coverage report creation
|
||||
run: |
|
||||
cat xaa.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock'
|
||||
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='norace ledger test_ledger_mock'
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
|
||||
path: ./${{ matrix.part }}profile.out
|
||||
|
||||
upload-coverage-report:
|
||||
runs-on: ubuntu-latest
|
||||
needs: tests
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-00-coverage"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-01-coverage"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-02-coverage"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-03-coverage"
|
||||
if: env.GIT_DIFF
|
||||
- run: |
|
||||
cat ./*profile.out | grep -v "mode: atomic" >> coverage.txt
|
||||
if: env.GIT_DIFF
|
||||
- name: filter out DONTCOVER
|
||||
run: |
|
||||
|
@ -126,19 +156,19 @@ jobs:
|
|||
file: ./coverage.txt
|
||||
if: env.GIT_DIFF
|
||||
|
||||
test-coverage-run-2:
|
||||
test-race:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 15
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
part: ["00", "01", "02", "03"]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
|
@ -146,235 +176,20 @@ jobs:
|
|||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ab"
|
||||
name: "${{ github.sha }}-${{ matrix.part }}"
|
||||
if: env.GIT_DIFF
|
||||
- name: test & coverage report creation
|
||||
run: |
|
||||
cat xab.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock'
|
||||
if: env.GIT_DIFF
|
||||
- name: filter out DONTCOVER
|
||||
run: |
|
||||
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
|
||||
excludelist+=" $(find ./ -type f -name '*.pb.go')"
|
||||
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')"
|
||||
for filename in ${excludelist}; do
|
||||
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g')
|
||||
echo "Excluding ${filename} from coverage report..."
|
||||
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
|
||||
done
|
||||
if: env.GIT_DIFF
|
||||
- uses: codecov/codecov-action@v1.0.14
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
if: env.GIT_DIFF
|
||||
|
||||
test-coverage-run-3:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ac"
|
||||
if: env.GIT_DIFF
|
||||
- name: test & coverage report creation
|
||||
run: |
|
||||
cat xac.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock'
|
||||
if: env.GIT_DIFF
|
||||
- name: filter out DONTCOVER
|
||||
run: |
|
||||
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
|
||||
excludelist+=" $(find ./ -type f -name '*.pb.go')"
|
||||
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')"
|
||||
for filename in ${excludelist}; do
|
||||
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g')
|
||||
echo "Excluding ${filename} from coverage report..."
|
||||
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
|
||||
done
|
||||
if: env.GIT_DIFF
|
||||
- uses: codecov/codecov-action@v1.0.14
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
if: env.GIT_DIFF
|
||||
|
||||
test-coverage-run-4:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ad"
|
||||
if: env.GIT_DIFF
|
||||
- name: test & coverage report creation
|
||||
run: |
|
||||
cat xad.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock'
|
||||
if: env.GIT_DIFF
|
||||
- name: filter out DONTCOVER
|
||||
run: |
|
||||
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
|
||||
excludelist+=" $(find ./ -type f -name '*.pb.go')"
|
||||
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')"
|
||||
for filename in ${excludelist}; do
|
||||
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/cosmos-sdk/g')
|
||||
echo "Excluding ${filename} from coverage report..."
|
||||
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
|
||||
done
|
||||
if: env.GIT_DIFF
|
||||
- uses: codecov/codecov-action@v1.0.14
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
if: env.GIT_DIFF
|
||||
|
||||
test-race-1:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-aa"
|
||||
if: env.GIT_DIFF
|
||||
- name: Run tests with race detector
|
||||
run: cat xaa.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xaa-race-output.txt
|
||||
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -mod=readonly -timeout 30m -race -tags='cgo ledger test_ledger_mock' > ${{ matrix.part }}-race-output.txt
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-aa-race-output"
|
||||
path: ./xaa-race-output.txt
|
||||
|
||||
test-race-2:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ab"
|
||||
if: env.GIT_DIFF
|
||||
- name: Run tests with race detector
|
||||
run: cat xab.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xab-race-output.txt
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ab-race-output"
|
||||
path: ./xab-race-output.txt
|
||||
|
||||
test-race-3:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ac"
|
||||
if: env.GIT_DIFF
|
||||
- name: Run tests with race detector
|
||||
run: cat xac.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xac-race-output.txt
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ac-race-output"
|
||||
path: ./xac-race-output.txt
|
||||
|
||||
test-race-4:
|
||||
runs-on: ubuntu-latest
|
||||
needs: split-test-files
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2.1.3
|
||||
with:
|
||||
go-version: 1.15
|
||||
- name: Display go version
|
||||
run: go version
|
||||
- uses: technote-space/get-diff-action@v4
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/**.go
|
||||
go.mod
|
||||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ad"
|
||||
if: env.GIT_DIFF
|
||||
- name: Run tests with race detector
|
||||
run: cat xad.txt | xargs go test -mod=readonly -json -timeout 30m -race -tags='cgo ledger test_ledger_mock' > xad-race-output.txt
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ad-race-output"
|
||||
path: ./xad-race-output.txt
|
||||
name: "${{ github.sha }}-${{ matrix.part }}-race-output"
|
||||
path: ./${{ matrix.part }}-race-output.txt
|
||||
|
||||
race-detector-report:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test-race-1, test-race-2, test-race-3, test-race-4, install-tparse]
|
||||
needs: [test-race, install-tparse]
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -387,19 +202,19 @@ jobs:
|
|||
go.sum
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-aa-race-output"
|
||||
name: "${{ github.sha }}-00-race-output"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ab-race-output"
|
||||
name: "${{ github.sha }}-01-race-output"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ac-race-output"
|
||||
name: "${{ github.sha }}-02-race-output"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: "${{ github.sha }}-ad-race-output"
|
||||
name: "${{ github.sha }}-03-race-output"
|
||||
if: env.GIT_DIFF
|
||||
- uses: actions/cache@v2.1.2
|
||||
with:
|
||||
|
@ -407,7 +222,7 @@ jobs:
|
|||
key: ${{ runner.os }}-go-tparse-binary
|
||||
if: env.GIT_DIFF
|
||||
- name: Generate test report (go test -race)
|
||||
run: cat xa*-race-output.txt | ~/go/bin/tparse
|
||||
run: cat ./*-race-output.txt | ~/go/bin/tparse
|
||||
if: env.GIT_DIFF
|
||||
|
||||
liveness-test:
|
||||
|
|
|
@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
|
||||
* (x/staking) [\#7499](https://github.com/cosmos/cosmos-sdk/pull/7499) `BondStatus` is now a protobuf `enum` instead of an `int32`, and JSON serialized using its protobuf name, so expect names like `BOND_STATUS_UNBONDING` as opposed to `Unbonding`.
|
||||
* (x/evidence) [\#7538](https://github.com/cosmos/cosmos-sdk/pull/7538) The ABCI's `Result.Data` field of `MsgSubmitEvidence` does not contain the raw evidence's hash, but the encoded `MsgSubmitEvidenceResponse` struct.
|
||||
* (x/upgrade) [#7697](https://github.com/cosmos/cosmos-sdk/pull/7697) Rename flag name "--time" to "--upgrade-time", "--info" to "--upgrade-info", to keep it consistent with help message.
|
||||
|
||||
### API Breaking
|
||||
|
||||
|
@ -49,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
* `Validator` update. Methods changed in `ValidatorI` (as described above) and `ToTmValidator` return error.
|
||||
* `Validator.ConsensusPubkey` type changed from `string` to `codectypes.Any`.
|
||||
* `MsgCreateValidator.Pubkey` type changed from `string` to `codectypes.Any`.
|
||||
* Deprecating and renaming `MakeEncodingConfig` to `MakeTestEncodingConfig` (both in `simapp` and `simapp/params` packages).
|
||||
|
||||
### Features
|
||||
|
||||
|
@ -58,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
### Bug Fixes
|
||||
|
||||
* (kvstore) [\#7415](https://github.com/cosmos/cosmos-sdk/pull/7415) Allow new stores to be registered during on-chain upgrades.
|
||||
* (client) [\#7699](https://github.com/cosmos/cosmos-sdk/pull/7699) Fix panic in context when setting invalid nodeURI. `WithNodeURI` does not set the `Client` in the context.
|
||||
|
||||
|
||||
## [v0.40.0-rc0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0-rc0) - 2020-10-13
|
||||
|
|
|
@ -142,6 +142,8 @@ build, in which case we can fall back on `go mod tidy -v`.
|
|||
|
||||
We use [Protocol Buffers](https://developers.google.com/protocol-buffers) along with [gogoproto](https://github.com/gogo/protobuf) to generate code for use in Cosmos-SDK.
|
||||
|
||||
For formatting code in `.proto` files, you can run `make proto-format` command.
|
||||
|
||||
For linting and checking breaking changes, we use [buf](https://buf.build/). There are two options for linting and to check if your changes will cause a break. The first is that you can install [buf](https://buf.build/docs/installation) locally, the commands for running buf after installing are `make proto-lint` and the breaking changes check will be `make proto-check-breaking`. If you do not want to install buf and have docker installed already then you can use these commands `make proto-lint-docker` and `make proto-check-breaking-docker`.
|
||||
|
||||
To generate the protobuf stubs you must have `protoc` and `protoc-gen-gocosmos` installed. To install these tools run `make proto-tools`. After this step you will be able to run `make proto-gen` to generate the protobuf stubs.
|
||||
|
|
10
Makefile
10
Makefile
|
@ -222,9 +222,9 @@ $(TEST_TARGETS): run-tests
|
|||
|
||||
# check-* compiles and collects tests without running them
|
||||
# note: go test -c doesn't support multiple packages yet (https://github.com/golang/go/issues/15513)
|
||||
CHECK_TEST_TARGETS := test-unit test-unit-amino
|
||||
check-test-unit: test-unit
|
||||
check-test-unit-amino: test-unit-amino
|
||||
CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino
|
||||
check-test-unit: ARGS=-tags='cgo ledger test_ledger_mock norace'
|
||||
check-test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino norace'
|
||||
$(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none
|
||||
$(CHECK_TEST_TARGETS): run-tests
|
||||
|
||||
|
@ -362,7 +362,11 @@ proto-gen:
|
|||
@./scripts/protocgen.sh
|
||||
|
||||
proto-format:
|
||||
@echo "Formatting Protobuf files"
|
||||
docker run -v $(shell pwd):/workspace \
|
||||
--workdir /workspace tendermintdev/docker-build-proto \
|
||||
find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
|
||||
.PHONY: proto-format
|
||||
|
||||
# This generates the SDK's custom wrapper for google.protobuf.Any. It should only be run manually when needed
|
||||
proto-gen-any:
|
||||
|
|
|
@ -54,13 +54,31 @@ func (qrt *GRPCQueryRouter) Route(path string) GRPCQueryHandler {
|
|||
}
|
||||
|
||||
// RegisterService implements the gRPC Server.RegisterService method. sd is a gRPC
|
||||
// service description, handler is an object which implements that gRPC service
|
||||
// service description, handler is an object which implements that gRPC service/
|
||||
//
|
||||
// This functions PANICS:
|
||||
// - if a protobuf service is registered twice.
|
||||
func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) {
|
||||
// adds a top-level query handler based on the gRPC service name
|
||||
for _, method := range sd.Methods {
|
||||
fqName := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
|
||||
methodHandler := method.Handler
|
||||
|
||||
// Check that each service is only registered once. If a service is
|
||||
// registered more than once, then we should error. Since we can't
|
||||
// return an error (`Server.RegisterService` interface restriction) we
|
||||
// panic (at startup).
|
||||
_, found := qrt.routes[fqName]
|
||||
if found {
|
||||
panic(
|
||||
fmt.Errorf(
|
||||
"gRPC query service %s has already been registered. Please make sure to only register each service once. "+
|
||||
"This usually means that there are conflicting modules registering the same gRPC query service",
|
||||
fqName,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
qrt.routes[fqName] = func(ctx sdk.Context, req abci.RequestQuery) (abci.ResponseQuery, error) {
|
||||
// call the method handler from the service description with the handler object,
|
||||
// a wrapped sdk.Context with proto-unmarshaled data from the ABCI request data
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
// service client.
|
||||
type QueryServiceTestHelper struct {
|
||||
*GRPCQueryRouter
|
||||
ctx sdk.Context
|
||||
Ctx sdk.Context
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -31,7 +31,7 @@ var (
|
|||
func NewQueryServerTestHelper(ctx sdk.Context, interfaceRegistry types.InterfaceRegistry) *QueryServiceTestHelper {
|
||||
qrt := NewGRPCQueryRouter()
|
||||
qrt.SetInterfaceRegistry(interfaceRegistry)
|
||||
return &QueryServiceTestHelper{GRPCQueryRouter: qrt, ctx: ctx}
|
||||
return &QueryServiceTestHelper{GRPCQueryRouter: qrt, Ctx: ctx}
|
||||
}
|
||||
|
||||
// Invoke implements the grpc ClientConn.Invoke method
|
||||
|
@ -45,7 +45,7 @@ func (q *QueryServiceTestHelper) Invoke(_ gocontext.Context, method string, args
|
|||
return err
|
||||
}
|
||||
|
||||
res, err := querier(q.ctx, abci.RequestQuery{Data: reqBz})
|
||||
res, err := querier(q.Ctx, abci.RequestQuery{Data: reqBz})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
package baseapp
|
||||
package baseapp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func TestGRPCRouter(t *testing.T) {
|
||||
qr := NewGRPCQueryRouter()
|
||||
qr := baseapp.NewGRPCQueryRouter()
|
||||
interfaceRegistry := testdata.NewTestInterfaceRegistry()
|
||||
qr.SetInterfaceRegistry(interfaceRegistry)
|
||||
testdata.RegisterQueryServer(qr, testdata.QueryImpl{})
|
||||
helper := &QueryServiceTestHelper{
|
||||
helper := &baseapp.QueryServiceTestHelper{
|
||||
GRPCQueryRouter: qr,
|
||||
ctx: sdk.Context{}.WithContext(context.Background()),
|
||||
Ctx: sdk.Context{}.WithContext(context.Background()),
|
||||
}
|
||||
client := testdata.NewQueryClient(helper)
|
||||
|
||||
|
@ -44,3 +49,28 @@ func TestGRPCRouter(t *testing.T) {
|
|||
require.NotNil(t, res3)
|
||||
require.Equal(t, spot, res3.HasAnimal.Animal.GetCachedValue())
|
||||
}
|
||||
|
||||
func TestRegisterQueryServiceTwice(t *testing.T) {
|
||||
// Setup baseapp.
|
||||
db := dbm.NewMemDB()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
||||
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
||||
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
|
||||
// First time registering service shouldn't panic.
|
||||
require.NotPanics(t, func() {
|
||||
testdata.RegisterQueryServer(
|
||||
app.GRPCQueryRouter(),
|
||||
testdata.QueryImpl{},
|
||||
)
|
||||
})
|
||||
|
||||
// Second time should panic.
|
||||
require.Panics(t, func() {
|
||||
testdata.RegisterQueryServer(
|
||||
app.GRPCQueryRouter(),
|
||||
testdata.QueryImpl{},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -39,27 +39,49 @@ func (msr *MsgServiceRouter) Handler(methodName string) MsgServiceHandler {
|
|||
|
||||
// RegisterService implements the gRPC Server.RegisterService method. sd is a gRPC
|
||||
// service description, handler is an object which implements that gRPC service.
|
||||
//
|
||||
// This function PANICs:
|
||||
// - if it is called before the service `Msg`s have been registered using
|
||||
// RegisterInterfaces,
|
||||
// - or if a service is being registered twice.
|
||||
func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) {
|
||||
// Adds a top-level query handler based on the gRPC service name.
|
||||
for _, method := range sd.Methods {
|
||||
fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
|
||||
methodHandler := method.Handler
|
||||
|
||||
// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.
|
||||
// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.
|
||||
// We use a no-op interceptor to avoid actually calling into the handler itself.
|
||||
_, _ = methodHandler(nil, context.Background(), func(i interface{}) error {
|
||||
msg, ok := i.(proto.Message)
|
||||
if !ok {
|
||||
// We panic here because there is no other alternative and the app cannot be initialized correctly
|
||||
// this should only happen if there is a problem with code generation in which case the app won't
|
||||
// work correctly anyway.
|
||||
panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
|
||||
}
|
||||
// Check that the service Msg fully-qualified method name has already
|
||||
// been registered (via RegisterInterfaces). If the user registers a
|
||||
// service without registering according service Msg type, there might be
|
||||
// some unexpected behavior down the road. Since we can't return an error
|
||||
// (`Server.RegisterService` interface restriction) we panic (at startup).
|
||||
serviceMsg, err := msr.interfaceRegistry.Resolve(fqMethod)
|
||||
if err != nil || serviceMsg == nil {
|
||||
panic(
|
||||
fmt.Errorf(
|
||||
"type_url %s has not been registered yet. "+
|
||||
"Before calling RegisterService, you must register all interfaces by calling the `RegisterInterfaces` "+
|
||||
"method on module.BasicManager. Each module should call `msgservice.RegisterMsgServiceDesc` inside its "+
|
||||
"`RegisterInterfaces` method with the `_Msg_serviceDesc` generated by proto-gen",
|
||||
fqMethod,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
msr.interfaceRegistry.RegisterCustomTypeURL((*sdk.MsgRequest)(nil), fqMethod, msg)
|
||||
return nil
|
||||
}, noopInterceptor)
|
||||
// Check that each service is only registered once. If a service is
|
||||
// registered more than once, then we should error. Since we can't
|
||||
// return an error (`Server.RegisterService` interface restriction) we
|
||||
// panic (at startup).
|
||||
_, found := msr.routes[fqMethod]
|
||||
if found {
|
||||
panic(
|
||||
fmt.Errorf(
|
||||
"msg service %s has already been registered. Please make sure to only register each service once. "+
|
||||
"This usually means that there are conflicting modules registering the same msg service",
|
||||
fqMethod,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
msr.routes[fqMethod] = func(ctx sdk.Context, req sdk.MsgRequest) (*sdk.Result, error) {
|
||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||
|
@ -89,9 +111,4 @@ func (msr *MsgServiceRouter) SetInterfaceRegistry(interfaceRegistry codectypes.I
|
|||
msr.interfaceRegistry = interfaceRegistry
|
||||
}
|
||||
|
||||
// gRPC NOOP interceptor
|
||||
func noopInterceptor(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func noopDecoder(_ interface{}) error { return nil }
|
||||
|
|
|
@ -4,15 +4,13 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
|
@ -20,9 +18,59 @@ import (
|
|||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||
)
|
||||
|
||||
func TestRegisterMsgService(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
|
||||
// Create an encoding config that doesn't register testdata Msg services.
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
||||
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
||||
require.Panics(t, func() {
|
||||
testdata.RegisterMsgServer(
|
||||
app.MsgServiceRouter(),
|
||||
testdata.MsgServerImpl{},
|
||||
)
|
||||
})
|
||||
|
||||
// Register testdata Msg services, and rerun `RegisterService`.
|
||||
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
require.NotPanics(t, func() {
|
||||
testdata.RegisterMsgServer(
|
||||
app.MsgServiceRouter(),
|
||||
testdata.MsgServerImpl{},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegisterMsgServiceTwice(t *testing.T) {
|
||||
// Setup baseapp.
|
||||
db := dbm.NewMemDB()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
||||
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
||||
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
|
||||
// First time registering service shouldn't panic.
|
||||
require.NotPanics(t, func() {
|
||||
testdata.RegisterMsgServer(
|
||||
app.MsgServiceRouter(),
|
||||
testdata.MsgServerImpl{},
|
||||
)
|
||||
})
|
||||
|
||||
// Second time should panic.
|
||||
require.Panics(t, func() {
|
||||
testdata.RegisterMsgServer(
|
||||
app.MsgServiceRouter(),
|
||||
testdata.MsgServerImpl{},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMsgService(t *testing.T) {
|
||||
priv, _, _ := testdata.KeyTestPubAddr()
|
||||
encCfg := simapp.MakeEncodingConfig()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
db := dbm.NewMemDB()
|
||||
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
||||
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -131,6 +132,13 @@ func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Cont
|
|||
rpcURI, _ := flagSet.GetString(flags.FlagNode)
|
||||
if rpcURI != "" {
|
||||
clientCtx = clientCtx.WithNodeURI(rpcURI)
|
||||
|
||||
client, err := rpchttp.New(rpcURI, "/websocket")
|
||||
if err != nil {
|
||||
return clientCtx, err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithClient(client)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
|
@ -95,12 +94,6 @@ func (ctx Context) WithOutputFormat(format string) Context {
|
|||
// WithNodeURI returns a copy of the context with an updated node URI.
|
||||
func (ctx Context) WithNodeURI(nodeURI string) Context {
|
||||
ctx.NodeURI = nodeURI
|
||||
client, err := rpchttp.New(nodeURI, "/websocket")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx.Client = client
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
|
|
@ -41773,4 +41773,4 @@
|
|||
}, o.resolve = i, e.exports = o, o.id = 1058
|
||||
}])
|
||||
});
|
||||
//# sourceMappingURL=swagger-ui-bundle.js.map
|
||||
//# sourceMappingURL=swagger-ui-bundle.js.map
|
||||
|
|
|
@ -2595,4 +2595,4 @@ definitions:
|
|||
total:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/Coin"
|
||||
$ref: "#/definitions/Coin"
|
||||
|
|
|
@ -21,14 +21,9 @@ type IntegrationTestSuite struct {
|
|||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
app := simapp.Setup(false)
|
||||
|
||||
srv := reflection.NewReflectionServiceServer(app.InterfaceRegistry())
|
||||
|
||||
sdkCtx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(sdkCtx, app.InterfaceRegistry())
|
||||
|
||||
reflection.RegisterReflectionServiceServer(queryHelper, srv)
|
||||
queryClient := reflection.NewReflectionServiceClient(queryHelper)
|
||||
|
||||
s.queryClient = queryClient
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
|||
app.BankKeeper.SetParams(sdkCtx, banktypes.DefaultParams())
|
||||
|
||||
// Set up TxConfig.
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
||||
|
||||
// Create new simulation server.
|
||||
|
|
|
@ -306,7 +306,6 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
|
|||
|
||||
// print mnemonic unless requested not to.
|
||||
if showMnemonic {
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "It is the only way to recover your account if you ever forget your password.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "")
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP
|
||||
// Deprecation headers to a http handler
|
||||
func addHTTPDeprecationHeaders(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Deprecation", "true")
|
||||
w.Header().Set("Link", "<https://docs.cosmos.network/v0.40/interfaces/rest.html>; rel=\"deprecation\"")
|
||||
w.Header().Set("Warning", "199 - \"this endpoint is deprecated and may not work as before, see deprecation link for more info\"")
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input
|
||||
// but with the addition of HTTP Deprecation headers. This is used to mark legacy
|
||||
// amino REST endpoints as deprecated in the REST API.
|
||||
func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router {
|
||||
subRouter := r.NewRoute().Subrouter()
|
||||
subRouter.Use(addHTTPDeprecationHeaders)
|
||||
return subRouter
|
||||
}
|
|
@ -57,7 +57,7 @@ type TestSuite struct {
|
|||
}
|
||||
|
||||
func (s *TestSuite) SetupSuite() {
|
||||
encCfg := simapp.MakeEncodingConfig()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
s.encCfg = encCfg
|
||||
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), tx.DefaultSignModes)
|
||||
s.aminoCfg = legacytx.StdTxConfig{Cdc: encCfg.Amino}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func NewTestTxConfig() client.TxConfig {
|
||||
cfg := simapp.MakeEncodingConfig()
|
||||
cfg := simapp.MakeTestEncodingConfig()
|
||||
return cfg.TxConfig
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,13 @@ import (
|
|||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// ProtoCodecMarshaler defines an interface for codecs that utilize Protobuf for both
|
||||
// binary and JSON encoding.
|
||||
type ProtoCodecMarshaler interface {
|
||||
Marshaler
|
||||
InterfaceRegistry() types.InterfaceRegistry
|
||||
}
|
||||
|
||||
// ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON
|
||||
// encoding.
|
||||
type ProtoCodec struct {
|
||||
|
@ -18,6 +25,7 @@ type ProtoCodec struct {
|
|||
}
|
||||
|
||||
var _ Marshaler = &ProtoCodec{}
|
||||
var _ ProtoCodecMarshaler = &ProtoCodec{}
|
||||
|
||||
// NewProtoCodec returns a reference to a new ProtoCodec
|
||||
func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {
|
||||
|
|
|
@ -115,6 +115,11 @@ func (registry *interfaceRegistry) RegisterInterface(protoName string, iface int
|
|||
registry.RegisterImplementations(iface, impls...)
|
||||
}
|
||||
|
||||
// RegisterImplementations registers a concrete proto Message which implements
|
||||
// the given interface.
|
||||
//
|
||||
// This function PANICs if different concrete types are registered under the
|
||||
// same typeURL.
|
||||
func (registry *interfaceRegistry) RegisterImplementations(iface interface{}, impls ...proto.Message) {
|
||||
for _, impl := range impls {
|
||||
typeURL := "/" + proto.MessageName(impl)
|
||||
|
@ -122,10 +127,20 @@ func (registry *interfaceRegistry) RegisterImplementations(iface interface{}, im
|
|||
}
|
||||
}
|
||||
|
||||
// RegisterCustomTypeURL registers a concrete type which implements the given
|
||||
// interface under `typeURL`.
|
||||
//
|
||||
// This function PANICs if different concrete types are registered under the
|
||||
// same typeURL.
|
||||
func (registry *interfaceRegistry) RegisterCustomTypeURL(iface interface{}, typeURL string, impl proto.Message) {
|
||||
registry.registerImpl(iface, typeURL, impl)
|
||||
}
|
||||
|
||||
// registerImpl registers a concrete type which implements the given
|
||||
// interface under `typeURL`.
|
||||
//
|
||||
// This function PANICs if different concrete types are registered under the
|
||||
// same typeURL.
|
||||
func (registry *interfaceRegistry) registerImpl(iface interface{}, typeURL string, impl proto.Message) {
|
||||
ityp := reflect.TypeOf(iface).Elem()
|
||||
imap, found := registry.interfaceImpls[ityp]
|
||||
|
@ -138,6 +153,24 @@ func (registry *interfaceRegistry) registerImpl(iface interface{}, typeURL strin
|
|||
panic(fmt.Errorf("type %T doesn't actually implement interface %+v", impl, ityp))
|
||||
}
|
||||
|
||||
// Check if we already registered something under the given typeURL. It's
|
||||
// okay to register the same concrete type again, but if we are registering
|
||||
// a new concrete type under the same typeURL, then we throw an error (here,
|
||||
// we panic).
|
||||
foundImplType, found := imap[typeURL]
|
||||
if found && foundImplType != implType {
|
||||
panic(
|
||||
fmt.Errorf(
|
||||
"concrete type %s has already been registered under typeURL %s, cannot register %s under same typeURL. "+
|
||||
"This usually means that there are conflicting modules registering different concrete types "+
|
||||
"for a same interface implementation",
|
||||
foundImplType,
|
||||
typeURL,
|
||||
implType,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
imap[typeURL] = implType
|
||||
registry.typeURLMap[typeURL] = implType
|
||||
|
||||
|
|
|
@ -48,22 +48,61 @@ type TestI interface {
|
|||
DoSomething()
|
||||
}
|
||||
|
||||
// A struct that has the same typeURL as testdata.Dog, but is actually another
|
||||
// concrete type.
|
||||
type FakeDog struct{}
|
||||
|
||||
var (
|
||||
_ proto.Message = &FakeDog{}
|
||||
_ testdata.Animal = &FakeDog{}
|
||||
)
|
||||
|
||||
// dummy implementation of proto.Message and testdata.Animal
|
||||
func (dog FakeDog) Reset() {}
|
||||
func (dog FakeDog) String() string { return "fakedog" }
|
||||
func (dog FakeDog) ProtoMessage() {}
|
||||
func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) }
|
||||
func (dog FakeDog) Greet() string { return "fakedog" }
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
registry := types.NewInterfaceRegistry()
|
||||
registry.RegisterInterface("Animal", (*testdata.Animal)(nil))
|
||||
registry.RegisterInterface("TestI", (*TestI)(nil))
|
||||
|
||||
// Happy path.
|
||||
require.NotPanics(t, func() {
|
||||
registry.RegisterImplementations((*testdata.Animal)(nil), &testdata.Dog{})
|
||||
})
|
||||
|
||||
// testdata.Dog doesn't implement TestI
|
||||
require.Panics(t, func() {
|
||||
registry.RegisterImplementations((*TestI)(nil), &testdata.Dog{})
|
||||
})
|
||||
|
||||
// nil proto message
|
||||
require.Panics(t, func() {
|
||||
registry.RegisterImplementations((*TestI)(nil), nil)
|
||||
})
|
||||
|
||||
// Not an interface.
|
||||
require.Panics(t, func() {
|
||||
registry.RegisterInterface("not_an_interface", (*testdata.Dog)(nil))
|
||||
})
|
||||
|
||||
// Duplicate registration with same concrete type.
|
||||
require.NotPanics(t, func() {
|
||||
registry.RegisterImplementations((*testdata.Animal)(nil), &testdata.Dog{})
|
||||
})
|
||||
|
||||
// Duplicate registration with different concrete type on same typeURL.
|
||||
require.PanicsWithError(
|
||||
t,
|
||||
"concrete type *testdata.Dog has already been registered under typeURL /testdata.Dog, cannot register *types_test.FakeDog under same typeURL. "+
|
||||
"This usually means that there are conflicting modules registering different concrete types for a same interface implementation",
|
||||
func() {
|
||||
registry.RegisterImplementations((*testdata.Animal)(nil), &FakeDog{})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestUnpackInterfaces(t *testing.T) {
|
||||
|
|
|
@ -119,32 +119,6 @@ f_install_protoc_gen_swagger() {
|
|||
f_print_done
|
||||
}
|
||||
|
||||
f_install_clang_format() {
|
||||
f_print_installing_with_padding clang-format
|
||||
|
||||
if which clang-format &>/dev/null ; then
|
||||
echo -e "\talready installed. Skipping."
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "${UNAME_S}" in
|
||||
Linux)
|
||||
if [ -e /etc/debian_version ]; then
|
||||
echo -e "\tRun: sudo apt-get install clang-format" >&2
|
||||
elif [ -e /etc/fedora-release ]; then
|
||||
echo -e "\tRun: sudo dnf install clang" >&2
|
||||
else
|
||||
echo -e "\tRun (as root): subscription-manager repos --enable rhel-7-server-devtools-rpms ; yum install llvm-toolset-7" >&2
|
||||
fi
|
||||
;;
|
||||
Darwin)
|
||||
echo "\tRun: brew install clang-format" >&2
|
||||
;;
|
||||
*)
|
||||
echo "\tunknown operating system. Skipping." >&2
|
||||
esac
|
||||
}
|
||||
|
||||
f_ensure_tools
|
||||
f_ensure_dirs
|
||||
f_install_protoc
|
||||
|
@ -152,4 +126,3 @@ f_install_buf
|
|||
f_install_protoc_gen_gocosmos
|
||||
f_install_protoc_gen_grpc_gateway
|
||||
f_install_protoc_gen_swagger
|
||||
f_install_clang_format
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ed25519
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -8,7 +9,6 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto"
|
||||
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
@ -50,7 +50,7 @@ func (privKey *PrivKey) Bytes() []byte {
|
|||
// If these conditions aren't met, Sign will panic or produce an
|
||||
// incorrect signature.
|
||||
func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
|
||||
return ed25519.Sign(ed25519.PrivateKey(privKey.Key), msg), nil
|
||||
return ed25519.Sign(privKey.Key, msg), nil
|
||||
}
|
||||
|
||||
// PubKey gets the corresponding public key from the private key.
|
||||
|
@ -171,7 +171,7 @@ func (pubKey *PubKey) VerifySignature(msg []byte, sig []byte) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return ed25519.Verify(ed25519.PublicKey(pubKey.Key), msg, sig)
|
||||
return ed25519.Verify(pubKey.Key, msg, sig)
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) String() string {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ed25519_test
|
||||
|
||||
import (
|
||||
stded25519 "crypto/ed25519"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
|
@ -11,7 +12,7 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
ed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
)
|
||||
|
||||
|
@ -19,17 +20,28 @@ func TestSignAndValidateEd25519(t *testing.T) {
|
|||
privKey := ed25519.GenPrivKey()
|
||||
pubKey := privKey.PubKey()
|
||||
|
||||
msg := crypto.CRandBytes(128)
|
||||
msg := crypto.CRandBytes(1000)
|
||||
sig, err := privKey.Sign(msg)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Test the signature
|
||||
assert.True(t, pubKey.VerifySignature(msg, sig))
|
||||
|
||||
// ----
|
||||
// Test cross packages verification
|
||||
stdPrivKey := stded25519.PrivateKey(privKey.Key)
|
||||
stdPubKey := stdPrivKey.Public().(stded25519.PublicKey)
|
||||
|
||||
assert.Equal(t, stdPubKey, pubKey.(*ed25519.PubKey).Key)
|
||||
assert.Equal(t, stdPrivKey, privKey.Key)
|
||||
assert.True(t, stded25519.Verify(stdPubKey, msg, sig))
|
||||
sig2 := stded25519.Sign(stdPrivKey, msg)
|
||||
assert.True(t, pubKey.VerifySignature(msg, sig2))
|
||||
|
||||
// ----
|
||||
// Mutate the signature, just one bit.
|
||||
// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
|
||||
sig[7] ^= byte(0x01)
|
||||
|
||||
assert.False(t, pubKey.VerifySignature(msg, sig))
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package ed25519
|
||||
|
||||
import (
|
||||
crypto_ed25519 "crypto/ed25519"
|
||||
fmt "fmt"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
|
@ -29,7 +30,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|||
// the x-coordinate. Otherwise the first byte is a 0x03.
|
||||
// This prefix is followed with the x-coordinate.
|
||||
type PubKey struct {
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Key crypto_ed25519.PublicKey `protobuf:"bytes,1,opt,name=key,proto3,casttype=crypto/ed25519.PublicKey" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PubKey) Reset() { *m = PubKey{} }
|
||||
|
@ -64,7 +65,7 @@ func (m *PubKey) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_PubKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PubKey) GetKey() []byte {
|
||||
func (m *PubKey) GetKey() crypto_ed25519.PublicKey {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
|
@ -73,7 +74,7 @@ func (m *PubKey) GetKey() []byte {
|
|||
|
||||
// PrivKey defines a ed25519 private key.
|
||||
type PrivKey struct {
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Key crypto_ed25519.PrivateKey `protobuf:"bytes,1,opt,name=key,proto3,casttype=crypto/ed25519.PrivateKey" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PrivKey) Reset() { *m = PrivKey{} }
|
||||
|
@ -109,7 +110,7 @@ func (m *PrivKey) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_PrivKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PrivKey) GetKey() []byte {
|
||||
func (m *PrivKey) GetKey() crypto_ed25519.PrivateKey {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
|
@ -124,19 +125,21 @@ func init() {
|
|||
func init() { proto.RegisterFile("cosmos/crypto/ed25519/keys.proto", fileDescriptor_48fe3336771e732d) }
|
||||
|
||||
var fileDescriptor_48fe3336771e732d = []byte{
|
||||
// 183 bytes of a gzipped FileDescriptorProto
|
||||
// 221 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0x4f, 0x4d, 0x31, 0x32, 0x35, 0x35,
|
||||
0xb4, 0xd4, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0xa8,
|
||||
0xd0, 0x83, 0xa8, 0xd0, 0x83, 0xaa, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd0, 0x07,
|
||||
0xb1, 0x20, 0x8a, 0x95, 0x14, 0xb8, 0xd8, 0x02, 0x4a, 0x93, 0xbc, 0x53, 0x2b, 0x85, 0x04, 0xb8,
|
||||
0x98, 0xb3, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x78, 0x82, 0x40, 0x4c, 0x2b, 0x96, 0x19,
|
||||
0x0b, 0xe4, 0x19, 0x94, 0xa4, 0xb9, 0xd8, 0x03, 0x8a, 0x32, 0xcb, 0xb0, 0x2a, 0x71, 0xf2, 0x3a,
|
||||
0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63,
|
||||
0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2,
|
||||
0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x98, 0x93, 0xc1, 0x94, 0x6e, 0x71, 0x4a, 0x36, 0xcc, 0xf5,
|
||||
0x20, 0x57, 0xc3, 0xbc, 0x90, 0xc4, 0x06, 0x76, 0x91, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xcc,
|
||||
0xf3, 0x11, 0x99, 0xe2, 0x00, 0x00, 0x00,
|
||||
0xb1, 0x20, 0x8a, 0x95, 0xec, 0xb8, 0xd8, 0x02, 0x4a, 0x93, 0xbc, 0x53, 0x2b, 0x85, 0xf4, 0xb8,
|
||||
0x98, 0xb3, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x78, 0x9c, 0x64, 0x7e, 0xdd, 0x93, 0x97,
|
||||
0x40, 0xb5, 0x42, 0x2f, 0xa0, 0x34, 0x29, 0x27, 0x33, 0xd9, 0x3b, 0xb5, 0x32, 0x08, 0xa4, 0xd0,
|
||||
0x8a, 0x65, 0xc6, 0x02, 0x79, 0x06, 0x25, 0x2b, 0x2e, 0xf6, 0x80, 0xa2, 0xcc, 0x32, 0x90, 0x01,
|
||||
0xfa, 0xc8, 0x06, 0xc8, 0xfe, 0xba, 0x27, 0x2f, 0x89, 0x6e, 0x40, 0x51, 0x66, 0x59, 0x62, 0x49,
|
||||
0x2a, 0xcc, 0x04, 0x27, 0xaf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48,
|
||||
0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32,
|
||||
0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0xf9, 0x17, 0x4c, 0xe9,
|
||||
0x16, 0xa7, 0x64, 0xc3, 0xbc, 0x0e, 0xf2, 0x32, 0xcc, 0xec, 0x24, 0x36, 0xb0, 0x77, 0x8c, 0x01,
|
||||
0x01, 0x00, 0x00, 0xff, 0xff, 0xb0, 0xd8, 0x01, 0xc0, 0x1f, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *PubKey) Marshal() (dAtA []byte, err error) {
|
||||
|
|
|
@ -9,13 +9,12 @@ import (
|
|||
"math/big"
|
||||
|
||||
secp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"golang.org/x/crypto/ripemd160" // nolint: staticcheck // necessary for Bitcoin address format
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
var _ cryptotypes.PrivKey = &PrivKey{}
|
||||
|
|
|
@ -19,6 +19,8 @@ func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
|
|||
return rs, nil
|
||||
}
|
||||
|
||||
// VerifySignature validates the signature.
|
||||
// The msg will be hashed prior to signature verification.
|
||||
func (pubKey *PrivKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
return secp256k1.VerifySignature(pubKey.Key, crypto.Sha256(msg), sig)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,8 @@ import (
|
|||
"math/big"
|
||||
"testing"
|
||||
|
||||
btcSecp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
underlyingSecp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
)
|
||||
|
||||
func Test_genPrivKey(t *testing.T) {
|
||||
|
@ -25,7 +24,7 @@ func Test_genPrivKey(t *testing.T) {
|
|||
shouldPanic bool
|
||||
}{
|
||||
{"empty bytes (panics because 1st 32 bytes are zero and 0 is not a valid field element)", empty, true},
|
||||
{"curve order: N", underlyingSecp256k1.S256().N.Bytes(), true},
|
||||
{"curve order: N", btcSecp256k1.S256().N.Bytes(), true},
|
||||
{"valid because 0 < 1 < N", validOne, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -39,7 +38,7 @@ func Test_genPrivKey(t *testing.T) {
|
|||
}
|
||||
got := genPrivKey(bytes.NewReader(tt.notSoRand))
|
||||
fe := new(big.Int).SetBytes(got[:])
|
||||
require.True(t, fe.Cmp(underlyingSecp256k1.S256().N) < 0)
|
||||
require.True(t, fe.Cmp(btcSecp256k1.S256().N) < 0)
|
||||
require.True(t, fe.Sign() > 0)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package secp256k1_test
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
btcSecp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
|
||||
underlyingSecp256k1 "github.com/btcsuite/btcd/btcec"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
@ -41,7 +40,7 @@ func TestPubKeySecp256k1Address(t *testing.T) {
|
|||
addrBbz, _, _ := base58.CheckDecode(d.addr)
|
||||
addrB := crypto.Address(addrBbz)
|
||||
|
||||
var priv secp256k1.PrivKey = secp256k1.PrivKey{Key: privB}
|
||||
var priv = secp256k1.PrivKey{Key: privB}
|
||||
|
||||
pubKey := priv.PubKey()
|
||||
pubT, _ := pubKey.(*secp256k1.PubKey)
|
||||
|
@ -56,15 +55,34 @@ func TestSignAndValidateSecp256k1(t *testing.T) {
|
|||
privKey := secp256k1.GenPrivKey()
|
||||
pubKey := privKey.PubKey()
|
||||
|
||||
msg := crypto.CRandBytes(128)
|
||||
msg := crypto.CRandBytes(1000)
|
||||
sig, err := privKey.Sign(msg)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.True(t, pubKey.VerifySignature(msg, sig))
|
||||
|
||||
// ----
|
||||
// Test cross packages verification
|
||||
msgHash := crypto.Sha256(msg)
|
||||
btcPrivKey, btcPubKey := btcSecp256k1.PrivKeyFromBytes(btcSecp256k1.S256(), privKey.Key)
|
||||
// This fails: malformed signature: no header magic
|
||||
// btcSig, err := secp256k1.ParseSignature(sig, secp256k1.S256())
|
||||
// require.NoError(t, err)
|
||||
// assert.True(t, btcSig.Verify(msgHash, btcPubKey))
|
||||
// So we do a hacky way:
|
||||
r := new(big.Int)
|
||||
s := new(big.Int)
|
||||
r.SetBytes(sig[:32])
|
||||
s.SetBytes(sig[32:])
|
||||
ok := ecdsa.Verify(btcPubKey.ToECDSA(), msgHash, r, s)
|
||||
require.True(t, ok)
|
||||
|
||||
sig2, err := btcPrivKey.Sign(msgHash)
|
||||
require.NoError(t, err)
|
||||
pubKey.VerifySignature(msg, sig2.Serialize())
|
||||
|
||||
// ----
|
||||
// Mutate the signature, just one bit.
|
||||
sig[3] ^= byte(0x01)
|
||||
|
||||
assert.False(t, pubKey.VerifySignature(msg, sig))
|
||||
}
|
||||
|
||||
|
@ -79,7 +97,7 @@ func TestSecp256k1LoadPrivkeyAndSerializeIsIdentity(t *testing.T) {
|
|||
|
||||
// This function creates a private and public key in the underlying libraries format.
|
||||
// The private key is basically calling new(big.Int).SetBytes(pk), which removes leading zero bytes
|
||||
priv, _ := underlyingSecp256k1.PrivKeyFromBytes(underlyingSecp256k1.S256(), privKeyBytes[:])
|
||||
priv, _ := btcSecp256k1.PrivKeyFromBytes(btcSecp256k1.S256(), privKeyBytes[:])
|
||||
// this takes the bytes returned by `(big int).Bytes()`, and if the length is less than 32 bytes,
|
||||
// pads the bytes from the left with zero bytes. Therefore these two functions composed
|
||||
// result in the identity function on privKeyBytes, hence the following equality check
|
||||
|
@ -91,7 +109,7 @@ func TestSecp256k1LoadPrivkeyAndSerializeIsIdentity(t *testing.T) {
|
|||
|
||||
func TestGenPrivKeyFromSecret(t *testing.T) {
|
||||
// curve oder N
|
||||
N := underlyingSecp256k1.S256().N
|
||||
N := btcSecp256k1.S256().N
|
||||
tests := []struct {
|
||||
name string
|
||||
secret []byte
|
||||
|
|
|
@ -49,17 +49,17 @@ The first thing defined in `app.go` is the `type` of the application. It is gene
|
|||
- **A list of module's `keeper`s.** Each module defines an abstraction called [`keeper`](../building-modules/keeper.md), which handles reads and writes for this module's store(s). The `keeper`'s methods of one module can be called from other modules (if authorized), which is why they are declared in the application's type and exported as interfaces to other modules so that the latter can only access the authorized functions.
|
||||
- **A reference to an [`appCodec`](../core/encoding.md).** The application's `appCodec` is used to serialize and deserialize data structures in order to store them, as stores can only persist `[]bytes`. The default codec is [Protocol Buffers](../core/encoding.md).
|
||||
- **A reference to a [`legacyAmino`](../core/encoding.md) codec.** Some parts of the SDK have not been migrated to use the `appCodec` above, and are still hardcoded to use Amino. Other parts explicity use Amino for backwards compatibility. For these reasons, the application still holds a reference to the legacy Amino codec. Please note that the Amino codec will be removed from the SDK in the upcoming releases.
|
||||
- **A reference to a [module manager](../building-modules/module-manager.md#manager)** and a [basic module manager](../building-modules/module-manager.md#basicmanager). The module manager is an object that contains a list of the application's module. It facilitates operations related to these modules, like registering [`routes`](../core/baseapp.md#routing), [gRPC query services](../core/baseapp.md#grpc-query-services) and [legacy Tendermint query routes](../core/baseapp.md#legacy-query-routing) or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker).
|
||||
- **A reference to a [module manager](../building-modules/module-manager.md#manager)** and a [basic module manager](../building-modules/module-manager.md#basicmanager). The module manager is an object that contains a list of the application's module. It facilitates operations related to these modules, like registering their [`Msg` services](../core/baseapp.md#msg-services) and [gRPC `Query` services](../core/baseapp.md#grpc-query-services), or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker). For backwards-compatibility reasons, all modules expose [legacy `Msg`s routes](../core/baseapp.md#routing) and [legacy query routes](../core/baseapp.md#legacy-query-routing), which are also registered by the module manager..
|
||||
|
||||
See an example of application type definition from `simapp`, the SDK's own app used for demo and testing purposes:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/app.go#L140-L179
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/app.go#L139-L181
|
||||
|
||||
### Constructor Function
|
||||
|
||||
This function constructs a new application of the type defined in the section above. It must fulfill the `AppCreator` signature in order to be used in the [`start` command](../core/node.md#start-command) of the application's daemon command.
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/server/types/app.go#L42-L44
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/server/types/app.go#L42-L44
|
||||
|
||||
Here are the main actions performed by this function:
|
||||
|
||||
|
@ -67,7 +67,7 @@ Here are the main actions performed by this function:
|
|||
- Instantiate a new application with a reference to a `baseapp` instance, a codec and all the appropriate store keys.
|
||||
- Instantiate all the [`keeper`s](#keeper) defined in the application's `type` using the `NewKeeper` function of each of the application's modules. Note that `keepers` must be instantiated in the correct order, as the `NewKeeper` of one module might require a reference to another module's `keeper`.
|
||||
- Instantiate the application's [module manager](../building-modules/module-manager.md#manager) with the [`AppModule`](#application-module-interface) object of each of the application's modules.
|
||||
- With the module manager, initialize the application's [`routes`](../core/baseapp.md#routing), [`gRPC query services`](../core/baseapp.md#grpc-query-services) and [`legacy query routes`](../core/baseapp.md#query-routing). When a transaction is relayed to the application by Tendermint via the ABCI, it is routed to the appropriate module's [`handler`](#handler) using the `routes` defined here. Likewise, when a gRPC request is received by the application, it is routed to the appropriate module's [`gRPC query service`](#grpc-query-services) using the gRPC routes defined here. The SDK still supports legacy Tendermint queries, and these queries are routes using the `legacy query routes`.
|
||||
- With the module manager, initialize the application's [`Msg` services](../core/baseapp.md#msg-services), [gRPC `Query` services](../core/baseapp.md#grpc-query-services), [legacy `Msg` routes](../core/baseapp.md#routing) and [legacy query routes](../core/baseapp.md#query-routing). When a transaction is relayed to the application by Tendermint via the ABCI, it is routed to the appropriate module's [`Msg` service](#msg-services) using the routes defined here. Likewise, when a gRPC query request is received by the application, it is routed to the appropriate module's [`gRPC query service`](#grpc-query-services) using the gRPC routes defined here. The SDK still supports legacy `Msg`s and legacy Tendermint queries, which are routed using respectively the legacy `Msg` routes and the legacy query routes.
|
||||
- With the module manager, register the [application's modules' invariants](../building-modules/invariants.md). Invariants are variables (e.g. total supply of a token) that are evaluated at the end of each block. The process of checking invariants is done via a special module called the [`InvariantsRegistry`](../building-modules/invariants.md#invariant-registry). The value of the invariant should be equal to a predicted value defined in the module. Should the value be different than the predicted one, special logic defined in the invariant registry will be triggered (usually the chain is halted). This is useful to make sure no critical bug goes unnoticed and produces long-lasting effects that would be hard to fix.
|
||||
- With the module manager, set the order of execution between the `InitGenesis`, `BegingBlocker` and `EndBlocker` functions of each of the [application's modules](#application-module-interface). Note that not all modules implement these functions.
|
||||
- Set the remainer of application's parameters:
|
||||
|
@ -81,7 +81,7 @@ Note that this function only creates an instance of the app, while the actual st
|
|||
|
||||
See an example of application constructor from `simapp`:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/app.go#L190-L427
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/app.go#L192-L429
|
||||
|
||||
### InitChainer
|
||||
|
||||
|
@ -91,7 +91,7 @@ In general, the `InitChainer` is mostly composed of the [`InitGenesis`](../build
|
|||
|
||||
See an example of an `InitChainer` from `simapp`:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/app.go#L450-L455
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/app.go#L452-L459
|
||||
|
||||
### BeginBlocker and EndBlocker
|
||||
|
||||
|
@ -103,13 +103,13 @@ As a sidenote, it is important to remember that application-specific blockchains
|
|||
|
||||
See an example of `BeginBlocker` and `EndBlocker` functions from `simapp`
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/app.go#L440-L448
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/app.go#L442-L450
|
||||
|
||||
### Register Codec
|
||||
|
||||
The `EncodingConfig` structure is the last important part of the `app.go` file. The goal of this structure is to define the codecs that will be used throughout the app.
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/params/encoding.go#L9-L16
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/params/encoding.go#L9-L16
|
||||
|
||||
Here are descriptions of what each of the four fields means:
|
||||
|
||||
|
@ -123,7 +123,7 @@ The SDK exposes a `MakeCodecs` function used to create a `EncodingConfig`. It us
|
|||
|
||||
See an example of a `MakeCodecs` from `simapp`:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/simapp/app.go#L429-L435
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/simapp/app.go#L429-L435
|
||||
|
||||
## Modules
|
||||
|
||||
|
@ -135,56 +135,73 @@ Modules must implement [interfaces](../building-modules/module-manager.md#applic
|
|||
|
||||
`AppModule` exposes a collection of useful methods on the module that facilitates the composition of modules into a coherent application. These methods are are called from the `module manager`(../building-modules/module-manager.md#manager), which manages the application's collection of modules.
|
||||
|
||||
### Message Types
|
||||
### `Msg` Services
|
||||
|
||||
[`Message`s](../building-modules/messages-and-queries.md#messages) are objects defined by each module that implement the [`message`](../building-modules/messages-and-queries.md#messages) interface. Each [`transaction`](../core/transactions.md) contains one or multiple `messages`.
|
||||
Each module defines two [Protobuf services](https://developers.google.com/protocol-buffers/docs/proto#services): one `Msg` service to handle messages, and one gRPC `Query` service to handle queries. If we consider the module as a state-machine, then a `Msg` is a state transition. A `Msg` service is a Protobuf service defining all possible `Msg`s a module exposes. Note that `Msg`s are bundled in [`transactions`](../core/transactions.md), and each transaction contains one or multiple `messages`.
|
||||
|
||||
When a valid block of transactions is received by the full-node, Tendermint relays each one to the application via [`DeliverTx`](https://tendermint.com/docs/app-dev/abci-spec.html#delivertx). Then, the application handles the transaction:
|
||||
|
||||
1. Upon receiving the transaction, the application first unmarshalls it from `[]bytes`.
|
||||
2. Then, it verifies a few things about the transaction like [fee payment and signatures](#gas-fees.md#antehandler) before extracting the message(s) contained in the transaction.
|
||||
3. With the `Type()` method of the `message`, `baseapp` is able to route it to the appropriate module's [`handler`](#handler) in order for it to be processed.
|
||||
2. Then, it verifies a few things about the transaction like [fee payment and signatures](#gas-fees.md#antehandler) before extracting the `Msg`(s) contained in the transaction.
|
||||
3. `Msg`s are encoded as Protobuf [`Any`s](#register-codec) via the `sdk.ServiceMsg` struct. By analyzing each `Any`'s `type_url`, the application routes the `Msg` to the corresponding module's `Msg` service.
|
||||
4. If the message is successfully processed, the state is updated.
|
||||
|
||||
For a more detailed look at a transaction lifecycle, click [here](./tx-lifecycle.md).
|
||||
|
||||
Module developers create custom message types when they build their own module. The general practice is to prefix the type declaration of the message with `Msg`. For example, the message type `MsgSend` allows users to transfer tokens:
|
||||
Module developers create custom `Msg`s when they build their own module. The general practice is to define all `Msg`s in a Protobuf service called `service Msg {}`, and define each `Msg` as a Protobuf service method, using the `rpc` keyword. These definitions usually reside in a `tx.proto` file. For example, the `x/bank` module defines two `Msg`s to allows users to transfer tokens:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/proto/cosmos/bank/v1beta1/tx.proto#L10-L19
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L10-L17
|
||||
|
||||
It is processed by the `handler` of the `bank` module, which ultimately calls the `keeper` of the `auth` module in order to update the state.
|
||||
These two `Msg`s are processed by the `Msg` service of the `x/bank` module, which ultimately calls the `keeper` of the `x/auth` module in order to update the state.
|
||||
|
||||
### Handler
|
||||
Each module should also implement the `RegisterServices` method as part of the [`AppModule` interface](#application-module-interface). This method should call the `RegisterMsgServer` function provided by the generated Protobuf code.
|
||||
|
||||
The [`handler`](../building-modules/handler.md) refers to the part of the module responsible for processing the `message` after it is routed by `baseapp`. `handler` functions of modules are only executed if the transaction is relayed from Tendermint by the `DeliverTx` ABCI message. If the transaction is relayed by `CheckTx`, only stateless checks and fee-related stateful checks are performed. To better understand the difference between `DeliverTx`and `CheckTx`, as well as the difference between stateful and stateless checks, click [here](./tx-lifecycle.md).
|
||||
#### Handlers
|
||||
|
||||
The [handler](../building-modules/handler.md) refers to the part of the module responsible for processing the `Msg` after it is routed by `baseapp`. Handler functions of modules are only executed if the transaction is relayed from Tendermint by the `DeliverTx` ABCI message. If the transaction is relayed by `CheckTx`, only stateless checks and fee-related stateful checks are performed. To better understand the difference between `DeliverTx`and `CheckTx`, as well as the difference between stateful and stateless checks, click [here](./tx-lifecycle.md).
|
||||
|
||||
The `handler` of a module is generally defined in a file called `handler.go` and consists of:
|
||||
|
||||
- A **switch function** `NewHandler` to route the message to the appropriate `handler` function. This function returns a `handler` function, and is registered in the [`AppModule`](#application-module-interface) to be used in the application's module manager to initialize the [application's router](../core/baseapp.md#routing). Next is an example of such a switch from the [nameservice tutorial](https://github.com/cosmos/sdk-tutorials/tree/master/nameservice)
|
||||
+++ https://github.com/cosmos/sdk-tutorials/blob/master/nameservice/x/nameservice/handler.go#L12-L26
|
||||
- A **switch function** `NewHandler` to route the message to the appropriate `handler` function. This function returns a `handler` function, and is registered in the [`AppModule`](#application-module-interface) to be used in the application's module manager to initialize the [application's router](../core/baseapp.md#routing). Next is an example from `x/bank`:
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/handler.go#L10-L30
|
||||
- **One handler function for each message type defined by the module**. Developers write the message processing logic in these functions. This generally involves doing stateful checks to ensure the message is valid and calling [`keeper`](#keeper)'s methods to update the state.
|
||||
|
||||
Handler functions return a result of type `sdk.Result`, which informs the application on whether the message was successfully processed:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/types/result.go#L15-L40
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/types/result.go#L15-L40
|
||||
|
||||
### gRPC Query Services
|
||||
### gRPC `Query` Services
|
||||
|
||||
gRPC query services are introduced in the v0.40 Stargate release. They allow users to query the state using [gRPC](https://grpc.io). They are enabled by default, and can be configued under the `grpc.enable` and `grpc.address` fields inside `app.toml`.
|
||||
gRPC `Query` services are introduced in the v0.40 Stargate release. They allow users to query the state using [gRPC](https://grpc.io). They are enabled by default, and can be configued under the `grpc.enable` and `grpc.address` fields inside `app.toml`.
|
||||
|
||||
gRPC query services are defined in the module's Protobuf definition, specifically inside `query.proto`. The `query.proto` definition file exposes a single `Query` [Protobuf service](https://developers.google.com/protocol-buffers/docs/proto#services). Each gRPC query endpoint corresponds to a service method, starting with the `rpc` keyword, inside the `Query` service.
|
||||
gRPC `Query` services are defined in the module's Protobuf definition files, specifically inside `query.proto`. The `query.proto` definition file exposes a single `Query` [Protobuf service](https://developers.google.com/protocol-buffers/docs/proto#services). Each gRPC query endpoint corresponds to a service method, starting with the `rpc` keyword, inside the `Query` service.
|
||||
|
||||
Protobuf generates a `QueryServer` interface for each module, containing all the service methods. A module's [`keeper`](#keeper) then needs to implement this `QueryServer` interface, by providing the concrete implementation of each service method. This concrete implementation is the handler of the corresponding gRPC query endpoint.
|
||||
|
||||
Finally, each module should also implement the `RegisterQueryService` method as part of the [`AppModule` interface](#application-module-interface). This method should call the `RegisterQueryServer` function provided by the generated Protobuf code.
|
||||
Finally, each module should also implement the `RegisterServices` method as part of the [`AppModule` interface](#application-module-interface). This method should call the `RegisterQueryServer` function provided by the generated Protobuf code.
|
||||
|
||||
### Legacy Querier
|
||||
### Legacy `Msg`s
|
||||
|
||||
Legacy queriers were queriers used before the introduction of Protobuf and gRPC in the SDK. They are present for existing modules, but will be deprecated in a future release of the SDK. If you are developing new modules, gRPC query services should be preferred, and you only need to implement the `LegacyQuerierHandler` interface if you wish to use legacy queriers.
|
||||
While the [`Msg` service](#msg-services) introduced in v0.40 is the official way to define `Msg`s, the SDK still handles legacy `Msg`s defined with previous versions of the SDK.
|
||||
|
||||
[Legacy `Msg`s](../building-modules/messages-and-queries.md#messages) are objects defined by each module that implement the [`sdk.Msg`](../building-modules/messages-and-queries.md#messages) interface. Each [`transaction`](../core/transactions.md) contains one or multiple legacy `Msg`s, and can also contain both legacy and non-legacy `Msg`s.
|
||||
|
||||
The application handles the transaction almost like with `Msg` service `Msg`s, only the third step (routing) differs:
|
||||
|
||||
1. Upon receiving the transaction, the application first unmarshalls it from `[]bytes`.
|
||||
2. Then, it verifies a few things about the transaction like [fee payment and signatures](#gas-fees.md#antehandler) before extracting the message(s) contained in the transaction.
|
||||
3. With the `Type()` method of the legacy `Msg`, `baseapp` is able to route it to the appropriate module's [legacy `Msg` handler](#handler) in order for it to be processed.
|
||||
4. If the message is successfully processed, the state is updated.
|
||||
|
||||
New `Msg` services are compatible with legacy `Msg`s in terms of how `Msg`s are handled, please refer to the [handler](#handlers) section for more information.
|
||||
|
||||
### Legacy Query Routes
|
||||
|
||||
Legacy queriers were queriers used before the introduction of Protobuf and gRPC in the SDK. They are present for existing modules, but will be deprecated in a future release of the SDK. If you are developing new modules, gRPC `Query` services should be preferred, and you only need to implement the `LegacyQuerierHandler` interface if you wish to use legacy queriers.
|
||||
|
||||
[`Legacy queriers`](../building-modules/query-services.md#legacy-queriers) are very similar to `handlers`, except they serve user queries to the state as opposed to processing transactions. A [query](../building-modules/messages-and-queries.md#queries) is initiated from an [interface](#application-interface) by an end-user who provides a `queryRoute` and some `data`. The query is then routed to the correct application's `querier` by `baseapp`'s `handleQueryCustom` method using `queryRoute`:
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/baseapp/abci.go#L388-L418
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/baseapp/abci.go#L388-L418
|
||||
|
||||
The `Querier` of a module is defined in a file called `keeper/querier.go`, and consists of:
|
||||
|
||||
|
@ -223,7 +240,7 @@ Generally, the [commands related to a module](../building-modules/module-interfa
|
|||
|
||||
Each module can expose gRPC endpoints, called [service methods](https://grpc.io/docs/what-is-grpc/core-concepts/#service-definition) and are defined in the [module's Protobuf `query.proto` file](#grpc-query-services). A service method is defined by its name, input arguments and output response. The module then needs to:
|
||||
|
||||
- define a `RegisterGRPCRoutes` method on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
|
||||
- define a `RegisterGRPCGatewayRoutes` method on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
|
||||
- for each service method, define a corresponding handler. The handler implements the core logic necessary to serve the gRPC request, and is located in the `keeper/grpc_query.go` file.
|
||||
|
||||
#### gRPC-gateway REST Endpoints
|
||||
|
@ -240,7 +257,7 @@ The [module's Legacy REST interface](../building-modules/module-interfaces.md#le
|
|||
|
||||
- A `RegisterRoutes` function, which registers each route defined in the file. This function is called from the [main application's interface](#application-interfaces) for each module used within the application. The router used in the SDK is [Gorilla's mux](https://github.com/gorilla/mux).
|
||||
- Custom request type definitions for each query or transaction creation function that needs to be exposed. These custom request types build on the base `request` type of the Cosmos SDK:
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d9175200920e96bfa4182b5c8bc46d91b17a28a1/types/rest/rest.go#L62-L76
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/types/rest/rest.go#L62-L76
|
||||
- One handler function for each request that can be routed to the given module. These functions implement the core logic necessary to serve the request.
|
||||
|
||||
These Legacy API endpoints are present in the SDK for backward compatibility purposes and will be removed in the next release.
|
||||
|
|
|
@ -97,7 +97,7 @@ Similarly, there is a `AddQueryFlagsToCmd(cmd *cobra.Command)` to add common fla
|
|||
|
||||
In addition to providing an ABCI query pathway, modules [custom queries](./messages-and-queries.md#grpc-queries) can provide a GRPC proxy server that routes requests in the GRPC protocol to ABCI query requests under the hood.
|
||||
|
||||
In order to do that, module should implement `RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux)` on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
|
||||
In order to do that, module should implement `RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux)` on `AppModuleBasic` to wire the client gRPC requests to the correct handler inside the module.
|
||||
|
||||
Here's an example from the `auth` module:
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ Let us go through the methods:
|
|||
- `DefaultGenesis(codec.JSONMarshaler)`: Returns a default [`GenesisState`](./genesis.md#genesisstate) for the module, marshalled to `json.RawMessage`. The default `GenesisState` need to be defined by the module developer and is primarily used for testing.
|
||||
- `ValidateGenesis(codec.JSONMarshaler, client.TxEncodingConfig, json.RawMessage)`: Used to validate the `GenesisState` defined by a module, given in its `json.RawMessage` form. It will usually unmarshall the `json` before running a custom [`ValidateGenesis`](./genesis.md#validategenesis) function defined by the module developer.
|
||||
- `RegisterRESTRoutes(client.Context, *mux.Router)`: Registers the REST routes for the module. These routes will be used to map REST request to the module in order to process them. See [../interfaces/rest.md] for more.
|
||||
- `RegisterGRPCRoutes(client.Context, *runtime.ServeMux)`: Registers gRPC routes for the module.
|
||||
- `RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)`: Registers gRPC routes for the module.
|
||||
- `GetTxCmd()`: Returns the root [`Tx` command](./module-interfaces.md#tx) for the module. The subcommands of this root command are used by end-users to generate new transactions containing [`message`s](./messages-and-queries.md#queries) defined in the module.
|
||||
- `GetQueryCmd()`: Return the root [`query` command](./module-interfaces.md#query) for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module.
|
||||
|
||||
|
@ -116,7 +116,7 @@ It implements the following methods:
|
|||
- `DefaultGenesis(cdc codec.JSONMarshaler)`: Provides default genesis information for modules in the application by calling the [`DefaultGenesis(cdc codec.JSONMarshaler)`](./genesis.md#defaultgenesis) function of each module. It is used to construct a default genesis file for the application.
|
||||
- `ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client.TxEncodingConfig, genesis map[string]json.RawMessage)`: Validates the genesis information modules by calling the [`ValidateGenesis(codec.JSONMarshaler, client.TxEncodingConfig, json.RawMessage)`](./genesis.md#validategenesis) function of each module.
|
||||
- `RegisterRESTRoutes(ctx client.Context, rtr *mux.Router)`: Registers REST routes for modules by calling the [`RegisterRESTRoutes`](./module-interfaces.md#register-routes) function of each module. This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md).
|
||||
- `RegisterGRPCRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules.
|
||||
- `RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux)`: Registers gRPC routes for modules.
|
||||
- `AddTxCommands(rootTxCmd *cobra.Command)`: Adds modules' transaction commands to the application's [`rootTxCommand`](../interfaces/cli.md#transaction-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md).
|
||||
- `AddQueryCommands(rootQueryCmd *cobra.Command)`: Adds modules' query commands to the application's [`rootQueryCommand`](../interfaces/cli.md#query-commands). This function is usually called function from the `main.go` function of the [application's command-line interface](../interfaces/cli.md).
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ option go_package = "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519";
|
|||
message PubKey {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
|
||||
bytes key = 1;
|
||||
bytes key = 1 [(gogoproto.casttype) = "crypto/ed25519.PublicKey"];
|
||||
}
|
||||
|
||||
// PrivKey defines a ed25519 private key.
|
||||
message PrivKey {
|
||||
bytes key = 1;
|
||||
bytes key = 1 [(gogoproto.casttype) = "crypto/ed25519.PrivateKey"];
|
||||
}
|
||||
|
|
|
@ -4,43 +4,6 @@ package ibc.applications.transfer.v1;
|
|||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
|
||||
// Msg defines the ibc/transfer Msg service.
|
||||
service Msg {
|
||||
// Transfer defines a rpc handler method for MsgTransfer.
|
||||
rpc Transfer(MsgTransfer) returns (MsgTransferResponse);
|
||||
}
|
||||
|
||||
// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between
|
||||
// ICS20 enabled chains. See ICS Spec here:
|
||||
// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
|
||||
message MsgTransfer {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
// the port on which the packet will be sent
|
||||
string source_port = 1 [(gogoproto.moretags) = "yaml:\"source_port\""];
|
||||
// the channel by which the packet will be sent
|
||||
string source_channel = 2 [(gogoproto.moretags) = "yaml:\"source_channel\""];
|
||||
// the tokens to be transferred
|
||||
cosmos.base.v1beta1.Coin token = 3 [(gogoproto.nullable) = false];
|
||||
// the sender address
|
||||
string sender = 4;
|
||||
// the recipient address on the destination chain
|
||||
string receiver = 5;
|
||||
// Timeout height relative to the current block height.
|
||||
// The timeout is disabled when set to 0.
|
||||
ibc.core.client.v1.Height timeout_height = 6
|
||||
[(gogoproto.moretags) = "yaml:\"timeout_height\"", (gogoproto.nullable) = false];
|
||||
// Timeout timestamp (in nanoseconds) relative to the current block timestamp.
|
||||
// The timeout is disabled when set to 0.
|
||||
uint64 timeout_timestamp = 7 [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""];
|
||||
}
|
||||
|
||||
// MsgTransferResponse defines the Msg/Transfer response type.
|
||||
message MsgTransferResponse { }
|
||||
|
||||
// FungibleTokenPacketData defines a struct for the packet payload
|
||||
// See FungibleTokenPacketData spec:
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
syntax = "proto3";
|
||||
package ibc.applications.transfer.v1;
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
|
||||
// Msg defines the ibc/transfer Msg service.
|
||||
service Msg {
|
||||
// Transfer defines a rpc handler method for MsgTransfer.
|
||||
rpc Transfer(MsgTransfer) returns (MsgTransferResponse);
|
||||
}
|
||||
|
||||
// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between
|
||||
// ICS20 enabled chains. See ICS Spec here:
|
||||
// https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
|
||||
message MsgTransfer {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
// the port on which the packet will be sent
|
||||
string source_port = 1 [(gogoproto.moretags) = "yaml:\"source_port\""];
|
||||
// the channel by which the packet will be sent
|
||||
string source_channel = 2 [(gogoproto.moretags) = "yaml:\"source_channel\""];
|
||||
// the tokens to be transferred
|
||||
cosmos.base.v1beta1.Coin token = 3 [(gogoproto.nullable) = false];
|
||||
// the sender address
|
||||
string sender = 4;
|
||||
// the recipient address on the destination chain
|
||||
string receiver = 5;
|
||||
// Timeout height relative to the current block height.
|
||||
// The timeout is disabled when set to 0.
|
||||
ibc.core.client.v1.Height timeout_height = 6
|
||||
[(gogoproto.moretags) = "yaml:\"timeout_height\"", (gogoproto.nullable) = false];
|
||||
// Timeout timestamp (in nanoseconds) relative to the current block timestamp.
|
||||
// The timeout is disabled when set to 0.
|
||||
uint64 timeout_timestamp = 7 [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""];
|
||||
}
|
||||
|
||||
// MsgTransferResponse defines the Msg/Transfer response type.
|
||||
message MsgTransferResponse { }
|
|
@ -6,205 +6,6 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types";
|
|||
import "gogoproto/gogo.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
|
||||
// Msg defines the ibc/channel Msg service.
|
||||
service Msg {
|
||||
// ChannelOpenInit defines a rpc handler method for MsgChannelOpenInit.
|
||||
rpc ChannelOpenInit(MsgChannelOpenInit) returns (MsgChannelOpenInitResponse);
|
||||
|
||||
// ChannelOpenTry defines a rpc handler method for MsgChannelOpenTry.
|
||||
rpc ChannelOpenTry(MsgChannelOpenTry) returns (MsgChannelOpenTryResponse);
|
||||
|
||||
// ChannelOpenAck defines a rpc handler method for MsgChannelOpenAck.
|
||||
rpc ChannelOpenAck(MsgChannelOpenAck) returns (MsgChannelOpenAckResponse);
|
||||
|
||||
// ChannelOpenConfirm defines a rpc handler method for MsgChannelOpenConfirm.
|
||||
rpc ChannelOpenConfirm(MsgChannelOpenConfirm) returns (MsgChannelOpenConfirmResponse);
|
||||
|
||||
// ChannelCloseInit defines a rpc handler method for MsgChannelCloseInit.
|
||||
rpc ChannelCloseInit(MsgChannelCloseInit) returns (MsgChannelCloseInitResponse);
|
||||
|
||||
// ChannelCloseConfirm defines a rpc handler method for MsgChannelCloseConfirm.
|
||||
rpc ChannelCloseConfirm(MsgChannelCloseConfirm) returns (MsgChannelCloseConfirmResponse);
|
||||
|
||||
// RecvPacket defines a rpc handler method for MsgRecvPacket.
|
||||
rpc RecvPacket(MsgRecvPacket) returns (MsgRecvPacketResponse);
|
||||
|
||||
// Timeout defines a rpc handler method for MsgTimeout.
|
||||
rpc Timeout(MsgTimeout) returns (MsgTimeoutResponse);
|
||||
|
||||
// TimeoutOnClose defines a rpc handler method for MsgTimeoutOnClose.
|
||||
rpc TimeoutOnClose(MsgTimeoutOnClose) returns (MsgTimeoutOnCloseResponse);
|
||||
|
||||
// Acknowledgement defines a rpc handler method for MsgAcknowledgement.
|
||||
rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse);
|
||||
}
|
||||
|
||||
// MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It
|
||||
// is called by a relayer on Chain A.
|
||||
message MsgChannelOpenInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
Channel channel = 3 [(gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgChannelOpenInitResponse defines the Msg/ChannelOpenInit response type.
|
||||
message MsgChannelOpenInitResponse {}
|
||||
|
||||
// MsgChannelOpenInit defines a msg sent by a Relayer to try to open a channel
|
||||
// on Chain B.
|
||||
message MsgChannelOpenTry {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string desired_channel_id = 2 [(gogoproto.moretags) = "yaml:\"desired_channel_id\""];
|
||||
string counterparty_chosen_channel_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_chosen_channel_id\""];
|
||||
Channel channel = 4 [(gogoproto.nullable) = false];
|
||||
string counterparty_version = 5 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
|
||||
bytes proof_init = 6 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
ibc.core.client.v1.Height proof_height = 7
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 8;
|
||||
}
|
||||
|
||||
// MsgChannelOpenTryResponse defines the Msg/ChannelOpenTry response type.
|
||||
message MsgChannelOpenTryResponse {}
|
||||
|
||||
// MsgChannelOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
|
||||
// the change of channel state to TRYOPEN on Chain B.
|
||||
message MsgChannelOpenAck {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
string counterparty_channel_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_channel_id\""];
|
||||
string counterparty_version = 4 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
|
||||
bytes proof_try = 5 [(gogoproto.moretags) = "yaml:\"proof_try\""];
|
||||
ibc.core.client.v1.Height proof_height = 6
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 7;
|
||||
}
|
||||
|
||||
// MsgChannelOpenAckResponse defines the Msg/ChannelOpenAck response type.
|
||||
message MsgChannelOpenAckResponse {}
|
||||
|
||||
// MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain B to
|
||||
// acknowledge the change of channel state to OPEN on Chain A.
|
||||
message MsgChannelOpenConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
bytes proof_ack = 3 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgChannelOpenConfirmResponse defines the Msg/ChannelOpenConfirm response type.
|
||||
message MsgChannelOpenConfirmResponse {}
|
||||
|
||||
// MsgChannelCloseInit defines a msg sent by a Relayer to Chain A
|
||||
// to close a channel with Chain B.
|
||||
message MsgChannelCloseInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
string signer = 3;
|
||||
}
|
||||
|
||||
// MsgChannelCloseInitResponse defines the Msg/ChannelCloseInit response type.
|
||||
message MsgChannelCloseInitResponse {}
|
||||
|
||||
// MsgChannelCloseConfirm defines a msg sent by a Relayer to Chain B
|
||||
// to acknowledge the change of channel state to CLOSED on Chain A.
|
||||
message MsgChannelCloseConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
bytes proof_init = 3 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgChannelCloseConfirmResponse defines the Msg/ChannelCloseConfirm response type.
|
||||
message MsgChannelCloseConfirmResponse {}
|
||||
|
||||
// MsgRecvPacket receives incoming IBC packet
|
||||
message MsgRecvPacket {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgRecvPacketResponse defines the Msg/RecvPacket response type.
|
||||
message MsgRecvPacketResponse {}
|
||||
|
||||
// MsgTimeout receives timed-out packet
|
||||
message MsgTimeout {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
uint64 next_sequence_recv = 4 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgTimeoutResponse defines the Msg/Timeout response type.
|
||||
message MsgTimeoutResponse {}
|
||||
|
||||
// MsgTimeoutOnClose timed-out packet upon counterparty channel closure.
|
||||
message MsgTimeoutOnClose {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
bytes proof_close = 3 [(gogoproto.moretags) = "yaml:\"proof_close\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
uint64 next_sequence_recv = 5 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
|
||||
string signer = 6;
|
||||
}
|
||||
|
||||
// MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.
|
||||
message MsgTimeoutOnCloseResponse {}
|
||||
|
||||
// MsgAcknowledgement receives incoming IBC acknowledgement
|
||||
message MsgAcknowledgement {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes acknowledgement = 2;
|
||||
bytes proof = 3;
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.
|
||||
message MsgAcknowledgementResponse {}
|
||||
|
||||
// Channel defines pipeline for exactly-once packet delivery between specific
|
||||
// modules on separate blockchains, which has at least one end capable of
|
||||
// sending packets and one end capable of receiving packets.
|
||||
|
|
|
@ -94,10 +94,8 @@ message QueryChannelResponse {
|
|||
ibc.core.channel.v1.Channel channel = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryChannelsRequest is the request type for the Query/Channels RPC method
|
||||
|
@ -152,10 +150,8 @@ message QueryChannelClientStateResponse {
|
|||
ibc.core.client.v1.IdentifiedClientState identified_client_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryChannelConsensusStateRequest is the request type for the
|
||||
|
@ -180,10 +176,8 @@ message QueryChannelConsensusStateResponse {
|
|||
string client_id = 2;
|
||||
// merkle proof of existence
|
||||
bytes proof = 3;
|
||||
// merkle proof path
|
||||
string proof_path = 4;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 5 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryPacketCommitmentRequest is the request type for the
|
||||
|
@ -205,10 +199,8 @@ message QueryPacketCommitmentResponse {
|
|||
bytes commitment = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryPacketCommitmentsRequest is the request type for the
|
||||
|
@ -251,10 +243,8 @@ message QueryPacketAcknowledgementResponse {
|
|||
bytes acknowledgement = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryUnreceivedPacketsRequest is the request type for the
|
||||
|
@ -313,8 +303,6 @@ message QueryNextSequenceReceiveResponse {
|
|||
uint64 next_sequence_receive = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
syntax = "proto3";
|
||||
package ibc.core.channel.v1;
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
import "ibc/core/channel/v1/channel.proto";
|
||||
|
||||
// Msg defines the ibc/channel Msg service.
|
||||
service Msg {
|
||||
// ChannelOpenInit defines a rpc handler method for MsgChannelOpenInit.
|
||||
rpc ChannelOpenInit(MsgChannelOpenInit) returns (MsgChannelOpenInitResponse);
|
||||
|
||||
// ChannelOpenTry defines a rpc handler method for MsgChannelOpenTry.
|
||||
rpc ChannelOpenTry(MsgChannelOpenTry) returns (MsgChannelOpenTryResponse);
|
||||
|
||||
// ChannelOpenAck defines a rpc handler method for MsgChannelOpenAck.
|
||||
rpc ChannelOpenAck(MsgChannelOpenAck) returns (MsgChannelOpenAckResponse);
|
||||
|
||||
// ChannelOpenConfirm defines a rpc handler method for MsgChannelOpenConfirm.
|
||||
rpc ChannelOpenConfirm(MsgChannelOpenConfirm) returns (MsgChannelOpenConfirmResponse);
|
||||
|
||||
// ChannelCloseInit defines a rpc handler method for MsgChannelCloseInit.
|
||||
rpc ChannelCloseInit(MsgChannelCloseInit) returns (MsgChannelCloseInitResponse);
|
||||
|
||||
// ChannelCloseConfirm defines a rpc handler method for MsgChannelCloseConfirm.
|
||||
rpc ChannelCloseConfirm(MsgChannelCloseConfirm) returns (MsgChannelCloseConfirmResponse);
|
||||
|
||||
// RecvPacket defines a rpc handler method for MsgRecvPacket.
|
||||
rpc RecvPacket(MsgRecvPacket) returns (MsgRecvPacketResponse);
|
||||
|
||||
// Timeout defines a rpc handler method for MsgTimeout.
|
||||
rpc Timeout(MsgTimeout) returns (MsgTimeoutResponse);
|
||||
|
||||
// TimeoutOnClose defines a rpc handler method for MsgTimeoutOnClose.
|
||||
rpc TimeoutOnClose(MsgTimeoutOnClose) returns (MsgTimeoutOnCloseResponse);
|
||||
|
||||
// Acknowledgement defines a rpc handler method for MsgAcknowledgement.
|
||||
rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse);
|
||||
}
|
||||
|
||||
// MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It
|
||||
// is called by a relayer on Chain A.
|
||||
message MsgChannelOpenInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
Channel channel = 3 [(gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgChannelOpenInitResponse defines the Msg/ChannelOpenInit response type.
|
||||
message MsgChannelOpenInitResponse {}
|
||||
|
||||
// MsgChannelOpenInit defines a msg sent by a Relayer to try to open a channel
|
||||
// on Chain B.
|
||||
message MsgChannelOpenTry {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string desired_channel_id = 2 [(gogoproto.moretags) = "yaml:\"desired_channel_id\""];
|
||||
string counterparty_chosen_channel_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_chosen_channel_id\""];
|
||||
Channel channel = 4 [(gogoproto.nullable) = false];
|
||||
string counterparty_version = 5 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
|
||||
bytes proof_init = 6 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
ibc.core.client.v1.Height proof_height = 7
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 8;
|
||||
}
|
||||
|
||||
// MsgChannelOpenTryResponse defines the Msg/ChannelOpenTry response type.
|
||||
message MsgChannelOpenTryResponse {}
|
||||
|
||||
// MsgChannelOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
|
||||
// the change of channel state to TRYOPEN on Chain B.
|
||||
message MsgChannelOpenAck {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
string counterparty_channel_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_channel_id\""];
|
||||
string counterparty_version = 4 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
|
||||
bytes proof_try = 5 [(gogoproto.moretags) = "yaml:\"proof_try\""];
|
||||
ibc.core.client.v1.Height proof_height = 6
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 7;
|
||||
}
|
||||
|
||||
// MsgChannelOpenAckResponse defines the Msg/ChannelOpenAck response type.
|
||||
message MsgChannelOpenAckResponse {}
|
||||
|
||||
// MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain B to
|
||||
// acknowledge the change of channel state to OPEN on Chain A.
|
||||
message MsgChannelOpenConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
bytes proof_ack = 3 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgChannelOpenConfirmResponse defines the Msg/ChannelOpenConfirm response type.
|
||||
message MsgChannelOpenConfirmResponse {}
|
||||
|
||||
// MsgChannelCloseInit defines a msg sent by a Relayer to Chain A
|
||||
// to close a channel with Chain B.
|
||||
message MsgChannelCloseInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
string signer = 3;
|
||||
}
|
||||
|
||||
// MsgChannelCloseInitResponse defines the Msg/ChannelCloseInit response type.
|
||||
message MsgChannelCloseInitResponse {}
|
||||
|
||||
// MsgChannelCloseConfirm defines a msg sent by a Relayer to Chain B
|
||||
// to acknowledge the change of channel state to CLOSED on Chain A.
|
||||
message MsgChannelCloseConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string port_id = 1 [(gogoproto.moretags) = "yaml:\"port_id\""];
|
||||
string channel_id = 2 [(gogoproto.moretags) = "yaml:\"channel_id\""];
|
||||
bytes proof_init = 3 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgChannelCloseConfirmResponse defines the Msg/ChannelCloseConfirm response type.
|
||||
message MsgChannelCloseConfirmResponse {}
|
||||
|
||||
// MsgRecvPacket receives incoming IBC packet
|
||||
message MsgRecvPacket {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgRecvPacketResponse defines the Msg/RecvPacket response type.
|
||||
message MsgRecvPacketResponse {}
|
||||
|
||||
// MsgTimeout receives timed-out packet
|
||||
message MsgTimeout {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
uint64 next_sequence_recv = 4 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgTimeoutResponse defines the Msg/Timeout response type.
|
||||
message MsgTimeoutResponse {}
|
||||
|
||||
// MsgTimeoutOnClose timed-out packet upon counterparty channel closure.
|
||||
message MsgTimeoutOnClose {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes proof = 2;
|
||||
bytes proof_close = 3 [(gogoproto.moretags) = "yaml:\"proof_close\""];
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
uint64 next_sequence_recv = 5 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
|
||||
string signer = 6;
|
||||
}
|
||||
|
||||
// MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.
|
||||
message MsgTimeoutOnCloseResponse {}
|
||||
|
||||
// MsgAcknowledgement receives incoming IBC acknowledgement
|
||||
message MsgAcknowledgement {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Packet packet = 1 [(gogoproto.nullable) = false];
|
||||
bytes acknowledgement = 2;
|
||||
bytes proof = 3;
|
||||
ibc.core.client.v1.Height proof_height = 4
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.
|
||||
message MsgAcknowledgementResponse {}
|
|
@ -50,10 +50,8 @@ message QueryClientStateResponse {
|
|||
google.protobuf.Any client_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryClientStatesRequest is the request type for the Query/ClientStates RPC
|
||||
|
@ -94,10 +92,8 @@ message QueryConsensusStateResponse {
|
|||
google.protobuf.Any consensus_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryConsensusStatesRequest is the request type for the Query/ConsensusStates
|
||||
|
|
|
@ -4,113 +4,7 @@ package ibc.core.connection.v1;
|
|||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "ibc/core/commitment/v1/commitment.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
|
||||
// Msg defines the ibc/connection Msg service.
|
||||
service Msg {
|
||||
// ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit.
|
||||
rpc ConnectionOpenInit(MsgConnectionOpenInit) returns (MsgConnectionOpenInitResponse);
|
||||
|
||||
// ConnectionOpenTry defines a rpc handler method for MsgConnectionOpenTry.
|
||||
rpc ConnectionOpenTry(MsgConnectionOpenTry) returns (MsgConnectionOpenTryResponse);
|
||||
|
||||
// ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck.
|
||||
rpc ConnectionOpenAck(MsgConnectionOpenAck) returns (MsgConnectionOpenAckResponse);
|
||||
|
||||
// ConnectionOpenConfirm defines a rpc handler method for MsgConnectionOpenConfirm.
|
||||
rpc ConnectionOpenConfirm(MsgConnectionOpenConfirm) returns (MsgConnectionOpenConfirmResponse);
|
||||
}
|
||||
|
||||
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
|
||||
// initialize a connection with Chain B.
|
||||
message MsgConnectionOpenInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
|
||||
string version = 4;
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenInitResponse defines the Msg/ConnectionOpenInit response type.
|
||||
message MsgConnectionOpenInitResponse { }
|
||||
|
||||
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a
|
||||
// connection on Chain B.
|
||||
message MsgConnectionOpenTry {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
string desired_connection_id = 2 [(gogoproto.moretags) = "yaml:\"desired_connection_id\""];
|
||||
string counterparty_chosen_connection_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_chosen_connection_id\""];
|
||||
google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
Counterparty counterparty = 5 [(gogoproto.nullable) = false];
|
||||
repeated string counterparty_versions = 6 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""];
|
||||
ibc.core.client.v1.Height proof_height = 7
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
// proof of the initialization the connection on Chain A: `UNITIALIZED ->
|
||||
// INIT`
|
||||
bytes proof_init = 8 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
// proof of client state included in message
|
||||
bytes proof_client = 9 [(gogoproto.moretags) = "yaml:\"proof_client\""];
|
||||
// proof of client consensus state
|
||||
bytes proof_consensus = 10 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
|
||||
ibc.core.client.v1.Height consensus_height = 11
|
||||
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 12;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type.
|
||||
message MsgConnectionOpenTryResponse { }
|
||||
|
||||
// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to
|
||||
// acknowledge the change of connection state to TRYOPEN on Chain B.
|
||||
message MsgConnectionOpenAck {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
string counterparty_connection_id = 2 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""];
|
||||
string version = 3;
|
||||
google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
ibc.core.client.v1.Height proof_height = 5
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
// proof of the initialization the connection on Chain B: `UNITIALIZED ->
|
||||
// TRYOPEN`
|
||||
bytes proof_try = 6 [(gogoproto.moretags) = "yaml:\"proof_try\""];
|
||||
// proof of client state included in message
|
||||
bytes proof_client = 7 [(gogoproto.moretags) = "yaml:\"proof_client\""];
|
||||
// proof of client consensus state
|
||||
bytes proof_consensus = 8 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
|
||||
ibc.core.client.v1.Height consensus_height = 9
|
||||
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 10;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type.
|
||||
message MsgConnectionOpenAckResponse { }
|
||||
|
||||
// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to
|
||||
// acknowledge the change of connection state to OPEN on Chain A.
|
||||
message MsgConnectionOpenConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
// proof for the change of the connection state on Chain A: `INIT -> OPEN`
|
||||
bytes proof_ack = 2 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm response type.
|
||||
message MsgConnectionOpenConfirmResponse { }
|
||||
|
||||
// ICS03 - Connection Data Structures as defined in
|
||||
// https://github.com/cosmos/ics/tree/master/spec/ics-003-connection-semantics#data-structures
|
||||
|
@ -124,7 +18,7 @@ message ConnectionEnd {
|
|||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
// IBC version which can be utilised to determine encodings or protocols for
|
||||
// channels or packets utilising this connection
|
||||
repeated string versions = 2;
|
||||
repeated Version versions = 2;
|
||||
// current state of the connection end.
|
||||
State state = 3;
|
||||
// counterparty chain associated with this connection.
|
||||
|
@ -141,7 +35,7 @@ message IdentifiedConnection {
|
|||
string client_id = 2 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
// IBC version which can be utilised to determine encodings or protocols for
|
||||
// channels or packets utilising this connection
|
||||
repeated string versions = 3;
|
||||
repeated Version versions = 3;
|
||||
// current state of the connection end.
|
||||
State state = 4;
|
||||
// counterparty chain associated with this connection.
|
||||
|
|
|
@ -57,10 +57,8 @@ message QueryConnectionResponse {
|
|||
ibc.core.connection.v1.ConnectionEnd connection = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryConnectionsRequest is the request type for the Query/Connections RPC
|
||||
|
@ -94,10 +92,8 @@ message QueryClientConnectionsResponse {
|
|||
repeated string connection_paths = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was generated
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryConnectionClientStateRequest is the request type for the
|
||||
|
@ -114,10 +110,8 @@ message QueryConnectionClientStateResponse {
|
|||
ibc.core.client.v1.IdentifiedClientState identified_client_state = 1;
|
||||
// merkle proof of existence
|
||||
bytes proof = 2;
|
||||
// merkle proof path
|
||||
string proof_path = 3;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryConnectionConsensusStateRequest is the request type for the
|
||||
|
@ -138,8 +132,6 @@ message QueryConnectionConsensusStateResponse {
|
|||
string client_id = 2;
|
||||
// merkle proof of existence
|
||||
bytes proof = 3;
|
||||
// merkle proof path
|
||||
string proof_path = 4;
|
||||
// height at which the proof was retrieved
|
||||
ibc.core.client.v1.Height proof_height = 5 [(gogoproto.nullable) = false];
|
||||
ibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
syntax = "proto3";
|
||||
package ibc.core.connection.v1;
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "ibc/core/client/v1/client.proto";
|
||||
import "ibc/core/connection/v1/connection.proto";
|
||||
|
||||
// Msg defines the ibc/connection Msg service.
|
||||
service Msg {
|
||||
// ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit.
|
||||
rpc ConnectionOpenInit(MsgConnectionOpenInit) returns (MsgConnectionOpenInitResponse);
|
||||
|
||||
// ConnectionOpenTry defines a rpc handler method for MsgConnectionOpenTry.
|
||||
rpc ConnectionOpenTry(MsgConnectionOpenTry) returns (MsgConnectionOpenTryResponse);
|
||||
|
||||
// ConnectionOpenAck defines a rpc handler method for MsgConnectionOpenAck.
|
||||
rpc ConnectionOpenAck(MsgConnectionOpenAck) returns (MsgConnectionOpenAckResponse);
|
||||
|
||||
// ConnectionOpenConfirm defines a rpc handler method for MsgConnectionOpenConfirm.
|
||||
rpc ConnectionOpenConfirm(MsgConnectionOpenConfirm) returns (MsgConnectionOpenConfirmResponse);
|
||||
}
|
||||
|
||||
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
|
||||
// initialize a connection with Chain B.
|
||||
message MsgConnectionOpenInit {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
|
||||
Version version = 4;
|
||||
string signer = 5;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenInitResponse defines the Msg/ConnectionOpenInit response type.
|
||||
message MsgConnectionOpenInitResponse { }
|
||||
|
||||
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a
|
||||
// connection on Chain B.
|
||||
message MsgConnectionOpenTry {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
string desired_connection_id = 2 [(gogoproto.moretags) = "yaml:\"desired_connection_id\""];
|
||||
string counterparty_chosen_connection_id = 3 [(gogoproto.moretags) = "yaml:\"counterparty_chosen_connection_id\""];
|
||||
google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
Counterparty counterparty = 5 [(gogoproto.nullable) = false];
|
||||
repeated Version counterparty_versions = 6 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""];
|
||||
ibc.core.client.v1.Height proof_height = 7
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
// proof of the initialization the connection on Chain A: `UNITIALIZED ->
|
||||
// INIT`
|
||||
bytes proof_init = 8 [(gogoproto.moretags) = "yaml:\"proof_init\""];
|
||||
// proof of client state included in message
|
||||
bytes proof_client = 9 [(gogoproto.moretags) = "yaml:\"proof_client\""];
|
||||
// proof of client consensus state
|
||||
bytes proof_consensus = 10 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
|
||||
ibc.core.client.v1.Height consensus_height = 11
|
||||
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 12;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenTryResponse defines the Msg/ConnectionOpenTry response type.
|
||||
message MsgConnectionOpenTryResponse { }
|
||||
|
||||
// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to
|
||||
// acknowledge the change of connection state to TRYOPEN on Chain B.
|
||||
message MsgConnectionOpenAck {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
string counterparty_connection_id = 2 [(gogoproto.moretags) = "yaml:\"counterparty_connection_id\""];
|
||||
Version version = 3;
|
||||
google.protobuf.Any client_state = 4 [(gogoproto.moretags) = "yaml:\"client_state\""];
|
||||
ibc.core.client.v1.Height proof_height = 5
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
// proof of the initialization the connection on Chain B: `UNITIALIZED ->
|
||||
// TRYOPEN`
|
||||
bytes proof_try = 6 [(gogoproto.moretags) = "yaml:\"proof_try\""];
|
||||
// proof of client state included in message
|
||||
bytes proof_client = 7 [(gogoproto.moretags) = "yaml:\"proof_client\""];
|
||||
// proof of client consensus state
|
||||
bytes proof_consensus = 8 [(gogoproto.moretags) = "yaml:\"proof_consensus\""];
|
||||
ibc.core.client.v1.Height consensus_height = 9
|
||||
[(gogoproto.moretags) = "yaml:\"consensus_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 10;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenAckResponse defines the Msg/ConnectionOpenAck response type.
|
||||
message MsgConnectionOpenAckResponse { }
|
||||
|
||||
// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to
|
||||
// acknowledge the change of connection state to OPEN on Chain A.
|
||||
message MsgConnectionOpenConfirm {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
|
||||
// proof for the change of the connection state on Chain A: `INIT -> OPEN`
|
||||
bytes proof_ack = 2 [(gogoproto.moretags) = "yaml:\"proof_ack\""];
|
||||
ibc.core.client.v1.Height proof_height = 3
|
||||
[(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
|
||||
string signer = 4;
|
||||
}
|
||||
|
||||
// MsgConnectionOpenConfirmResponse defines the Msg/ConnectionOpenConfirm response type.
|
||||
message MsgConnectionOpenConfirmResponse { }
|
|
@ -34,7 +34,7 @@ var (
|
|||
},
|
||||
}
|
||||
|
||||
encodingConfig = simapp.MakeEncodingConfig()
|
||||
encodingConfig = simapp.MakeTestEncodingConfig()
|
||||
initClientCtx = client.Context{}.
|
||||
WithJSONMarshaler(encodingConfig.Marshaler).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
|
|
|
@ -104,7 +104,7 @@ func (s *Server) Start(cfg config.Config) error {
|
|||
return err
|
||||
}
|
||||
|
||||
s.registerGRPCRoutes()
|
||||
s.registerGRPCGatewayRoutes()
|
||||
|
||||
s.listener = listener
|
||||
var h http.Handler = s.Router
|
||||
|
@ -123,7 +123,7 @@ func (s *Server) Close() error {
|
|||
return s.listener.Close()
|
||||
}
|
||||
|
||||
func (s *Server) registerGRPCRoutes() {
|
||||
func (s *Server) registerGRPCGatewayRoutes() {
|
||||
s.Router.PathPrefix("/").Handler(s.GRPCRouter)
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t
|
|||
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||
db := dbm.NewMemDB()
|
||||
encCfg := simapp.MakeEncodingConfig()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg)
|
||||
|
||||
serverCtx := server.NewDefaultContext()
|
||||
|
@ -149,7 +149,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t
|
|||
|
||||
cmd := server.ExportCmd(
|
||||
func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string) (types.ExportedApp, error) {
|
||||
encCfg := simapp.MakeEncodingConfig()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
|
||||
var simApp *simapp.SimApp
|
||||
if height != -1 {
|
||||
|
|
|
@ -432,7 +432,7 @@ func NewSimApp(
|
|||
// simapp. It is useful for tests and clients who do not want to construct the
|
||||
// full simapp
|
||||
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
|
||||
config := MakeEncodingConfig()
|
||||
config := MakeTestEncodingConfig()
|
||||
return config.Marshaler, config.Amino
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,7 @@ func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICon
|
|||
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
|
||||
|
||||
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
|
||||
ModuleBasics.RegisterGRPCRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter)
|
||||
ModuleBasics.RegisterGRPCGatewayRoutes(apiSvr.ClientCtx, apiSvr.GRPCRouter)
|
||||
|
||||
// register swagger API from root so that other applications can override easily
|
||||
if apiConfig.Swagger {
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
func TestSimAppExport(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
|
||||
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeTestEncodingConfig())
|
||||
|
||||
genesisState := NewDefaultGenesisState()
|
||||
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
|
||||
|
@ -30,7 +30,7 @@ func TestSimAppExport(t *testing.T) {
|
|||
app.Commit()
|
||||
|
||||
// Making a new app object with the db, so that initchain hasn't been called
|
||||
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
|
||||
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeTestEncodingConfig())
|
||||
_, err = app2.ExportAppStateAndValidators(false, []string{})
|
||||
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func TestSimAppExport(t *testing.T) {
|
|||
// ensure that blocked addresses are properly set in bank keeper
|
||||
func TestBlockedAddrs(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
|
||||
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeTestEncodingConfig())
|
||||
|
||||
for acc := range maccPerms {
|
||||
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)))
|
||||
|
|
|
@ -5,9 +5,12 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/std"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig for testing
|
||||
func MakeEncodingConfig() simappparams.EncodingConfig {
|
||||
encodingConfig := simappparams.MakeEncodingConfig()
|
||||
// MakeTestEncodingConfig creates an EncodingConfig for testing.
|
||||
// This function should be used only internally (in the SDK).
|
||||
// App user should'nt create new codecs - use the app.AppCodec instead.
|
||||
// [DEPRECATED]
|
||||
func MakeTestEncodingConfig() simappparams.EncodingConfig {
|
||||
encodingConfig := simappparams.MakeTestEncodingConfig()
|
||||
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
|
||||
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
|
||||
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
|
||||
|
|
|
@ -15,6 +15,6 @@ type GenesisState map[string]json.RawMessage
|
|||
|
||||
// NewDefaultGenesisState generates the default state for the application.
|
||||
func NewDefaultGenesisState() GenesisState {
|
||||
encCfg := MakeEncodingConfig()
|
||||
encCfg := MakeTestEncodingConfig()
|
||||
return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,11 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
|
||||
func MakeEncodingConfig() EncodingConfig {
|
||||
// MakeTestEncodingConfig creates an EncodingConfig for an amino based test configuration.
|
||||
// This function should be used only internally (in the SDK).
|
||||
// App user should'nt create new codecs - use the app.AppCodec instead.
|
||||
// [DEPRECATED]
|
||||
func MakeTestEncodingConfig() EncodingConfig {
|
||||
cdc := codec.NewLegacyAmino()
|
||||
interfaceRegistry := types.NewInterfaceRegistry()
|
||||
marshaler := codec.NewAminoCodec(cdc)
|
||||
|
|
|
@ -8,8 +8,11 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
|
||||
func MakeEncodingConfig() EncodingConfig {
|
||||
// MakeTestEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
|
||||
// This function should be used only internally (in the SDK).
|
||||
// App user should'nt create new codecs - use the app.AppCodec instead.
|
||||
// [DEPRECATED]
|
||||
func MakeTestEncodingConfig() EncodingConfig {
|
||||
cdc := codec.NewLegacyAmino()
|
||||
interfaceRegistry := types.NewInterfaceRegistry()
|
||||
marshaler := codec.NewProtoCodec(interfaceRegistry)
|
||||
|
|
|
@ -27,7 +27,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
|
|||
}
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), interBlockCacheOpt())
|
||||
|
||||
// run randomized simulation
|
||||
_, simParams, simErr := simulation.SimulateFromSeed(
|
||||
|
@ -72,7 +72,7 @@ func BenchmarkInvariants(b *testing.B) {
|
|||
}
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), interBlockCacheOpt())
|
||||
|
||||
// run randomized simulation
|
||||
_, simParams, simErr := simulation.SimulateFromSeed(
|
||||
|
|
|
@ -68,7 +68,7 @@ func TestFullAppSimulation(t *testing.T) {
|
|||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// run randomized simulation
|
||||
|
@ -106,7 +106,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// Run randomized simulation
|
||||
|
@ -146,7 +146,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
require.NoError(t, os.RemoveAll(newDir))
|
||||
}()
|
||||
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", newApp.Name())
|
||||
|
||||
var genesisState GenesisState
|
||||
|
@ -203,7 +203,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// Run randomized simulation
|
||||
|
@ -248,7 +248,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
require.NoError(t, os.RemoveAll(newDir))
|
||||
}()
|
||||
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", newApp.Name())
|
||||
|
||||
newApp.InitChain(abci.RequestInitChain{
|
||||
|
@ -299,7 +299,7 @@ func TestAppStateDeterminism(t *testing.T) {
|
|||
}
|
||||
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), interBlockCacheOpt())
|
||||
|
||||
fmt.Printf(
|
||||
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
|
||||
|
|
|
@ -38,7 +38,7 @@ import (
|
|||
// NewRootCmd creates a new root command for simd. It is called once in the
|
||||
// main function.
|
||||
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
initClientCtx := client.Context{}.
|
||||
WithJSONMarshaler(encodingConfig.Marshaler).
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
|
@ -191,7 +191,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
|
|||
logger, db, traceStore, true, skipUpgradeHeights,
|
||||
cast.ToString(appOpts.Get(flags.FlagHome)),
|
||||
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
||||
simapp.MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd.
|
||||
simapp.MakeTestEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd.
|
||||
baseapp.SetPruning(pruningOpts),
|
||||
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
|
||||
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
|
||||
|
@ -211,7 +211,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
|
|||
func createSimappAndExport(
|
||||
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
|
||||
) (servertypes.ExportedApp, error) {
|
||||
encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
|
||||
encCfg := simapp.MakeTestEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
|
||||
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
|
||||
var simApp *simapp.SimApp
|
||||
if height != -1 {
|
||||
|
|
|
@ -51,7 +51,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
|
|||
// Setup initializes a new SimApp. A Nop logger is set in SimApp.
|
||||
func Setup(isCheckTx bool) *SimApp {
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeTestEncodingConfig())
|
||||
if !isCheckTx {
|
||||
// init chain must be called to stop deliverState from being nil
|
||||
genesisState := NewDefaultGenesisState()
|
||||
|
@ -79,7 +79,7 @@ func Setup(isCheckTx bool) *SimApp {
|
|||
// account. A Nop logger is set in SimApp.
|
||||
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeTestEncodingConfig())
|
||||
|
||||
genesisState := NewDefaultGenesisState()
|
||||
|
||||
|
@ -160,7 +160,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
|
|||
// accounts and possible balances.
|
||||
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
|
||||
db := dbm.NewMemDB()
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
|
||||
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeTestEncodingConfig())
|
||||
|
||||
// initialize the chain with the passed in genesis accounts
|
||||
genesisState := NewDefaultGenesisState()
|
||||
|
|
|
@ -120,16 +120,16 @@ func (mr *MockAppModuleBasicMockRecorder) RegisterRESTRoutes(arg0, arg1 interfac
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterRESTRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes mocks base method
|
||||
func (m *MockAppModuleBasic) RegisterGRPCRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes mocks base method
|
||||
func (m *MockAppModuleBasic) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterGRPCRoutes", arg0, arg1)
|
||||
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes indicates an expected call of RegisterGRPCRoutes
|
||||
func (mr *MockAppModuleBasicMockRecorder) RegisterGRPCRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes
|
||||
func (mr *MockAppModuleBasicMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCRoutes", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterGRPCRoutes), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetTxCmd mocks base method
|
||||
|
@ -261,16 +261,16 @@ func (mr *MockAppModuleGenesisMockRecorder) RegisterRESTRoutes(arg0, arg1 interf
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockAppModuleGenesis)(nil).RegisterRESTRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes mocks base method
|
||||
func (m *MockAppModuleGenesis) RegisterGRPCRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes mocks base method
|
||||
func (m *MockAppModuleGenesis) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterGRPCRoutes", arg0, arg1)
|
||||
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes indicates an expected call of RegisterGRPCRoutes
|
||||
func (mr *MockAppModuleGenesisMockRecorder) RegisterGRPCRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes
|
||||
func (mr *MockAppModuleGenesisMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCRoutes", reflect.TypeOf((*MockAppModuleGenesis)(nil).RegisterGRPCRoutes), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModuleGenesis)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetTxCmd mocks base method
|
||||
|
@ -430,16 +430,16 @@ func (mr *MockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{})
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRESTRoutes", reflect.TypeOf((*MockAppModule)(nil).RegisterRESTRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes mocks base method
|
||||
func (m *MockAppModule) RegisterGRPCRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes mocks base method
|
||||
func (m *MockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "RegisterGRPCRoutes", arg0, arg1)
|
||||
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes indicates an expected call of RegisterGRPCRoutes
|
||||
func (mr *MockAppModuleMockRecorder) RegisterGRPCRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes
|
||||
func (mr *MockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCRoutes", reflect.TypeOf((*MockAppModule)(nil).RegisterGRPCRoutes), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetTxCmd mocks base method
|
||||
|
|
|
@ -94,7 +94,7 @@ type Config struct {
|
|||
// DefaultConfig returns a sane default configuration suitable for nearly all
|
||||
// testing requirements.
|
||||
func DefaultConfig() Config {
|
||||
encCfg := simapp.MakeEncodingConfig()
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
|
||||
return Config{
|
||||
Codec: encCfg.Marshaler,
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
func NewTestInterfaceRegistry() types.InterfaceRegistry {
|
||||
|
@ -30,6 +31,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||
(*HasHasAnimalI)(nil),
|
||||
&HasHasAnimal{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
func NewTestAmino() *amino.Codec {
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
|
@ -25,11 +30,13 @@ func NewEventManager() *EventManager {
|
|||
func (em *EventManager) Events() Events { return em.events }
|
||||
|
||||
// EmitEvent stores a single Event object.
|
||||
// Deprecated: Use EmitTypedEvent
|
||||
func (em *EventManager) EmitEvent(event Event) {
|
||||
em.events = em.events.AppendEvent(event)
|
||||
}
|
||||
|
||||
// EmitEvents stores a series of Event objects.
|
||||
// Deprecated: Use EmitTypedEvents
|
||||
func (em *EventManager) EmitEvents(events Events) {
|
||||
em.events = em.events.AppendEvents(events)
|
||||
}
|
||||
|
@ -39,6 +46,97 @@ func (em EventManager) ABCIEvents() []abci.Event {
|
|||
return em.events.ToABCIEvents()
|
||||
}
|
||||
|
||||
// EmitTypedEvent takes typed event and emits converting it into Event
|
||||
func (em *EventManager) EmitTypedEvent(tev proto.Message) error {
|
||||
event, err := TypedEventToEvent(tev)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
em.EmitEvent(event)
|
||||
return nil
|
||||
}
|
||||
|
||||
// EmitTypedEvents takes series of typed events and emit
|
||||
func (em *EventManager) EmitTypedEvents(tevs ...proto.Message) error {
|
||||
events := make(Events, len(tevs))
|
||||
for i, tev := range tevs {
|
||||
res, err := TypedEventToEvent(tev)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
events[i] = res
|
||||
}
|
||||
|
||||
em.EmitEvents(events)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TypedEventToEvent takes typed event and converts to Event object
|
||||
func TypedEventToEvent(tev proto.Message) (Event, error) {
|
||||
evtType := proto.MessageName(tev)
|
||||
evtJSON, err := codec.ProtoMarshalJSON(tev, nil)
|
||||
if err != nil {
|
||||
return Event{}, err
|
||||
}
|
||||
|
||||
var attrMap map[string]json.RawMessage
|
||||
err = json.Unmarshal(evtJSON, &attrMap)
|
||||
if err != nil {
|
||||
return Event{}, err
|
||||
}
|
||||
|
||||
attrs := make([]abci.EventAttribute, 0, len(attrMap))
|
||||
for k, v := range attrMap {
|
||||
attrs = append(attrs, abci.EventAttribute{
|
||||
Key: []byte(k),
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
|
||||
return Event{
|
||||
Type: evtType,
|
||||
Attributes: attrs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ParseTypedEvent converts abci.Event back to typed event
|
||||
func ParseTypedEvent(event abci.Event) (proto.Message, error) {
|
||||
concreteGoType := proto.MessageType(event.Type)
|
||||
if concreteGoType == nil {
|
||||
return nil, fmt.Errorf("failed to retrieve the message of type %q", event.Type)
|
||||
}
|
||||
|
||||
var value reflect.Value
|
||||
if concreteGoType.Kind() == reflect.Ptr {
|
||||
value = reflect.New(concreteGoType.Elem())
|
||||
} else {
|
||||
value = reflect.Zero(concreteGoType)
|
||||
}
|
||||
|
||||
protoMsg, ok := value.Interface().(proto.Message)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%q does not implement proto.Message", event.Type)
|
||||
}
|
||||
|
||||
attrMap := make(map[string]json.RawMessage)
|
||||
for _, attr := range event.Attributes {
|
||||
attrMap[string(attr.Key)] = attr.Value
|
||||
}
|
||||
|
||||
attrBytes, err := json.Marshal(attrMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = jsonpb.Unmarshal(strings.NewReader(string(attrBytes)), protoMsg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return protoMsg, nil
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Events
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -2,11 +2,14 @@ package types_test
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
testdata "github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
@ -68,6 +71,37 @@ func (s *eventsTestSuite) TestEventManager() {
|
|||
s.Require().Equal(em.Events(), events.AppendEvent(event))
|
||||
}
|
||||
|
||||
func (s *eventsTestSuite) TestEventManagerTypedEvents() {
|
||||
em := sdk.NewEventManager()
|
||||
|
||||
coin := sdk.NewCoin("fakedenom", sdk.NewInt(1999999))
|
||||
cat := testdata.Cat{
|
||||
Moniker: "Garfield",
|
||||
Lives: 6,
|
||||
}
|
||||
animal, err := codectypes.NewAnyWithValue(&cat)
|
||||
s.Require().NoError(err)
|
||||
hasAnimal := testdata.HasAnimal{
|
||||
X: 1000,
|
||||
Animal: animal,
|
||||
}
|
||||
|
||||
s.Require().NoError(em.EmitTypedEvents(&coin))
|
||||
s.Require().NoError(em.EmitTypedEvent(&hasAnimal))
|
||||
s.Require().Len(em.Events(), 2)
|
||||
|
||||
msg1, err := sdk.ParseTypedEvent(em.Events().ToABCIEvents()[0])
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(coin.String(), msg1.String())
|
||||
s.Require().Equal(reflect.TypeOf(&coin), reflect.TypeOf(msg1))
|
||||
|
||||
msg2, err := sdk.ParseTypedEvent(em.Events().ToABCIEvents()[1])
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(reflect.TypeOf(&hasAnimal), reflect.TypeOf(msg2))
|
||||
response := msg2.(*testdata.HasAnimal)
|
||||
s.Require().Equal(hasAnimal.Animal.String(), response.Animal.String())
|
||||
}
|
||||
|
||||
func (s *eventsTestSuite) TestStringifyEvents() {
|
||||
e := sdk.Events{
|
||||
sdk.NewEvent("message", sdk.NewAttribute("sender", "foo")),
|
||||
|
|
|
@ -31,9 +31,8 @@ package module
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
|
@ -56,7 +55,7 @@ type AppModuleBasic interface {
|
|||
|
||||
// client functionality
|
||||
RegisterRESTRoutes(client.Context, *mux.Router)
|
||||
RegisterGRPCRoutes(client.Context, *runtime.ServeMux)
|
||||
RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux)
|
||||
GetTxCmd() *cobra.Command
|
||||
GetQueryCmd() *cobra.Command
|
||||
}
|
||||
|
@ -115,10 +114,10 @@ func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rou
|
|||
}
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes registers all module rest routes
|
||||
func (bm BasicManager) RegisterGRPCRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes registers all module rest routes
|
||||
func (bm BasicManager) RegisterGRPCGatewayRoutes(clientCtx client.Context, rtr *runtime.ServeMux) {
|
||||
for _, b := range bm {
|
||||
b.RegisterGRPCRoutes(clientCtx, rtr)
|
||||
b.RegisterGRPCGatewayRoutes(clientCtx, rtr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package msgservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// RegisterMsgServiceDesc registers all type_urls from Msg services described
|
||||
// in `sd` into the registry.
|
||||
func RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.ServiceDesc) {
|
||||
// Adds a top-level type_url based on the Msg service name.
|
||||
for _, method := range sd.Methods {
|
||||
fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
|
||||
methodHandler := method.Handler
|
||||
|
||||
// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.
|
||||
// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.
|
||||
// We use a no-op interceptor to avoid actually calling into the handler itself.
|
||||
_, _ = methodHandler(nil, context.Background(), func(i interface{}) error {
|
||||
msg, ok := i.(proto.Message)
|
||||
if !ok {
|
||||
// We panic here because there is no other alternative and the app cannot be initialized correctly
|
||||
// this should only happen if there is a problem with code generation in which case the app won't
|
||||
// work correctly anyway.
|
||||
panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
|
||||
}
|
||||
|
||||
registry.RegisterCustomTypeURL((*sdk.MsgRequest)(nil), fqMethod, msg)
|
||||
return nil
|
||||
}, noopInterceptor)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// gRPC NOOP interceptor
|
||||
func noopInterceptor(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
|
@ -307,7 +307,7 @@ func TestParseQueryParamBool(t *testing.T) {
|
|||
func TestPostProcessResponseBare(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
encodingConfig := simappparams.MakeEncodingConfig()
|
||||
encodingConfig := simappparams.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithLegacyAmino(encodingConfig.Amino) // amino used intentionally here
|
||||
|
|
|
@ -23,8 +23,10 @@ func NewVersionCommand() *cobra.Command {
|
|||
return nil
|
||||
}
|
||||
|
||||
var bz []byte
|
||||
var err error
|
||||
var (
|
||||
bz []byte
|
||||
err error
|
||||
)
|
||||
|
||||
output, _ := cmd.Flags().GetString(cli.OutputFlag)
|
||||
switch strings.ToLower(output) {
|
||||
|
|
|
@ -53,7 +53,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
|
|||
suite.ctx = suite.ctx.WithBlockHeight(1)
|
||||
|
||||
// Set up TxConfig.
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
// We're using TestMsg encoding in some tests, so register it here.
|
||||
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
|
||||
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)
|
||||
|
|
|
@ -174,9 +174,11 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
|||
account2, err := val.ClientCtx.Keyring.Key("newAccount2")
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Send coins.
|
||||
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
|
||||
out, err := bankcli.MsgSendExec(
|
||||
|
||||
// Send coins, try both with legacy Msg and with Msg service.
|
||||
// Legacy Msg.
|
||||
legacyMsgOut, err := bankcli.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
account2.GetAddress(),
|
||||
|
@ -187,31 +189,55 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
|||
fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
var legacyMsgTxRes sdk.TxResponse
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(legacyMsgOut.Bytes(), &legacyMsgTxRes))
|
||||
|
||||
// Service Msg.
|
||||
out, err := bankcli.ServiceMsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
account2.GetAddress(),
|
||||
sdk.NewCoins(sendTokens),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
fmt.Sprintf("--gas=%d", flags.DefaultGasLimit),
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
var txRes sdk.TxResponse
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &txRes))
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
name string
|
||||
args []string
|
||||
expectErr bool
|
||||
rawLogContains string
|
||||
}{
|
||||
{
|
||||
"with invalid hash",
|
||||
[]string{"somethinginvalid", fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"with valid and not existing hash",
|
||||
[]string{"C7E7D3A86A17AB3A321172239F3B61357937AF0F25D9FA4D2F4DCCAD9B0D7747", fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"happy case",
|
||||
"happy case (legacy Msg)",
|
||||
[]string{legacyMsgTxRes.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
false,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"happy case (service Msg)",
|
||||
[]string{txRes.TxHash, fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
false,
|
||||
"/cosmos.bank.v1beta1.Msg/Send",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -230,6 +256,7 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmd() {
|
|||
var result sdk.TxResponse
|
||||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &result))
|
||||
s.Require().NotNil(result.Height)
|
||||
s.Require().Contains(result.RawLog, tc.rawLogContains)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -756,7 +783,7 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() {
|
|||
|
||||
func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
|
||||
clientCtx := client.Context{}.WithOffline(true)
|
||||
clientCtx = clientCtx.WithTxConfig(simapp.MakeEncodingConfig().TxConfig)
|
||||
clientCtx = clientCtx.WithTxConfig(simapp.MakeTestEncodingConfig().TxConfig)
|
||||
|
||||
cmd := authcli.GetBroadcastCommand()
|
||||
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
||||
|
@ -767,7 +794,7 @@ func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
|
|||
|
||||
func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) {
|
||||
clientCtx := client.Context{}
|
||||
txCfg := simapp.MakeEncodingConfig().TxConfig
|
||||
txCfg := simapp.MakeTestEncodingConfig().TxConfig
|
||||
clientCtx = clientCtx.WithTxConfig(txCfg)
|
||||
|
||||
ctx := context.Background()
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetCommandEncode(t *testing.T) {
|
||||
encodingConfig := simappparams.MakeEncodingConfig()
|
||||
encodingConfig := simappparams.MakeTestEncodingConfig()
|
||||
|
||||
cmd := GetEncodeCommand()
|
||||
_ = testutil.ApplyMockIODiscardOutErr(cmd)
|
||||
|
@ -49,7 +49,7 @@ func TestGetCommandEncode(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetCommandDecode(t *testing.T) {
|
||||
encodingConfig := simappparams.MakeEncodingConfig()
|
||||
encodingConfig := simappparams.MakeTestEncodingConfig()
|
||||
|
||||
clientCtx := client.Context{}.
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
)
|
||||
|
||||
// REST query and parameter values
|
||||
|
@ -12,7 +13,8 @@ const (
|
|||
)
|
||||
|
||||
// RegisterRoutes registers the auth module REST routes.
|
||||
func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) {
|
||||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, storeName string) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc(
|
||||
"/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx),
|
||||
).Methods(MethodGet)
|
||||
|
@ -24,7 +26,8 @@ func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) {
|
|||
}
|
||||
|
||||
// RegisterTxRoutes registers all transaction routes on the provided router.
|
||||
func RegisterTxRoutes(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST")
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestDefaultTxEncoder(t *testing.T) {
|
|||
|
||||
func TestReadTxFromFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
|
||||
txCfg := encodingConfig.TxConfig
|
||||
clientCtx := client.Context{}
|
||||
|
@ -90,7 +90,7 @@ func TestReadTxFromFile(t *testing.T) {
|
|||
|
||||
func TestBatchScanner_Scan(t *testing.T) {
|
||||
t.Parallel()
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
|
||||
txGen := encodingConfig.TxConfig
|
||||
clientCtx := client.Context{}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
|
|
|
@ -65,8 +65,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
|||
rest.RegisterRoutes(clientCtx, rtr, types.StoreKey)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the auth module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the auth module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ type config struct {
|
|||
encoder sdk.TxEncoder
|
||||
jsonDecoder sdk.TxDecoder
|
||||
jsonEncoder sdk.TxEncoder
|
||||
protoCodec *codec.ProtoCodec
|
||||
protoCodec codec.ProtoCodecMarshaler
|
||||
}
|
||||
|
||||
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The
|
||||
// first enabled sign mode will become the default sign mode.
|
||||
func NewTxConfig(protoCodec *codec.ProtoCodec, enabledSignModes []signingtypes.SignMode) client.TxConfig {
|
||||
func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig {
|
||||
return &config{
|
||||
handler: makeSignModeHandler(enabledSignModes),
|
||||
decoder: DefaultTxDecoder(protoCodec),
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler.
|
||||
func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
||||
func DefaultTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
var raw tx.TxRaw
|
||||
|
||||
|
@ -66,7 +66,7 @@ func DefaultTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
|||
}
|
||||
|
||||
// DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler.
|
||||
func DefaultJSONTxDecoder(cdc *codec.ProtoCodec) sdk.TxDecoder {
|
||||
func DefaultJSONTxDecoder(cdc codec.ProtoCodecMarshaler) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
var theTx tx.Tx
|
||||
err := cdc.UnmarshalJSON(txBytes, &theTx)
|
||||
|
|
|
@ -29,7 +29,7 @@ func DefaultTxEncoder() sdk.TxEncoder {
|
|||
}
|
||||
|
||||
// DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler.
|
||||
func DefaultJSONTxEncoder(cdc *codec.ProtoCodec) sdk.TxEncoder {
|
||||
func DefaultJSONTxEncoder(cdc codec.ProtoCodecMarshaler) sdk.TxEncoder {
|
||||
return func(tx sdk.Tx) ([]byte, error) {
|
||||
txWrapper, ok := tx.(*wrapper)
|
||||
if ok {
|
||||
|
|
|
@ -57,9 +57,9 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ client.TxEncoding
|
|||
// RegisterRESTRoutes registers module's REST handlers. Currently, this is a no-op.
|
||||
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
|
||||
|
||||
// RegisterGRPCRoutes registers the module's gRPC Gateway routes. Currently, this
|
||||
// RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this
|
||||
// is a no-op.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {}
|
||||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
|
||||
|
||||
// GetTxCmd returns the root tx command for the auth module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
|
|
|
@ -4,6 +4,7 @@ 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"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
||||
)
|
||||
|
@ -49,6 +50,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||
(*sdk.Msg)(nil),
|
||||
&MsgCreateVestingAccount{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
var amino = codec.NewLegacyAmino()
|
||||
|
|
|
@ -109,7 +109,7 @@ func TestSendNotEnoughBalance(t *testing.T) {
|
|||
|
||||
sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{sendMsg}, "", []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
|
||||
require.Error(t, err)
|
||||
|
||||
|
@ -182,7 +182,7 @@ func TestSendToModuleAcc(t *testing.T) {
|
|||
origSeq := res1.GetSequence()
|
||||
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{test.msg}, "", []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1)
|
||||
if test.expPass {
|
||||
require.NoError(t, err)
|
||||
|
@ -256,7 +256,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
if tc.expPass {
|
||||
require.NoError(t, err)
|
||||
|
@ -308,7 +308,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -363,7 +363,7 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -416,7 +416,7 @@ func TestMsgMultiSendDependent(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
txGen := simapp.MakeEncodingConfig().TxConfig
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
_, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
|
|||
require.NoError(b, err)
|
||||
|
||||
benchmarkApp.Commit()
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
|
||||
// Precompute all txs
|
||||
txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
|
||||
|
@ -75,7 +75,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
|
|||
require.NoError(b, err)
|
||||
|
||||
benchmarkApp.Commit()
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
|
||||
// Precompute all txs
|
||||
txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
|
||||
|
|
|
@ -5,13 +5,6 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
|
||||
"github.com/gogo/protobuf/grpc"
|
||||
grpc2 "google.golang.org/grpc"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
@ -302,82 +295,6 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() {
|
|||
}
|
||||
}
|
||||
|
||||
// serviceMsgClientConn is an instance of grpc.ClientConn that is used to test building
|
||||
// transactions with MsgClient's. It is intended to be replaced by the work in
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/7541 when that is ready.
|
||||
type serviceMsgClientConn struct {
|
||||
msgs []sdk.Msg
|
||||
}
|
||||
|
||||
func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc2.CallOption) error {
|
||||
req, ok := args.(sdk.MsgRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil))
|
||||
}
|
||||
|
||||
err := req.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.msgs = append(t.msgs, sdk.ServiceMsg{
|
||||
MethodName: method,
|
||||
Request: req,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *serviceMsgClientConn) NewStream(context.Context, *grpc2.StreamDesc, string, ...grpc2.CallOption) (grpc2.ClientStream, error) {
|
||||
return nil, fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
var _ grpc.ClientConn = &serviceMsgClientConn{}
|
||||
|
||||
// newSendTxMsgServiceCmd is just for the purpose of testing ServiceMsg's in an end-to-end case. It is effectively
|
||||
// NewSendTxCmd but using MsgClient.
|
||||
func newSendTxMsgServiceCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
Short: `Send funds from one account to another. Note, the'--from' flag is
|
||||
ignored as it is implied from [from_key_or_address].`,
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Flags().Set(flags.FlagFrom, args[0])
|
||||
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coins, err := sdk.ParseCoins(args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins)
|
||||
svcMsgClientConn := &serviceMsgClientConn{}
|
||||
bankMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = bankMsgClient.Send(context.Background(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// TestBankMsgService does a basic test of whether or not service Msg's as defined
|
||||
// in ADR 031 work in the most basic end-to-end case.
|
||||
func (s *IntegrationTestSuite) TestBankMsgService() {
|
||||
|
@ -419,10 +336,7 @@ func (s *IntegrationTestSuite) TestBankMsgService() {
|
|||
s.Run(tc.name, func() {
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
args := []string{tc.from.String(), tc.to.String(), tc.amount.String()}
|
||||
args = append(args, tc.args...)
|
||||
|
||||
bz, err := clitestutil.ExecTestCLICmd(clientCtx, newSendTxMsgServiceCmd(), args)
|
||||
bz, err := banktestutil.ServiceMsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
@ -8,7 +9,8 @@ import (
|
|||
|
||||
// RegisterHandlers registers all x/bank transaction and query HTTP REST handlers
|
||||
// on the provided mux router.
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(clientCtx)).Methods("POST")
|
||||
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET")
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *IntegrationTestSuite) TestCoinSend() {
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
authclient.Codec = encodingConfig.Marshaler
|
||||
|
||||
val := s.network.Validators[0]
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
gogogrpc "github.com/gogo/protobuf/grpc"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
grpc "google.golang.org/grpc"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
|
@ -24,3 +32,90 @@ func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs
|
|||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, bankcli.GetBalancesCmd(), args)
|
||||
}
|
||||
|
||||
// serviceMsgClientConn is an instance of grpc.ClientConn that is used to test building
|
||||
// transactions with MsgClient's. It is intended to be replaced by the work in
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/7541 when that is ready.
|
||||
type serviceMsgClientConn struct {
|
||||
msgs []sdk.Msg
|
||||
}
|
||||
|
||||
func (t *serviceMsgClientConn) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc.CallOption) error {
|
||||
req, ok := args.(sdk.MsgRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf("%T should implement %T", args, (*sdk.MsgRequest)(nil))
|
||||
}
|
||||
|
||||
err := req.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.msgs = append(t.msgs, sdk.ServiceMsg{
|
||||
MethodName: method,
|
||||
Request: req,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *serviceMsgClientConn) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||
return nil, fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
var _ gogogrpc.ClientConn = &serviceMsgClientConn{}
|
||||
|
||||
// newSendTxMsgServiceCmd is just for the purpose of testing ServiceMsg's in an end-to-end case. It is effectively
|
||||
// NewSendTxCmd but using MsgClient.
|
||||
func newSendTxMsgServiceCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
Short: `Send funds from one account to another. Note, the'--from' flag is
|
||||
ignored as it is implied from [from_key_or_address].`,
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cmd.Flags().Set(flags.FlagFrom, args[0])
|
||||
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coins, err := sdk.ParseCoins(args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSend(clientCtx.GetFromAddress(), toAddr, coins)
|
||||
svcMsgClientConn := &serviceMsgClientConn{}
|
||||
bankMsgClient := types.NewMsgClient(svcMsgClientConn)
|
||||
_, err = bankMsgClient.Send(context.Background(), msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), svcMsgClientConn.msgs...)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ServiceMsgSendExec is a temporary method to test Msg services in CLI using
|
||||
// x/bank's Msg/Send service. After https://github.com/cosmos/cosmos-sdk/issues/7541
|
||||
// is merged, this method should be removed, and we should prefer MsgSendExec
|
||||
// instead.
|
||||
func ServiceMsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{from.String(), to.String(), amount.String()}
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, newSendTxMsgServiceCmd(), args)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
encodingConfig := simapp.MakeEncodingConfig()
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
|
|
|
@ -64,8 +64,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
|
|||
rest.RegisterHandlers(clientCtx, rtr)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the bank module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ func sendMsgSend(
|
|||
return err
|
||||
}
|
||||
}
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
@ -265,7 +265,7 @@ func sendMsgMultiSend(
|
|||
}
|
||||
}
|
||||
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/exported"
|
||||
)
|
||||
|
||||
|
@ -28,6 +29,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||
(*exported.SupplyI)(nil),
|
||||
&Supply{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -69,8 +69,8 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
|
|||
// RegisterRESTRoutes registers the capability module's REST service handlers.
|
||||
func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the capability module.
|
||||
func (a AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
|
||||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {
|
||||
}
|
||||
|
||||
// GetTxCmd returns the capability module's root tx command.
|
||||
|
|
|
@ -27,7 +27,7 @@ var (
|
|||
|
||||
func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) {
|
||||
db := dbm.NewMemDB()
|
||||
app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 1, simapp.MakeEncodingConfig())
|
||||
app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 1, simapp.MakeTestEncodingConfig())
|
||||
ctx := app.NewContext(true, tmproto.Header{})
|
||||
|
||||
constantFee := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)
|
||||
|
|
|
@ -56,8 +56,8 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
|
|||
// RegisterRESTRoutes registers no REST routes for the crisis module.
|
||||
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the capability module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(_ client.Context, _ *runtime.ServeMux) {}
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {}
|
||||
|
||||
// GetTxCmd returns the root tx command for the crisis module.
|
||||
func (b AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
// RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types
|
||||
|
@ -17,6 +18,8 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||
registry.RegisterImplementations((*sdk.Msg)(nil),
|
||||
&MsgVerifyInvariant{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -65,7 +65,7 @@ func Test_splitAndCall_Splitting(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestParseProposal(t *testing.T) {
|
||||
encodingConfig := params.MakeEncodingConfig()
|
||||
encodingConfig := params.MakeTestEncodingConfig()
|
||||
|
||||
okJSON, cleanup := testutil.WriteToNewTempFile(t, `
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
|
@ -13,7 +14,9 @@ import (
|
|||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := clientrest.WithHTTPDeprecationHeaders(rtr)
|
||||
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r)
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.R
|
|||
rest.RegisterHandlers(clientCtx, rtr)
|
||||
}
|
||||
|
||||
// RegisterGRPCRoutes registers the gRPC Gateway routes for the distribution module.
|
||||
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper,
|
|||
|
||||
msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address)
|
||||
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
@ -152,7 +152,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee
|
|||
|
||||
msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator())
|
||||
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
@ -207,7 +207,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban
|
|||
|
||||
msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator())
|
||||
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
@ -262,7 +262,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k
|
|||
}
|
||||
|
||||
msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address)
|
||||
txGen := simappparams.MakeEncodingConfig().TxConfig
|
||||
txGen := simappparams.MakeTestEncodingConfig().TxConfig
|
||||
tx, err := helpers.GenTx(
|
||||
txGen,
|
||||
[]sdk.Msg{msg},
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
|
@ -30,6 +31,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||
(*govtypes.Content)(nil),
|
||||
&CommunityPoolSpendProposal{},
|
||||
)
|
||||
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue