├── .github
└── workflows
│ ├── lint.yml
│ └── test.yml
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── app
├── app.go
├── encoding.go
├── export.go
├── genesis.go
├── params
│ ├── encoding.go
│ └── proto.go
├── prefix.go
├── test_utils.go
└── types.go
├── cmd
└── cnsd
│ ├── cmd
│ ├── genaccounts.go
│ └── root.go
│ └── main.go
├── config.yml
├── docs
├── proto.md
└── spec.md
├── go.mod
├── go.sum
├── proto
└── cns
│ ├── cns.proto
│ ├── genesis.proto
│ ├── query.proto
│ └── tx.proto
├── scripts
└── protogen.sh
└── x
└── cns
├── client
├── cli
│ ├── flags.go
│ ├── query.go
│ └── tx.go
└── rest
│ └── rest.go
├── genesis.go
├── handler.go
├── keeper
├── grpc_query.go
├── grpc_query_test.go
├── keeper.go
├── keeper_test.go
├── msg_server.go
└── query.go
├── module.go
└── types
├── cns.pb.go
├── codec.go
├── errors.go
├── expected_keepers.go
├── genesis.go
├── genesis.pb.go
├── info.go
├── keys.go
├── msg.go
├── query.go
├── query.pb.go
├── query.pb.gw.go
├── tx.pb.go
└── types.go
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: Lint
2 | # Lint runs golangci-lint over the entire cosmos-rosetta-gateway repository
3 | # This workflow is run on every pull request and push to master or develop
4 | on:
5 | pull_request:
6 | push:
7 | branches:
8 | - master
9 | - develop
10 | jobs:
11 | golangci:
12 | name: golangci-lint
13 | runs-on: ubuntu-latest
14 | timeout-minutes: 10
15 | steps:
16 | - uses: actions/checkout@v2
17 | - uses: golangci/golangci-lint-action@master
18 | with:
19 | version: v1.37
20 | args: --timeout 10m
21 | github-token: ${{ secrets.github_token }}
22 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: unit-test
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - master
8 | - develop
9 |
10 | jobs:
11 | test:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: actions/setup-go@v2
16 | with:
17 | go-version: '1.15'
18 | - run: go test -v -race -coverprofile coverage.txt github.com/tendermint/cns/...
19 | - uses: codecov/codecov-action@v1
20 | with:
21 | file: ./coverage.txt
22 | fail_ci_if_error: true
23 | github-token: ${{ secrets.codecov }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.exe~
4 | *.dll
5 | *.so
6 | *.dylib
7 |
8 | # Test binary, built with `go test -c`
9 | *.test
10 |
11 | # Output of the go coverage tool, specifically when used with LiteIDE
12 | *.out
13 |
14 | # Dependency directories (remove the comment below to include it)
15 | # vendor/
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PACKAGES=$(shell go list ./...)
2 |
3 | ###############################################################################
4 | ### Basic Golang Commands ###
5 | ###############################################################################
6 |
7 | all: install
8 |
9 | install: go.sum
10 | go install -mod=readonly ./cmd/cnsd
11 |
12 | install-debug: go.sum
13 | go build -mod=readonly -gcflags="all=-N -l" ./cmd/cnsd
14 |
15 | go.sum: go.mod
16 | @echo "--> Ensure dependencies have not been modified"
17 | GO111MODULE=on go mod verify
18 |
19 | test:
20 | @go test -mod=readonly $(PACKAGES)
21 |
22 | lint:
23 | @echo "--> Running linter"
24 | @golangci-lint run
25 | @go mod verify
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chain Name Service (CNS)
2 |
3 | The CNS module is a new Cosmos SDK module that allows Cosmos addresses to obtain and administer chain names.
4 |
5 | ## Why Cosmos Hub needs a CNS
6 |
7 | For the Cosmos Hub to function as an interchain router, it needs to access a canonical list of chain names. For example, token holders on the Hub need a trusted way to determine that, e.g., IRIS tokens on the Hub are actually from the IRISnet mainnet. If the Hub decides to add services like DEXes onto the Hub, trusted chain names allow token holders to more quickly verify ticker symbols and provide liquidity to the right pools.
8 |
9 | A CNS on the Hub will provide security to interchain transfers by registering chain names, this will allow proper token tracking for every token transferred onto cosmos hub and off the cosmos hub. The cosmos hub will then become the defacto hub with all other zones relying on the trusted setup on the hub to define valid tokens. This value proposition will contribute to the growth of the ATOM.
10 |
11 | While the CNS can exist on another chain and function correctly, we think that the CNS has the most aligned incentives with the Cosmos Hub. By adopting this module, ATOM stakers will be securing a crucial component of the interchain and will move us further into the direction of a Hub-centric model of Cosmos.
12 |
--------------------------------------------------------------------------------
/app/app.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "io"
5 | "os"
6 | "path/filepath"
7 |
8 | "github.com/cosmos/cosmos-sdk/client"
9 | "github.com/cosmos/cosmos-sdk/codec/types"
10 | "github.com/spf13/cast"
11 |
12 | abci "github.com/tendermint/tendermint/abci/types"
13 | "github.com/tendermint/tendermint/libs/log"
14 | tmos "github.com/tendermint/tendermint/libs/os"
15 | dbm "github.com/tendermint/tm-db"
16 |
17 | "github.com/cosmos/cosmos-sdk/baseapp"
18 | "github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
19 | "github.com/cosmos/cosmos-sdk/client/rpc"
20 | "github.com/cosmos/cosmos-sdk/codec"
21 | "github.com/cosmos/cosmos-sdk/server/api"
22 | "github.com/cosmos/cosmos-sdk/server/config"
23 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
24 | sdk "github.com/cosmos/cosmos-sdk/types"
25 | "github.com/cosmos/cosmos-sdk/types/module"
26 | "github.com/cosmos/cosmos-sdk/version"
27 | "github.com/cosmos/cosmos-sdk/x/auth"
28 | "github.com/cosmos/cosmos-sdk/x/auth/ante"
29 | authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
30 | authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
31 | authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
32 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
33 | "github.com/cosmos/cosmos-sdk/x/auth/vesting"
34 | "github.com/cosmos/cosmos-sdk/x/bank"
35 | bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
36 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
37 | "github.com/cosmos/cosmos-sdk/x/capability"
38 | capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
39 | capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
40 | "github.com/cosmos/cosmos-sdk/x/crisis"
41 | crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
42 | crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
43 | distr "github.com/cosmos/cosmos-sdk/x/distribution"
44 | distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
45 | distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
46 | distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
47 | "github.com/cosmos/cosmos-sdk/x/evidence"
48 | evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
49 | evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
50 | "github.com/cosmos/cosmos-sdk/x/genutil"
51 | genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
52 | "github.com/cosmos/cosmos-sdk/x/gov"
53 | govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
54 | govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
55 | govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
56 | transfer "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
57 | ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
58 | ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
59 | ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
60 | ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client"
61 | porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types"
62 | ibchost "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
63 | ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/core/keeper"
64 | "github.com/cosmos/cosmos-sdk/x/mint"
65 | mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
66 | minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
67 | "github.com/cosmos/cosmos-sdk/x/params"
68 | paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
69 | paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
70 | paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
71 | paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
72 | "github.com/cosmos/cosmos-sdk/x/slashing"
73 | slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
74 | slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
75 | "github.com/cosmos/cosmos-sdk/x/staking"
76 | stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
77 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
78 | "github.com/cosmos/cosmos-sdk/x/upgrade"
79 | upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
80 | upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
81 | upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
82 | appparams "github.com/tendermint/cns/app/params"
83 | "github.com/tendermint/cns/x/cns"
84 | cnskeeper "github.com/tendermint/cns/x/cns/keeper"
85 | cnstypes "github.com/tendermint/cns/x/cns/types"
86 | tmjson "github.com/tendermint/tendermint/libs/json"
87 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
88 | // this line is used by starport scaffolding # stargate/app/moduleImport
89 | )
90 |
91 | const Name = "cns"
92 |
93 | // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
94 |
95 | func getGovProposalHandlers() []govclient.ProposalHandler {
96 | var govProposalHandlers []govclient.ProposalHandler
97 | // this line is used by starport scaffolding # stargate/app/govProposalHandlers
98 |
99 | govProposalHandlers = append(govProposalHandlers,
100 | paramsclient.ProposalHandler,
101 | distrclient.ProposalHandler,
102 | upgradeclient.ProposalHandler,
103 | upgradeclient.CancelProposalHandler,
104 | // this line is used by starport scaffolding # stargate/app/govProposalHandler
105 | )
106 |
107 | return govProposalHandlers
108 | }
109 |
110 | var (
111 | // DefaultNodeHome default home directories for the application daemon
112 | DefaultNodeHome string
113 |
114 | // ModuleBasics defines the module BasicManager is in charge of setting up basic,
115 | // non-dependant module elements, such as codec registration
116 | // and genesis verification.
117 | ModuleBasics = module.NewBasicManager(
118 | auth.AppModuleBasic{},
119 | genutil.AppModuleBasic{},
120 | bank.AppModuleBasic{},
121 | capability.AppModuleBasic{},
122 | staking.AppModuleBasic{},
123 | mint.AppModuleBasic{},
124 | distr.AppModuleBasic{},
125 | gov.NewAppModuleBasic(getGovProposalHandlers()...),
126 | params.AppModuleBasic{},
127 | crisis.AppModuleBasic{},
128 | slashing.AppModuleBasic{},
129 | ibc.AppModuleBasic{},
130 | upgrade.AppModuleBasic{},
131 | evidence.AppModuleBasic{},
132 | transfer.AppModuleBasic{},
133 | vesting.AppModuleBasic{},
134 | cns.AppModuleBasic{},
135 | // this line is used by starport scaffolding # stargate/app/moduleBasic
136 | )
137 |
138 | // module account permissions
139 | maccPerms = map[string][]string{
140 | authtypes.FeeCollectorName: nil,
141 | distrtypes.ModuleName: nil,
142 | minttypes.ModuleName: {authtypes.Minter},
143 | stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
144 | stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
145 | govtypes.ModuleName: {authtypes.Burner},
146 | ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
147 | }
148 |
149 | // module accounts that are allowed to receive tokens
150 | allowedReceivingModAcc = map[string]bool{
151 | distrtypes.ModuleName: true,
152 | }
153 | )
154 |
155 | var (
156 | _ CosmosApp = (*App)(nil)
157 | _ servertypes.Application = (*App)(nil)
158 | )
159 |
160 | func init() {
161 | userHomeDir, err := os.UserHomeDir()
162 | if err != nil {
163 | panic(err)
164 | }
165 |
166 | DefaultNodeHome = filepath.Join(userHomeDir, "."+Name)
167 | }
168 |
169 | // App extends an ABCI application, but with most of its parameters exported.
170 | // They are exported for convenience in creating helper functions, as object
171 | // capabilities aren't needed for testing.
172 | type App struct {
173 | *baseapp.BaseApp
174 |
175 | cdc *codec.LegacyAmino
176 | appCodec codec.Marshaler
177 | interfaceRegistry types.InterfaceRegistry
178 |
179 | invCheckPeriod uint
180 |
181 | // keys to access the substores
182 | keys map[string]*sdk.KVStoreKey
183 | tkeys map[string]*sdk.TransientStoreKey
184 | memKeys map[string]*sdk.MemoryStoreKey
185 |
186 | // keepers
187 | AccountKeeper authkeeper.AccountKeeper
188 | BankKeeper bankkeeper.Keeper
189 | CapabilityKeeper *capabilitykeeper.Keeper
190 | StakingKeeper stakingkeeper.Keeper
191 | SlashingKeeper slashingkeeper.Keeper
192 | MintKeeper mintkeeper.Keeper
193 | DistrKeeper distrkeeper.Keeper
194 | GovKeeper govkeeper.Keeper
195 | CrisisKeeper crisiskeeper.Keeper
196 | UpgradeKeeper upgradekeeper.Keeper
197 | ParamsKeeper paramskeeper.Keeper
198 | IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
199 | EvidenceKeeper evidencekeeper.Keeper
200 | TransferKeeper ibctransferkeeper.Keeper
201 |
202 | // make scoped keepers public for test purposes
203 | ScopedIBCKeeper capabilitykeeper.ScopedKeeper
204 | ScopedTransferKeeper capabilitykeeper.ScopedKeeper
205 |
206 | CNSkeeper cnskeeper.Keeper
207 | // this line is used by starport scaffolding # stargate/app/keeperDeclaration
208 |
209 | // the module manager
210 | mm *module.Manager
211 | }
212 |
213 | // New returns a reference to an initialized Gaia.
214 | // NewSimApp returns a reference to an initialized SimApp.
215 | func New(
216 | logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
217 | homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
218 | // this line is used by starport scaffolding # stargate/app/newArgument
219 | appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
220 | ) *App {
221 |
222 | appCodec := encodingConfig.Marshaler
223 | cdc := encodingConfig.Amino
224 | interfaceRegistry := encodingConfig.InterfaceRegistry
225 |
226 | bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
227 | bApp.SetCommitMultiStoreTracer(traceStore)
228 | bApp.SetAppVersion(version.Version)
229 | bApp.SetInterfaceRegistry(interfaceRegistry)
230 |
231 | keys := sdk.NewKVStoreKeys(
232 | authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
233 | minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
234 | govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
235 | evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
236 | cnstypes.StoreKey,
237 | // this line is used by starport scaffolding # stargate/app/storeKey
238 | )
239 | tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
240 | memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
241 |
242 | app := &App{
243 | BaseApp: bApp,
244 | cdc: cdc,
245 | appCodec: appCodec,
246 | interfaceRegistry: interfaceRegistry,
247 | invCheckPeriod: invCheckPeriod,
248 | keys: keys,
249 | tkeys: tkeys,
250 | memKeys: memKeys,
251 | }
252 |
253 | app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
254 |
255 | // set the BaseApp's parameter store
256 | bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
257 |
258 | // add capability keeper and ScopeToModule for ibc module
259 | app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
260 |
261 | // grant capabilities for the ibc and ibc-transfer modules
262 | scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
263 | scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
264 |
265 | // add keepers
266 | app.AccountKeeper = authkeeper.NewAccountKeeper(
267 | appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
268 | )
269 | app.BankKeeper = bankkeeper.NewBaseKeeper(
270 | appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
271 | )
272 | stakingKeeper := stakingkeeper.NewKeeper(
273 | appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
274 | )
275 | app.MintKeeper = mintkeeper.NewKeeper(
276 | appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
277 | app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
278 | )
279 | app.DistrKeeper = distrkeeper.NewKeeper(
280 | appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
281 | &stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
282 | )
283 | app.SlashingKeeper = slashingkeeper.NewKeeper(
284 | appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
285 | )
286 | app.CrisisKeeper = crisiskeeper.NewKeeper(
287 | app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
288 | )
289 | app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)
290 |
291 | // register the staking hooks
292 | // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
293 | app.StakingKeeper = *stakingKeeper.SetHooks(
294 | stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
295 | )
296 |
297 | // ... other modules keepers
298 |
299 | // Create IBC Keeper
300 | app.IBCKeeper = ibckeeper.NewKeeper(
301 | appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
302 | )
303 |
304 | // register the proposal types
305 | govRouter := govtypes.NewRouter()
306 | govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
307 | AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
308 | AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
309 | AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
310 | AddRoute(ibchost.RouterKey, ibcclient.NewClientUpdateProposalHandler(app.IBCKeeper.ClientKeeper))
311 |
312 | // Create Transfer Keepers
313 | app.TransferKeeper = ibctransferkeeper.NewKeeper(
314 | appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
315 | app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
316 | app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
317 | )
318 | transferModule := transfer.NewAppModule(app.TransferKeeper)
319 |
320 | // Create static IBC router, add transfer route, then set and seal it
321 | ibcRouter := porttypes.NewRouter()
322 | ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
323 | app.IBCKeeper.SetRouter(ibcRouter)
324 |
325 | // Create evidence Keeper for to register the IBC light client misbehaviour evidence route
326 | evidenceKeeper := evidencekeeper.NewKeeper(
327 | appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
328 | )
329 | // If evidence needs to be handled for the app, set routes in router here and seal
330 | app.EvidenceKeeper = *evidenceKeeper
331 |
332 | app.CNSkeeper = *cnskeeper.NewKeeper(
333 | appCodec, keys[cnstypes.StoreKey], keys[cnstypes.MemStoreKey], app.DistrKeeper,
334 | )
335 |
336 | // this line is used by starport scaffolding # stargate/app/keeperDefinition
337 |
338 | app.GovKeeper = govkeeper.NewKeeper(
339 | appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
340 | &stakingKeeper, govRouter,
341 | )
342 |
343 | /**** Module Options ****/
344 |
345 | // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
346 | // we prefer to be more strict in what arguments the modules expect.
347 | var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
348 |
349 | // NOTE: Any module instantiated in the module manager that is later modified
350 | // must be passed by reference here.
351 |
352 | app.mm = module.NewManager(
353 | genutil.NewAppModule(
354 | app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
355 | encodingConfig.TxConfig,
356 | ),
357 | auth.NewAppModule(appCodec, app.AccountKeeper, nil),
358 | vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
359 | bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
360 | capability.NewAppModule(appCodec, *app.CapabilityKeeper),
361 | crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
362 | gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
363 | mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
364 | slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
365 | distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
366 | staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
367 | upgrade.NewAppModule(app.UpgradeKeeper),
368 | evidence.NewAppModule(app.EvidenceKeeper),
369 | ibc.NewAppModule(app.IBCKeeper),
370 | params.NewAppModule(app.ParamsKeeper),
371 | transferModule,
372 | cns.NewAppModule(appCodec, app.CNSkeeper),
373 | // this line is used by starport scaffolding # stargate/app/appModule
374 | )
375 |
376 | // During begin block slashing happens after distr.BeginBlocker so that
377 | // there is nothing left over in the validator fee pool, so as to keep the
378 | // CanWithdrawInvariant invariant.
379 | // NOTE: staking module is required if HistoricalEntries param > 0
380 | app.mm.SetOrderBeginBlockers(
381 | upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
382 | evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
383 | )
384 |
385 | app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)
386 |
387 | // NOTE: The genutils module must occur after staking so that pools are
388 | // properly initialized with tokens from genesis accounts.
389 | // NOTE: Capability module must occur first so that it can initialize any capabilities
390 | // so that other modules that want to create or claim capabilities afterwards in InitChain
391 | // can do so safely.
392 | app.mm.SetOrderInitGenesis(
393 | capabilitytypes.ModuleName,
394 | authtypes.ModuleName,
395 | banktypes.ModuleName,
396 | distrtypes.ModuleName,
397 | stakingtypes.ModuleName,
398 | slashingtypes.ModuleName,
399 | govtypes.ModuleName,
400 | minttypes.ModuleName,
401 | crisistypes.ModuleName,
402 | ibchost.ModuleName,
403 | genutiltypes.ModuleName,
404 | evidencetypes.ModuleName,
405 | ibctransfertypes.ModuleName,
406 | cnstypes.ModuleName,
407 | // this line is used by starport scaffolding # stargate/app/initGenesis
408 | )
409 |
410 | app.mm.RegisterInvariants(&app.CrisisKeeper)
411 | app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
412 | app.mm.RegisterServices(module.NewConfigurator(app.MsgServiceRouter(), app.GRPCQueryRouter()))
413 |
414 | // initialize stores
415 | app.MountKVStores(keys)
416 | app.MountTransientStores(tkeys)
417 | app.MountMemoryStores(memKeys)
418 |
419 | // initialize BaseApp
420 | app.SetInitChainer(app.InitChainer)
421 | app.SetBeginBlocker(app.BeginBlocker)
422 | app.SetAnteHandler(
423 | ante.NewAnteHandler(
424 | app.AccountKeeper, app.BankKeeper, ante.DefaultSigVerificationGasConsumer,
425 | encodingConfig.TxConfig.SignModeHandler(),
426 | ),
427 | )
428 | app.SetEndBlocker(app.EndBlocker)
429 |
430 | if loadLatest {
431 | if err := app.LoadLatestVersion(); err != nil {
432 | tmos.Exit(err.Error())
433 | }
434 |
435 | // Initialize and seal the capability keeper so all persistent capabilities
436 | // are loaded in-memory and prevent any further modules from creating scoped
437 | // sub-keepers.
438 | // This must be done during creation of baseapp rather than in InitChain so
439 | // that in-memory capabilities get regenerated on app restart.
440 | // Note that since this reads from the store, we can only perform it when
441 | // `loadLatest` is set to true.
442 | ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
443 | app.CapabilityKeeper.InitializeAndSeal(ctx)
444 | }
445 |
446 | app.ScopedIBCKeeper = scopedIBCKeeper
447 | app.ScopedTransferKeeper = scopedTransferKeeper
448 |
449 | return app
450 | }
451 |
452 | // Name returns the name of the App
453 | func (app *App) Name() string { return app.BaseApp.Name() }
454 |
455 | // BeginBlocker application updates every begin block
456 | func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
457 | return app.mm.BeginBlock(ctx, req)
458 | }
459 |
460 | // EndBlocker application updates every end block
461 | func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
462 | return app.mm.EndBlock(ctx, req)
463 | }
464 |
465 | // InitChainer application update at chain initialization
466 | func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
467 | var genesisState GenesisState
468 | if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
469 | panic(err)
470 | }
471 | return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
472 | }
473 |
474 | // LoadHeight loads a particular height
475 | func (app *App) LoadHeight(height int64) error {
476 | return app.LoadVersion(height)
477 | }
478 |
479 | // ModuleAccountAddrs returns all the app's module account addresses.
480 | func (app *App) ModuleAccountAddrs() map[string]bool {
481 | modAccAddrs := make(map[string]bool)
482 | for acc := range maccPerms {
483 | modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
484 | }
485 |
486 | return modAccAddrs
487 | }
488 |
489 | // BlockedAddrs returns all the app's module account addresses that are not
490 | // allowed to receive external tokens.
491 | func (app *App) BlockedAddrs() map[string]bool {
492 | blockedAddrs := make(map[string]bool)
493 | for acc := range maccPerms {
494 | blockedAddrs[authtypes.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
495 | }
496 |
497 | return blockedAddrs
498 | }
499 |
500 | // LegacyAmino returns SimApp's amino codec.
501 | //
502 | // NOTE: This is solely to be used for testing purposes as it may be desirable
503 | // for modules to register their own custom testing types.
504 | func (app *App) LegacyAmino() *codec.LegacyAmino {
505 | return app.cdc
506 | }
507 |
508 | // AppCodec returns Gaia's app codec.
509 | //
510 | // NOTE: This is solely to be used for testing purposes as it may be desirable
511 | // for modules to register their own custom testing types.
512 | func (app *App) AppCodec() codec.Marshaler {
513 | return app.appCodec
514 | }
515 |
516 | // InterfaceRegistry returns Gaia's InterfaceRegistry
517 | func (app *App) InterfaceRegistry() types.InterfaceRegistry {
518 | return app.interfaceRegistry
519 | }
520 |
521 | // GetKey returns the KVStoreKey for the provided store key.
522 | //
523 | // NOTE: This is solely to be used for testing purposes.
524 | func (app *App) GetKey(storeKey string) *sdk.KVStoreKey {
525 | return app.keys[storeKey]
526 | }
527 |
528 | // GetTKey returns the TransientStoreKey for the provided store key.
529 | //
530 | // NOTE: This is solely to be used for testing purposes.
531 | func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey {
532 | return app.tkeys[storeKey]
533 | }
534 |
535 | // GetMemKey returns the MemStoreKey for the provided mem key.
536 | //
537 | // NOTE: This is solely used for testing purposes.
538 | func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
539 | return app.memKeys[storeKey]
540 | }
541 |
542 | // GetSubspace returns a param subspace for a given module name.
543 | //
544 | // NOTE: This is solely to be used for testing purposes.
545 | func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
546 | subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
547 | return subspace
548 | }
549 |
550 | // RegisterAPIRoutes registers all application module routes with the provided
551 | // API server.
552 | func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
553 | clientCtx := apiSvr.ClientCtx
554 | rpc.RegisterRoutes(clientCtx, apiSvr.Router)
555 | // Register legacy tx routes.
556 | authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
557 | // Register new tx routes from grpc-gateway.
558 | authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
559 | // Register new tendermint queries routes from grpc-gateway.
560 | tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
561 |
562 | // Register legacy and grpc-gateway routes for all modules.
563 | ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
564 | ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
565 | }
566 |
567 | // RegisterTxService implements the Application.RegisterTxService method.
568 | func (app *App) RegisterTxService(clientCtx client.Context) {
569 | authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
570 | }
571 |
572 | // RegisterTendermintService implements the Application.RegisterTendermintService method.
573 | func (app *App) RegisterTendermintService(clientCtx client.Context) {
574 | tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
575 | }
576 |
577 | // GetMaccPerms returns a copy of the module account permissions
578 | func GetMaccPerms() map[string][]string {
579 | dupMaccPerms := make(map[string][]string)
580 | for k, v := range maccPerms {
581 | dupMaccPerms[k] = v
582 | }
583 | return dupMaccPerms
584 | }
585 |
586 | // initParamsKeeper init params keeper and its subspaces
587 | func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
588 | paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
589 |
590 | paramsKeeper.Subspace(authtypes.ModuleName)
591 | paramsKeeper.Subspace(banktypes.ModuleName)
592 | paramsKeeper.Subspace(stakingtypes.ModuleName)
593 | paramsKeeper.Subspace(minttypes.ModuleName)
594 | paramsKeeper.Subspace(distrtypes.ModuleName)
595 | paramsKeeper.Subspace(slashingtypes.ModuleName)
596 | paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
597 | paramsKeeper.Subspace(crisistypes.ModuleName)
598 | paramsKeeper.Subspace(ibctransfertypes.ModuleName)
599 | paramsKeeper.Subspace(ibchost.ModuleName)
600 | // this line is used by starport scaffolding # stargate/app/paramSubspace
601 |
602 | return paramsKeeper
603 | }
604 |
--------------------------------------------------------------------------------
/app/encoding.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/std"
5 | "github.com/tendermint/cns/app/params"
6 | )
7 |
8 | // MakeEncodingConfig creates an EncodingConfig for testing
9 | func MakeEncodingConfig() params.EncodingConfig {
10 | encodingConfig := params.MakeEncodingConfig()
11 | std.RegisterLegacyAminoCodec(encodingConfig.Amino)
12 | std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
13 | ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
14 | ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
15 | return encodingConfig
16 | }
17 |
--------------------------------------------------------------------------------
/app/export.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "encoding/json"
5 | "log"
6 |
7 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
8 |
9 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
10 | sdk "github.com/cosmos/cosmos-sdk/types"
11 | slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
12 | "github.com/cosmos/cosmos-sdk/x/staking"
13 | stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
14 | )
15 |
16 | // ExportAppStateAndValidators exports the state of the application for a genesis
17 | // file.
18 | func (app *App) ExportAppStateAndValidators(
19 | forZeroHeight bool, jailAllowedAddrs []string,
20 | ) (servertypes.ExportedApp, error) {
21 |
22 | // as if they could withdraw from the start of the next block
23 | ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
24 |
25 | // We export at last height + 1, because that's the height at which
26 | // Tendermint will start InitChain.
27 | height := app.LastBlockHeight() + 1
28 | if forZeroHeight {
29 | height = 0
30 | app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs)
31 | }
32 |
33 | genState := app.mm.ExportGenesis(ctx, app.appCodec)
34 | appState, err := json.MarshalIndent(genState, "", " ")
35 | if err != nil {
36 | return servertypes.ExportedApp{}, err
37 | }
38 |
39 | validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
40 | if err != nil {
41 | return servertypes.ExportedApp{}, err
42 | }
43 | return servertypes.ExportedApp{
44 | AppState: appState,
45 | Validators: validators,
46 | Height: height,
47 | ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
48 | }, nil
49 | }
50 |
51 | // prepare for fresh start at zero height
52 | // NOTE zero height genesis is a temporary feature which will be deprecated
53 | // in favour of export at a block height
54 | func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
55 | applyAllowedAddrs := false
56 |
57 | // check if there is a allowed address list
58 | if len(jailAllowedAddrs) > 0 {
59 | applyAllowedAddrs = true
60 | }
61 |
62 | allowedAddrsMap := make(map[string]bool)
63 |
64 | for _, addr := range jailAllowedAddrs {
65 | _, err := sdk.ValAddressFromBech32(addr)
66 | if err != nil {
67 | log.Fatal(err)
68 | }
69 | allowedAddrsMap[addr] = true
70 | }
71 |
72 | /* Just to be safe, assert the invariants on current state. */
73 | app.CrisisKeeper.AssertInvariants(ctx)
74 |
75 | /* Handle fee distribution state. */
76 |
77 | // withdraw all validator commission
78 | app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
79 | _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
80 | if err != nil {
81 | panic(err)
82 | }
83 | return false
84 | })
85 |
86 | // withdraw all delegator rewards
87 | dels := app.StakingKeeper.GetAllDelegations(ctx)
88 | for _, delegation := range dels {
89 | _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
90 | if err != nil {
91 | panic(err)
92 | }
93 | }
94 |
95 | // clear validator slash events
96 | app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
97 |
98 | // clear validator historical rewards
99 | app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
100 |
101 | // set context height to zero
102 | height := ctx.BlockHeight()
103 | ctx = ctx.WithBlockHeight(0)
104 |
105 | // reinitialize all validators
106 | app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
107 | // donate any unwithdrawn outstanding reward fraction tokens to the community pool
108 | scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
109 | feePool := app.DistrKeeper.GetFeePool(ctx)
110 | feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
111 | app.DistrKeeper.SetFeePool(ctx, feePool)
112 |
113 | app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
114 | return false
115 | })
116 |
117 | // reinitialize all delegations
118 | for _, del := range dels {
119 | app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
120 | app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
121 | }
122 |
123 | // reset context height
124 | ctx = ctx.WithBlockHeight(height)
125 |
126 | /* Handle staking state. */
127 |
128 | // iterate through redelegations, reset creation height
129 | app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
130 | for i := range red.Entries {
131 | red.Entries[i].CreationHeight = 0
132 | }
133 | app.StakingKeeper.SetRedelegation(ctx, red)
134 | return false
135 | })
136 |
137 | // iterate through unbonding delegations, reset creation height
138 | app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
139 | for i := range ubd.Entries {
140 | ubd.Entries[i].CreationHeight = 0
141 | }
142 | app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
143 | return false
144 | })
145 |
146 | // Iterate through validators by power descending, reset bond heights, and
147 | // update bond intra-tx counters.
148 | store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
149 | iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
150 | counter := int16(0)
151 |
152 | for ; iter.Valid(); iter.Next() {
153 | addr := sdk.ValAddress(iter.Key()[1:])
154 | validator, found := app.StakingKeeper.GetValidator(ctx, addr)
155 | if !found {
156 | panic("expected validator, not found")
157 | }
158 |
159 | validator.UnbondingHeight = 0
160 | if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
161 | validator.Jailed = true
162 | }
163 |
164 | app.StakingKeeper.SetValidator(ctx, validator)
165 | counter++
166 | }
167 |
168 | iter.Close()
169 |
170 | if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
171 | panic(err)
172 | }
173 |
174 | /* Handle slashing state. */
175 |
176 | // reset start height on signing infos
177 | app.SlashingKeeper.IterateValidatorSigningInfos(
178 | ctx,
179 | func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
180 | info.StartHeight = 0
181 | app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
182 | return false
183 | },
184 | )
185 | }
186 |
--------------------------------------------------------------------------------
/app/genesis.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "encoding/json"
5 |
6 | "github.com/cosmos/cosmos-sdk/codec"
7 | )
8 |
9 | // The genesis state of the blockchain is represented here as a map of raw json
10 | // messages key'd by a identifier string.
11 | // The identifier is used to determine which module genesis information belongs
12 | // to so it may be appropriately routed during init chain.
13 | // Within this application default genesis information is retrieved from
14 | // the ModuleBasicManager which populates json from each BasicModule
15 | // object provided to it during init.
16 | type GenesisState map[string]json.RawMessage
17 |
18 | // NewDefaultGenesisState generates the default state for the application.
19 | func NewDefaultGenesisState(cdc codec.JSONMarshaler) GenesisState {
20 | return ModuleBasics.DefaultGenesis(cdc)
21 | }
22 |
--------------------------------------------------------------------------------
/app/params/encoding.go:
--------------------------------------------------------------------------------
1 | package params
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/client"
5 | "github.com/cosmos/cosmos-sdk/codec"
6 | "github.com/cosmos/cosmos-sdk/codec/types"
7 | )
8 |
9 | // EncodingConfig specifies the concrete encoding types to use for a given app.
10 | // This is provided for compatibility between protobuf and amino implementations.
11 | type EncodingConfig struct {
12 | InterfaceRegistry types.InterfaceRegistry
13 | Marshaler codec.Marshaler
14 | TxConfig client.TxConfig
15 | Amino *codec.LegacyAmino
16 | }
17 |
--------------------------------------------------------------------------------
/app/params/proto.go:
--------------------------------------------------------------------------------
1 | package params
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/codec"
5 | "github.com/cosmos/cosmos-sdk/codec/types"
6 | "github.com/cosmos/cosmos-sdk/x/auth/tx"
7 | )
8 |
9 | // MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
10 | func MakeEncodingConfig() EncodingConfig {
11 | amino := codec.NewLegacyAmino()
12 | interfaceRegistry := types.NewInterfaceRegistry()
13 | marshaler := codec.NewProtoCodec(interfaceRegistry)
14 | txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
15 |
16 | return EncodingConfig{
17 | InterfaceRegistry: interfaceRegistry,
18 | Marshaler: marshaler,
19 | TxConfig: txCfg,
20 | Amino: amino,
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/prefix.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | sdk "github.com/cosmos/cosmos-sdk/types"
5 | )
6 |
7 | const (
8 | AccountAddressPrefix = "cosmos"
9 | )
10 |
11 | var (
12 | AccountPubKeyPrefix = AccountAddressPrefix + "pub"
13 | ValidatorAddressPrefix = AccountAddressPrefix + "valoper"
14 | ValidatorPubKeyPrefix = AccountAddressPrefix + "valoperpub"
15 | ConsNodeAddressPrefix = AccountAddressPrefix + "valcons"
16 | ConsNodePubKeyPrefix = AccountAddressPrefix + "valconspub"
17 | )
18 |
19 | func SetConfig() {
20 | config := sdk.GetConfig()
21 | config.SetBech32PrefixForAccount(AccountAddressPrefix, AccountPubKeyPrefix)
22 | config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix)
23 | config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix)
24 | config.Seal()
25 | }
26 |
--------------------------------------------------------------------------------
/app/test_utils.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | "encoding/json"
5 | "github.com/cosmos/cosmos-sdk/simapp"
6 | abci "github.com/tendermint/tendermint/abci/types"
7 | "github.com/tendermint/tendermint/libs/log"
8 | dbm "github.com/tendermint/tm-db"
9 | )
10 |
11 | func setup(withGenesis bool, invCheckPeriod uint) (*App, GenesisState) {
12 | db := dbm.NewMemDB()
13 | encCdc := MakeEncodingConfig()
14 | newApp := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, simapp.EmptyAppOptions{})
15 | if withGenesis {
16 | return newApp, NewDefaultGenesisState(encCdc.Marshaler)
17 | }
18 | return newApp, GenesisState{}
19 | }
20 |
21 | // Setup initializes a new SimApp. A Nop logger is set in SimApp.
22 | func Setup(isCheckTx bool) *App {
23 | newApp, genesisState := setup(!isCheckTx, 5)
24 | if !isCheckTx {
25 | // init chain must be called to stop deliverState from being nil
26 | stateBytes, err := json.MarshalIndent(genesisState, "", " ")
27 | if err != nil {
28 | panic(err)
29 | }
30 |
31 | // Initialize the chain
32 | newApp.InitChain(
33 | abci.RequestInitChain{
34 | Validators: []abci.ValidatorUpdate{},
35 | ConsensusParams: simapp.DefaultConsensusParams,
36 | AppStateBytes: stateBytes,
37 | },
38 | )
39 | }
40 |
41 | return newApp
42 | }
43 |
--------------------------------------------------------------------------------
/app/types.go:
--------------------------------------------------------------------------------
1 | package app
2 |
3 | import (
4 | abci "github.com/tendermint/tendermint/abci/types"
5 |
6 | "github.com/cosmos/cosmos-sdk/codec"
7 | "github.com/cosmos/cosmos-sdk/server/types"
8 | sdk "github.com/cosmos/cosmos-sdk/types"
9 | )
10 |
11 | // App implements the common methods for a Cosmos SDK-based application
12 | // specific blockchain.
13 | type CosmosApp interface {
14 | // The assigned name of the app.
15 | Name() string
16 |
17 | // The application types codec.
18 | // NOTE: This shoult be sealed before being returned.
19 | LegacyAmino() *codec.LegacyAmino
20 |
21 | // Application updates every begin block.
22 | BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock
23 |
24 | // Application updates every end block.
25 | EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
26 |
27 | // Application update at chain (i.e app) initialization.
28 | InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
29 |
30 | // Loads the app at a given height.
31 | LoadHeight(height int64) error
32 |
33 | // Exports the state of the application for a genesis file.
34 | ExportAppStateAndValidators(
35 | forZeroHeight bool, jailAllowedAddrs []string,
36 | ) (types.ExportedApp, error)
37 |
38 | // All the registered module account addreses.
39 | ModuleAccountAddrs() map[string]bool
40 | }
41 |
--------------------------------------------------------------------------------
/cmd/cnsd/cmd/genaccounts.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "bufio"
5 | "encoding/json"
6 | "errors"
7 | "fmt"
8 |
9 | "github.com/spf13/cobra"
10 |
11 | "github.com/cosmos/cosmos-sdk/client"
12 | "github.com/cosmos/cosmos-sdk/client/flags"
13 | "github.com/cosmos/cosmos-sdk/codec"
14 | "github.com/cosmos/cosmos-sdk/crypto/keyring"
15 | "github.com/cosmos/cosmos-sdk/server"
16 | sdk "github.com/cosmos/cosmos-sdk/types"
17 | authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
18 | authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
19 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
20 | "github.com/cosmos/cosmos-sdk/x/genutil"
21 | genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
22 | )
23 |
24 | const (
25 | flagVestingStart = "vesting-start-time"
26 | flagVestingEnd = "vesting-end-time"
27 | flagVestingAmt = "vesting-amount"
28 | )
29 |
30 | // AddGenesisAccountCmd returns add-genesis-account cobra Command.
31 | func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
32 | cmd := &cobra.Command{
33 | Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
34 | Short: "Add a genesis account to genesis.json",
35 | Long: `Add a genesis account to genesis.json. The provided account must specify
36 | the account address or key name and a list of initial coins. If a key name is given,
37 | the address will be looked up in the local Keybase. The list of initial tokens must
38 | contain valid denominations. Accounts may optionally be supplied with vesting parameters.
39 | `,
40 | Args: cobra.ExactArgs(2),
41 | RunE: func(cmd *cobra.Command, args []string) error {
42 | clientCtx := client.GetClientContextFromCmd(cmd)
43 | depCdc := clientCtx.JSONMarshaler
44 | cdc := depCdc.(codec.Marshaler)
45 |
46 | serverCtx := server.GetServerContextFromCmd(cmd)
47 | config := serverCtx.Config
48 |
49 | config.SetRoot(clientCtx.HomeDir)
50 |
51 | coins, err := sdk.ParseCoinsNormalized(args[1])
52 | if err != nil {
53 | return fmt.Errorf("failed to parse coins: %w", err)
54 | }
55 |
56 | addr, err := sdk.AccAddressFromBech32(args[0])
57 | if err != nil {
58 | inBuf := bufio.NewReader(cmd.InOrStdin())
59 | keyringBackend, err := cmd.Flags().GetString(flags.FlagKeyringBackend)
60 | if err != nil {
61 | return err
62 | }
63 |
64 | // attempt to lookup address from Keybase if no address was provided
65 | kb, err := keyring.New(sdk.KeyringServiceName(), keyringBackend, clientCtx.HomeDir, inBuf)
66 | if err != nil {
67 | return err
68 | }
69 |
70 | info, err := kb.Key(args[0])
71 | if err != nil {
72 | return fmt.Errorf("failed to get address from Keybase: %w", err)
73 | }
74 |
75 | addr = info.GetAddress()
76 | }
77 |
78 | vestingStart, err := cmd.Flags().GetInt64(flagVestingStart)
79 | if err != nil {
80 | return err
81 | }
82 | vestingEnd, err := cmd.Flags().GetInt64(flagVestingEnd)
83 | if err != nil {
84 | return err
85 | }
86 | vestingAmtStr, err := cmd.Flags().GetString(flagVestingAmt)
87 | if err != nil {
88 | return err
89 | }
90 |
91 | vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr)
92 | if err != nil {
93 | return fmt.Errorf("failed to parse vesting amount: %w", err)
94 | }
95 |
96 | // create concrete account type based on input parameters
97 | var genAccount authtypes.GenesisAccount
98 |
99 | balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}
100 | baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0)
101 |
102 | if !vestingAmt.IsZero() {
103 | baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd)
104 |
105 | if (balances.Coins.IsZero() && !baseVestingAccount.OriginalVesting.IsZero()) ||
106 | baseVestingAccount.OriginalVesting.IsAnyGT(balances.Coins) {
107 | return errors.New("vesting amount cannot be greater than total amount")
108 | }
109 |
110 | switch {
111 | case vestingStart != 0 && vestingEnd != 0:
112 | genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)
113 |
114 | case vestingEnd != 0:
115 | genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount)
116 |
117 | default:
118 | return errors.New("invalid vesting parameters; must supply start and end time or end time")
119 | }
120 | } else {
121 | genAccount = baseAccount
122 | }
123 |
124 | if err := genAccount.Validate(); err != nil {
125 | return fmt.Errorf("failed to validate new genesis account: %w", err)
126 | }
127 |
128 | genFile := config.GenesisFile()
129 | appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
130 | if err != nil {
131 | return fmt.Errorf("failed to unmarshal genesis state: %w", err)
132 | }
133 |
134 | authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState)
135 |
136 | accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
137 | if err != nil {
138 | return fmt.Errorf("failed to get accounts from any: %w", err)
139 | }
140 |
141 | if accs.Contains(addr) {
142 | return fmt.Errorf("cannot add account at existing address %s", addr)
143 | }
144 |
145 | // Add the new account to the set of genesis accounts and sanitize the
146 | // accounts afterwards.
147 | accs = append(accs, genAccount)
148 | accs = authtypes.SanitizeGenesisAccounts(accs)
149 |
150 | genAccs, err := authtypes.PackAccounts(accs)
151 | if err != nil {
152 | return fmt.Errorf("failed to convert accounts into any's: %w", err)
153 | }
154 | authGenState.Accounts = genAccs
155 |
156 | authGenStateBz, err := cdc.MarshalJSON(&authGenState)
157 | if err != nil {
158 | return fmt.Errorf("failed to marshal auth genesis state: %w", err)
159 | }
160 |
161 | appState[authtypes.ModuleName] = authGenStateBz
162 |
163 | bankGenState := banktypes.GetGenesisStateFromAppState(depCdc, appState)
164 | bankGenState.Balances = append(bankGenState.Balances, balances)
165 | bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
166 |
167 | bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
168 | if err != nil {
169 | return fmt.Errorf("failed to marshal bank genesis state: %w", err)
170 | }
171 |
172 | appState[banktypes.ModuleName] = bankGenStateBz
173 |
174 | appStateJSON, err := json.Marshal(appState)
175 | if err != nil {
176 | return fmt.Errorf("failed to marshal application genesis state: %w", err)
177 | }
178 |
179 | genDoc.AppState = appStateJSON
180 | return genutil.ExportGenesisFile(genDoc, genFile)
181 | },
182 | }
183 |
184 | cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
185 | cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
186 | cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
187 | cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
188 | cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
189 | flags.AddQueryFlagsToCmd(cmd)
190 |
191 | return cmd
192 | }
193 |
--------------------------------------------------------------------------------
/cmd/cnsd/cmd/root.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "errors"
5 | "io"
6 | "os"
7 | "path/filepath"
8 |
9 | "github.com/cosmos/cosmos-sdk/snapshots"
10 | "github.com/tendermint/cns/app/params"
11 |
12 | "github.com/spf13/cast"
13 | "github.com/spf13/cobra"
14 | "github.com/spf13/pflag"
15 | tmcli "github.com/tendermint/tendermint/libs/cli"
16 | "github.com/tendermint/tendermint/libs/log"
17 | dbm "github.com/tendermint/tm-db"
18 |
19 | "github.com/cosmos/cosmos-sdk/baseapp"
20 | "github.com/cosmos/cosmos-sdk/client"
21 | "github.com/cosmos/cosmos-sdk/client/debug"
22 | "github.com/cosmos/cosmos-sdk/client/flags"
23 | "github.com/cosmos/cosmos-sdk/client/keys"
24 | "github.com/cosmos/cosmos-sdk/client/rpc"
25 | "github.com/cosmos/cosmos-sdk/server"
26 | servertypes "github.com/cosmos/cosmos-sdk/server/types"
27 | "github.com/cosmos/cosmos-sdk/store"
28 | sdk "github.com/cosmos/cosmos-sdk/types"
29 | authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
30 | authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
31 | "github.com/cosmos/cosmos-sdk/x/auth/types"
32 | vestingcli "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli"
33 | banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
34 | "github.com/cosmos/cosmos-sdk/x/crisis"
35 | genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
36 | "github.com/tendermint/cns/app"
37 | // this line is used by starport scaffolding # stargate/root/import
38 | )
39 |
40 | var ChainID string
41 |
42 | // NewRootCmd creates a new root command for simd. It is called once in the
43 | // main function.
44 | func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
45 | // Set config for prefixes
46 | app.SetConfig()
47 |
48 | encodingConfig := app.MakeEncodingConfig()
49 | initClientCtx := client.Context{}.
50 | WithJSONMarshaler(encodingConfig.Marshaler).
51 | WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
52 | WithTxConfig(encodingConfig.TxConfig).
53 | WithLegacyAmino(encodingConfig.Amino).
54 | WithInput(os.Stdin).
55 | WithAccountRetriever(types.AccountRetriever{}).
56 | WithBroadcastMode(flags.BroadcastBlock).
57 | WithHomeDir(app.DefaultNodeHome)
58 |
59 | rootCmd := &cobra.Command{
60 | Use: app.Name + "d",
61 | Short: "Stargate CosmosHub App",
62 | PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
63 | if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
64 | return err
65 | }
66 |
67 | return server.InterceptConfigsPreRunHandler(cmd)
68 | },
69 | }
70 |
71 | initRootCmd(rootCmd, encodingConfig)
72 | overwriteFlagDefaults(rootCmd, map[string]string{
73 | flags.FlagChainID: ChainID,
74 | flags.FlagKeyringBackend: "test",
75 | })
76 |
77 | return rootCmd, encodingConfig
78 | }
79 |
80 | func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
81 | authclient.Codec = encodingConfig.Marshaler
82 |
83 | rootCmd.AddCommand(
84 | genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
85 | genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
86 | genutilcli.MigrateGenesisCmd(),
87 | genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
88 | genutilcli.ValidateGenesisCmd(app.ModuleBasics),
89 | AddGenesisAccountCmd(app.DefaultNodeHome),
90 | tmcli.NewCompletionCmd(rootCmd, true),
91 | debug.Cmd(),
92 | // this line is used by starport scaffolding # stargate/root/commands
93 | )
94 |
95 | a := appCreator{encodingConfig}
96 | server.AddCommands(rootCmd, app.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
97 |
98 | // add keybase, auxiliary RPC, query, and tx child commands
99 | rootCmd.AddCommand(
100 | rpc.StatusCommand(),
101 | queryCommand(),
102 | txCommand(),
103 | keys.Commands(app.DefaultNodeHome),
104 | )
105 | }
106 |
107 | func addModuleInitFlags(startCmd *cobra.Command) {
108 | crisis.AddModuleInitFlags(startCmd)
109 | // this line is used by starport scaffolding # stargate/root/initFlags
110 | }
111 |
112 | func queryCommand() *cobra.Command {
113 | cmd := &cobra.Command{
114 | Use: "query",
115 | Aliases: []string{"q"},
116 | Short: "Querying subcommands",
117 | DisableFlagParsing: true,
118 | SuggestionsMinimumDistance: 2,
119 | RunE: client.ValidateCmd,
120 | }
121 |
122 | cmd.AddCommand(
123 | authcmd.GetAccountCmd(),
124 | rpc.ValidatorCommand(),
125 | rpc.BlockCommand(),
126 | authcmd.QueryTxsByEventsCmd(),
127 | authcmd.QueryTxCmd(),
128 | )
129 |
130 | app.ModuleBasics.AddQueryCommands(cmd)
131 | cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
132 |
133 | return cmd
134 | }
135 |
136 | func txCommand() *cobra.Command {
137 | cmd := &cobra.Command{
138 | Use: "tx",
139 | Short: "Transactions subcommands",
140 | DisableFlagParsing: true,
141 | SuggestionsMinimumDistance: 2,
142 | RunE: client.ValidateCmd,
143 | }
144 |
145 | cmd.AddCommand(
146 | authcmd.GetSignCommand(),
147 | authcmd.GetSignBatchCommand(),
148 | authcmd.GetMultiSignCommand(),
149 | authcmd.GetValidateSignaturesCommand(),
150 | flags.LineBreak,
151 | authcmd.GetBroadcastCommand(),
152 | authcmd.GetEncodeCommand(),
153 | authcmd.GetDecodeCommand(),
154 | flags.LineBreak,
155 | vestingcli.GetTxCmd(),
156 | )
157 |
158 | app.ModuleBasics.AddTxCommands(cmd)
159 | cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
160 |
161 | return cmd
162 | }
163 |
164 | type appCreator struct {
165 | encCfg params.EncodingConfig
166 | }
167 |
168 | // newApp is an AppCreator
169 | func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
170 | var cache sdk.MultiStorePersistentCache
171 |
172 | if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
173 | cache = store.NewCommitKVStoreCacheManager()
174 | }
175 |
176 | skipUpgradeHeights := make(map[int64]bool)
177 | for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
178 | skipUpgradeHeights[int64(h)] = true
179 | }
180 |
181 | pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
182 | if err != nil {
183 | panic(err)
184 | }
185 |
186 | snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
187 | snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
188 | if err != nil {
189 | panic(err)
190 | }
191 | snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
192 | if err != nil {
193 | panic(err)
194 | }
195 |
196 | return app.New(
197 | logger, db, traceStore, true, skipUpgradeHeights,
198 | cast.ToString(appOpts.Get(flags.FlagHome)),
199 | cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
200 | a.encCfg,
201 | // this line is used by starport scaffolding # stargate/root/appArgument
202 | appOpts,
203 | baseapp.SetPruning(pruningOpts),
204 | baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
205 | baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))),
206 | baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
207 | baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
208 | baseapp.SetInterBlockCache(cache),
209 | baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
210 | baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
211 | baseapp.SetSnapshotStore(snapshotStore),
212 | baseapp.SetSnapshotInterval(cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval))),
213 | baseapp.SetSnapshotKeepRecent(cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent))),
214 | )
215 | }
216 |
217 | // appExport creates a new simapp (optionally at a given height)
218 | func (a appCreator) appExport(
219 | logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
220 | appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) {
221 |
222 | var anApp *app.App
223 |
224 | homePath, ok := appOpts.Get(flags.FlagHome).(string)
225 | if !ok || homePath == "" {
226 | return servertypes.ExportedApp{}, errors.New("application home not set")
227 | }
228 |
229 | if height != -1 {
230 | anApp = app.New(
231 | logger,
232 | db,
233 | traceStore,
234 | false,
235 | map[int64]bool{},
236 | homePath,
237 | uint(1),
238 | a.encCfg,
239 | // this line is used by starport scaffolding # stargate/root/exportArgument
240 | appOpts,
241 | )
242 |
243 | if err := anApp.LoadHeight(height); err != nil {
244 | return servertypes.ExportedApp{}, err
245 | }
246 | } else {
247 | anApp = app.New(
248 | logger,
249 | db,
250 | traceStore,
251 | true,
252 | map[int64]bool{},
253 | homePath,
254 | uint(1),
255 | a.encCfg,
256 | // this line is used by starport scaffolding # stargate/root/noHeightExportArgument
257 | appOpts,
258 | )
259 | }
260 |
261 | return anApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
262 | }
263 |
264 | func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
265 | set := func(s *pflag.FlagSet, key, val string) {
266 | if f := s.Lookup(key); f != nil {
267 | f.DefValue = val
268 | if err := f.Value.Set(val); err != nil {
269 | panic(err)
270 | }
271 | }
272 | }
273 | for key, val := range defaults {
274 | set(c.Flags(), key, val)
275 | set(c.PersistentFlags(), key, val)
276 | }
277 | for _, c := range c.Commands() {
278 | overwriteFlagDefaults(c, defaults)
279 | }
280 | }
281 |
--------------------------------------------------------------------------------
/cmd/cnsd/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "os"
5 |
6 | svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
7 | "github.com/tendermint/cns/app"
8 | "github.com/tendermint/cns/cmd/cnsd/cmd"
9 | )
10 |
11 | func main() {
12 | rootCmd, _ := cmd.NewRootCmd()
13 | if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil {
14 | os.Exit(1)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/config.yml:
--------------------------------------------------------------------------------
1 | accounts:
2 | - name: alice
3 | coins: ["1000token", "100000000stake"]
4 | - name: bob
5 | coins: ["500token"]
6 | validator:
7 | name: alice
8 | staked: "100000000stake"
9 |
--------------------------------------------------------------------------------
/docs/proto.md:
--------------------------------------------------------------------------------
1 | # Protocol Documentation
2 |
3 |
4 | ## Table of Contents
5 |
6 | - [cns/cns.proto](#cns/cns.proto)
7 | - [ChainInfo](#tendermint.cns.cns.ChainInfo)
8 | - [VersionInfo](#tendermint.cns.cns.VersionInfo)
9 |
10 | - [cns/query.proto](#cns/query.proto)
11 | - [QueryChainInfoRequest](#tendermint.cns.cns.QueryChainInfoRequest)
12 | - [QueryChainInfoResponse](#tendermint.cns.cns.QueryChainInfoResponse)
13 |
14 | - [Query](#tendermint.cns.cns.Query)
15 |
16 | - [cns/tx.proto](#cns/tx.proto)
17 | - [MsgRegisterChainName](#tendermint.cns.cns.MsgRegisterChainName)
18 | - [MsgRegisterChainNameResponse](#tendermint.cns.cns.MsgRegisterChainNameResponse)
19 | - [MsgUpdateChainInfo](#tendermint.cns.cns.MsgUpdateChainInfo)
20 | - [MsgUpdateChainInfoResponse](#tendermint.cns.cns.MsgUpdateChainInfoResponse)
21 |
22 | - [Msg](#tendermint.cns.cns.Msg)
23 |
24 | - [cns/genesis.proto](#cns/genesis.proto)
25 | - [GenesisState](#tendermint.cns.cns.GenesisState)
26 |
27 | - [Scalar Value Types](#scalar-value-types)
28 |
29 |
30 |
31 |
32 |
Top
33 |
34 | ## cns/cns.proto
35 |
36 |
37 |
38 |
39 |
40 | ### ChainInfo
41 | TODO(sahith): Add json and yaml flags
42 |
43 |
44 | | Field | Type | Label | Description |
45 | | ----- | ---- | ----- | ----------- |
46 | | chain_name | [string](#string) | | |
47 | | expiration | [int64](#int64) | | |
48 | | owner | [string](#string) | | |
49 | | canonical_ibc_client | [string](#string) | | |
50 | | seed | [string](#string) | repeated | |
51 | | source_code_url | [string](#string) | | |
52 | | version | [VersionInfo](#tendermint.cns.cns.VersionInfo) | | |
53 | | fee | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | ### VersionInfo
63 |
64 |
65 |
66 | | Field | Type | Label | Description |
67 | | ----- | ---- | ----- | ----------- |
68 | | version | [int64](#int64) | | |
69 | | source_commit_hash | [string](#string) | | |
70 | | genesis_hash | [string](#string) | | |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Top
88 |
89 | ## cns/query.proto
90 |
91 |
92 |
93 |
94 |
95 | ### QueryChainInfoRequest
96 |
97 |
98 |
99 | | Field | Type | Label | Description |
100 | | ----- | ---- | ----- | ----------- |
101 | | chain_name | [string](#string) | | |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 | ### QueryChainInfoResponse
111 |
112 |
113 |
114 | | Field | Type | Label | Description |
115 | | ----- | ---- | ----- | ----------- |
116 | | info | [ChainInfo](#tendermint.cns.cns.ChainInfo) | | |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | ### Query
132 | Query defines the gRPC querier service.
133 |
134 | | Method Name | Request Type | Response Type | Description |
135 | | ----------- | ------------ | ------------- | ------------|
136 | | QueryChainInfo | [QueryChainInfoRequest](#tendermint.cns.cns.QueryChainInfoRequest) | [QueryChainInfoResponse](#tendermint.cns.cns.QueryChainInfoResponse) | |
137 |
138 |
139 |
140 |
141 |
142 |
143 | Top
144 |
145 | ## cns/tx.proto
146 |
147 |
148 |
149 |
150 |
151 | ### MsgRegisterChainName
152 |
153 |
154 |
155 | | Field | Type | Label | Description |
156 | | ----- | ---- | ----- | ----------- |
157 | | chain_name | [string](#string) | | |
158 | | owner | [string](#string) | | |
159 | | seed | [string](#string) | repeated | |
160 | | source_code_url | [string](#string) | | |
161 | | canonical_ibc_client | [string](#string) | | |
162 | | version | [VersionInfo](#tendermint.cns.cns.VersionInfo) | | |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 | ### MsgRegisterChainNameResponse
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 | ### MsgUpdateChainInfo
182 |
183 |
184 |
185 | | Field | Type | Label | Description |
186 | | ----- | ---- | ----- | ----------- |
187 | | chain_name | [string](#string) | | |
188 | | owner | [string](#string) | | |
189 | | seed | [string](#string) | repeated | |
190 | | source_code_url | [string](#string) | | |
191 | | canonical_ibc_client | [string](#string) | | |
192 | | version | [VersionInfo](#tendermint.cns.cns.VersionInfo) | | |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | ### MsgUpdateChainInfoResponse
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 | ### Msg
218 |
219 |
220 | | Method Name | Request Type | Response Type | Description |
221 | | ----------- | ------------ | ------------- | ------------|
222 | | RegisterChainName | [MsgRegisterChainName](#tendermint.cns.cns.MsgRegisterChainName) | [MsgRegisterChainNameResponse](#tendermint.cns.cns.MsgRegisterChainNameResponse) | |
223 | | UpdateChainInfo | [MsgUpdateChainInfo](#tendermint.cns.cns.MsgUpdateChainInfo) | [MsgUpdateChainInfoResponse](#tendermint.cns.cns.MsgUpdateChainInfoResponse) | |
224 |
225 |
226 |
227 |
228 |
229 |
230 | Top
231 |
232 | ## cns/genesis.proto
233 |
234 |
235 |
236 |
237 |
238 | ### GenesisState
239 | GenesisState defines the capability module's genesis state.
240 |
241 |
242 | | Field | Type | Label | Description |
243 | | ----- | ---- | ----- | ----------- |
244 | | fee | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
245 | | infos | [ChainInfo](#tendermint.cns.cns.ChainInfo) | repeated | |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 | ## Scalar Value Types
262 |
263 | | .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
264 | | ----------- | ----- | --- | ---- | ------ | -- | -- | --- | ---- |
265 | | double | | double | double | float | float64 | double | float | Float |
266 | | float | | float | float | float | float32 | float | float | Float |
267 | | int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
268 | | int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long | int/long | int64 | long | integer/string | Bignum |
269 | | uint32 | Uses variable-length encoding. | uint32 | int | int/long | uint32 | uint | integer | Bignum or Fixnum (as required) |
270 | | uint64 | Uses variable-length encoding. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum or Fixnum (as required) |
271 | | sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
272 | | sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long | int64 | long | integer/string | Bignum |
273 | | fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 2^28. | uint32 | int | int | uint32 | uint | integer | Bignum or Fixnum (as required) |
274 | | fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum |
275 | | sfixed32 | Always four bytes. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
276 | | sfixed64 | Always eight bytes. | int64 | long | int/long | int64 | long | integer/string | Bignum |
277 | | bool | | bool | boolean | boolean | bool | bool | boolean | TrueClass/FalseClass |
278 | | string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode | string | string | string | String (UTF-8) |
279 | | bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str | []byte | ByteString | string | String (ASCII-8BIT) |
280 |
281 |
--------------------------------------------------------------------------------
/docs/spec.md:
--------------------------------------------------------------------------------
1 | # Chain Name Service Draft
2 |
3 | The CNS module is a new Cosmos SDK module that allows Cosmos addresses to purchase, sell, and administer chain names. The development of CNS is planned to be divided into 3 separate phases in order to ensure there's enough time for existing chains and prevent front running.
4 |
5 | ## Phase 0
6 |
7 | The goal of phase 0 is to launch a directory of chain names for Cosmos SDK chains that currently exist. For expediency, we plan on setting up a multisig that initially has the authority to modify information about blockchains on the CNS. After all existing major blockchains are recorded on the CNS and phase 0 is over the multisig will hand off these chain names one by one to trusted parties from the various sovereign Cosmos chain communities.
8 |
9 | ## Phase 1
10 |
11 | The goal of phase 1 is to allow users of Cosmos Hub to purchase chain names and assign them to the blockchain networks they have affiliation with. Proceeds from the sale of chain names will go to the community pool. For example, a newly launched chain using its governance mechanism can elect an account that the chain will trust to register a chain name on CNS.
12 |
13 | ## Phase 2
14 |
15 | The goal of phase 2 is name transfers. If by the time CNS reaches phase 2 an NFT module becomes available on the Hub, chain names will conform to the NFT standard. Otherwise, CNS will include functionality to transfer ownership of names through a proposal system where a “buyer” sends a proposal with an atom value (bid) and the current chain name owner can either accept or reject the proposal. If a proposal is accepted, the bid value is transferred to the seller and the chain name ownership is transferred to the buyer.
16 |
17 | # State
18 |
19 | Goal 1 (end-users): let users determine whether the tokens they got through IBC came from a chain they claim to come from. This will be possible through the mapping of chain names to IBC clients.
20 |
21 | Goal 2 (validators): let nodes (validators, full-nodes, etc.) join networks.
22 |
23 | ```go
24 | type ChainInfo struct {
25 | ChainName string
26 | Owner OwnerProps
27 | Expiration int64
28 | Metadata [][2]string
29 |
30 | // Goal 1
31 | CanonicalIBCClientId string
32 |
33 | // Goal 2
34 | Seed []seed
35 | SourceCodeURL string //how likely is the possibility of code url changing
36 | Version VersionInfo
37 | }
38 | ```
39 |
40 | ```go
41 | type VersionInfo struct {
42 | Version int64
43 | SourceCommitHash string
44 | GenesisHash string
45 | }
46 | ```
47 |
48 | ```go
49 | type OwnerProps interface {
50 | String() string
51 | }
52 | ```
53 |
54 | ```go
55 | type Claim struct {
56 | ID int64
57 | ChainName string
58 | Owner OwnerProps
59 | Proof string
60 | }
61 | ```
62 |
63 | # Messages
64 |
65 | ### Phase - 0
66 |
67 | Ideally, we would want the chains to approve via a gov proposal the owner (likely address) of the chain name. This makes it easy for approvers and also prevent collision for the same namespace.
68 |
69 | ### MsgClaimChainName
70 |
71 | Claim is about mapping chain name to owner. Name, owner, IBC client, meta.
72 |
73 | ```go
74 | type MsgClaimChainName struct {
75 | ChainName string
76 | CanonicalIBCClientId string
77 | Proof string
78 | Owner OwnerProps
79 | }
80 | ```
81 |
82 | ### MsgApproveClaim
83 |
84 | ```go
85 | type MsgApproveClaim struct {
86 | ClaimID int32
87 | Approver sdk.AccAddress
88 | }
89 | ```
90 |
91 | ### MsgRejectClaim
92 |
93 | ```go
94 | type MsgRejectClaim struct{
95 | ClaimID int32
96 | Approver sdk.AccAddress
97 | }
98 | ```
99 |
100 | ### MsgUpdateInfo
101 |
102 | ```go
103 | type MsgUpdateInfo struct{
104 | ChainName string
105 | Owner OwnerProps
106 | Seed []seed
107 | CanonicalIBCClientId string
108 | Version VersionInfo
109 | Metadata [][2]string
110 | }
111 | ```
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/tendermint/cns
2 |
3 | go 1.15
4 |
5 | require (
6 | github.com/cosmos/cosmos-sdk v0.41.0
7 | github.com/gogo/protobuf v1.3.3
8 | github.com/golang/protobuf v1.4.3
9 | github.com/gorilla/mux v1.8.0
10 | github.com/grpc-ecosystem/grpc-gateway v1.16.0
11 | github.com/spf13/cast v1.3.1
12 | github.com/spf13/cobra v1.1.1
13 | github.com/spf13/pflag v1.0.5
14 | github.com/stretchr/testify v1.7.0
15 | github.com/tendermint/tendermint v0.34.3
16 | github.com/tendermint/tm-db v0.6.3
17 | google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f
18 | google.golang.org/grpc v1.35.0
19 | )
20 |
21 | replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
22 |
--------------------------------------------------------------------------------
/proto/cns/cns.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.cns.cns;
3 |
4 | import "cosmos/base/v1beta1/coin.proto";
5 | import "gogoproto/gogo.proto";
6 |
7 | option go_package = "github.com/tendermint/cns/x/cns/types";
8 |
9 | //TODO(sahith): Add json and yaml flags
10 | message ChainInfo{
11 | option (gogoproto.equal) = true;
12 | option (gogoproto.goproto_stringer) = true;
13 |
14 | string chain_name = 1;
15 | int64 expiration = 2;
16 | string owner = 3;
17 |
18 | string canonical_ibc_client = 4;
19 |
20 | repeated string seed = 5;
21 | string source_code_url = 6;
22 | VersionInfo version = 7;
23 |
24 | repeated cosmos.base.v1beta1.Coin fee = 8 [(gogoproto.nullable) = false];
25 | }
26 |
27 | message VersionInfo{
28 | option (gogoproto.equal) = true;
29 |
30 | int64 version = 1;
31 | string source_commit_hash = 2;
32 | string genesis_hash = 3;
33 | }
34 |
--------------------------------------------------------------------------------
/proto/cns/genesis.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.cns.cns;
3 |
4 | import "cosmos/base/v1beta1/coin.proto";
5 | import "cns/cns.proto";
6 | import "gogoproto/gogo.proto";
7 |
8 | option go_package = "github.com/tendermint/cns/x/cns/types";
9 |
10 | // GenesisState defines the capability module's genesis state.
11 | message GenesisState {
12 |
13 | repeated cosmos.base.v1beta1.Coin fee = 1 [(gogoproto.nullable) = false];
14 |
15 | repeated ChainInfo infos = 2[(gogoproto.nullable) = false];
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/proto/cns/query.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.cns.cns;
3 |
4 | import "google/api/annotations.proto";
5 | import "cosmos/base/query/v1beta1/pagination.proto";
6 | import "gogoproto/gogo.proto";
7 | import "cns/cns.proto";
8 |
9 | option go_package = "github.com/tendermint/cns/x/cns/types";
10 |
11 | // Query defines the gRPC querier service.
12 | service Query {
13 | rpc QueryChainInfo(QueryChainInfoRequest) returns (QueryChainInfoResponse) {
14 | option (google.api.http).get = "/cns/cns/info/{chain_name}";
15 | }
16 | }
17 |
18 | message QueryChainInfoRequest{
19 | option (gogoproto.equal) = true;
20 | option (gogoproto.goproto_stringer) = true;
21 |
22 | string chain_name = 1;
23 | }
24 |
25 | message QueryChainInfoResponse{
26 | option (gogoproto.equal) = true;
27 | option (gogoproto.goproto_stringer) = true;
28 |
29 | ChainInfo info = 1[(gogoproto.nullable) = false];
30 | }
--------------------------------------------------------------------------------
/proto/cns/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.cns.cns;
3 |
4 | import "gogoproto/gogo.proto";
5 | import "cns/cns.proto";
6 |
7 | option go_package = "github.com/tendermint/cns/x/cns/types";
8 |
9 | service Msg {
10 | rpc RegisterChainName(MsgRegisterChainName) returns (MsgRegisterChainNameResponse);
11 |
12 | rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse);
13 | }
14 |
15 | message MsgRegisterChainName{
16 | string chain_name = 1;
17 | string owner = 2;
18 | repeated string seed = 3;
19 | string source_code_url = 4;
20 | string canonical_ibc_client = 5;
21 | VersionInfo version = 6;
22 | }
23 |
24 | message MsgRegisterChainNameResponse{ }
25 |
26 | message MsgUpdateChainInfo{
27 | string chain_name = 1;
28 | string owner = 2;
29 | repeated string seed = 3;
30 | string source_code_url = 4;
31 | string canonical_ibc_client = 5;
32 | VersionInfo version = 6;
33 | }
34 |
35 | message MsgUpdateChainInfoResponse{ }
--------------------------------------------------------------------------------
/scripts/protogen.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -eo pipefail
4 |
5 | COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)}
6 |
7 | proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
8 | for dir in $proto_dirs; do
9 | protoc \
10 | -I "proto" \
11 | -I="$COSMOS_SDK_DIR/third_party/proto" \
12 | -I="$COSMOS_SDK_DIR/proto" \
13 | --gocosmos_out=plugins=interfacetype+grpc,\
14 | Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
15 | --doc_out=./docs \
16 | --doc_opt=markdown,proto.md \
17 | $(find "${dir}" -maxdepth 1 -name '*.proto')
18 |
19 | # command to generate gRPC gateway (*.pb.gw.go in respective modules) files
20 | protoc \
21 | -I "proto" \
22 | -I="$COSMOS_SDK_DIR/third_party/proto" \
23 | -I="$COSMOS_SDK_DIR/proto" \
24 | --grpc-gateway_out=logtostderr=true:. \
25 | $(find "${dir}" -maxdepth 1 -name '*.proto')
26 | done
27 |
28 | # move proto files to the right places
29 | cp -r github.com/tendermint/cns/* ./
30 | rm -rf github.com
--------------------------------------------------------------------------------
/x/cns/client/cli/flags.go:
--------------------------------------------------------------------------------
1 | package cli
2 |
3 | import "github.com/spf13/cobra"
4 |
5 | const (
6 | FlagCanonicalIbcClient = "canonical-ibc-client"
7 | FlagSourceCodeUrl = "code-url"
8 | FlagVersion = "version"
9 | FlagSeeds = "seeds"
10 | FlagGenesisHash = "genesis-hash"
11 | FlagCommitHash = "commit-hash"
12 | )
13 |
14 | func AddCnsTxFlags(cmd *cobra.Command) {
15 | cmd.Flags().String(FlagCanonicalIbcClient, "", "Canonical ibc client")
16 | cmd.Flags().String(FlagSourceCodeUrl, "", "Link to source code url")
17 | cmd.Flags().Int64(FlagVersion, 0, "Current version of the chain")
18 | cmd.Flags().String(FlagCommitHash, "", "Commit hash of source code")
19 | cmd.Flags().String(FlagGenesisHash, "", "Hash of genesis file")
20 | cmd.Flags().String(FlagSeeds, "", "Comma seperated seeds of the chain")
21 | }
22 |
--------------------------------------------------------------------------------
/x/cns/client/cli/query.go:
--------------------------------------------------------------------------------
1 | package cli
2 |
3 | import (
4 | "fmt"
5 | "github.com/cosmos/cosmos-sdk/client/flags"
6 | "github.com/cosmos/cosmos-sdk/version"
7 | "strings"
8 |
9 | // "strings"
10 |
11 | "github.com/spf13/cobra"
12 |
13 | "github.com/cosmos/cosmos-sdk/client"
14 | // "github.com/cosmos/cosmos-sdk/client/flags"
15 | // sdk "github.com/cosmos/cosmos-sdk/types"
16 |
17 | "github.com/tendermint/cns/x/cns/types"
18 | )
19 |
20 | // GetQueryCmd returns the cli query commands for this module
21 | func GetQueryCmd(queryRoute string) *cobra.Command {
22 | // Group cns queries under a subcommand
23 | cmd := &cobra.Command{
24 | Use: types.ModuleName,
25 | Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
26 | DisableFlagParsing: true,
27 | SuggestionsMinimumDistance: 2,
28 | RunE: client.ValidateCmd,
29 | }
30 |
31 | cmd.AddCommand(GetCmdQueryChainInfo())
32 |
33 | return cmd
34 | }
35 |
36 | // GetCmdQueryChainInfo implements the chaininfo query command.
37 | func GetCmdQueryChainInfo() *cobra.Command {
38 | cmd := &cobra.Command{
39 | Use: "chain-info [chain-name]",
40 | Short: "Query chain info",
41 | Long: strings.TrimSpace(
42 | fmt.Sprintf(`Query information of a chain name.
43 |
44 | Example:
45 | $ %s query cns chain-info
46 | `,
47 | version.AppName,
48 | ),
49 | ),
50 | Args: cobra.ExactArgs(1),
51 | RunE: func(cmd *cobra.Command, args []string) error {
52 | clientCtx, err := client.GetClientQueryContext(cmd)
53 | if err != nil {
54 | return err
55 | }
56 | queryClient := types.NewQueryClient(clientCtx)
57 |
58 | params := &types.QueryChainInfoRequest{ChainName: args[0]}
59 | res, err := queryClient.QueryChainInfo(cmd.Context(), params)
60 | if err != nil {
61 | return err
62 | }
63 |
64 | return clientCtx.PrintProto(&res.Info)
65 | },
66 | }
67 |
68 | flags.AddQueryFlagsToCmd(cmd)
69 |
70 | return cmd
71 | }
72 |
--------------------------------------------------------------------------------
/x/cns/client/cli/tx.go:
--------------------------------------------------------------------------------
1 | package cli
2 |
3 | import (
4 | "fmt"
5 | "github.com/cosmos/cosmos-sdk/client/flags"
6 | "github.com/cosmos/cosmos-sdk/client/tx"
7 | "github.com/spf13/cobra"
8 |
9 | "github.com/cosmos/cosmos-sdk/client"
10 | // "github.com/cosmos/cosmos-sdk/client/flags"
11 | "github.com/tendermint/cns/x/cns/types"
12 | )
13 |
14 | // GetTxCmd returns the transaction commands for this module
15 | func GetTxCmd() *cobra.Command {
16 | cmd := &cobra.Command{
17 | Use: types.ModuleName,
18 | Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
19 | DisableFlagParsing: true,
20 | SuggestionsMinimumDistance: 2,
21 | RunE: client.ValidateCmd,
22 | }
23 |
24 | cmd.AddCommand(RegisterChainNameCmd())
25 | cmd.AddCommand(UpdateChainInfoCmd())
26 | return cmd
27 | }
28 |
29 | func RegisterChainNameCmd() *cobra.Command {
30 | cmd := &cobra.Command{
31 | Use: "register",
32 | Args: cobra.ExactArgs(1),
33 | Short: "register chain name",
34 | Long: `register chain name :
35 |
36 | $ tx cns register flags --from owner
37 | `,
38 | RunE: func(cmd *cobra.Command, args []string) error {
39 | clientCtx, err := client.GetClientTxContext(cmd)
40 | if err != nil {
41 | return err
42 | }
43 |
44 | ibcClient, _ := cmd.Flags().GetString(FlagCanonicalIbcClient)
45 | sourceCodeUrl, _ := cmd.Flags().GetString(FlagSourceCodeUrl)
46 | version, _ := cmd.Flags().GetInt64(FlagVersion)
47 | commitHash, _ := cmd.Flags().GetString(FlagCommitHash)
48 | genesisHash, _ := cmd.Flags().GetString(FlagGenesisHash)
49 | seeds, _ := cmd.Flags().GetString(FlagSeeds)
50 | owner := clientCtx.GetFromAddress()
51 |
52 | msg := types.NewMsgRegisterChainName(args[0], owner.String(), seeds, sourceCodeUrl,
53 | ibcClient, commitHash, genesisHash, version)
54 |
55 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
56 | },
57 | }
58 |
59 | flags.AddTxFlagsToCmd(cmd)
60 | AddCnsTxFlags(cmd)
61 | return cmd
62 | }
63 |
64 | func UpdateChainInfoCmd() *cobra.Command {
65 | cmd := &cobra.Command{
66 | Use: "update",
67 | Args: cobra.ExactArgs(1),
68 | Short: "update chain info",
69 | Long: `update chain info :
70 |
71 | $ tx cns update flags --from owner
72 | `,
73 | RunE: func(cmd *cobra.Command, args []string) error {
74 | clientCtx, err := client.GetClientTxContext(cmd)
75 | if err != nil {
76 | return err
77 | }
78 |
79 | ibcClient, _ := cmd.Flags().GetString(FlagCanonicalIbcClient)
80 | sourceCodeUrl, _ := cmd.Flags().GetString(FlagSourceCodeUrl)
81 | version, _ := cmd.Flags().GetInt64(FlagVersion)
82 | commitHash, _ := cmd.Flags().GetString(FlagCommitHash)
83 | genesisHash, _ := cmd.Flags().GetString(FlagGenesisHash)
84 | seeds, _ := cmd.Flags().GetString(FlagSeeds)
85 | owner := clientCtx.GetFromAddress()
86 |
87 | msg := types.NewMsgUpdateChainInfo(args[0], owner.String(), seeds, sourceCodeUrl,
88 | ibcClient, commitHash, genesisHash, version)
89 |
90 | return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
91 | },
92 | }
93 |
94 | flags.AddTxFlagsToCmd(cmd)
95 | AddCnsTxFlags(cmd)
96 |
97 | return cmd
98 | }
99 |
--------------------------------------------------------------------------------
/x/cns/client/rest/rest.go:
--------------------------------------------------------------------------------
1 | package rest
2 |
3 | import (
4 | "github.com/gorilla/mux"
5 |
6 | "github.com/cosmos/cosmos-sdk/client"
7 | // this line is used by starport scaffolding # 1
8 | )
9 |
10 | const (
11 | MethodGet = "GET"
12 | )
13 |
14 | // RegisterRoutes registers cns-related REST handlers to a router
15 | func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
16 | // this line is used by starport scaffolding # 2
17 | }
18 |
--------------------------------------------------------------------------------
/x/cns/genesis.go:
--------------------------------------------------------------------------------
1 | package cns
2 |
3 | import (
4 | sdk "github.com/cosmos/cosmos-sdk/types"
5 | "github.com/tendermint/cns/x/cns/keeper"
6 | "github.com/tendermint/cns/x/cns/types"
7 | )
8 |
9 | // InitGenesis initializes the capability module's state from a provided genesis
10 | // state.
11 | func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
12 | //TODO: Use params to set fee and accepted denoms
13 | for _, info := range genState.Infos {
14 | err := k.SetChainInfo(ctx, info)
15 | if err != nil {
16 | panic(err)
17 | }
18 | }
19 | }
20 |
21 | // ExportGenesis returns the capability module's exported genesis.
22 | func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
23 | var infos []types.ChainInfo
24 | k.IterateAllInfos(ctx, func(info types.ChainInfo) bool {
25 | infos = append(infos, info)
26 | return false
27 | })
28 |
29 | return &types.GenesisState{
30 | Fee: sdk.NewCoins(types.DefaultFee(types.DefaultDenom)),
31 | Infos: infos,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/x/cns/handler.go:
--------------------------------------------------------------------------------
1 | package cns
2 |
3 | import (
4 | "fmt"
5 |
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8 | "github.com/tendermint/cns/x/cns/keeper"
9 | "github.com/tendermint/cns/x/cns/types"
10 | )
11 |
12 | // NewHandler ...
13 | func NewHandler(k keeper.Keeper) sdk.Handler {
14 | return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
15 | msgServer := keeper.NewMsgServerImpl(k)
16 | ctx = ctx.WithEventManager(sdk.NewEventManager())
17 |
18 | switch msg := msg.(type) {
19 | case *types.MsgRegisterChainName:
20 | res, err := msgServer.RegisterChainName(sdk.WrapSDKContext(ctx), msg)
21 | return sdk.WrapServiceResult(ctx, res, err)
22 | case *types.MsgUpdateChainInfo:
23 | res, err := msgServer.UpdateChainInfo(sdk.WrapSDKContext(ctx), msg)
24 | return sdk.WrapServiceResult(ctx, res, err)
25 | default:
26 | errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
27 | return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/x/cns/keeper/grpc_query.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | "context"
5 | sdk "github.com/cosmos/cosmos-sdk/types"
6 | "github.com/tendermint/cns/x/cns/types"
7 | "google.golang.org/grpc/codes"
8 | "google.golang.org/grpc/status"
9 | )
10 |
11 | var _ types.QueryServer = Keeper{}
12 |
13 | func (k Keeper) QueryChainInfo(c context.Context, req *types.QueryChainInfoRequest) (*types.QueryChainInfoResponse, error) {
14 | if req == nil {
15 | return nil, status.Errorf(codes.InvalidArgument, "empty request")
16 | }
17 |
18 | if req.ChainName == "" {
19 | return nil, status.Errorf(codes.InvalidArgument, "empty chain name")
20 | }
21 | ctx := sdk.UnwrapSDKContext(c)
22 |
23 | info := k.GetChainInfoFromName(ctx, req.ChainName)
24 |
25 | return &types.QueryChainInfoResponse{Info: info}, nil
26 | }
27 |
28 | //TODO(sahith) Add query for all chain infos
29 |
--------------------------------------------------------------------------------
/x/cns/keeper/grpc_query_test.go:
--------------------------------------------------------------------------------
1 | package keeper_test
2 |
--------------------------------------------------------------------------------
/x/cns/keeper/keeper.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | "fmt"
5 | "github.com/tendermint/tendermint/libs/log"
6 |
7 | "github.com/cosmos/cosmos-sdk/codec"
8 | sdk "github.com/cosmos/cosmos-sdk/types"
9 | "github.com/tendermint/cns/x/cns/types"
10 | )
11 |
12 | type (
13 | Keeper struct {
14 | cdc codec.Marshaler
15 | storeKey sdk.StoreKey
16 | memKey sdk.StoreKey
17 |
18 | distrKeeper types.DistributionKeeper
19 | }
20 | )
21 |
22 | func NewKeeper(cdc codec.Marshaler, storeKey, memKey sdk.StoreKey, distrKeeper types.DistributionKeeper) *Keeper {
23 | return &Keeper{
24 | cdc: cdc,
25 | storeKey: storeKey,
26 | memKey: memKey,
27 | distrKeeper: distrKeeper,
28 | }
29 | }
30 |
31 | func (k Keeper) Logger(ctx sdk.Context) log.Logger {
32 | return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
33 | }
34 |
35 | func (k Keeper) Register(ctx sdk.Context, cInfo types.ChainInfo) error {
36 | err := cInfo.ValidateBasic()
37 | if err != nil {
38 | return err
39 | }
40 |
41 | info := k.GetChainInfoFromName(ctx, cInfo.ChainName)
42 | if !info.Equal(types.ChainInfo{}) {
43 | return types.ErrChainAlreadyExists
44 | }
45 | ownerAddr, err := sdk.AccAddressFromBech32(cInfo.Owner)
46 | if err != nil {
47 | return err
48 | }
49 |
50 | err = k.distrKeeper.FundCommunityPool(ctx, sdk.NewCoins(types.DefaultFee(types.DefaultDenom)), ownerAddr)
51 | if err != nil {
52 | return err
53 | }
54 |
55 | err = k.SetChainInfo(ctx, cInfo)
56 | if err != nil {
57 | return err
58 | }
59 |
60 | return nil
61 | }
62 |
63 | func (k Keeper) Update(ctx sdk.Context, cInfo types.ChainInfo) error {
64 | storeInfo, err := k.GetChainInfo(ctx, cInfo.ChainName, cInfo.Owner)
65 | if err != nil {
66 | return err
67 | }
68 |
69 | err = cInfo.ValidateBasic()
70 | if err != nil {
71 | return err
72 | }
73 |
74 | storeInfo.Update(cInfo)
75 |
76 | return k.SetChainInfo(ctx, storeInfo)
77 | }
78 |
79 | func (k Keeper) GetChainInfo(ctx sdk.Context, cName, owner string) (types.ChainInfo, error) {
80 | store := ctx.KVStore(k.storeKey)
81 |
82 | bz := store.Get(types.GetStoreKey(cName, owner))
83 | if bz == nil {
84 | return types.ChainInfo{}, fmt.Errorf("chain info not found for name %s", cName)
85 | }
86 |
87 | var cInfo types.ChainInfo
88 | err := k.cdc.UnmarshalBinaryBare(bz, &cInfo)
89 | if err != nil {
90 | return types.ChainInfo{}, err
91 | }
92 |
93 | return cInfo, err
94 | }
95 |
96 | func (k Keeper) SetChainInfo(ctx sdk.Context, info types.ChainInfo) error {
97 | store := ctx.KVStore(k.storeKey)
98 |
99 | bytes, err := k.cdc.MarshalBinaryBare(&info)
100 | if err != nil {
101 | return err
102 | }
103 |
104 | store.Set(types.GetStoreKey(info.ChainName, info.Owner), bytes)
105 | return nil
106 | }
107 |
108 | func (k Keeper) GetChainInfoFromName(ctx sdk.Context, name string) types.ChainInfo {
109 | store := ctx.KVStore(k.storeKey)
110 |
111 | iterator := sdk.KVStorePrefixIterator(store, append(types.CnsKey, []byte(name)...))
112 | defer iterator.Close()
113 |
114 | var info types.ChainInfo
115 | for ; iterator.Valid(); iterator.Next() {
116 | k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &info)
117 | }
118 |
119 | return info
120 | }
121 |
122 | func (k Keeper) IterateAllInfos(ctx sdk.Context, cb func(info types.ChainInfo) bool) {
123 | store := ctx.KVStore(k.storeKey)
124 |
125 | iterator := store.Iterator(nil, nil)
126 | defer iterator.Close()
127 |
128 | for ; iterator.Valid(); iterator.Next() {
129 | var info types.ChainInfo
130 | k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &info)
131 |
132 | if cb(info) {
133 | break
134 | }
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/x/cns/keeper/keeper_test.go:
--------------------------------------------------------------------------------
1 | package keeper_test
2 |
3 | import (
4 | "fmt"
5 | "github.com/cosmos/cosmos-sdk/baseapp"
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | "github.com/stretchr/testify/suite"
8 | "github.com/tendermint/cns/app"
9 | "github.com/tendermint/cns/x/cns/types"
10 | tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
11 | "testing"
12 | )
13 |
14 | type TestSuite struct {
15 | suite.Suite
16 | app *app.App
17 | ctx sdk.Context
18 | queryClient types.QueryClient
19 | cInfo types.ChainInfo
20 | }
21 |
22 | func (s *TestSuite) SetupTest() {
23 | app := app.Setup(false)
24 | ctx := app.BaseApp.NewContext(false, tmproto.Header{})
25 | queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
26 | types.RegisterQueryServer(queryHelper, app.CNSkeeper)
27 | queryClient := types.NewQueryClient(queryHelper)
28 | addr := "cosmos1wrx0x9m9ykdhw9sg04v7uljme53wuj03cfqce6"
29 | ownerAddr, err := sdk.AccAddressFromBech32(addr)
30 | s.Require().NoError(err)
31 | s.Require().NoError(app.BankKeeper.SetBalances(ctx, ownerAddr,
32 | sdk.NewCoins(sdk.NewInt64Coin("stake", 100000000))))
33 | s.cInfo = types.ChainInfo{
34 | ChainName: "test",
35 | Expiration: 0,
36 | Owner: addr,
37 | CanonicalIbcClient: "test",
38 | Seed: []string{"xyz@abc:1"},
39 | SourceCodeUrl: "github.com/tendermint/cns",
40 | Version: &types.VersionInfo{
41 | Version: 1,
42 | SourceCommitHash: "d29ef87107420fe2e5443f7436da2ff69ce3a5f8",
43 | GenesisHash: "d29ef87107420fe2e5443f7436da2ff69ce3a5f8",
44 | },
45 | }
46 | // register test info
47 | err = app.CNSkeeper.Register(ctx, s.cInfo)
48 | s.Require().NoError(err)
49 | s.ctx, s.app, s.queryClient = ctx, app, queryClient
50 | }
51 | func (s *TestSuite) TestKeeper() {
52 | k := s.app.CNSkeeper
53 | addr := "cosmos1wrx0x9m9ykdhw9sg04v7uljme53wuj03cfqce6"
54 | testCases := []struct {
55 | msg string
56 | cInfo types.ChainInfo
57 | register bool
58 | expPass bool
59 | }{
60 | {
61 | msg: "fetch valid chain info",
62 | cInfo: types.ChainInfo{
63 | ChainName: "test",
64 | Owner: addr,
65 | },
66 | expPass: true,
67 | },
68 | {
69 | msg: "Fetch random chain name",
70 | cInfo: types.ChainInfo{
71 | ChainName: "random",
72 | },
73 | expPass: false,
74 | },
75 | }
76 | for _, tc := range testCases {
77 | s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
78 | if tc.expPass {
79 | info, err := k.GetChainInfo(s.ctx, tc.cInfo.ChainName, tc.cInfo.Owner)
80 | s.Require().NoError(err)
81 | s.Require().Equal(s.cInfo, info)
82 | } else {
83 | info, err := k.GetChainInfo(s.ctx, tc.cInfo.ChainName, tc.cInfo.Owner)
84 | s.Require().Error(err)
85 | s.Require().Empty(info)
86 | }
87 | })
88 | }
89 | // test IterateAllInfos
90 | var infos []types.ChainInfo
91 | k.IterateAllInfos(s.ctx, func(info types.ChainInfo) bool {
92 | infos = append(infos, info)
93 | return false
94 | })
95 | s.Require().Equal(1, len(infos))
96 | }
97 | func (s *TestSuite) TestUpdate() {
98 | k := s.app.CNSkeeper
99 | addr := "cosmos1wrx0x9m9ykdhw9sg04v7uljme53wuj03cfqce6"
100 | updatedInfo := types.ChainInfo{
101 | ChainName: "test",
102 | Expiration: 0,
103 | Owner: addr,
104 | CanonicalIbcClient: "test2",
105 | Seed: []string{"abc@xyz:1"},
106 | SourceCodeUrl: "github.com/tendermint/starport",
107 | Version: &types.VersionInfo{
108 | Version: 2,
109 | SourceCommitHash: "d29ef87107420fe2e5443f7436da2rg49ce3a5f8",
110 | GenesisHash: "d29ef87107420fe2e5443f7436da2rg49ce3a5f8",
111 | },
112 | }
113 |
114 | testCases := []struct {
115 | msg string
116 | newInfo types.ChainInfo
117 | cInfo types.ChainInfo
118 | register bool
119 | expPass bool
120 | }{
121 | {
122 | msg: "update chain info",
123 | cInfo: types.ChainInfo{
124 | ChainName: "test",
125 | Owner: addr,
126 | },
127 | expPass: true,
128 | },
129 | }
130 |
131 | for _, tc := range testCases {
132 | s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
133 | if tc.expPass {
134 | err := k.Update(s.ctx, updatedInfo)
135 | s.Require().NoError(err)
136 | info, err := k.GetChainInfo(s.ctx, tc.cInfo.ChainName, tc.cInfo.Owner)
137 | s.Require().NoError(err)
138 | s.Require().Equal(updatedInfo, info)
139 | } else {
140 | info, err := k.GetChainInfo(s.ctx, tc.cInfo.ChainName, tc.cInfo.Owner)
141 | s.Require().Error(err)
142 | s.Require().Empty(info)
143 | }
144 | })
145 | }
146 | }
147 | func TestTestSuite(t *testing.T) {
148 | suite.Run(t, new(TestSuite))
149 | }
150 |
--------------------------------------------------------------------------------
/x/cns/keeper/msg_server.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | "context"
5 | sdk "github.com/cosmos/cosmos-sdk/types"
6 | "github.com/tendermint/cns/x/cns/types"
7 | )
8 |
9 | type msgServer struct {
10 | Keeper
11 | }
12 |
13 | // NewMsgServerImpl returns an implementation of the identity MsgServer interface
14 | // for the provided Keeper.
15 | func NewMsgServerImpl(keeper Keeper) types.MsgServer {
16 | return &msgServer{Keeper: keeper}
17 | }
18 |
19 | var _ types.MsgServer = msgServer{}
20 |
21 | func (k msgServer) RegisterChainName(goCtx context.Context, msg *types.MsgRegisterChainName) (*types.MsgRegisterChainNameResponse, error) {
22 | ctx := sdk.UnwrapSDKContext(goCtx)
23 |
24 | _, err := sdk.AccAddressFromBech32(msg.Owner)
25 | if err != nil {
26 | return nil, err
27 | }
28 |
29 | cInfo := types.ChainInfo{
30 | ChainName: msg.ChainName,
31 | Expiration: 0,
32 | Owner: msg.Owner,
33 | CanonicalIbcClient: msg.CanonicalIbcClient,
34 | Seed: msg.Seed,
35 | SourceCodeUrl: msg.SourceCodeUrl,
36 | Version: msg.Version,
37 | Fee: sdk.NewCoins(types.DefaultFee(types.DefaultDenom)),
38 | }
39 |
40 | err = k.Register(ctx, cInfo)
41 | if err != nil {
42 | return nil, err
43 | }
44 |
45 | return &types.MsgRegisterChainNameResponse{}, err
46 | }
47 |
48 | func (k msgServer) UpdateChainInfo(goCtx context.Context, msg *types.MsgUpdateChainInfo) (*types.MsgUpdateChainInfoResponse, error) {
49 | ctx := sdk.UnwrapSDKContext(goCtx)
50 |
51 | _, err := sdk.AccAddressFromBech32(msg.Owner)
52 | if err != nil {
53 | return nil, err
54 | }
55 |
56 | cInfo := types.ChainInfo{
57 | ChainName: msg.ChainName,
58 | Expiration: 0,
59 | Owner: msg.Owner,
60 | CanonicalIbcClient: msg.CanonicalIbcClient,
61 | Seed: msg.Seed,
62 | SourceCodeUrl: msg.SourceCodeUrl,
63 | Version: msg.Version,
64 | }
65 |
66 | err = k.Update(ctx, cInfo)
67 | if err != nil {
68 | return nil, err
69 | }
70 |
71 | return &types.MsgUpdateChainInfoResponse{}, nil
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/x/cns/keeper/query.go:
--------------------------------------------------------------------------------
1 | package keeper
2 |
3 | import (
4 | // this line is used by starport scaffolding # 1
5 |
6 | "github.com/cosmos/cosmos-sdk/codec"
7 | sdk "github.com/cosmos/cosmos-sdk/types"
8 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
9 | "github.com/tendermint/cns/x/cns/types"
10 |
11 | abci "github.com/tendermint/tendermint/abci/types"
12 | )
13 |
14 | func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
15 | return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
16 | var (
17 | res []byte
18 | err error
19 | )
20 |
21 | switch path[0] {
22 | default:
23 | err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0])
24 | }
25 |
26 | return res, err
27 | }
28 | }
29 |
30 | //TODO Add query handlers
31 |
--------------------------------------------------------------------------------
/x/cns/module.go:
--------------------------------------------------------------------------------
1 | package cns
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | // this line is used by starport scaffolding # 1
7 |
8 | "github.com/gorilla/mux"
9 | "github.com/grpc-ecosystem/grpc-gateway/runtime"
10 | "github.com/spf13/cobra"
11 |
12 | abci "github.com/tendermint/tendermint/abci/types"
13 |
14 | "github.com/cosmos/cosmos-sdk/client"
15 | "github.com/cosmos/cosmos-sdk/codec"
16 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
17 | sdk "github.com/cosmos/cosmos-sdk/types"
18 | "github.com/cosmos/cosmos-sdk/types/module"
19 | "github.com/tendermint/cns/x/cns/client/cli"
20 | "github.com/tendermint/cns/x/cns/client/rest"
21 | "github.com/tendermint/cns/x/cns/keeper"
22 | "github.com/tendermint/cns/x/cns/types"
23 | )
24 |
25 | var (
26 | _ module.AppModule = AppModule{}
27 | _ module.AppModuleBasic = AppModuleBasic{}
28 | )
29 |
30 | // ----------------------------------------------------------------------------
31 | // AppModuleBasic
32 | // ----------------------------------------------------------------------------
33 |
34 | // AppModuleBasic implements the AppModuleBasic interface for the capability module.
35 | type AppModuleBasic struct {
36 | cdc codec.Marshaler
37 | }
38 |
39 | func NewAppModuleBasic(cdc codec.Marshaler) AppModuleBasic {
40 | return AppModuleBasic{cdc: cdc}
41 | }
42 |
43 | // Name returns the capability module's name.
44 | func (AppModuleBasic) Name() string {
45 | return types.ModuleName
46 | }
47 |
48 | func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
49 | types.RegisterCodec(cdc)
50 | }
51 |
52 | func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
53 | types.RegisterCodec(cdc)
54 | }
55 |
56 | // RegisterInterfaces registers the module's interface types
57 | func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
58 | types.RegisterInterfaces(reg)
59 | }
60 |
61 | // DefaultGenesis returns the capability module's default genesis state.
62 | func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
63 | return cdc.MustMarshalJSON(types.DefaultGenesis())
64 | }
65 |
66 | // ValidateGenesis performs genesis state validation for the capability module.
67 | func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error {
68 | var genState types.GenesisState
69 | if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
70 | return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
71 | }
72 | return genState.Validate()
73 | }
74 |
75 | // RegisterRESTRoutes registers the capability module's REST service handlers.
76 | func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
77 | rest.RegisterRoutes(clientCtx, rtr)
78 | }
79 |
80 | // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
81 | func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
82 | // this line is used by starport scaffolding # 2
83 | }
84 |
85 | // GetTxCmd returns the capability module's root tx command.
86 | func (a AppModuleBasic) GetTxCmd() *cobra.Command {
87 | return cli.GetTxCmd()
88 | }
89 |
90 | // GetQueryCmd returns the capability module's root query command.
91 | func (AppModuleBasic) GetQueryCmd() *cobra.Command {
92 | return cli.GetQueryCmd(types.StoreKey)
93 | }
94 |
95 | // ----------------------------------------------------------------------------
96 | // AppModule
97 | // ----------------------------------------------------------------------------
98 |
99 | // AppModule implements the AppModule interface for the capability module.
100 | type AppModule struct {
101 | AppModuleBasic
102 |
103 | keeper keeper.Keeper
104 | }
105 |
106 | func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper) AppModule {
107 | return AppModule{
108 | AppModuleBasic: NewAppModuleBasic(cdc),
109 | keeper: keeper,
110 | }
111 | }
112 |
113 | // Name returns the capability module's name.
114 | func (am AppModule) Name() string {
115 | return am.AppModuleBasic.Name()
116 | }
117 |
118 | // Route returns the capability module's message routing key.
119 | func (am AppModule) Route() sdk.Route {
120 | return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper))
121 | }
122 |
123 | // QuerierRoute returns the capability module's query routing key.
124 | func (AppModule) QuerierRoute() string { return types.QuerierRoute }
125 |
126 | // LegacyQuerierHandler returns the capability module's Querier.
127 | func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
128 | return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
129 | }
130 |
131 | // RegisterServices registers a GRPC query service to respond to the
132 | // module-specific GRPC queries.
133 | func (am AppModule) RegisterServices(cfg module.Configurator) {
134 | types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
135 | }
136 |
137 | // RegisterInvariants registers the capability module's invariants.
138 | func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
139 |
140 | // InitGenesis performs the capability module's genesis initialization It returns
141 | // no validator updates.
142 | func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, gs json.RawMessage) []abci.ValidatorUpdate {
143 | var genState types.GenesisState
144 | // Initialize global index to index in genesis state
145 | cdc.MustUnmarshalJSON(gs, &genState)
146 |
147 | InitGenesis(ctx, am.keeper, genState)
148 |
149 | return []abci.ValidatorUpdate{}
150 | }
151 |
152 | // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
153 | func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
154 | genState := ExportGenesis(ctx, am.keeper)
155 | return cdc.MustMarshalJSON(genState)
156 | }
157 |
158 | // BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
159 | func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
160 |
161 | // EndBlock executes all ABCI EndBlock logic respective to the capability module. It
162 | // returns no validator updates.
163 | func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
164 | return []abci.ValidatorUpdate{}
165 | }
166 |
--------------------------------------------------------------------------------
/x/cns/types/cns.pb.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-gogo. DO NOT EDIT.
2 | // source: cns/cns.proto
3 |
4 | package types
5 |
6 | import (
7 | fmt "fmt"
8 | types "github.com/cosmos/cosmos-sdk/types"
9 | _ "github.com/gogo/protobuf/gogoproto"
10 | proto "github.com/gogo/protobuf/proto"
11 | io "io"
12 | math "math"
13 | math_bits "math/bits"
14 | )
15 |
16 | // Reference imports to suppress errors if they are not otherwise used.
17 | var _ = proto.Marshal
18 | var _ = fmt.Errorf
19 | var _ = math.Inf
20 |
21 | // This is a compile-time assertion to ensure that this generated file
22 | // is compatible with the proto package it is being compiled against.
23 | // A compilation error at this line likely means your copy of the
24 | // proto package needs to be updated.
25 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
26 |
27 | //TODO(sahith): Add json and yaml flags
28 | type ChainInfo struct {
29 | ChainName string `protobuf:"bytes,1,opt,name=chain_name,json=chainName,proto3" json:"chain_name,omitempty"`
30 | Expiration int64 `protobuf:"varint,2,opt,name=expiration,proto3" json:"expiration,omitempty"`
31 | Owner string `protobuf:"bytes,3,opt,name=owner,proto3" json:"owner,omitempty"`
32 | CanonicalIbcClient string `protobuf:"bytes,4,opt,name=canonical_ibc_client,json=canonicalIbcClient,proto3" json:"canonical_ibc_client,omitempty"`
33 | Seed []string `protobuf:"bytes,5,rep,name=seed,proto3" json:"seed,omitempty"`
34 | SourceCodeUrl string `protobuf:"bytes,6,opt,name=source_code_url,json=sourceCodeUrl,proto3" json:"source_code_url,omitempty"`
35 | Version *VersionInfo `protobuf:"bytes,7,opt,name=version,proto3" json:"version,omitempty"`
36 | Fee []types.Coin `protobuf:"bytes,8,rep,name=fee,proto3" json:"fee"`
37 | }
38 |
39 | func (m *ChainInfo) Reset() { *m = ChainInfo{} }
40 | func (m *ChainInfo) String() string { return proto.CompactTextString(m) }
41 | func (*ChainInfo) ProtoMessage() {}
42 | func (*ChainInfo) Descriptor() ([]byte, []int) {
43 | return fileDescriptor_4614c872fdf07012, []int{0}
44 | }
45 | func (m *ChainInfo) XXX_Unmarshal(b []byte) error {
46 | return m.Unmarshal(b)
47 | }
48 | func (m *ChainInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
49 | if deterministic {
50 | return xxx_messageInfo_ChainInfo.Marshal(b, m, deterministic)
51 | } else {
52 | b = b[:cap(b)]
53 | n, err := m.MarshalToSizedBuffer(b)
54 | if err != nil {
55 | return nil, err
56 | }
57 | return b[:n], nil
58 | }
59 | }
60 | func (m *ChainInfo) XXX_Merge(src proto.Message) {
61 | xxx_messageInfo_ChainInfo.Merge(m, src)
62 | }
63 | func (m *ChainInfo) XXX_Size() int {
64 | return m.Size()
65 | }
66 | func (m *ChainInfo) XXX_DiscardUnknown() {
67 | xxx_messageInfo_ChainInfo.DiscardUnknown(m)
68 | }
69 |
70 | var xxx_messageInfo_ChainInfo proto.InternalMessageInfo
71 |
72 | func (m *ChainInfo) GetChainName() string {
73 | if m != nil {
74 | return m.ChainName
75 | }
76 | return ""
77 | }
78 |
79 | func (m *ChainInfo) GetExpiration() int64 {
80 | if m != nil {
81 | return m.Expiration
82 | }
83 | return 0
84 | }
85 |
86 | func (m *ChainInfo) GetOwner() string {
87 | if m != nil {
88 | return m.Owner
89 | }
90 | return ""
91 | }
92 |
93 | func (m *ChainInfo) GetCanonicalIbcClient() string {
94 | if m != nil {
95 | return m.CanonicalIbcClient
96 | }
97 | return ""
98 | }
99 |
100 | func (m *ChainInfo) GetSeed() []string {
101 | if m != nil {
102 | return m.Seed
103 | }
104 | return nil
105 | }
106 |
107 | func (m *ChainInfo) GetSourceCodeUrl() string {
108 | if m != nil {
109 | return m.SourceCodeUrl
110 | }
111 | return ""
112 | }
113 |
114 | func (m *ChainInfo) GetVersion() *VersionInfo {
115 | if m != nil {
116 | return m.Version
117 | }
118 | return nil
119 | }
120 |
121 | func (m *ChainInfo) GetFee() []types.Coin {
122 | if m != nil {
123 | return m.Fee
124 | }
125 | return nil
126 | }
127 |
128 | type VersionInfo struct {
129 | Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
130 | SourceCommitHash string `protobuf:"bytes,2,opt,name=source_commit_hash,json=sourceCommitHash,proto3" json:"source_commit_hash,omitempty"`
131 | GenesisHash string `protobuf:"bytes,3,opt,name=genesis_hash,json=genesisHash,proto3" json:"genesis_hash,omitempty"`
132 | }
133 |
134 | func (m *VersionInfo) Reset() { *m = VersionInfo{} }
135 | func (m *VersionInfo) String() string { return proto.CompactTextString(m) }
136 | func (*VersionInfo) ProtoMessage() {}
137 | func (*VersionInfo) Descriptor() ([]byte, []int) {
138 | return fileDescriptor_4614c872fdf07012, []int{1}
139 | }
140 | func (m *VersionInfo) XXX_Unmarshal(b []byte) error {
141 | return m.Unmarshal(b)
142 | }
143 | func (m *VersionInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
144 | if deterministic {
145 | return xxx_messageInfo_VersionInfo.Marshal(b, m, deterministic)
146 | } else {
147 | b = b[:cap(b)]
148 | n, err := m.MarshalToSizedBuffer(b)
149 | if err != nil {
150 | return nil, err
151 | }
152 | return b[:n], nil
153 | }
154 | }
155 | func (m *VersionInfo) XXX_Merge(src proto.Message) {
156 | xxx_messageInfo_VersionInfo.Merge(m, src)
157 | }
158 | func (m *VersionInfo) XXX_Size() int {
159 | return m.Size()
160 | }
161 | func (m *VersionInfo) XXX_DiscardUnknown() {
162 | xxx_messageInfo_VersionInfo.DiscardUnknown(m)
163 | }
164 |
165 | var xxx_messageInfo_VersionInfo proto.InternalMessageInfo
166 |
167 | func (m *VersionInfo) GetVersion() int64 {
168 | if m != nil {
169 | return m.Version
170 | }
171 | return 0
172 | }
173 |
174 | func (m *VersionInfo) GetSourceCommitHash() string {
175 | if m != nil {
176 | return m.SourceCommitHash
177 | }
178 | return ""
179 | }
180 |
181 | func (m *VersionInfo) GetGenesisHash() string {
182 | if m != nil {
183 | return m.GenesisHash
184 | }
185 | return ""
186 | }
187 |
188 | func init() {
189 | proto.RegisterType((*ChainInfo)(nil), "tendermint.cns.cns.ChainInfo")
190 | proto.RegisterType((*VersionInfo)(nil), "tendermint.cns.cns.VersionInfo")
191 | }
192 |
193 | func init() { proto.RegisterFile("cns/cns.proto", fileDescriptor_4614c872fdf07012) }
194 |
195 | var fileDescriptor_4614c872fdf07012 = []byte{
196 | // 442 bytes of a gzipped FileDescriptorProto
197 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0xbf, 0x6f, 0x13, 0x31,
198 | 0x14, 0xc7, 0xe3, 0x5e, 0xfa, 0xe3, 0x1c, 0x2a, 0x90, 0x95, 0xe1, 0xa8, 0xc4, 0xe5, 0xa8, 0x04,
199 | 0xba, 0x01, 0xf9, 0x48, 0x99, 0xe8, 0x82, 0xd4, 0x2c, 0x74, 0x61, 0x38, 0x09, 0x06, 0x96, 0x93,
200 | 0xcf, 0x79, 0xcd, 0x59, 0xca, 0xf9, 0x45, 0x67, 0xa7, 0x94, 0x85, 0xbf, 0x81, 0x91, 0xb1, 0x7f,
201 | 0x0d, 0xea, 0xd8, 0x91, 0x09, 0xa1, 0x64, 0xe1, 0xcf, 0x40, 0xb6, 0xdb, 0x34, 0x12, 0x8b, 0xf5,
202 | 0xfc, 0x7d, 0x5f, 0xfb, 0xbd, 0xf7, 0xd1, 0xa3, 0x87, 0x52, 0x9b, 0x42, 0x6a, 0xc3, 0x17, 0x1d,
203 | 0x5a, 0x64, 0xcc, 0x82, 0x9e, 0x42, 0xd7, 0x2a, 0x6d, 0xb9, 0x53, 0xa5, 0x36, 0x47, 0xa9, 0x44,
204 | 0xd3, 0xa2, 0x29, 0x6a, 0x61, 0xa0, 0xb8, 0x1c, 0xd7, 0x60, 0xc5, 0xb8, 0x90, 0xa8, 0x74, 0x78,
205 | 0x73, 0x34, 0x9c, 0xe1, 0x0c, 0x7d, 0x58, 0xb8, 0x28, 0xa8, 0xc7, 0x3f, 0x77, 0x68, 0x3c, 0x69,
206 | 0x84, 0xd2, 0xe7, 0xfa, 0x02, 0xd9, 0x33, 0x4a, 0xa5, 0xbb, 0x54, 0x5a, 0xb4, 0x90, 0x90, 0x8c,
207 | 0xe4, 0x71, 0x19, 0x7b, 0xe5, 0x83, 0x68, 0x81, 0xa5, 0x94, 0xc2, 0xd5, 0x42, 0x75, 0xc2, 0x2a,
208 | 0xd4, 0xc9, 0x4e, 0x46, 0xf2, 0xa8, 0xdc, 0x52, 0xd8, 0x90, 0xee, 0xe2, 0x17, 0x0d, 0x5d, 0x12,
209 | 0xf9, 0x97, 0xe1, 0xc2, 0x5e, 0xd3, 0xa1, 0x14, 0x1a, 0xb5, 0x92, 0x62, 0x5e, 0xa9, 0x5a, 0x56,
210 | 0x72, 0xae, 0x40, 0xdb, 0xa4, 0xef, 0x4d, 0x6c, 0x93, 0x3b, 0xaf, 0xe5, 0xc4, 0x67, 0x18, 0xa3,
211 | 0x7d, 0x03, 0x30, 0x4d, 0x76, 0xb3, 0x28, 0x8f, 0x4b, 0x1f, 0xb3, 0x97, 0xf4, 0xb1, 0xc1, 0x65,
212 | 0x27, 0xa1, 0x92, 0x38, 0x85, 0x6a, 0xd9, 0xcd, 0x93, 0x3d, 0xff, 0xc1, 0x61, 0x90, 0x27, 0x38,
213 | 0x85, 0x8f, 0xdd, 0x9c, 0xbd, 0xa5, 0xfb, 0x97, 0xd0, 0x19, 0xd7, 0xe0, 0x7e, 0x46, 0xf2, 0xc1,
214 | 0xc9, 0x88, 0xff, 0x0f, 0x8b, 0x7f, 0x0a, 0x16, 0x37, 0x74, 0x79, 0xef, 0x67, 0x63, 0x1a, 0x5d,
215 | 0x00, 0x24, 0x07, 0x59, 0x94, 0x0f, 0x4e, 0x9e, 0xf2, 0xc0, 0x93, 0x3b, 0x9e, 0xfc, 0x8e, 0x27,
216 | 0x9f, 0xa0, 0xd2, 0x67, 0xfd, 0x9b, 0xdf, 0xa3, 0x5e, 0xe9, 0xbc, 0xa7, 0x07, 0x3f, 0xae, 0x47,
217 | 0xe4, 0xef, 0xf5, 0x88, 0x1c, 0x7f, 0xa3, 0x83, 0xad, 0x4f, 0x59, 0xf2, 0xd0, 0x06, 0xf1, 0x9c,
218 | 0x36, 0x55, 0x5e, 0x51, 0xb6, 0x19, 0xa4, 0x6d, 0x95, 0xad, 0x1a, 0x61, 0x1a, 0x0f, 0x33, 0x2e,
219 | 0x9f, 0xdc, 0xcf, 0xe2, 0x12, 0xef, 0x85, 0x69, 0xd8, 0x73, 0xfa, 0x68, 0x06, 0x1a, 0x8c, 0x32,
220 | 0xc1, 0x17, 0xc8, 0x0e, 0xee, 0x34, 0x67, 0x39, 0xed, 0xbb, 0xfa, 0x67, 0xef, 0x6e, 0x56, 0x29,
221 | 0xb9, 0x5d, 0xa5, 0xe4, 0xcf, 0x2a, 0x25, 0xdf, 0xd7, 0x69, 0xef, 0x76, 0x9d, 0xf6, 0x7e, 0xad,
222 | 0xd3, 0xde, 0xe7, 0x17, 0x33, 0x65, 0x9b, 0x65, 0xcd, 0x25, 0xb6, 0xc5, 0x03, 0x0a, 0xb7, 0x4d,
223 | 0xc5, 0x95, 0x3f, 0xed, 0xd7, 0x05, 0x98, 0x7a, 0xcf, 0x2f, 0xc4, 0x9b, 0x7f, 0x01, 0x00, 0x00,
224 | 0xff, 0xff, 0xd5, 0x57, 0x10, 0x00, 0x6b, 0x02, 0x00, 0x00,
225 | }
226 |
227 | func (this *ChainInfo) Equal(that interface{}) bool {
228 | if that == nil {
229 | return this == nil
230 | }
231 |
232 | that1, ok := that.(*ChainInfo)
233 | if !ok {
234 | that2, ok := that.(ChainInfo)
235 | if ok {
236 | that1 = &that2
237 | } else {
238 | return false
239 | }
240 | }
241 | if that1 == nil {
242 | return this == nil
243 | } else if this == nil {
244 | return false
245 | }
246 | if this.ChainName != that1.ChainName {
247 | return false
248 | }
249 | if this.Expiration != that1.Expiration {
250 | return false
251 | }
252 | if this.Owner != that1.Owner {
253 | return false
254 | }
255 | if this.CanonicalIbcClient != that1.CanonicalIbcClient {
256 | return false
257 | }
258 | if len(this.Seed) != len(that1.Seed) {
259 | return false
260 | }
261 | for i := range this.Seed {
262 | if this.Seed[i] != that1.Seed[i] {
263 | return false
264 | }
265 | }
266 | if this.SourceCodeUrl != that1.SourceCodeUrl {
267 | return false
268 | }
269 | if !this.Version.Equal(that1.Version) {
270 | return false
271 | }
272 | if len(this.Fee) != len(that1.Fee) {
273 | return false
274 | }
275 | for i := range this.Fee {
276 | if !this.Fee[i].Equal(&that1.Fee[i]) {
277 | return false
278 | }
279 | }
280 | return true
281 | }
282 | func (this *VersionInfo) Equal(that interface{}) bool {
283 | if that == nil {
284 | return this == nil
285 | }
286 |
287 | that1, ok := that.(*VersionInfo)
288 | if !ok {
289 | that2, ok := that.(VersionInfo)
290 | if ok {
291 | that1 = &that2
292 | } else {
293 | return false
294 | }
295 | }
296 | if that1 == nil {
297 | return this == nil
298 | } else if this == nil {
299 | return false
300 | }
301 | if this.Version != that1.Version {
302 | return false
303 | }
304 | if this.SourceCommitHash != that1.SourceCommitHash {
305 | return false
306 | }
307 | if this.GenesisHash != that1.GenesisHash {
308 | return false
309 | }
310 | return true
311 | }
312 | func (m *ChainInfo) Marshal() (dAtA []byte, err error) {
313 | size := m.Size()
314 | dAtA = make([]byte, size)
315 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
316 | if err != nil {
317 | return nil, err
318 | }
319 | return dAtA[:n], nil
320 | }
321 |
322 | func (m *ChainInfo) MarshalTo(dAtA []byte) (int, error) {
323 | size := m.Size()
324 | return m.MarshalToSizedBuffer(dAtA[:size])
325 | }
326 |
327 | func (m *ChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) {
328 | i := len(dAtA)
329 | _ = i
330 | var l int
331 | _ = l
332 | if len(m.Fee) > 0 {
333 | for iNdEx := len(m.Fee) - 1; iNdEx >= 0; iNdEx-- {
334 | {
335 | size, err := m.Fee[iNdEx].MarshalToSizedBuffer(dAtA[:i])
336 | if err != nil {
337 | return 0, err
338 | }
339 | i -= size
340 | i = encodeVarintCns(dAtA, i, uint64(size))
341 | }
342 | i--
343 | dAtA[i] = 0x42
344 | }
345 | }
346 | if m.Version != nil {
347 | {
348 | size, err := m.Version.MarshalToSizedBuffer(dAtA[:i])
349 | if err != nil {
350 | return 0, err
351 | }
352 | i -= size
353 | i = encodeVarintCns(dAtA, i, uint64(size))
354 | }
355 | i--
356 | dAtA[i] = 0x3a
357 | }
358 | if len(m.SourceCodeUrl) > 0 {
359 | i -= len(m.SourceCodeUrl)
360 | copy(dAtA[i:], m.SourceCodeUrl)
361 | i = encodeVarintCns(dAtA, i, uint64(len(m.SourceCodeUrl)))
362 | i--
363 | dAtA[i] = 0x32
364 | }
365 | if len(m.Seed) > 0 {
366 | for iNdEx := len(m.Seed) - 1; iNdEx >= 0; iNdEx-- {
367 | i -= len(m.Seed[iNdEx])
368 | copy(dAtA[i:], m.Seed[iNdEx])
369 | i = encodeVarintCns(dAtA, i, uint64(len(m.Seed[iNdEx])))
370 | i--
371 | dAtA[i] = 0x2a
372 | }
373 | }
374 | if len(m.CanonicalIbcClient) > 0 {
375 | i -= len(m.CanonicalIbcClient)
376 | copy(dAtA[i:], m.CanonicalIbcClient)
377 | i = encodeVarintCns(dAtA, i, uint64(len(m.CanonicalIbcClient)))
378 | i--
379 | dAtA[i] = 0x22
380 | }
381 | if len(m.Owner) > 0 {
382 | i -= len(m.Owner)
383 | copy(dAtA[i:], m.Owner)
384 | i = encodeVarintCns(dAtA, i, uint64(len(m.Owner)))
385 | i--
386 | dAtA[i] = 0x1a
387 | }
388 | if m.Expiration != 0 {
389 | i = encodeVarintCns(dAtA, i, uint64(m.Expiration))
390 | i--
391 | dAtA[i] = 0x10
392 | }
393 | if len(m.ChainName) > 0 {
394 | i -= len(m.ChainName)
395 | copy(dAtA[i:], m.ChainName)
396 | i = encodeVarintCns(dAtA, i, uint64(len(m.ChainName)))
397 | i--
398 | dAtA[i] = 0xa
399 | }
400 | return len(dAtA) - i, nil
401 | }
402 |
403 | func (m *VersionInfo) Marshal() (dAtA []byte, err error) {
404 | size := m.Size()
405 | dAtA = make([]byte, size)
406 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
407 | if err != nil {
408 | return nil, err
409 | }
410 | return dAtA[:n], nil
411 | }
412 |
413 | func (m *VersionInfo) MarshalTo(dAtA []byte) (int, error) {
414 | size := m.Size()
415 | return m.MarshalToSizedBuffer(dAtA[:size])
416 | }
417 |
418 | func (m *VersionInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) {
419 | i := len(dAtA)
420 | _ = i
421 | var l int
422 | _ = l
423 | if len(m.GenesisHash) > 0 {
424 | i -= len(m.GenesisHash)
425 | copy(dAtA[i:], m.GenesisHash)
426 | i = encodeVarintCns(dAtA, i, uint64(len(m.GenesisHash)))
427 | i--
428 | dAtA[i] = 0x1a
429 | }
430 | if len(m.SourceCommitHash) > 0 {
431 | i -= len(m.SourceCommitHash)
432 | copy(dAtA[i:], m.SourceCommitHash)
433 | i = encodeVarintCns(dAtA, i, uint64(len(m.SourceCommitHash)))
434 | i--
435 | dAtA[i] = 0x12
436 | }
437 | if m.Version != 0 {
438 | i = encodeVarintCns(dAtA, i, uint64(m.Version))
439 | i--
440 | dAtA[i] = 0x8
441 | }
442 | return len(dAtA) - i, nil
443 | }
444 |
445 | func encodeVarintCns(dAtA []byte, offset int, v uint64) int {
446 | offset -= sovCns(v)
447 | base := offset
448 | for v >= 1<<7 {
449 | dAtA[offset] = uint8(v&0x7f | 0x80)
450 | v >>= 7
451 | offset++
452 | }
453 | dAtA[offset] = uint8(v)
454 | return base
455 | }
456 | func (m *ChainInfo) Size() (n int) {
457 | if m == nil {
458 | return 0
459 | }
460 | var l int
461 | _ = l
462 | l = len(m.ChainName)
463 | if l > 0 {
464 | n += 1 + l + sovCns(uint64(l))
465 | }
466 | if m.Expiration != 0 {
467 | n += 1 + sovCns(uint64(m.Expiration))
468 | }
469 | l = len(m.Owner)
470 | if l > 0 {
471 | n += 1 + l + sovCns(uint64(l))
472 | }
473 | l = len(m.CanonicalIbcClient)
474 | if l > 0 {
475 | n += 1 + l + sovCns(uint64(l))
476 | }
477 | if len(m.Seed) > 0 {
478 | for _, s := range m.Seed {
479 | l = len(s)
480 | n += 1 + l + sovCns(uint64(l))
481 | }
482 | }
483 | l = len(m.SourceCodeUrl)
484 | if l > 0 {
485 | n += 1 + l + sovCns(uint64(l))
486 | }
487 | if m.Version != nil {
488 | l = m.Version.Size()
489 | n += 1 + l + sovCns(uint64(l))
490 | }
491 | if len(m.Fee) > 0 {
492 | for _, e := range m.Fee {
493 | l = e.Size()
494 | n += 1 + l + sovCns(uint64(l))
495 | }
496 | }
497 | return n
498 | }
499 |
500 | func (m *VersionInfo) Size() (n int) {
501 | if m == nil {
502 | return 0
503 | }
504 | var l int
505 | _ = l
506 | if m.Version != 0 {
507 | n += 1 + sovCns(uint64(m.Version))
508 | }
509 | l = len(m.SourceCommitHash)
510 | if l > 0 {
511 | n += 1 + l + sovCns(uint64(l))
512 | }
513 | l = len(m.GenesisHash)
514 | if l > 0 {
515 | n += 1 + l + sovCns(uint64(l))
516 | }
517 | return n
518 | }
519 |
520 | func sovCns(x uint64) (n int) {
521 | return (math_bits.Len64(x|1) + 6) / 7
522 | }
523 | func sozCns(x uint64) (n int) {
524 | return sovCns(uint64((x << 1) ^ uint64((int64(x) >> 63))))
525 | }
526 | func (m *ChainInfo) Unmarshal(dAtA []byte) error {
527 | l := len(dAtA)
528 | iNdEx := 0
529 | for iNdEx < l {
530 | preIndex := iNdEx
531 | var wire uint64
532 | for shift := uint(0); ; shift += 7 {
533 | if shift >= 64 {
534 | return ErrIntOverflowCns
535 | }
536 | if iNdEx >= l {
537 | return io.ErrUnexpectedEOF
538 | }
539 | b := dAtA[iNdEx]
540 | iNdEx++
541 | wire |= uint64(b&0x7F) << shift
542 | if b < 0x80 {
543 | break
544 | }
545 | }
546 | fieldNum := int32(wire >> 3)
547 | wireType := int(wire & 0x7)
548 | if wireType == 4 {
549 | return fmt.Errorf("proto: ChainInfo: wiretype end group for non-group")
550 | }
551 | if fieldNum <= 0 {
552 | return fmt.Errorf("proto: ChainInfo: illegal tag %d (wire type %d)", fieldNum, wire)
553 | }
554 | switch fieldNum {
555 | case 1:
556 | if wireType != 2 {
557 | return fmt.Errorf("proto: wrong wireType = %d for field ChainName", wireType)
558 | }
559 | var stringLen uint64
560 | for shift := uint(0); ; shift += 7 {
561 | if shift >= 64 {
562 | return ErrIntOverflowCns
563 | }
564 | if iNdEx >= l {
565 | return io.ErrUnexpectedEOF
566 | }
567 | b := dAtA[iNdEx]
568 | iNdEx++
569 | stringLen |= uint64(b&0x7F) << shift
570 | if b < 0x80 {
571 | break
572 | }
573 | }
574 | intStringLen := int(stringLen)
575 | if intStringLen < 0 {
576 | return ErrInvalidLengthCns
577 | }
578 | postIndex := iNdEx + intStringLen
579 | if postIndex < 0 {
580 | return ErrInvalidLengthCns
581 | }
582 | if postIndex > l {
583 | return io.ErrUnexpectedEOF
584 | }
585 | m.ChainName = string(dAtA[iNdEx:postIndex])
586 | iNdEx = postIndex
587 | case 2:
588 | if wireType != 0 {
589 | return fmt.Errorf("proto: wrong wireType = %d for field Expiration", wireType)
590 | }
591 | m.Expiration = 0
592 | for shift := uint(0); ; shift += 7 {
593 | if shift >= 64 {
594 | return ErrIntOverflowCns
595 | }
596 | if iNdEx >= l {
597 | return io.ErrUnexpectedEOF
598 | }
599 | b := dAtA[iNdEx]
600 | iNdEx++
601 | m.Expiration |= int64(b&0x7F) << shift
602 | if b < 0x80 {
603 | break
604 | }
605 | }
606 | case 3:
607 | if wireType != 2 {
608 | return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType)
609 | }
610 | var stringLen uint64
611 | for shift := uint(0); ; shift += 7 {
612 | if shift >= 64 {
613 | return ErrIntOverflowCns
614 | }
615 | if iNdEx >= l {
616 | return io.ErrUnexpectedEOF
617 | }
618 | b := dAtA[iNdEx]
619 | iNdEx++
620 | stringLen |= uint64(b&0x7F) << shift
621 | if b < 0x80 {
622 | break
623 | }
624 | }
625 | intStringLen := int(stringLen)
626 | if intStringLen < 0 {
627 | return ErrInvalidLengthCns
628 | }
629 | postIndex := iNdEx + intStringLen
630 | if postIndex < 0 {
631 | return ErrInvalidLengthCns
632 | }
633 | if postIndex > l {
634 | return io.ErrUnexpectedEOF
635 | }
636 | m.Owner = string(dAtA[iNdEx:postIndex])
637 | iNdEx = postIndex
638 | case 4:
639 | if wireType != 2 {
640 | return fmt.Errorf("proto: wrong wireType = %d for field CanonicalIbcClient", wireType)
641 | }
642 | var stringLen uint64
643 | for shift := uint(0); ; shift += 7 {
644 | if shift >= 64 {
645 | return ErrIntOverflowCns
646 | }
647 | if iNdEx >= l {
648 | return io.ErrUnexpectedEOF
649 | }
650 | b := dAtA[iNdEx]
651 | iNdEx++
652 | stringLen |= uint64(b&0x7F) << shift
653 | if b < 0x80 {
654 | break
655 | }
656 | }
657 | intStringLen := int(stringLen)
658 | if intStringLen < 0 {
659 | return ErrInvalidLengthCns
660 | }
661 | postIndex := iNdEx + intStringLen
662 | if postIndex < 0 {
663 | return ErrInvalidLengthCns
664 | }
665 | if postIndex > l {
666 | return io.ErrUnexpectedEOF
667 | }
668 | m.CanonicalIbcClient = string(dAtA[iNdEx:postIndex])
669 | iNdEx = postIndex
670 | case 5:
671 | if wireType != 2 {
672 | return fmt.Errorf("proto: wrong wireType = %d for field Seed", wireType)
673 | }
674 | var stringLen uint64
675 | for shift := uint(0); ; shift += 7 {
676 | if shift >= 64 {
677 | return ErrIntOverflowCns
678 | }
679 | if iNdEx >= l {
680 | return io.ErrUnexpectedEOF
681 | }
682 | b := dAtA[iNdEx]
683 | iNdEx++
684 | stringLen |= uint64(b&0x7F) << shift
685 | if b < 0x80 {
686 | break
687 | }
688 | }
689 | intStringLen := int(stringLen)
690 | if intStringLen < 0 {
691 | return ErrInvalidLengthCns
692 | }
693 | postIndex := iNdEx + intStringLen
694 | if postIndex < 0 {
695 | return ErrInvalidLengthCns
696 | }
697 | if postIndex > l {
698 | return io.ErrUnexpectedEOF
699 | }
700 | m.Seed = append(m.Seed, string(dAtA[iNdEx:postIndex]))
701 | iNdEx = postIndex
702 | case 6:
703 | if wireType != 2 {
704 | return fmt.Errorf("proto: wrong wireType = %d for field SourceCodeUrl", wireType)
705 | }
706 | var stringLen uint64
707 | for shift := uint(0); ; shift += 7 {
708 | if shift >= 64 {
709 | return ErrIntOverflowCns
710 | }
711 | if iNdEx >= l {
712 | return io.ErrUnexpectedEOF
713 | }
714 | b := dAtA[iNdEx]
715 | iNdEx++
716 | stringLen |= uint64(b&0x7F) << shift
717 | if b < 0x80 {
718 | break
719 | }
720 | }
721 | intStringLen := int(stringLen)
722 | if intStringLen < 0 {
723 | return ErrInvalidLengthCns
724 | }
725 | postIndex := iNdEx + intStringLen
726 | if postIndex < 0 {
727 | return ErrInvalidLengthCns
728 | }
729 | if postIndex > l {
730 | return io.ErrUnexpectedEOF
731 | }
732 | m.SourceCodeUrl = string(dAtA[iNdEx:postIndex])
733 | iNdEx = postIndex
734 | case 7:
735 | if wireType != 2 {
736 | return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType)
737 | }
738 | var msglen int
739 | for shift := uint(0); ; shift += 7 {
740 | if shift >= 64 {
741 | return ErrIntOverflowCns
742 | }
743 | if iNdEx >= l {
744 | return io.ErrUnexpectedEOF
745 | }
746 | b := dAtA[iNdEx]
747 | iNdEx++
748 | msglen |= int(b&0x7F) << shift
749 | if b < 0x80 {
750 | break
751 | }
752 | }
753 | if msglen < 0 {
754 | return ErrInvalidLengthCns
755 | }
756 | postIndex := iNdEx + msglen
757 | if postIndex < 0 {
758 | return ErrInvalidLengthCns
759 | }
760 | if postIndex > l {
761 | return io.ErrUnexpectedEOF
762 | }
763 | if m.Version == nil {
764 | m.Version = &VersionInfo{}
765 | }
766 | if err := m.Version.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
767 | return err
768 | }
769 | iNdEx = postIndex
770 | case 8:
771 | if wireType != 2 {
772 | return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType)
773 | }
774 | var msglen int
775 | for shift := uint(0); ; shift += 7 {
776 | if shift >= 64 {
777 | return ErrIntOverflowCns
778 | }
779 | if iNdEx >= l {
780 | return io.ErrUnexpectedEOF
781 | }
782 | b := dAtA[iNdEx]
783 | iNdEx++
784 | msglen |= int(b&0x7F) << shift
785 | if b < 0x80 {
786 | break
787 | }
788 | }
789 | if msglen < 0 {
790 | return ErrInvalidLengthCns
791 | }
792 | postIndex := iNdEx + msglen
793 | if postIndex < 0 {
794 | return ErrInvalidLengthCns
795 | }
796 | if postIndex > l {
797 | return io.ErrUnexpectedEOF
798 | }
799 | m.Fee = append(m.Fee, types.Coin{})
800 | if err := m.Fee[len(m.Fee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
801 | return err
802 | }
803 | iNdEx = postIndex
804 | default:
805 | iNdEx = preIndex
806 | skippy, err := skipCns(dAtA[iNdEx:])
807 | if err != nil {
808 | return err
809 | }
810 | if (skippy < 0) || (iNdEx+skippy) < 0 {
811 | return ErrInvalidLengthCns
812 | }
813 | if (iNdEx + skippy) > l {
814 | return io.ErrUnexpectedEOF
815 | }
816 | iNdEx += skippy
817 | }
818 | }
819 |
820 | if iNdEx > l {
821 | return io.ErrUnexpectedEOF
822 | }
823 | return nil
824 | }
825 | func (m *VersionInfo) Unmarshal(dAtA []byte) error {
826 | l := len(dAtA)
827 | iNdEx := 0
828 | for iNdEx < l {
829 | preIndex := iNdEx
830 | var wire uint64
831 | for shift := uint(0); ; shift += 7 {
832 | if shift >= 64 {
833 | return ErrIntOverflowCns
834 | }
835 | if iNdEx >= l {
836 | return io.ErrUnexpectedEOF
837 | }
838 | b := dAtA[iNdEx]
839 | iNdEx++
840 | wire |= uint64(b&0x7F) << shift
841 | if b < 0x80 {
842 | break
843 | }
844 | }
845 | fieldNum := int32(wire >> 3)
846 | wireType := int(wire & 0x7)
847 | if wireType == 4 {
848 | return fmt.Errorf("proto: VersionInfo: wiretype end group for non-group")
849 | }
850 | if fieldNum <= 0 {
851 | return fmt.Errorf("proto: VersionInfo: illegal tag %d (wire type %d)", fieldNum, wire)
852 | }
853 | switch fieldNum {
854 | case 1:
855 | if wireType != 0 {
856 | return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType)
857 | }
858 | m.Version = 0
859 | for shift := uint(0); ; shift += 7 {
860 | if shift >= 64 {
861 | return ErrIntOverflowCns
862 | }
863 | if iNdEx >= l {
864 | return io.ErrUnexpectedEOF
865 | }
866 | b := dAtA[iNdEx]
867 | iNdEx++
868 | m.Version |= int64(b&0x7F) << shift
869 | if b < 0x80 {
870 | break
871 | }
872 | }
873 | case 2:
874 | if wireType != 2 {
875 | return fmt.Errorf("proto: wrong wireType = %d for field SourceCommitHash", wireType)
876 | }
877 | var stringLen uint64
878 | for shift := uint(0); ; shift += 7 {
879 | if shift >= 64 {
880 | return ErrIntOverflowCns
881 | }
882 | if iNdEx >= l {
883 | return io.ErrUnexpectedEOF
884 | }
885 | b := dAtA[iNdEx]
886 | iNdEx++
887 | stringLen |= uint64(b&0x7F) << shift
888 | if b < 0x80 {
889 | break
890 | }
891 | }
892 | intStringLen := int(stringLen)
893 | if intStringLen < 0 {
894 | return ErrInvalidLengthCns
895 | }
896 | postIndex := iNdEx + intStringLen
897 | if postIndex < 0 {
898 | return ErrInvalidLengthCns
899 | }
900 | if postIndex > l {
901 | return io.ErrUnexpectedEOF
902 | }
903 | m.SourceCommitHash = string(dAtA[iNdEx:postIndex])
904 | iNdEx = postIndex
905 | case 3:
906 | if wireType != 2 {
907 | return fmt.Errorf("proto: wrong wireType = %d for field GenesisHash", wireType)
908 | }
909 | var stringLen uint64
910 | for shift := uint(0); ; shift += 7 {
911 | if shift >= 64 {
912 | return ErrIntOverflowCns
913 | }
914 | if iNdEx >= l {
915 | return io.ErrUnexpectedEOF
916 | }
917 | b := dAtA[iNdEx]
918 | iNdEx++
919 | stringLen |= uint64(b&0x7F) << shift
920 | if b < 0x80 {
921 | break
922 | }
923 | }
924 | intStringLen := int(stringLen)
925 | if intStringLen < 0 {
926 | return ErrInvalidLengthCns
927 | }
928 | postIndex := iNdEx + intStringLen
929 | if postIndex < 0 {
930 | return ErrInvalidLengthCns
931 | }
932 | if postIndex > l {
933 | return io.ErrUnexpectedEOF
934 | }
935 | m.GenesisHash = string(dAtA[iNdEx:postIndex])
936 | iNdEx = postIndex
937 | default:
938 | iNdEx = preIndex
939 | skippy, err := skipCns(dAtA[iNdEx:])
940 | if err != nil {
941 | return err
942 | }
943 | if (skippy < 0) || (iNdEx+skippy) < 0 {
944 | return ErrInvalidLengthCns
945 | }
946 | if (iNdEx + skippy) > l {
947 | return io.ErrUnexpectedEOF
948 | }
949 | iNdEx += skippy
950 | }
951 | }
952 |
953 | if iNdEx > l {
954 | return io.ErrUnexpectedEOF
955 | }
956 | return nil
957 | }
958 | func skipCns(dAtA []byte) (n int, err error) {
959 | l := len(dAtA)
960 | iNdEx := 0
961 | depth := 0
962 | for iNdEx < l {
963 | var wire uint64
964 | for shift := uint(0); ; shift += 7 {
965 | if shift >= 64 {
966 | return 0, ErrIntOverflowCns
967 | }
968 | if iNdEx >= l {
969 | return 0, io.ErrUnexpectedEOF
970 | }
971 | b := dAtA[iNdEx]
972 | iNdEx++
973 | wire |= (uint64(b) & 0x7F) << shift
974 | if b < 0x80 {
975 | break
976 | }
977 | }
978 | wireType := int(wire & 0x7)
979 | switch wireType {
980 | case 0:
981 | for shift := uint(0); ; shift += 7 {
982 | if shift >= 64 {
983 | return 0, ErrIntOverflowCns
984 | }
985 | if iNdEx >= l {
986 | return 0, io.ErrUnexpectedEOF
987 | }
988 | iNdEx++
989 | if dAtA[iNdEx-1] < 0x80 {
990 | break
991 | }
992 | }
993 | case 1:
994 | iNdEx += 8
995 | case 2:
996 | var length int
997 | for shift := uint(0); ; shift += 7 {
998 | if shift >= 64 {
999 | return 0, ErrIntOverflowCns
1000 | }
1001 | if iNdEx >= l {
1002 | return 0, io.ErrUnexpectedEOF
1003 | }
1004 | b := dAtA[iNdEx]
1005 | iNdEx++
1006 | length |= (int(b) & 0x7F) << shift
1007 | if b < 0x80 {
1008 | break
1009 | }
1010 | }
1011 | if length < 0 {
1012 | return 0, ErrInvalidLengthCns
1013 | }
1014 | iNdEx += length
1015 | case 3:
1016 | depth++
1017 | case 4:
1018 | if depth == 0 {
1019 | return 0, ErrUnexpectedEndOfGroupCns
1020 | }
1021 | depth--
1022 | case 5:
1023 | iNdEx += 4
1024 | default:
1025 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
1026 | }
1027 | if iNdEx < 0 {
1028 | return 0, ErrInvalidLengthCns
1029 | }
1030 | if depth == 0 {
1031 | return iNdEx, nil
1032 | }
1033 | }
1034 | return 0, io.ErrUnexpectedEOF
1035 | }
1036 |
1037 | var (
1038 | ErrInvalidLengthCns = fmt.Errorf("proto: negative length found during unmarshaling")
1039 | ErrIntOverflowCns = fmt.Errorf("proto: integer overflow")
1040 | ErrUnexpectedEndOfGroupCns = fmt.Errorf("proto: unexpected end of group")
1041 | )
1042 |
--------------------------------------------------------------------------------
/x/cns/types/codec.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "github.com/cosmos/cosmos-sdk/codec"
5 | cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
6 | sdk "github.com/cosmos/cosmos-sdk/types"
7 | // this line is used by starport scaffolding # 1
8 | )
9 |
10 | func RegisterCodec(cdc *codec.LegacyAmino) {
11 | cdc.RegisterConcrete(&MsgRegisterChainName{}, "cosmos-sdk/MsgRegisterChainName", nil)
12 | }
13 |
14 | func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
15 | registry.RegisterImplementations((*sdk.Msg)(nil),
16 | &MsgRegisterChainName{},
17 | &MsgUpdateChainInfo{},
18 | )
19 | }
20 |
21 | var (
22 | amino = codec.NewLegacyAmino()
23 | ModuleCdc = codec.NewAminoCodec(amino)
24 | )
25 |
--------------------------------------------------------------------------------
/x/cns/types/errors.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | // DONTCOVER
4 |
5 | import (
6 | sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
7 | )
8 |
9 | // x/cns module sentinel errors
10 | var (
11 | ErrChainAlreadyExists = sdkerrors.Register(ModuleName, 2, "chain name is already registered")
12 | )
13 |
--------------------------------------------------------------------------------
/x/cns/types/expected_keepers.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import sdk "github.com/cosmos/cosmos-sdk/types"
4 |
5 | type DistributionKeeper interface {
6 | FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
7 | }
8 |
9 | type BankKeeper interface {
10 | GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
11 | }
12 |
--------------------------------------------------------------------------------
/x/cns/types/genesis.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import sdk "github.com/cosmos/cosmos-sdk/types"
4 |
5 | // this line is used by starport scaffolding # genesis/types/import
6 |
7 | // DefaultIndex is the default capability global index
8 | const DefaultIndex uint64 = 1
9 |
10 | // DefaultGenesis returns the default Capability genesis state
11 | func DefaultGenesis() *GenesisState {
12 | return &GenesisState{
13 | Fee: sdk.NewCoins(DefaultFee(DefaultDenom)),
14 | Infos: []ChainInfo{},
15 | }
16 | }
17 |
18 | // Validate performs basic genesis state validation returning an error upon any
19 | // failure.
20 | func (gs GenesisState) Validate() error {
21 | // this line is used by starport scaffolding # genesis/types/validate
22 |
23 | return nil
24 | }
25 |
--------------------------------------------------------------------------------
/x/cns/types/genesis.pb.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-gogo. DO NOT EDIT.
2 | // source: cns/genesis.proto
3 |
4 | package types
5 |
6 | import (
7 | fmt "fmt"
8 | types "github.com/cosmos/cosmos-sdk/types"
9 | _ "github.com/gogo/protobuf/gogoproto"
10 | proto "github.com/gogo/protobuf/proto"
11 | io "io"
12 | math "math"
13 | math_bits "math/bits"
14 | )
15 |
16 | // Reference imports to suppress errors if they are not otherwise used.
17 | var _ = proto.Marshal
18 | var _ = fmt.Errorf
19 | var _ = math.Inf
20 |
21 | // This is a compile-time assertion to ensure that this generated file
22 | // is compatible with the proto package it is being compiled against.
23 | // A compilation error at this line likely means your copy of the
24 | // proto package needs to be updated.
25 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
26 |
27 | // GenesisState defines the capability module's genesis state.
28 | type GenesisState struct {
29 | Fee []types.Coin `protobuf:"bytes,1,rep,name=fee,proto3" json:"fee"`
30 | Infos []ChainInfo `protobuf:"bytes,2,rep,name=infos,proto3" json:"infos"`
31 | }
32 |
33 | func (m *GenesisState) Reset() { *m = GenesisState{} }
34 | func (m *GenesisState) String() string { return proto.CompactTextString(m) }
35 | func (*GenesisState) ProtoMessage() {}
36 | func (*GenesisState) Descriptor() ([]byte, []int) {
37 | return fileDescriptor_dfe3e442969a75b4, []int{0}
38 | }
39 | func (m *GenesisState) XXX_Unmarshal(b []byte) error {
40 | return m.Unmarshal(b)
41 | }
42 | func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
43 | if deterministic {
44 | return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic)
45 | } else {
46 | b = b[:cap(b)]
47 | n, err := m.MarshalToSizedBuffer(b)
48 | if err != nil {
49 | return nil, err
50 | }
51 | return b[:n], nil
52 | }
53 | }
54 | func (m *GenesisState) XXX_Merge(src proto.Message) {
55 | xxx_messageInfo_GenesisState.Merge(m, src)
56 | }
57 | func (m *GenesisState) XXX_Size() int {
58 | return m.Size()
59 | }
60 | func (m *GenesisState) XXX_DiscardUnknown() {
61 | xxx_messageInfo_GenesisState.DiscardUnknown(m)
62 | }
63 |
64 | var xxx_messageInfo_GenesisState proto.InternalMessageInfo
65 |
66 | func (m *GenesisState) GetFee() []types.Coin {
67 | if m != nil {
68 | return m.Fee
69 | }
70 | return nil
71 | }
72 |
73 | func (m *GenesisState) GetInfos() []ChainInfo {
74 | if m != nil {
75 | return m.Infos
76 | }
77 | return nil
78 | }
79 |
80 | func init() {
81 | proto.RegisterType((*GenesisState)(nil), "tendermint.cns.cns.GenesisState")
82 | }
83 |
84 | func init() { proto.RegisterFile("cns/genesis.proto", fileDescriptor_dfe3e442969a75b4) }
85 |
86 | var fileDescriptor_dfe3e442969a75b4 = []byte{
87 | // 249 bytes of a gzipped FileDescriptorProto
88 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0xce, 0x2b, 0xd6,
89 | 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2a,
90 | 0x49, 0xcd, 0x4b, 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4b, 0xce, 0x2b, 0x06, 0x61, 0x29,
91 | 0xb9, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc, 0x62, 0xfd, 0xa4, 0xc4, 0xe2, 0x54, 0xfd, 0x32, 0xc3, 0xa4,
92 | 0xd4, 0x92, 0x44, 0x43, 0xfd, 0xe4, 0xfc, 0xcc, 0x3c, 0x88, 0x1e, 0x29, 0x5e, 0x90, 0x31, 0x20,
93 | 0xc5, 0x10, 0xae, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0x6a,
94 | 0xb8, 0x78, 0xdc, 0x21, 0x36, 0x05, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x19, 0x72, 0x31, 0xa7, 0xa5,
95 | 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0x49, 0xea, 0x41, 0xac, 0xd0, 0x03, 0x59, 0xa1,
96 | 0x07, 0xb5, 0x42, 0xcf, 0x39, 0x3f, 0x33, 0xcf, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0x90,
97 | 0x5a, 0x21, 0x4b, 0x2e, 0xd6, 0xcc, 0xbc, 0xb4, 0xfc, 0x62, 0x09, 0x26, 0xb0, 0x26, 0x59, 0x3d,
98 | 0x4c, 0xb7, 0xea, 0x39, 0x67, 0x24, 0x66, 0xe6, 0x79, 0xe6, 0xa5, 0xe5, 0x43, 0x35, 0x42, 0x74,
99 | 0x38, 0xd9, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13,
100 | 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x6a, 0x7a, 0x66,
101 | 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xc2, 0x3c, 0x90, 0x77, 0xf4, 0x2b, 0xc0,
102 | 0x64, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x17, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff,
103 | 0xff, 0x00, 0x51, 0x82, 0xec, 0x33, 0x01, 0x00, 0x00,
104 | }
105 |
106 | func (m *GenesisState) Marshal() (dAtA []byte, err error) {
107 | size := m.Size()
108 | dAtA = make([]byte, size)
109 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
110 | if err != nil {
111 | return nil, err
112 | }
113 | return dAtA[:n], nil
114 | }
115 |
116 | func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) {
117 | size := m.Size()
118 | return m.MarshalToSizedBuffer(dAtA[:size])
119 | }
120 |
121 | func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
122 | i := len(dAtA)
123 | _ = i
124 | var l int
125 | _ = l
126 | if len(m.Infos) > 0 {
127 | for iNdEx := len(m.Infos) - 1; iNdEx >= 0; iNdEx-- {
128 | {
129 | size, err := m.Infos[iNdEx].MarshalToSizedBuffer(dAtA[:i])
130 | if err != nil {
131 | return 0, err
132 | }
133 | i -= size
134 | i = encodeVarintGenesis(dAtA, i, uint64(size))
135 | }
136 | i--
137 | dAtA[i] = 0x12
138 | }
139 | }
140 | if len(m.Fee) > 0 {
141 | for iNdEx := len(m.Fee) - 1; iNdEx >= 0; iNdEx-- {
142 | {
143 | size, err := m.Fee[iNdEx].MarshalToSizedBuffer(dAtA[:i])
144 | if err != nil {
145 | return 0, err
146 | }
147 | i -= size
148 | i = encodeVarintGenesis(dAtA, i, uint64(size))
149 | }
150 | i--
151 | dAtA[i] = 0xa
152 | }
153 | }
154 | return len(dAtA) - i, nil
155 | }
156 |
157 | func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
158 | offset -= sovGenesis(v)
159 | base := offset
160 | for v >= 1<<7 {
161 | dAtA[offset] = uint8(v&0x7f | 0x80)
162 | v >>= 7
163 | offset++
164 | }
165 | dAtA[offset] = uint8(v)
166 | return base
167 | }
168 | func (m *GenesisState) Size() (n int) {
169 | if m == nil {
170 | return 0
171 | }
172 | var l int
173 | _ = l
174 | if len(m.Fee) > 0 {
175 | for _, e := range m.Fee {
176 | l = e.Size()
177 | n += 1 + l + sovGenesis(uint64(l))
178 | }
179 | }
180 | if len(m.Infos) > 0 {
181 | for _, e := range m.Infos {
182 | l = e.Size()
183 | n += 1 + l + sovGenesis(uint64(l))
184 | }
185 | }
186 | return n
187 | }
188 |
189 | func sovGenesis(x uint64) (n int) {
190 | return (math_bits.Len64(x|1) + 6) / 7
191 | }
192 | func sozGenesis(x uint64) (n int) {
193 | return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
194 | }
195 | func (m *GenesisState) Unmarshal(dAtA []byte) error {
196 | l := len(dAtA)
197 | iNdEx := 0
198 | for iNdEx < l {
199 | preIndex := iNdEx
200 | var wire uint64
201 | for shift := uint(0); ; shift += 7 {
202 | if shift >= 64 {
203 | return ErrIntOverflowGenesis
204 | }
205 | if iNdEx >= l {
206 | return io.ErrUnexpectedEOF
207 | }
208 | b := dAtA[iNdEx]
209 | iNdEx++
210 | wire |= uint64(b&0x7F) << shift
211 | if b < 0x80 {
212 | break
213 | }
214 | }
215 | fieldNum := int32(wire >> 3)
216 | wireType := int(wire & 0x7)
217 | if wireType == 4 {
218 | return fmt.Errorf("proto: GenesisState: wiretype end group for non-group")
219 | }
220 | if fieldNum <= 0 {
221 | return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
222 | }
223 | switch fieldNum {
224 | case 1:
225 | if wireType != 2 {
226 | return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType)
227 | }
228 | var msglen int
229 | for shift := uint(0); ; shift += 7 {
230 | if shift >= 64 {
231 | return ErrIntOverflowGenesis
232 | }
233 | if iNdEx >= l {
234 | return io.ErrUnexpectedEOF
235 | }
236 | b := dAtA[iNdEx]
237 | iNdEx++
238 | msglen |= int(b&0x7F) << shift
239 | if b < 0x80 {
240 | break
241 | }
242 | }
243 | if msglen < 0 {
244 | return ErrInvalidLengthGenesis
245 | }
246 | postIndex := iNdEx + msglen
247 | if postIndex < 0 {
248 | return ErrInvalidLengthGenesis
249 | }
250 | if postIndex > l {
251 | return io.ErrUnexpectedEOF
252 | }
253 | m.Fee = append(m.Fee, types.Coin{})
254 | if err := m.Fee[len(m.Fee)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
255 | return err
256 | }
257 | iNdEx = postIndex
258 | case 2:
259 | if wireType != 2 {
260 | return fmt.Errorf("proto: wrong wireType = %d for field Infos", wireType)
261 | }
262 | var msglen int
263 | for shift := uint(0); ; shift += 7 {
264 | if shift >= 64 {
265 | return ErrIntOverflowGenesis
266 | }
267 | if iNdEx >= l {
268 | return io.ErrUnexpectedEOF
269 | }
270 | b := dAtA[iNdEx]
271 | iNdEx++
272 | msglen |= int(b&0x7F) << shift
273 | if b < 0x80 {
274 | break
275 | }
276 | }
277 | if msglen < 0 {
278 | return ErrInvalidLengthGenesis
279 | }
280 | postIndex := iNdEx + msglen
281 | if postIndex < 0 {
282 | return ErrInvalidLengthGenesis
283 | }
284 | if postIndex > l {
285 | return io.ErrUnexpectedEOF
286 | }
287 | m.Infos = append(m.Infos, ChainInfo{})
288 | if err := m.Infos[len(m.Infos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
289 | return err
290 | }
291 | iNdEx = postIndex
292 | default:
293 | iNdEx = preIndex
294 | skippy, err := skipGenesis(dAtA[iNdEx:])
295 | if err != nil {
296 | return err
297 | }
298 | if (skippy < 0) || (iNdEx+skippy) < 0 {
299 | return ErrInvalidLengthGenesis
300 | }
301 | if (iNdEx + skippy) > l {
302 | return io.ErrUnexpectedEOF
303 | }
304 | iNdEx += skippy
305 | }
306 | }
307 |
308 | if iNdEx > l {
309 | return io.ErrUnexpectedEOF
310 | }
311 | return nil
312 | }
313 | func skipGenesis(dAtA []byte) (n int, err error) {
314 | l := len(dAtA)
315 | iNdEx := 0
316 | depth := 0
317 | for iNdEx < l {
318 | var wire uint64
319 | for shift := uint(0); ; shift += 7 {
320 | if shift >= 64 {
321 | return 0, ErrIntOverflowGenesis
322 | }
323 | if iNdEx >= l {
324 | return 0, io.ErrUnexpectedEOF
325 | }
326 | b := dAtA[iNdEx]
327 | iNdEx++
328 | wire |= (uint64(b) & 0x7F) << shift
329 | if b < 0x80 {
330 | break
331 | }
332 | }
333 | wireType := int(wire & 0x7)
334 | switch wireType {
335 | case 0:
336 | for shift := uint(0); ; shift += 7 {
337 | if shift >= 64 {
338 | return 0, ErrIntOverflowGenesis
339 | }
340 | if iNdEx >= l {
341 | return 0, io.ErrUnexpectedEOF
342 | }
343 | iNdEx++
344 | if dAtA[iNdEx-1] < 0x80 {
345 | break
346 | }
347 | }
348 | case 1:
349 | iNdEx += 8
350 | case 2:
351 | var length int
352 | for shift := uint(0); ; shift += 7 {
353 | if shift >= 64 {
354 | return 0, ErrIntOverflowGenesis
355 | }
356 | if iNdEx >= l {
357 | return 0, io.ErrUnexpectedEOF
358 | }
359 | b := dAtA[iNdEx]
360 | iNdEx++
361 | length |= (int(b) & 0x7F) << shift
362 | if b < 0x80 {
363 | break
364 | }
365 | }
366 | if length < 0 {
367 | return 0, ErrInvalidLengthGenesis
368 | }
369 | iNdEx += length
370 | case 3:
371 | depth++
372 | case 4:
373 | if depth == 0 {
374 | return 0, ErrUnexpectedEndOfGroupGenesis
375 | }
376 | depth--
377 | case 5:
378 | iNdEx += 4
379 | default:
380 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
381 | }
382 | if iNdEx < 0 {
383 | return 0, ErrInvalidLengthGenesis
384 | }
385 | if depth == 0 {
386 | return iNdEx, nil
387 | }
388 | }
389 | return 0, io.ErrUnexpectedEOF
390 | }
391 |
392 | var (
393 | ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
394 | ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
395 | ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
396 | )
397 |
--------------------------------------------------------------------------------
/x/cns/types/info.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | func (c ChainInfo) ValidateBasic() error {
4 | return nil
5 | }
6 |
7 | func (c *ChainInfo) Update(newInfo ChainInfo) {
8 | if len(newInfo.Seed) != 0 {
9 | c.Seed = newInfo.Seed
10 | }
11 |
12 | if newInfo.SourceCodeUrl != "" {
13 | c.SourceCodeUrl = newInfo.SourceCodeUrl
14 | }
15 |
16 | if newInfo.CanonicalIbcClient != "" {
17 | c.CanonicalIbcClient = newInfo.CanonicalIbcClient
18 | }
19 |
20 | if !newInfo.Version.Equal(VersionInfo{}) {
21 | if newInfo.Version.Version != 0 {
22 | c.Version.Version = newInfo.Version.Version
23 | }
24 |
25 | if newInfo.Version.GenesisHash != "" {
26 | c.Version.GenesisHash = newInfo.Version.GenesisHash
27 | }
28 |
29 | if newInfo.Version.SourceCommitHash != "" {
30 | c.Version.SourceCommitHash = newInfo.Version.SourceCommitHash
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/x/cns/types/keys.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | const (
4 | // ModuleName defines the module name
5 | ModuleName = "cns"
6 |
7 | // StoreKey defines the primary module store key
8 | StoreKey = ModuleName
9 |
10 | // RouterKey is the message route for slashing
11 | RouterKey = ModuleName
12 |
13 | // QuerierRoute defines the module's query routing key
14 | QuerierRoute = ModuleName
15 |
16 | // MemStoreKey defines the in-memory store key
17 | MemStoreKey = "mem_capability"
18 | )
19 |
20 | var (
21 | // Keys for store prefixes
22 | CnsKey = []byte{0x01} // prefix for each key
23 | )
24 |
25 | //TODO(sahith) Is using owner and addr for key an overkill??
26 | func GetStoreKey(name, addr string) []byte {
27 | return append(CnsKey, append([]byte(name), []byte(addr)...)...)
28 | }
29 |
--------------------------------------------------------------------------------
/x/cns/types/msg.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | sdk "github.com/cosmos/cosmos-sdk/types"
5 | "strings"
6 | )
7 |
8 | var (
9 | _ sdk.Msg = &MsgRegisterChainName{}
10 | _ sdk.Msg = &MsgUpdateChainInfo{}
11 | )
12 |
13 | const (
14 | TypeMsgRegisterChainName = "register_name"
15 | TypeMsgUpdateChainInfo = "update_info"
16 | )
17 |
18 | func NewMsgRegisterChainName(name, owner, seeds, sourceCodeUrl, ibcClient, commitHash, genesisHash string, version int64) *MsgRegisterChainName {
19 | return &MsgRegisterChainName{
20 | ChainName: name,
21 | Owner: owner,
22 | Seed: strings.Split(seeds, ","),
23 | SourceCodeUrl: sourceCodeUrl,
24 | CanonicalIbcClient: ibcClient,
25 | Version: &VersionInfo{
26 | Version: version,
27 | SourceCommitHash: commitHash,
28 | GenesisHash: genesisHash,
29 | },
30 | }
31 | }
32 |
33 | func (m *MsgRegisterChainName) Route() string {
34 | return RouterKey
35 | }
36 |
37 | func (m *MsgRegisterChainName) Type() string {
38 | return TypeMsgRegisterChainName
39 | }
40 |
41 | func (m *MsgRegisterChainName) ValidateBasic() error {
42 | return nil
43 | }
44 |
45 | func (m *MsgRegisterChainName) GetSignBytes() []byte {
46 | bz := ModuleCdc.MustMarshalJSON(m)
47 | return sdk.MustSortJSON(bz)
48 | }
49 |
50 | func (m *MsgRegisterChainName) GetSigners() []sdk.AccAddress {
51 | owner, err := sdk.AccAddressFromBech32(m.Owner)
52 | if err != nil {
53 | panic(err)
54 | }
55 | return []sdk.AccAddress{owner}
56 | }
57 |
58 | func NewMsgUpdateChainInfo(name, owner, seeds, sourceCodeUrl, ibcClient, commitHash, genesisHash string, version int64) *MsgUpdateChainInfo {
59 | return &MsgUpdateChainInfo{
60 | ChainName: name,
61 | Owner: owner,
62 | Seed: strings.Split(seeds, ","),
63 | SourceCodeUrl: sourceCodeUrl,
64 | CanonicalIbcClient: ibcClient,
65 | Version: &VersionInfo{
66 | Version: version,
67 | SourceCommitHash: commitHash,
68 | GenesisHash: genesisHash,
69 | },
70 | }
71 | }
72 | func (m *MsgUpdateChainInfo) Route() string {
73 | return RouterKey
74 | }
75 |
76 | func (m *MsgUpdateChainInfo) Type() string {
77 | return TypeMsgUpdateChainInfo
78 | }
79 |
80 | func (m *MsgUpdateChainInfo) ValidateBasic() error {
81 | return nil
82 | }
83 |
84 | func (m *MsgUpdateChainInfo) GetSignBytes() []byte {
85 | bz := ModuleCdc.MustMarshalJSON(m)
86 | return sdk.MustSortJSON(bz)
87 | }
88 |
89 | func (m *MsgUpdateChainInfo) GetSigners() []sdk.AccAddress {
90 | owner, err := sdk.AccAddressFromBech32(m.Owner)
91 | if err != nil {
92 | panic(err)
93 | }
94 | return []sdk.AccAddress{owner}
95 | }
96 |
--------------------------------------------------------------------------------
/x/cns/types/query.go:
--------------------------------------------------------------------------------
1 | package types
2 |
--------------------------------------------------------------------------------
/x/cns/types/query.pb.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-gogo. DO NOT EDIT.
2 | // source: cns/query.proto
3 |
4 | package types
5 |
6 | import (
7 | context "context"
8 | fmt "fmt"
9 | _ "github.com/cosmos/cosmos-sdk/types/query"
10 | _ "github.com/gogo/protobuf/gogoproto"
11 | grpc1 "github.com/gogo/protobuf/grpc"
12 | proto "github.com/gogo/protobuf/proto"
13 | _ "google.golang.org/genproto/googleapis/api/annotations"
14 | grpc "google.golang.org/grpc"
15 | codes "google.golang.org/grpc/codes"
16 | status "google.golang.org/grpc/status"
17 | io "io"
18 | math "math"
19 | math_bits "math/bits"
20 | )
21 |
22 | // Reference imports to suppress errors if they are not otherwise used.
23 | var _ = proto.Marshal
24 | var _ = fmt.Errorf
25 | var _ = math.Inf
26 |
27 | // This is a compile-time assertion to ensure that this generated file
28 | // is compatible with the proto package it is being compiled against.
29 | // A compilation error at this line likely means your copy of the
30 | // proto package needs to be updated.
31 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
32 |
33 | type QueryChainInfoRequest struct {
34 | ChainName string `protobuf:"bytes,1,opt,name=chain_name,json=chainName,proto3" json:"chain_name,omitempty"`
35 | }
36 |
37 | func (m *QueryChainInfoRequest) Reset() { *m = QueryChainInfoRequest{} }
38 | func (m *QueryChainInfoRequest) String() string { return proto.CompactTextString(m) }
39 | func (*QueryChainInfoRequest) ProtoMessage() {}
40 | func (*QueryChainInfoRequest) Descriptor() ([]byte, []int) {
41 | return fileDescriptor_45081ff63ea4c0db, []int{0}
42 | }
43 | func (m *QueryChainInfoRequest) XXX_Unmarshal(b []byte) error {
44 | return m.Unmarshal(b)
45 | }
46 | func (m *QueryChainInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
47 | if deterministic {
48 | return xxx_messageInfo_QueryChainInfoRequest.Marshal(b, m, deterministic)
49 | } else {
50 | b = b[:cap(b)]
51 | n, err := m.MarshalToSizedBuffer(b)
52 | if err != nil {
53 | return nil, err
54 | }
55 | return b[:n], nil
56 | }
57 | }
58 | func (m *QueryChainInfoRequest) XXX_Merge(src proto.Message) {
59 | xxx_messageInfo_QueryChainInfoRequest.Merge(m, src)
60 | }
61 | func (m *QueryChainInfoRequest) XXX_Size() int {
62 | return m.Size()
63 | }
64 | func (m *QueryChainInfoRequest) XXX_DiscardUnknown() {
65 | xxx_messageInfo_QueryChainInfoRequest.DiscardUnknown(m)
66 | }
67 |
68 | var xxx_messageInfo_QueryChainInfoRequest proto.InternalMessageInfo
69 |
70 | func (m *QueryChainInfoRequest) GetChainName() string {
71 | if m != nil {
72 | return m.ChainName
73 | }
74 | return ""
75 | }
76 |
77 | type QueryChainInfoResponse struct {
78 | Info ChainInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info"`
79 | }
80 |
81 | func (m *QueryChainInfoResponse) Reset() { *m = QueryChainInfoResponse{} }
82 | func (m *QueryChainInfoResponse) String() string { return proto.CompactTextString(m) }
83 | func (*QueryChainInfoResponse) ProtoMessage() {}
84 | func (*QueryChainInfoResponse) Descriptor() ([]byte, []int) {
85 | return fileDescriptor_45081ff63ea4c0db, []int{1}
86 | }
87 | func (m *QueryChainInfoResponse) XXX_Unmarshal(b []byte) error {
88 | return m.Unmarshal(b)
89 | }
90 | func (m *QueryChainInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
91 | if deterministic {
92 | return xxx_messageInfo_QueryChainInfoResponse.Marshal(b, m, deterministic)
93 | } else {
94 | b = b[:cap(b)]
95 | n, err := m.MarshalToSizedBuffer(b)
96 | if err != nil {
97 | return nil, err
98 | }
99 | return b[:n], nil
100 | }
101 | }
102 | func (m *QueryChainInfoResponse) XXX_Merge(src proto.Message) {
103 | xxx_messageInfo_QueryChainInfoResponse.Merge(m, src)
104 | }
105 | func (m *QueryChainInfoResponse) XXX_Size() int {
106 | return m.Size()
107 | }
108 | func (m *QueryChainInfoResponse) XXX_DiscardUnknown() {
109 | xxx_messageInfo_QueryChainInfoResponse.DiscardUnknown(m)
110 | }
111 |
112 | var xxx_messageInfo_QueryChainInfoResponse proto.InternalMessageInfo
113 |
114 | func (m *QueryChainInfoResponse) GetInfo() ChainInfo {
115 | if m != nil {
116 | return m.Info
117 | }
118 | return ChainInfo{}
119 | }
120 |
121 | func init() {
122 | proto.RegisterType((*QueryChainInfoRequest)(nil), "tendermint.cns.cns.QueryChainInfoRequest")
123 | proto.RegisterType((*QueryChainInfoResponse)(nil), "tendermint.cns.cns.QueryChainInfoResponse")
124 | }
125 |
126 | func init() { proto.RegisterFile("cns/query.proto", fileDescriptor_45081ff63ea4c0db) }
127 |
128 | var fileDescriptor_45081ff63ea4c0db = []byte{
129 | // 346 bytes of a gzipped FileDescriptorProto
130 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0xce, 0x2b, 0xd6,
131 | 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2a, 0x49, 0xcd,
132 | 0x4b, 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4b, 0xce, 0x2b, 0x06, 0x61, 0x29, 0x99, 0xf4,
133 | 0xfc, 0xfc, 0xf4, 0x9c, 0x54, 0xfd, 0xc4, 0x82, 0x4c, 0xfd, 0xc4, 0xbc, 0xbc, 0xfc, 0x92, 0xc4,
134 | 0x92, 0xcc, 0xfc, 0xbc, 0x62, 0x88, 0x0e, 0x29, 0xad, 0xe4, 0xfc, 0xe2, 0xdc, 0xfc, 0x62, 0xfd,
135 | 0xa4, 0xc4, 0xe2, 0x54, 0x88, 0x51, 0xfa, 0x65, 0x86, 0x49, 0xa9, 0x25, 0x89, 0x86, 0xfa, 0x05,
136 | 0x89, 0xe9, 0x99, 0x79, 0x60, 0xc5, 0x50, 0xb5, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0xa6, 0x3e,
137 | 0x88, 0x05, 0x15, 0xe5, 0x05, 0x39, 0x22, 0x19, 0x66, 0xa0, 0x92, 0x03, 0x97, 0x68, 0x20, 0xc8,
138 | 0x18, 0xe7, 0x8c, 0xc4, 0xcc, 0x3c, 0xcf, 0xbc, 0xb4, 0xfc, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2,
139 | 0x12, 0x21, 0x59, 0x2e, 0xae, 0x64, 0x90, 0x58, 0x7c, 0x5e, 0x62, 0x6e, 0xaa, 0x04, 0xa3, 0x02,
140 | 0xa3, 0x06, 0x67, 0x10, 0x27, 0x58, 0xc4, 0x2f, 0x31, 0x37, 0xd5, 0x8a, 0x63, 0xc6, 0x02, 0x79,
141 | 0xc6, 0x17, 0x0b, 0xe4, 0x19, 0x95, 0xa2, 0xb9, 0xc4, 0xd0, 0x4d, 0x28, 0x2e, 0xc8, 0xcf, 0x2b,
142 | 0x4e, 0x15, 0x32, 0xe7, 0x62, 0xc9, 0xcc, 0x4b, 0xcb, 0x07, 0x6b, 0xe6, 0x36, 0x92, 0xd5, 0xc3,
143 | 0xf4, 0xad, 0x1e, 0x5c, 0x93, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x60, 0x0d, 0x08, 0xc3,
144 | 0x8d, 0xa6, 0x32, 0x72, 0xb1, 0x82, 0x4d, 0x17, 0xea, 0x66, 0xe4, 0xe2, 0x43, 0xb5, 0x47, 0x48,
145 | 0x13, 0x9b, 0x89, 0x58, 0x7d, 0x23, 0xa5, 0x45, 0x8c, 0x52, 0x88, 0xb3, 0x95, 0x94, 0x9a, 0x2e,
146 | 0x3f, 0x99, 0xcc, 0x24, 0x23, 0x24, 0xa5, 0x0f, 0x0d, 0x2a, 0x7d, 0x90, 0xa3, 0xf4, 0xab, 0x11,
147 | 0xc1, 0x51, 0xeb, 0x64, 0x7f, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9,
148 | 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xaa,
149 | 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x08, 0x3b, 0xc1, 0xc6, 0x54,
150 | 0x80, 0xc9, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0xf0, 0x1b, 0x03, 0x02, 0x00, 0x00,
151 | 0xff, 0xff, 0xa6, 0x5f, 0xc2, 0x58, 0x14, 0x02, 0x00, 0x00,
152 | }
153 |
154 | func (this *QueryChainInfoRequest) Equal(that interface{}) bool {
155 | if that == nil {
156 | return this == nil
157 | }
158 |
159 | that1, ok := that.(*QueryChainInfoRequest)
160 | if !ok {
161 | that2, ok := that.(QueryChainInfoRequest)
162 | if ok {
163 | that1 = &that2
164 | } else {
165 | return false
166 | }
167 | }
168 | if that1 == nil {
169 | return this == nil
170 | } else if this == nil {
171 | return false
172 | }
173 | if this.ChainName != that1.ChainName {
174 | return false
175 | }
176 | return true
177 | }
178 | func (this *QueryChainInfoResponse) Equal(that interface{}) bool {
179 | if that == nil {
180 | return this == nil
181 | }
182 |
183 | that1, ok := that.(*QueryChainInfoResponse)
184 | if !ok {
185 | that2, ok := that.(QueryChainInfoResponse)
186 | if ok {
187 | that1 = &that2
188 | } else {
189 | return false
190 | }
191 | }
192 | if that1 == nil {
193 | return this == nil
194 | } else if this == nil {
195 | return false
196 | }
197 | if !this.Info.Equal(&that1.Info) {
198 | return false
199 | }
200 | return true
201 | }
202 |
203 | // Reference imports to suppress errors if they are not otherwise used.
204 | var _ context.Context
205 | var _ grpc.ClientConn
206 |
207 | // This is a compile-time assertion to ensure that this generated file
208 | // is compatible with the grpc package it is being compiled against.
209 | const _ = grpc.SupportPackageIsVersion4
210 |
211 | // QueryClient is the client API for Query service.
212 | //
213 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
214 | type QueryClient interface {
215 | QueryChainInfo(ctx context.Context, in *QueryChainInfoRequest, opts ...grpc.CallOption) (*QueryChainInfoResponse, error)
216 | }
217 |
218 | type queryClient struct {
219 | cc grpc1.ClientConn
220 | }
221 |
222 | func NewQueryClient(cc grpc1.ClientConn) QueryClient {
223 | return &queryClient{cc}
224 | }
225 |
226 | func (c *queryClient) QueryChainInfo(ctx context.Context, in *QueryChainInfoRequest, opts ...grpc.CallOption) (*QueryChainInfoResponse, error) {
227 | out := new(QueryChainInfoResponse)
228 | err := c.cc.Invoke(ctx, "/tendermint.cns.cns.Query/QueryChainInfo", in, out, opts...)
229 | if err != nil {
230 | return nil, err
231 | }
232 | return out, nil
233 | }
234 |
235 | // QueryServer is the server API for Query service.
236 | type QueryServer interface {
237 | QueryChainInfo(context.Context, *QueryChainInfoRequest) (*QueryChainInfoResponse, error)
238 | }
239 |
240 | // UnimplementedQueryServer can be embedded to have forward compatible implementations.
241 | type UnimplementedQueryServer struct {
242 | }
243 |
244 | func (*UnimplementedQueryServer) QueryChainInfo(ctx context.Context, req *QueryChainInfoRequest) (*QueryChainInfoResponse, error) {
245 | return nil, status.Errorf(codes.Unimplemented, "method QueryChainInfo not implemented")
246 | }
247 |
248 | func RegisterQueryServer(s grpc1.Server, srv QueryServer) {
249 | s.RegisterService(&_Query_serviceDesc, srv)
250 | }
251 |
252 | func _Query_QueryChainInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
253 | in := new(QueryChainInfoRequest)
254 | if err := dec(in); err != nil {
255 | return nil, err
256 | }
257 | if interceptor == nil {
258 | return srv.(QueryServer).QueryChainInfo(ctx, in)
259 | }
260 | info := &grpc.UnaryServerInfo{
261 | Server: srv,
262 | FullMethod: "/tendermint.cns.cns.Query/QueryChainInfo",
263 | }
264 | handler := func(ctx context.Context, req interface{}) (interface{}, error) {
265 | return srv.(QueryServer).QueryChainInfo(ctx, req.(*QueryChainInfoRequest))
266 | }
267 | return interceptor(ctx, in, info, handler)
268 | }
269 |
270 | var _Query_serviceDesc = grpc.ServiceDesc{
271 | ServiceName: "tendermint.cns.cns.Query",
272 | HandlerType: (*QueryServer)(nil),
273 | Methods: []grpc.MethodDesc{
274 | {
275 | MethodName: "QueryChainInfo",
276 | Handler: _Query_QueryChainInfo_Handler,
277 | },
278 | },
279 | Streams: []grpc.StreamDesc{},
280 | Metadata: "cns/query.proto",
281 | }
282 |
283 | func (m *QueryChainInfoRequest) Marshal() (dAtA []byte, err error) {
284 | size := m.Size()
285 | dAtA = make([]byte, size)
286 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
287 | if err != nil {
288 | return nil, err
289 | }
290 | return dAtA[:n], nil
291 | }
292 |
293 | func (m *QueryChainInfoRequest) MarshalTo(dAtA []byte) (int, error) {
294 | size := m.Size()
295 | return m.MarshalToSizedBuffer(dAtA[:size])
296 | }
297 |
298 | func (m *QueryChainInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
299 | i := len(dAtA)
300 | _ = i
301 | var l int
302 | _ = l
303 | if len(m.ChainName) > 0 {
304 | i -= len(m.ChainName)
305 | copy(dAtA[i:], m.ChainName)
306 | i = encodeVarintQuery(dAtA, i, uint64(len(m.ChainName)))
307 | i--
308 | dAtA[i] = 0xa
309 | }
310 | return len(dAtA) - i, nil
311 | }
312 |
313 | func (m *QueryChainInfoResponse) Marshal() (dAtA []byte, err error) {
314 | size := m.Size()
315 | dAtA = make([]byte, size)
316 | n, err := m.MarshalToSizedBuffer(dAtA[:size])
317 | if err != nil {
318 | return nil, err
319 | }
320 | return dAtA[:n], nil
321 | }
322 |
323 | func (m *QueryChainInfoResponse) MarshalTo(dAtA []byte) (int, error) {
324 | size := m.Size()
325 | return m.MarshalToSizedBuffer(dAtA[:size])
326 | }
327 |
328 | func (m *QueryChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
329 | i := len(dAtA)
330 | _ = i
331 | var l int
332 | _ = l
333 | {
334 | size, err := m.Info.MarshalToSizedBuffer(dAtA[:i])
335 | if err != nil {
336 | return 0, err
337 | }
338 | i -= size
339 | i = encodeVarintQuery(dAtA, i, uint64(size))
340 | }
341 | i--
342 | dAtA[i] = 0xa
343 | return len(dAtA) - i, nil
344 | }
345 |
346 | func encodeVarintQuery(dAtA []byte, offset int, v uint64) int {
347 | offset -= sovQuery(v)
348 | base := offset
349 | for v >= 1<<7 {
350 | dAtA[offset] = uint8(v&0x7f | 0x80)
351 | v >>= 7
352 | offset++
353 | }
354 | dAtA[offset] = uint8(v)
355 | return base
356 | }
357 | func (m *QueryChainInfoRequest) Size() (n int) {
358 | if m == nil {
359 | return 0
360 | }
361 | var l int
362 | _ = l
363 | l = len(m.ChainName)
364 | if l > 0 {
365 | n += 1 + l + sovQuery(uint64(l))
366 | }
367 | return n
368 | }
369 |
370 | func (m *QueryChainInfoResponse) Size() (n int) {
371 | if m == nil {
372 | return 0
373 | }
374 | var l int
375 | _ = l
376 | l = m.Info.Size()
377 | n += 1 + l + sovQuery(uint64(l))
378 | return n
379 | }
380 |
381 | func sovQuery(x uint64) (n int) {
382 | return (math_bits.Len64(x|1) + 6) / 7
383 | }
384 | func sozQuery(x uint64) (n int) {
385 | return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63))))
386 | }
387 | func (m *QueryChainInfoRequest) Unmarshal(dAtA []byte) error {
388 | l := len(dAtA)
389 | iNdEx := 0
390 | for iNdEx < l {
391 | preIndex := iNdEx
392 | var wire uint64
393 | for shift := uint(0); ; shift += 7 {
394 | if shift >= 64 {
395 | return ErrIntOverflowQuery
396 | }
397 | if iNdEx >= l {
398 | return io.ErrUnexpectedEOF
399 | }
400 | b := dAtA[iNdEx]
401 | iNdEx++
402 | wire |= uint64(b&0x7F) << shift
403 | if b < 0x80 {
404 | break
405 | }
406 | }
407 | fieldNum := int32(wire >> 3)
408 | wireType := int(wire & 0x7)
409 | if wireType == 4 {
410 | return fmt.Errorf("proto: QueryChainInfoRequest: wiretype end group for non-group")
411 | }
412 | if fieldNum <= 0 {
413 | return fmt.Errorf("proto: QueryChainInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire)
414 | }
415 | switch fieldNum {
416 | case 1:
417 | if wireType != 2 {
418 | return fmt.Errorf("proto: wrong wireType = %d for field ChainName", wireType)
419 | }
420 | var stringLen uint64
421 | for shift := uint(0); ; shift += 7 {
422 | if shift >= 64 {
423 | return ErrIntOverflowQuery
424 | }
425 | if iNdEx >= l {
426 | return io.ErrUnexpectedEOF
427 | }
428 | b := dAtA[iNdEx]
429 | iNdEx++
430 | stringLen |= uint64(b&0x7F) << shift
431 | if b < 0x80 {
432 | break
433 | }
434 | }
435 | intStringLen := int(stringLen)
436 | if intStringLen < 0 {
437 | return ErrInvalidLengthQuery
438 | }
439 | postIndex := iNdEx + intStringLen
440 | if postIndex < 0 {
441 | return ErrInvalidLengthQuery
442 | }
443 | if postIndex > l {
444 | return io.ErrUnexpectedEOF
445 | }
446 | m.ChainName = string(dAtA[iNdEx:postIndex])
447 | iNdEx = postIndex
448 | default:
449 | iNdEx = preIndex
450 | skippy, err := skipQuery(dAtA[iNdEx:])
451 | if err != nil {
452 | return err
453 | }
454 | if (skippy < 0) || (iNdEx+skippy) < 0 {
455 | return ErrInvalidLengthQuery
456 | }
457 | if (iNdEx + skippy) > l {
458 | return io.ErrUnexpectedEOF
459 | }
460 | iNdEx += skippy
461 | }
462 | }
463 |
464 | if iNdEx > l {
465 | return io.ErrUnexpectedEOF
466 | }
467 | return nil
468 | }
469 | func (m *QueryChainInfoResponse) Unmarshal(dAtA []byte) error {
470 | l := len(dAtA)
471 | iNdEx := 0
472 | for iNdEx < l {
473 | preIndex := iNdEx
474 | var wire uint64
475 | for shift := uint(0); ; shift += 7 {
476 | if shift >= 64 {
477 | return ErrIntOverflowQuery
478 | }
479 | if iNdEx >= l {
480 | return io.ErrUnexpectedEOF
481 | }
482 | b := dAtA[iNdEx]
483 | iNdEx++
484 | wire |= uint64(b&0x7F) << shift
485 | if b < 0x80 {
486 | break
487 | }
488 | }
489 | fieldNum := int32(wire >> 3)
490 | wireType := int(wire & 0x7)
491 | if wireType == 4 {
492 | return fmt.Errorf("proto: QueryChainInfoResponse: wiretype end group for non-group")
493 | }
494 | if fieldNum <= 0 {
495 | return fmt.Errorf("proto: QueryChainInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire)
496 | }
497 | switch fieldNum {
498 | case 1:
499 | if wireType != 2 {
500 | return fmt.Errorf("proto: wrong wireType = %d for field Info", wireType)
501 | }
502 | var msglen int
503 | for shift := uint(0); ; shift += 7 {
504 | if shift >= 64 {
505 | return ErrIntOverflowQuery
506 | }
507 | if iNdEx >= l {
508 | return io.ErrUnexpectedEOF
509 | }
510 | b := dAtA[iNdEx]
511 | iNdEx++
512 | msglen |= int(b&0x7F) << shift
513 | if b < 0x80 {
514 | break
515 | }
516 | }
517 | if msglen < 0 {
518 | return ErrInvalidLengthQuery
519 | }
520 | postIndex := iNdEx + msglen
521 | if postIndex < 0 {
522 | return ErrInvalidLengthQuery
523 | }
524 | if postIndex > l {
525 | return io.ErrUnexpectedEOF
526 | }
527 | if err := m.Info.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
528 | return err
529 | }
530 | iNdEx = postIndex
531 | default:
532 | iNdEx = preIndex
533 | skippy, err := skipQuery(dAtA[iNdEx:])
534 | if err != nil {
535 | return err
536 | }
537 | if (skippy < 0) || (iNdEx+skippy) < 0 {
538 | return ErrInvalidLengthQuery
539 | }
540 | if (iNdEx + skippy) > l {
541 | return io.ErrUnexpectedEOF
542 | }
543 | iNdEx += skippy
544 | }
545 | }
546 |
547 | if iNdEx > l {
548 | return io.ErrUnexpectedEOF
549 | }
550 | return nil
551 | }
552 | func skipQuery(dAtA []byte) (n int, err error) {
553 | l := len(dAtA)
554 | iNdEx := 0
555 | depth := 0
556 | for iNdEx < l {
557 | var wire uint64
558 | for shift := uint(0); ; shift += 7 {
559 | if shift >= 64 {
560 | return 0, ErrIntOverflowQuery
561 | }
562 | if iNdEx >= l {
563 | return 0, io.ErrUnexpectedEOF
564 | }
565 | b := dAtA[iNdEx]
566 | iNdEx++
567 | wire |= (uint64(b) & 0x7F) << shift
568 | if b < 0x80 {
569 | break
570 | }
571 | }
572 | wireType := int(wire & 0x7)
573 | switch wireType {
574 | case 0:
575 | for shift := uint(0); ; shift += 7 {
576 | if shift >= 64 {
577 | return 0, ErrIntOverflowQuery
578 | }
579 | if iNdEx >= l {
580 | return 0, io.ErrUnexpectedEOF
581 | }
582 | iNdEx++
583 | if dAtA[iNdEx-1] < 0x80 {
584 | break
585 | }
586 | }
587 | case 1:
588 | iNdEx += 8
589 | case 2:
590 | var length int
591 | for shift := uint(0); ; shift += 7 {
592 | if shift >= 64 {
593 | return 0, ErrIntOverflowQuery
594 | }
595 | if iNdEx >= l {
596 | return 0, io.ErrUnexpectedEOF
597 | }
598 | b := dAtA[iNdEx]
599 | iNdEx++
600 | length |= (int(b) & 0x7F) << shift
601 | if b < 0x80 {
602 | break
603 | }
604 | }
605 | if length < 0 {
606 | return 0, ErrInvalidLengthQuery
607 | }
608 | iNdEx += length
609 | case 3:
610 | depth++
611 | case 4:
612 | if depth == 0 {
613 | return 0, ErrUnexpectedEndOfGroupQuery
614 | }
615 | depth--
616 | case 5:
617 | iNdEx += 4
618 | default:
619 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
620 | }
621 | if iNdEx < 0 {
622 | return 0, ErrInvalidLengthQuery
623 | }
624 | if depth == 0 {
625 | return iNdEx, nil
626 | }
627 | }
628 | return 0, io.ErrUnexpectedEOF
629 | }
630 |
631 | var (
632 | ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling")
633 | ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow")
634 | ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group")
635 | )
636 |
--------------------------------------------------------------------------------
/x/cns/types/query.pb.gw.go:
--------------------------------------------------------------------------------
1 | // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
2 | // source: cns/query.proto
3 |
4 | /*
5 | Package types is a reverse proxy.
6 |
7 | It translates gRPC into RESTful JSON APIs.
8 | */
9 | package types
10 |
11 | import (
12 | "context"
13 | "io"
14 | "net/http"
15 |
16 | "github.com/golang/protobuf/descriptor"
17 | "github.com/golang/protobuf/proto"
18 | "github.com/grpc-ecosystem/grpc-gateway/runtime"
19 | "github.com/grpc-ecosystem/grpc-gateway/utilities"
20 | "google.golang.org/grpc"
21 | "google.golang.org/grpc/codes"
22 | "google.golang.org/grpc/grpclog"
23 | "google.golang.org/grpc/metadata"
24 | "google.golang.org/grpc/status"
25 | )
26 |
27 | // Suppress "imported and not used" errors
28 | var _ codes.Code
29 | var _ io.Reader
30 | var _ status.Status
31 | var _ = runtime.String
32 | var _ = utilities.NewDoubleArray
33 | var _ = descriptor.ForMessage
34 | var _ = metadata.Join
35 |
36 | func request_Query_QueryChainInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
37 | var protoReq QueryChainInfoRequest
38 | var metadata runtime.ServerMetadata
39 |
40 | var (
41 | val string
42 | ok bool
43 | err error
44 | _ = err
45 | )
46 |
47 | val, ok = pathParams["chain_name"]
48 | if !ok {
49 | return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_name")
50 | }
51 |
52 | protoReq.ChainName, err = runtime.String(val)
53 |
54 | if err != nil {
55 | return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_name", err)
56 | }
57 |
58 | msg, err := client.QueryChainInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
59 | return msg, metadata, err
60 |
61 | }
62 |
63 | func local_request_Query_QueryChainInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
64 | var protoReq QueryChainInfoRequest
65 | var metadata runtime.ServerMetadata
66 |
67 | var (
68 | val string
69 | ok bool
70 | err error
71 | _ = err
72 | )
73 |
74 | val, ok = pathParams["chain_name"]
75 | if !ok {
76 | return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "chain_name")
77 | }
78 |
79 | protoReq.ChainName, err = runtime.String(val)
80 |
81 | if err != nil {
82 | return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chain_name", err)
83 | }
84 |
85 | msg, err := server.QueryChainInfo(ctx, &protoReq)
86 | return msg, metadata, err
87 |
88 | }
89 |
90 | // RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
91 | // UnaryRPC :call QueryServer directly.
92 | // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
93 | // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.
94 | func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error {
95 |
96 | mux.Handle("GET", pattern_Query_QueryChainInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
97 | ctx, cancel := context.WithCancel(req.Context())
98 | defer cancel()
99 | var stream runtime.ServerTransportStream
100 | ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
101 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
102 | rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
103 | if err != nil {
104 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
105 | return
106 | }
107 | resp, md, err := local_request_Query_QueryChainInfo_0(rctx, inboundMarshaler, server, req, pathParams)
108 | md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
109 | ctx = runtime.NewServerMetadataContext(ctx, md)
110 | if err != nil {
111 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
112 | return
113 | }
114 |
115 | forward_Query_QueryChainInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
116 |
117 | })
118 |
119 | return nil
120 | }
121 |
122 | // RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
123 | // automatically dials to "endpoint" and closes the connection when "ctx" gets done.
124 | func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
125 | conn, err := grpc.Dial(endpoint, opts...)
126 | if err != nil {
127 | return err
128 | }
129 | defer func() {
130 | if err != nil {
131 | if cerr := conn.Close(); cerr != nil {
132 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
133 | }
134 | return
135 | }
136 | go func() {
137 | <-ctx.Done()
138 | if cerr := conn.Close(); cerr != nil {
139 | grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
140 | }
141 | }()
142 | }()
143 |
144 | return RegisterQueryHandler(ctx, mux, conn)
145 | }
146 |
147 | // RegisterQueryHandler registers the http handlers for service Query to "mux".
148 | // The handlers forward requests to the grpc endpoint over "conn".
149 | func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
150 | return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
151 | }
152 |
153 | // RegisterQueryHandlerClient registers the http handlers for service Query
154 | // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
155 | // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
156 | // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
157 | // "QueryClient" to call the correct interceptors.
158 | func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
159 |
160 | mux.Handle("GET", pattern_Query_QueryChainInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
161 | ctx, cancel := context.WithCancel(req.Context())
162 | defer cancel()
163 | inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
164 | rctx, err := runtime.AnnotateContext(ctx, mux, req)
165 | if err != nil {
166 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
167 | return
168 | }
169 | resp, md, err := request_Query_QueryChainInfo_0(rctx, inboundMarshaler, client, req, pathParams)
170 | ctx = runtime.NewServerMetadataContext(ctx, md)
171 | if err != nil {
172 | runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
173 | return
174 | }
175 |
176 | forward_Query_QueryChainInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
177 |
178 | })
179 |
180 | return nil
181 | }
182 |
183 | var (
184 | pattern_Query_QueryChainInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"cns", "info", "chain_name"}, "", runtime.AssumeColonVerbOpt(true)))
185 | )
186 |
187 | var (
188 | forward_Query_QueryChainInfo_0 = runtime.ForwardResponseMessage
189 | )
190 |
--------------------------------------------------------------------------------
/x/cns/types/types.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import sdk "github.com/cosmos/cosmos-sdk/types"
4 |
5 | var DefaultFee = func(denom string) sdk.Coin { return sdk.NewCoin(denom, sdk.NewInt(100000)) }
6 |
7 | const DefaultDenom = sdk.DefaultBondDenom
8 |
--------------------------------------------------------------------------------