├── .gitignore
├── LICENSE
├── README.md
├── client.go
├── go.mod
├── go.sum
├── modules
├── apps
│ ├── mt_transfer
│ │ ├── codec.go
│ │ ├── mt_transfer.pb.go
│ │ ├── tx.pb.go
│ │ └── types.go
│ └── nft_transfer
│ │ ├── codec.go
│ │ ├── nft_transfer.pb.go
│ │ ├── tx.pb.go
│ │ └── types.go
├── core
│ ├── client
│ │ ├── client.pb.go
│ │ ├── genesis.pb.go
│ │ ├── height.go
│ │ ├── query.pb.go
│ │ ├── query.pb.gw.go
│ │ ├── tx.pb.go
│ │ └── types.go
│ ├── commitment
│ │ ├── commitment.pb.go
│ │ ├── errors.go
│ │ ├── types.go
│ │ └── utils.go
│ └── packet
│ │ ├── codec.go
│ │ ├── errors.go
│ │ ├── genesis.pb.go
│ │ ├── keys.go
│ │ ├── packet.pb.go
│ │ ├── query.pb.go
│ │ ├── query.pb.gw.go
│ │ ├── tx.pb.go
│ │ └── types.go
├── light-clients
│ ├── bsc
│ │ ├── bsc.go
│ │ ├── bsc.pb.go
│ │ ├── client_state.go
│ │ ├── codec.go
│ │ ├── consensus_state.go
│ │ ├── errors.go
│ │ ├── hashing.go
│ │ └── header.go
│ ├── eth
│ │ ├── client_state.go
│ │ ├── codec.go
│ │ ├── consensus_state.go
│ │ ├── eth.go
│ │ ├── eth.pb.go
│ │ ├── hashing.go
│ │ └── header.go
│ └── tendermint
│ │ ├── client_state.go
│ │ ├── codec.go
│ │ ├── consensus_state.go
│ │ ├── errors.go
│ │ ├── header.go
│ │ ├── tendermint.pb.go
│ │ └── types.go
└── types
│ ├── errors.go
│ └── exported.go
├── proto
└── tibc
│ ├── apps
│ ├── mt_transfer
│ │ └── v1
│ │ │ ├── mt_transfer.proto
│ │ │ └── tx.proto
│ └── nft_transfer
│ │ └── v1
│ │ ├── nft_transfer.proto
│ │ └── tx.proto
│ ├── core
│ ├── client
│ │ └── v1
│ │ │ ├── client.proto
│ │ │ ├── genesis.proto
│ │ │ ├── query.proto
│ │ │ └── tx.proto
│ ├── commitment
│ │ └── v1
│ │ │ └── commitment.proto
│ └── packet
│ │ └── v1
│ │ ├── genesis.proto
│ │ ├── packet.proto
│ │ ├── query.proto
│ │ └── tx.proto
│ └── lightclients
│ ├── bsc
│ └── v1
│ │ └── bsc.proto
│ ├── eth
│ └── v1
│ │ └── eth.proto
│ └── tendermint
│ └── v1
│ └── tendermint.proto
├── scripts
├── Makefile
└── protocgen.sh
├── testing
└── integration_test
│ ├── Tendermit_lightClient.go
│ ├── Tendermit_lightClient_test.go
│ ├── client.go
│ ├── getjson.go
│ └── packet.go
└── third_party
└── proto
├── confio
└── proofs.proto
├── cosmos
└── base
│ ├── query
│ └── v1beta1
│ │ └── pagination.proto
│ └── v1beta1
│ └── coin.proto
├── cosmos_proto
└── cosmos.proto
├── gogoproto
└── gogo.proto
├── google
├── api
│ ├── annotations.proto
│ ├── http.proto
│ └── httpbody.proto
└── protobuf
│ └── any.proto
└── tendermint
├── abci
└── types.proto
├── crypto
├── keys.proto
└── proof.proto
├── libs
└── bits
│ └── types.proto
├── p2p
└── types.proto
├── types
├── block.proto
├── evidence.proto
├── params.proto
├── types.proto
└── validator.proto
└── version
└── types.proto
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | .DS_Store
3 | .vscode
4 | .idea
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # tibc-sdk-go
2 |
3 | Golang SDK for Terse IBC
4 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/bianjieai/tibc-sdk-go
2 |
3 | go 1.15
4 |
5 | require (
6 | github.com/confio/ics23/go v0.6.6
7 | github.com/ethereum/go-ethereum v1.10.16
8 | github.com/gogo/protobuf v1.3.3
9 | github.com/golang/protobuf v1.5.2
10 | github.com/grpc-ecosystem/grpc-gateway v1.16.0
11 | github.com/irisnet/core-sdk-go v0.0.0-20220906070548-0c9d0a868f37
12 | github.com/pkg/errors v0.9.1
13 | github.com/tendermint/tendermint v0.34.21
14 | golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
15 | google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b
16 | google.golang.org/grpc v1.48.0
17 | google.golang.org/protobuf v1.28.0
18 | )
19 |
20 | replace (
21 | github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
22 | github.com/tendermint/tendermint => github.com/bianjieai/tendermint v0.34.21-irita-220906
23 | )
24 |
--------------------------------------------------------------------------------
/modules/apps/mt_transfer/codec.go:
--------------------------------------------------------------------------------
1 | package mt_transfer
2 |
3 | import (
4 | "github.com/irisnet/core-sdk-go/common/codec"
5 | "github.com/irisnet/core-sdk-go/common/codec/types"
6 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
7 | sdk "github.com/irisnet/core-sdk-go/types"
8 | )
9 |
10 | var (
11 | amino = codec.NewLegacyAmino()
12 | ModuleCdc = codec.NewAminoCodec(amino)
13 | )
14 |
15 | func init() {
16 | cryptocodec.RegisterCrypto(amino)
17 | amino.Seal()
18 | }
19 |
20 | func RegisterInterfaces(registry types.InterfaceRegistry) {
21 | registry.RegisterImplementations(
22 | (*sdk.Msg)(nil),
23 | &MsgMtTransfer{},
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/modules/apps/mt_transfer/types.go:
--------------------------------------------------------------------------------
1 | package mt_transfer
2 |
3 | import sdk "github.com/irisnet/core-sdk-go/types"
4 |
5 | // Route Implements Msg
6 | func (msg MsgMtTransfer) Route() string { return "MT" }
7 |
8 | // Type Implements Msg
9 | func (msg MsgMtTransfer) Type() string { return "tibc_mt_transfer" }
10 |
11 | // GetSignBytes implements sdk.Msg.
12 | func (msg MsgMtTransfer) GetSignBytes() []byte {
13 | return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
14 | }
15 |
16 | // GetSigners implements sdk.Msg
17 | func (msg MsgMtTransfer) GetSigners() []sdk.AccAddress {
18 | signer, err := sdk.AccAddressFromBech32(msg.Sender)
19 | if err != nil {
20 | panic(err)
21 | }
22 | return []sdk.AccAddress{signer}
23 | }
24 |
25 | // ValidateBasic Implements Msg.
26 | func (msg MsgMtTransfer) ValidateBasic() error {
27 | return nil
28 | }
29 |
--------------------------------------------------------------------------------
/modules/apps/nft_transfer/codec.go:
--------------------------------------------------------------------------------
1 | package nft_transfer
2 |
3 | import (
4 | "github.com/irisnet/core-sdk-go/common/codec"
5 | "github.com/irisnet/core-sdk-go/common/codec/types"
6 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
7 | sdk "github.com/irisnet/core-sdk-go/types"
8 | )
9 |
10 | var (
11 | amino = codec.NewLegacyAmino()
12 | ModuleCdc = codec.NewAminoCodec(amino)
13 | )
14 |
15 | func init() {
16 | cryptocodec.RegisterCrypto(amino)
17 | amino.Seal()
18 | }
19 |
20 | func RegisterInterfaces(registry types.InterfaceRegistry) {
21 | registry.RegisterImplementations(
22 | (*sdk.Msg)(nil),
23 | &MsgNftTransfer{},
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/modules/apps/nft_transfer/types.go:
--------------------------------------------------------------------------------
1 | package nft_transfer
2 |
3 | import sdk "github.com/irisnet/core-sdk-go/types"
4 |
5 | // Route Implements Msg
6 | func (msg MsgNftTransfer) Route() string { return "NFT" }
7 |
8 | // Type Implements Msg
9 | func (msg MsgNftTransfer) Type() string { return "tibc_nft_transfer" }
10 |
11 | // GetSignBytes implements sdk.Msg.
12 | func (msg MsgNftTransfer) GetSignBytes() []byte {
13 | return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
14 | }
15 |
16 | // GetSigners implements sdk.Msg
17 | func (msg MsgNftTransfer) GetSigners() []sdk.AccAddress {
18 | signer, err := sdk.AccAddressFromBech32(msg.Sender)
19 | if err != nil {
20 | panic(err)
21 | }
22 | return []sdk.AccAddress{signer}
23 | }
24 |
25 | // ValidateBasic Implements Msg.
26 | func (msg MsgNftTransfer) ValidateBasic() error {
27 | return nil
28 | }
29 |
--------------------------------------------------------------------------------
/modules/core/client/height.go:
--------------------------------------------------------------------------------
1 | package client
2 |
3 | import (
4 | "fmt"
5 | "regexp"
6 |
7 | "github.com/bianjieai/tibc-sdk-go/modules/types"
8 | )
9 |
10 | var _ types.Height = (*Height)(nil)
11 |
12 | // IsRevisionFormat checks if a chainID is in the format required for parsing revisions
13 | // The chainID must be in the form: `{chainID}-{revision}
14 | // 24-host may enforce stricter checks on chainID
15 | var IsRevisionFormat = regexp.MustCompile(`^.*[^-]-{1}[1-9][0-9]*$`).MatchString
16 |
17 | // ZeroHeight is a helper function which returns an uninitialized height.
18 | func ZeroHeight() Height {
19 | return Height{}
20 | }
21 |
22 | // NewHeight is a constructor for the IBC height type
23 | func NewHeight(revisionNumber, revisionHeight uint64) Height {
24 | return Height{
25 | RevisionNumber: revisionNumber,
26 | RevisionHeight: revisionHeight,
27 | }
28 | }
29 |
30 | // GetRevisionNumber returns the revision-number of the height
31 | func (h Height) GetRevisionNumber() uint64 {
32 | return h.RevisionNumber
33 | }
34 |
35 | // GetRevisionHeight returns the revision-height of the height
36 | func (h Height) GetRevisionHeight() uint64 {
37 | return h.RevisionHeight
38 | }
39 |
40 | // String returns a string representation of Height
41 | func (h Height) String() string {
42 | return fmt.Sprintf("%d-%d", h.RevisionNumber, h.RevisionHeight)
43 | }
44 |
45 | // Decrement will return a new height with the RevisionHeight decremented
46 | // If the RevisionHeight is already at lowest value (1), then false success flag is returend
47 | func (h Height) Decrement() (decremented types.Height, success bool) {
48 | if h.RevisionHeight == 0 {
49 | return Height{}, false
50 | }
51 | return NewHeight(h.RevisionNumber, h.RevisionHeight-1), true
52 | }
53 |
54 | // Increment will return a height with the same revision number but an
55 | // incremented revision height
56 | func (h Height) Increment() types.Height {
57 | return NewHeight(h.RevisionNumber, h.RevisionHeight+1)
58 | }
59 |
60 | // IsZero returns true if height revision and revision-height are both 0
61 | func (h Height) IsZero() bool {
62 | return h.RevisionNumber == 0 && h.RevisionHeight == 0
63 | }
64 |
--------------------------------------------------------------------------------
/modules/core/client/types.go:
--------------------------------------------------------------------------------
1 | package client
2 |
3 | import (
4 | "regexp"
5 | "sort"
6 | "strings"
7 |
8 | "github.com/bianjieai/tibc-sdk-go/modules/types"
9 | coretypes "github.com/irisnet/core-sdk-go/common/codec/types"
10 | sdk "github.com/irisnet/core-sdk-go/types"
11 | )
12 |
13 | var IsValidID = regexp.MustCompile(`^[a-zA-Z0-9\.\_\+\-\#\[\]\<\>]+$`).MatchString
14 |
15 | type IdentifiedClientStates []IdentifiedClientState
16 | type ClientsConsensusStates []ClientConsensusStates
17 |
18 | // Len implements sort.Interface
19 | func (ics IdentifiedClientStates) Len() int { return len(ics) }
20 |
21 | // Less implements sort.Interface
22 | func (ics IdentifiedClientStates) Less(i, j int) bool { return ics[i].ChainName < ics[j].ChainName }
23 |
24 | // Swap implements sort.Interface
25 | func (ics IdentifiedClientStates) Swap(i, j int) { ics[i], ics[j] = ics[j], ics[i] }
26 |
27 | // Sort is a helper function to sort the set of IdentifiedClientStates in place
28 | func (ics IdentifiedClientStates) Sort() IdentifiedClientStates {
29 | sort.Sort(ics)
30 | return ics
31 | }
32 |
33 | func (m *MsgUpdateClient) Route() string {
34 | return "tibc"
35 | }
36 |
37 | func (m *MsgUpdateClient) Type() string {
38 | return "update_client"
39 | }
40 |
41 | func (m *MsgUpdateClient) ValidateBasic() error {
42 | _, err0 := sdk.AccAddressFromBech32(m.Signer)
43 | if err0 != nil {
44 | return types.Wrapf(types.ErrInvalidAddress, "string could not be parsed as address: %v", err0)
45 | }
46 | header, err1 := UnpackHeader(m.Header)
47 | if err1 != nil {
48 | return err1
49 | }
50 | if err2 := header.ValidateBasic(); err2 != nil {
51 | return err2
52 | }
53 | return ClientIdentifierValidator(m.ChainName)
54 | }
55 | func ClientIdentifierValidator(id string) error {
56 | return defaultIdentifierValidator(id, 9, 64)
57 | }
58 |
59 | func defaultIdentifierValidator(id string, min, max int) error {
60 | if strings.TrimSpace(id) == "" {
61 | return types.Wrap(types.ErrInvalidID, "identifier cannot be blank")
62 | }
63 | // valid id MUST NOT contain "/" separator
64 | if strings.Contains(id, "/") {
65 | return types.Wrapf(types.ErrInvalidID, "identifier %s cannot contain separator '/'", id)
66 | }
67 | // valid id must fit the length requirements
68 | if len(id) < min || len(id) > max {
69 | return types.Wrapf(types.ErrInvalidID, "identifier %s has invalid length: %d, must be between %d-%d characters", id, len(id), min, max)
70 | }
71 | // valid id must contain only lower alphabetic characters
72 | if !IsValidID(id) {
73 | return types.Wrapf(
74 | types.ErrInvalidID,
75 | "identifier %s must contain only alphanumeric or the following characters: '.', '_', '+', '-', '#', '[', ']', '<', '>'",
76 | id,
77 | )
78 | }
79 | return nil
80 | }
81 |
82 | func (m *MsgUpdateClient) GetSignBytes() []byte {
83 | return []byte(m.Signer)
84 | }
85 |
86 | func (m *MsgUpdateClient) GetSigners() []sdk.AccAddress {
87 | accAddr, err := sdk.AccAddressFromBech32(m.Signer)
88 | if err != nil {
89 | panic(err)
90 | }
91 | return []sdk.AccAddress{accAddr}
92 | }
93 |
94 | // UnpackHeader unpacks an Any into a Header. It returns an error if the
95 | // consensus state can't be unpacked into a Header.
96 | // TODO: where to put this
97 | func UnpackHeader(any *coretypes.Any) (types.Header, error) {
98 | if any == nil {
99 | return nil, types.Wrap(types.ErrUnpackAny, "protobuf Any message cannot be nil")
100 | }
101 |
102 | header, ok := any.GetCachedValue().(types.Header)
103 | if !ok {
104 | return nil, types.Wrapf(types.ErrUnpackAny, "cannot unpack Any into Header %T", any)
105 | }
106 |
107 | return header, nil
108 | }
109 |
--------------------------------------------------------------------------------
/modules/core/commitment/errors.go:
--------------------------------------------------------------------------------
1 | package commitment
2 |
3 | import (
4 | "github.com/bianjieai/tibc-sdk-go/modules/types"
5 | )
6 |
7 | // SubModuleName is the error codespace
8 | const SubModuleName string = "commitment"
9 |
10 | const moduleName = "tibc" + "-" + SubModuleName
11 |
12 | // IBC connection sentinel errors
13 | var (
14 | ErrInvalidProof = types.Register(moduleName, 2, "invalid proof")
15 | ErrInvalidPrefix = types.Register(moduleName, 3, "invalid prefix")
16 | ErrInvalidMerkleProof = types.Register(moduleName, 4, "invalid merkle proof")
17 | )
18 |
--------------------------------------------------------------------------------
/modules/core/commitment/types.go:
--------------------------------------------------------------------------------
1 | package commitment
2 |
3 | import (
4 | "net/url"
5 |
6 | "github.com/bianjieai/tibc-sdk-go/modules/types"
7 | ics23 "github.com/confio/ics23/go"
8 | )
9 |
10 | var sdkSpecs = []*ics23.ProofSpec{ics23.IavlSpec, ics23.TendermintSpec}
11 |
12 | func (mp MerklePath) String() string {
13 | pathStr := ""
14 | for _, k := range mp.KeyPath {
15 | pathStr += "/" + url.PathEscape(k)
16 | }
17 | return pathStr
18 | }
19 |
20 | // Prefix implements spec:CommitmentPrefix.
21 | // Prefix represents the common "prefix" that a set of keys shares.
22 | type Prefix interface {
23 | Bytes() []byte
24 | Empty() bool
25 | }
26 |
27 | // NewMerklePrefix constructs new MerklePrefix instance
28 | func NewMerklePrefix(keyPrefix []byte) MerklePrefix {
29 | return MerklePrefix{
30 | KeyPrefix: keyPrefix,
31 | }
32 | }
33 |
34 | // Bytes returns the key prefix bytes
35 | func (mp MerklePrefix) Bytes() []byte {
36 | return mp.KeyPrefix
37 | }
38 |
39 | // Empty returns true if the prefix is empty
40 | func (mp MerklePrefix) Empty() bool {
41 | return len(mp.Bytes()) == 0
42 | }
43 |
44 | // Merkle proof implementation of the Proof interface
45 | // Applied on SDK-based IBC implementation
46 | var _ types.Root = (*MerkleRoot)(nil)
47 |
48 | // GetSDKSpecs is a getter function for the proofspecs of an sdk chain
49 | func GetSDKSpecs() []*ics23.ProofSpec {
50 | return sdkSpecs
51 | }
52 |
53 | // NewMerkleRoot constructs a new MerkleRoot
54 | func NewMerkleRoot(hash []byte) MerkleRoot {
55 | return MerkleRoot{
56 | Hash: hash,
57 | }
58 | }
59 |
60 | // GetHash implements RootI interface
61 | func (mr MerkleRoot) GetHash() []byte {
62 | return mr.Hash
63 | }
64 |
65 | // Empty returns true if the root is empty
66 | func (mr MerkleRoot) Empty() bool {
67 | return len(mr.GetHash()) == 0
68 | }
69 |
--------------------------------------------------------------------------------
/modules/core/commitment/utils.go:
--------------------------------------------------------------------------------
1 | package commitment
2 |
3 | import (
4 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
5 | ics23 "github.com/confio/ics23/go"
6 | "github.com/tendermint/tendermint/proto/tendermint/crypto"
7 | )
8 |
9 | // ConvertProofs converts crypto.ProofOps into MerkleProof
10 | func ConvertProofs(tmProof *crypto.ProofOps) (MerkleProof, error) {
11 | if tmProof == nil {
12 | return MerkleProof{}, tibctypes.Wrapf(ErrInvalidMerkleProof, "tendermint proof is nil")
13 | }
14 | // Unmarshal all proof ops to CommitmentProof
15 | proofs := make([]*ics23.CommitmentProof, len(tmProof.Ops))
16 | for i, op := range tmProof.Ops {
17 | var p ics23.CommitmentProof
18 | err := p.Unmarshal(op.Data)
19 | if err != nil || p.Proof == nil {
20 | return MerkleProof{}, tibctypes.Wrapf(ErrInvalidMerkleProof, "could not unmarshal proof op into CommitmentProof at index %d: %v", i, err)
21 | }
22 | proofs[i] = &p
23 | }
24 | return MerkleProof{
25 | Proofs: proofs,
26 | }, nil
27 | }
28 |
--------------------------------------------------------------------------------
/modules/core/packet/codec.go:
--------------------------------------------------------------------------------
1 | package packet
2 |
3 | import (
4 | "github.com/irisnet/core-sdk-go/common/codec"
5 | "github.com/irisnet/core-sdk-go/common/codec/types"
6 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
7 | sdk "github.com/irisnet/core-sdk-go/types"
8 | )
9 |
10 | var (
11 | amino = codec.NewLegacyAmino()
12 | ModuleCdc = codec.NewAminoCodec(amino)
13 | )
14 |
15 | func init() {
16 | cryptocodec.RegisterCrypto(amino)
17 | amino.Seal()
18 | }
19 |
20 | func RegisterInterfaces(registry types.InterfaceRegistry) {
21 | registry.RegisterImplementations(
22 | (*sdk.Msg)(nil),
23 | &MsgAcknowledgement{},
24 | &MsgCleanPacket{},
25 | &MsgRecvPacket{},
26 | &MsgRecvCleanPacket{},
27 | )
28 | }
29 |
--------------------------------------------------------------------------------
/modules/core/packet/errors.go:
--------------------------------------------------------------------------------
1 | package packet
2 |
3 | import "github.com/bianjieai/tibc-sdk-go/modules/types"
4 |
5 | const moduleName = "tibc" + "-" + "packet"
6 |
7 | // TIBC packet sentinel errors
8 | var (
9 | ErrSequenceSendNotFound = types.Register(moduleName, 2, "sequence send not found")
10 | ErrSequenceReceiveNotFound = types.Register(moduleName, 3, "sequence receive not found")
11 | ErrSequenceAckNotFound = types.Register(moduleName, 4, "sequence acknowledgement not found")
12 | ErrInvalidPacket = types.Register(moduleName, 5, "invalid packet")
13 | ErrInvalidAcknowledgement = types.Register(moduleName, 6, "invalid acknowledgement")
14 | ErrPacketCommitmentNotFound = types.Register(moduleName, 7, "packet commitment not found")
15 | ErrPacketReceived = types.Register(moduleName, 8, "packet already received")
16 | ErrAcknowledgementExists = types.Register(moduleName, 9, "acknowledgement for packet already exists")
17 | ErrInvalidCleanPacket = types.Register(moduleName, 10, "invalid clean packet")
18 | )
19 |
--------------------------------------------------------------------------------
/modules/core/packet/keys.go:
--------------------------------------------------------------------------------
1 | package packet
2 |
3 | import (
4 | "fmt"
5 |
6 | tibcclient "github.com/bianjieai/tibc-sdk-go/modules/core/client"
7 | )
8 |
9 | const (
10 | // ModuleName is the name of the IBC module
11 | ModuleName = "tibc"
12 |
13 | // StoreKey is the string store representation
14 | StoreKey string = ModuleName
15 |
16 | // QuerierRoute is the querier route for the IBC module
17 | QuerierRoute string = ModuleName
18 |
19 | // RouterKey is the msg router key for the IBC module
20 | RouterKey string = ModuleName
21 | )
22 |
23 | // KVStore key prefixes for IBC
24 | var (
25 | KeyClientStorePrefix = []byte("clients")
26 | )
27 |
28 | // KVStore key prefixes for IBC
29 | const (
30 | KeyClientState = "clientState"
31 | KeyConsensusStatePrefix = "consensusStates"
32 | KeyPortPrefix = "ports"
33 | KeySequencePrefix = "sequences"
34 | KeyNextSeqSendPrefix = "nextSequenceSend"
35 | KeyNextSeqRecvPrefix = "nextSequenceRecv"
36 | KeyNextSeqAckPrefix = "nextSequenceAck"
37 | KeyPacketCommitmentPrefix = "commitments"
38 | KeyPacketAckPrefix = "acks"
39 | KeyPacketReceiptPrefix = "receipts"
40 | KeyCleanPacketCommitmentPrefix = "clean"
41 | )
42 |
43 | // FullClientPath returns the full path of a specific client path in the format:
44 | // "clients/{chainName}/{path}" as a string.
45 | func FullClientPath(chainName string, path string) string {
46 | return fmt.Sprintf("%s/%s/%s", KeyClientStorePrefix, chainName, path)
47 | }
48 |
49 | // FullClientKey returns the full path of specific client path in the format:
50 | // "clients/{chainName}/{path}" as a byte array.
51 | func FullClientKey(chainName string, path []byte) []byte {
52 | return []byte(FullClientPath(chainName, string(path)))
53 | }
54 |
55 | // ICS02
56 | // The following paths are the keys to the store as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#path-space
57 |
58 | // FullClientStatePath takes a client identifier and returns a Path under which to store a
59 | // particular client state
60 | func FullClientStatePath(chainName string) string {
61 | return FullClientPath(chainName, KeyClientState)
62 | }
63 |
64 | // FullClientStateKey takes a client identifier and returns a Key under which to store a
65 | // particular client state.
66 | func FullClientStateKey(chainName string) []byte {
67 | return FullClientKey(chainName, []byte(KeyClientState))
68 | }
69 |
70 | // ClientStateKey returns a store key under which a particular client state is stored
71 | // in a client prefixed store
72 | func ClientStateKey() []byte {
73 | return []byte(KeyClientState)
74 | }
75 |
76 | // FullConsensusStatePath takes a client identifier and returns a Path under which to
77 | // store the consensus state of a client.
78 | func FullConsensusStatePath(chainName string, height tibcclient.Height) string {
79 | return FullClientPath(chainName, ConsensusStatePath(height))
80 | }
81 |
82 | // FullConsensusStateKey returns the store key for the consensus state of a particular
83 | // client.
84 | func FullConsensusStateKey(chainName string, height tibcclient.Height) []byte {
85 | return []byte(FullConsensusStatePath(chainName, height))
86 | }
87 |
88 | // ConsensusStatePath returns the suffix store key for the consensus state at a
89 | // particular height stored in a client prefixed store.
90 | func ConsensusStatePath(height tibcclient.Height) string {
91 | return fmt.Sprintf("%s/%s", KeyConsensusStatePrefix, height)
92 | }
93 |
94 | // ConsensusStateKey returns the store key for a the consensus state of a particular
95 | // client stored in a client prefixed store.
96 | func ConsensusStateKey(height tibcclient.Height) []byte {
97 | return []byte(ConsensusStatePath(height))
98 | }
99 |
100 | // ICS04
101 | // The following paths are the keys to the store as defined in https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#store-paths
102 |
103 | // NextSequenceSendPath defines the next send sequence counter store path
104 | func NextSequenceSendPath(sourceChain, destChain string) string {
105 | return fmt.Sprintf("%s/%s", KeyNextSeqSendPrefix, packetPath(sourceChain, destChain))
106 | }
107 |
108 | // NextSequenceSendKey returns the store key for the send sequence of a particular
109 | // channel binded to a specific port.
110 | func NextSequenceSendKey(sourceChain, destChain string) []byte {
111 | return []byte(NextSequenceSendPath(sourceChain, destChain))
112 | }
113 |
114 | // PacketCommitmentPath defines the commitments to packet data fields store path
115 | func PacketCommitmentPath(sourceChain, destinationChain string, sequence uint64) string {
116 | return fmt.Sprintf("%s/%d", PacketCommitmentPrefixPath(sourceChain, destinationChain), sequence)
117 | }
118 |
119 | // PacketCommitmentKey returns the store key of under which a packet commitment
120 | // is stored
121 | func PacketCommitmentKey(sourceChain, destinationChain string, sequence uint64) []byte {
122 | return []byte(PacketCommitmentPath(sourceChain, destinationChain, sequence))
123 | }
124 |
125 | // PacketCommitmentPrefixPath defines the prefix for commitments to packet data fields store path.
126 | func PacketCommitmentPrefixPath(sourceChain, destinationChain string) string {
127 | return fmt.Sprintf("%s/%s/%s", KeyPacketCommitmentPrefix, packetPath(sourceChain, destinationChain), KeySequencePrefix)
128 | }
129 |
130 | // PacketAcknowledgementPath defines the packet acknowledgement store path
131 | func PacketAcknowledgementPath(sourceChain, destinationChain string, sequence uint64) string {
132 | return fmt.Sprintf("%s/%d", PacketAcknowledgementPrefixPath(sourceChain, destinationChain), sequence)
133 | }
134 |
135 | // PacketAcknowledgementKey returns the store key of under which a packet
136 | // acknowledgement is stored
137 | func PacketAcknowledgementKey(sourceChain, destinationChain string, sequence uint64) []byte {
138 | return []byte(PacketAcknowledgementPath(sourceChain, destinationChain, sequence))
139 | }
140 |
141 | // PacketAcknowledgementPrefixPath defines the prefix for commitments to packet data fields store path.
142 | func PacketAcknowledgementPrefixPath(sourceChain, destinationChain string) string {
143 | return fmt.Sprintf("%s/%s/%s", KeyPacketAckPrefix, packetPath(sourceChain, destinationChain), KeySequencePrefix)
144 | }
145 |
146 | // PacketReceiptPath defines the packet receipt store path
147 | func PacketReceiptPath(sourceChain, destinationChain string, sequence uint64) string {
148 | return fmt.Sprintf("%s/%d", PacketReceiptPrefixPath(sourceChain, destinationChain), sequence)
149 | }
150 |
151 | // PacketReceiptKey returns the store key of under which a packet
152 | // receipt is stored
153 | func PacketReceiptKey(sourceChain, destinationChain string, sequence uint64) []byte {
154 | return []byte(PacketReceiptPath(sourceChain, destinationChain, sequence))
155 | }
156 |
157 | // PacketReceiptKey returns the store key of under which a packet
158 | // receipt is stored
159 | func PacketReceiptPrefixPath(sourceChain, destinationChain string) string {
160 | return fmt.Sprintf("%s/%s/%s", KeyPacketReceiptPrefix, packetPath(sourceChain, destinationChain), KeySequencePrefix)
161 | }
162 |
163 | func packetPath(sourceChain, destinationChain string) string {
164 | return fmt.Sprintf("%s/%s", sourceChain, destinationChain)
165 | }
166 |
167 | // ICS05
168 | // The following paths are the keys to the store as defined in https://github.com/cosmos/ics/tree/master/spec/ics-026-routing-allocation#store-paths
169 |
170 | // PortPath defines the path under which ports paths are stored on the capability module
171 | func PortPath(portID string) string {
172 | return fmt.Sprintf("%s/%s", KeyPortPrefix, portID)
173 | }
174 |
175 | // CleanPacketCommitmentKey returns the store key of under which a clean packet commitment
176 | // is stored
177 | func CleanPacketCommitmentKey(sourceChain, destinationChain string) []byte {
178 | return []byte(CleanPacketCommitmentPath(sourceChain, destinationChain))
179 | }
180 |
181 | // CleanPacketCommitmentPrefixPath defines the prefix for commitments to packet data fields store path.
182 | func CleanPacketCommitmentPath(sourceChain, destinationChain string) string {
183 | return fmt.Sprintf("%s/%s", KeyCleanPacketCommitmentPrefix, packetPath(sourceChain, destinationChain))
184 | }
185 |
--------------------------------------------------------------------------------
/modules/core/packet/types.go:
--------------------------------------------------------------------------------
1 | package packet
2 |
3 | import (
4 | "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | sdk "github.com/irisnet/core-sdk-go/types"
7 | )
8 |
9 | var _ sdk.Msg = &MsgRecvPacket{}
10 |
11 | // Route implements sdk.Msg
12 | func (msg MsgRecvPacket) Route() string {
13 | return "tibc"
14 | }
15 |
16 | // GetSignBytes implements sdk.Msg. The function will panic since it is used
17 | // for amino transaction verification which TIBC does not support.
18 | func (msg MsgRecvPacket) GetSignBytes() []byte {
19 | panic("IBC messages do not support amino")
20 | }
21 |
22 | // GetSigners implements sdk.Msg
23 | func (msg MsgRecvPacket) GetSigners() []sdk.AccAddress {
24 | signer, err := sdk.AccAddressFromBech32(msg.Signer)
25 | if err != nil {
26 | panic(err)
27 | }
28 | return []sdk.AccAddress{signer}
29 | }
30 |
31 | // ValidateBasic implements sdk.Msg
32 | func (msg MsgRecvPacket) ValidateBasic() error {
33 | if len(msg.ProofCommitment) == 0 {
34 | return tibctypes.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof")
35 | }
36 | if msg.ProofHeight.IsZero() {
37 | return tibctypes.Wrap(tibctypes.ErrInvalidHeight, "proof height must be non-zero")
38 | }
39 | _, err := sdk.AccAddressFromBech32(msg.Signer)
40 | if err != nil {
41 | return tibctypes.Wrapf(tibctypes.ErrInvalidAddress, "string could not be parsed as address: %v", err)
42 | }
43 | return msg.Packet.ValidateBasic()
44 | }
45 |
46 | // Type implements sdk.Msg
47 | func (msg MsgRecvPacket) Type() string {
48 | return "recv_packet"
49 | }
50 |
51 | var _ tibctypes.PacketI = (*Packet)(nil)
52 |
53 | // NewPacket creates a new Packet instance. It panics if the provided
54 | // packet data interface is not registered.
55 | func NewPacket(
56 | data []byte,
57 | sequence uint64, sourceChain, destinationChain, relayChain,
58 | port string,
59 | ) Packet {
60 | return Packet{
61 | Data: data,
62 | Sequence: sequence,
63 | SourceChain: sourceChain,
64 | DestinationChain: destinationChain,
65 | RelayChain: relayChain,
66 | Port: port,
67 | }
68 | }
69 |
70 | // GetSequence implements PacketI interface
71 | func (p Packet) GetSequence() uint64 { return p.Sequence }
72 |
73 | // GetPort implements PacketI interface
74 | func (p Packet) GetPort() string { return p.Port }
75 |
76 | // GetSourceChain implements PacketI interface
77 | func (p Packet) GetSourceChain() string { return p.SourceChain }
78 |
79 | // GetDestinationChain implements PacketI interface
80 | func (p Packet) GetDestChain() string { return p.DestinationChain }
81 |
82 | // GetRelayChain implements PacketI interface
83 | func (p Packet) GetRelayChain() string { return p.RelayChain }
84 |
85 | // GetData implements PacketI interface
86 | func (p Packet) GetData() []byte { return p.Data }
87 |
88 | // ValidateBasic implements PacketI interface
89 | func (p Packet) ValidateBasic() error {
90 | if p.Sequence == 0 {
91 | return tibctypes.Wrap(ErrInvalidPacket, "packet sequence cannot be 0")
92 | }
93 | if len(p.Data) == 0 {
94 | return tibctypes.Wrap(ErrInvalidPacket, "packet data bytes cannot be empty")
95 | }
96 | return nil
97 | }
98 |
99 | var _ sdk.Msg = &MsgAcknowledgement{}
100 |
101 | // Route implements sdk.Msg
102 | func (msg MsgAcknowledgement) Route() string {
103 | return "tibc"
104 | }
105 |
106 | // ValidateBasic implements sdk.Msg
107 | func (msg MsgAcknowledgement) ValidateBasic() error {
108 | if len(msg.ProofAcked) == 0 {
109 | return tibctypes.Wrap(commitment.ErrInvalidProof, "cannot submit an empty proof")
110 | }
111 | if msg.ProofHeight.IsZero() {
112 | return tibctypes.Wrap(tibctypes.ErrInvalidHeight, "proof height must be non-zero")
113 | }
114 | if len(msg.Acknowledgement) == 0 {
115 | return tibctypes.Wrap(ErrInvalidAcknowledgement, "ack bytes cannot be empty")
116 | }
117 | _, err := sdk.AccAddressFromBech32(msg.Signer)
118 | if err != nil {
119 | return tibctypes.Wrapf(tibctypes.ErrInvalidAddress, "string could not be parsed as address: %v", err)
120 | }
121 | return msg.Packet.ValidateBasic()
122 | }
123 |
124 | // GetSignBytes implements sdk.Msg. The function will panic since it is used
125 | // for amino transaction verification which TIBC does not support.
126 | func (msg MsgAcknowledgement) GetSignBytes() []byte {
127 | panic("IBC messages do not support amino")
128 | }
129 |
130 | // GetSigners implements sdk.Msg
131 | func (msg MsgAcknowledgement) GetSigners() []sdk.AccAddress {
132 | signer, err := sdk.AccAddressFromBech32(msg.Signer)
133 | if err != nil {
134 | panic(err)
135 | }
136 | return []sdk.AccAddress{signer}
137 | }
138 |
139 | // Type implements sdk.Msg
140 | func (msg MsgAcknowledgement) Type() string {
141 | return "acknowledge_packet"
142 | }
143 |
144 | var _ sdk.Msg = &MsgCleanPacket{}
145 |
146 | // Route implements sdk.Msg
147 | func (msg MsgCleanPacket) Route() string {
148 | return "tibc"
149 | }
150 |
151 | // ValidateBasic implements sdk.Msg
152 | func (msg MsgCleanPacket) ValidateBasic() error {
153 | _, err := sdk.AccAddressFromBech32(msg.Signer)
154 | if err != nil {
155 | return tibctypes.Wrapf(tibctypes.ErrInvalidAddress, "string could not be parsed as address: %v", err)
156 | }
157 | return msg.CleanPacket.ValidateBasic()
158 | }
159 |
160 | // GetSignBytes implements sdk.Msg. The function will panic since it is used
161 | // for amino transaction verification which TIBC does not support.
162 | func (msg MsgCleanPacket) GetSignBytes() []byte {
163 | panic("IBC messages do not support amino")
164 | }
165 |
166 | // GetSigners implements sdk.Msg
167 | func (msg MsgCleanPacket) GetSigners() []sdk.AccAddress {
168 | signer, err := sdk.AccAddressFromBech32(msg.Signer)
169 | if err != nil {
170 | panic(err)
171 | }
172 | return []sdk.AccAddress{signer}
173 | }
174 |
175 | // Type implements sdk.Msg
176 | func (msg MsgCleanPacket) Type() string {
177 | return "clean_packet"
178 | }
179 |
180 | var _ sdk.Msg = &MsgRecvCleanPacket{}
181 |
182 | // Route implements sdk.Msg
183 | func (msg MsgRecvCleanPacket) Route() string {
184 | return "tibc"
185 | }
186 |
187 | // ValidateBasic implements sdk.Msg
188 | func (msg MsgRecvCleanPacket) ValidateBasic() error {
189 | _, err := sdk.AccAddressFromBech32(msg.Signer)
190 | if err != nil {
191 | return tibctypes.Wrapf(tibctypes.ErrInvalidAddress, "string could not be parsed as address: %v", err)
192 | }
193 | return msg.CleanPacket.ValidateBasic()
194 | }
195 |
196 | // GetSignBytes implements sdk.Msg. The function will panic since it is used
197 | // for amino transaction verification which TIBC does not support.
198 | func (msg MsgRecvCleanPacket) GetSignBytes() []byte {
199 | panic("IBC messages do not support amino")
200 | }
201 |
202 | // GetSigners implements sdk.Msg
203 | func (msg MsgRecvCleanPacket) GetSigners() []sdk.AccAddress {
204 | signer, err := sdk.AccAddressFromBech32(msg.Signer)
205 | if err != nil {
206 | panic(err)
207 | }
208 | return []sdk.AccAddress{signer}
209 | }
210 |
211 | // Type implements sdk.Msg
212 | func (msg MsgRecvCleanPacket) Type() string {
213 | return "recv_clean_packet"
214 | }
215 |
216 | var _ tibctypes.CleanPacketI = (*CleanPacket)(nil)
217 |
218 | // GetSequence implements PacketI interface
219 | func (p CleanPacket) GetSequence() uint64 { return p.Sequence }
220 |
221 | // GetSourceChain implements PacketI interface
222 | func (p CleanPacket) GetSourceChain() string { return p.SourceChain }
223 |
224 | // GetDestinationChain implements PacketI interface
225 | func (p CleanPacket) GetDestChain() string { return p.DestinationChain }
226 |
227 | // GetRelayChain implements PacketI interface
228 | func (p CleanPacket) GetRelayChain() string { return p.RelayChain }
229 |
230 | // ValidateBasic implements PacketI interface
231 | func (p CleanPacket) ValidateBasic() error {
232 | if p.Sequence == 0 {
233 | return tibctypes.Wrap(ErrInvalidPacket, "packet sequence cannot be 0")
234 | }
235 | return nil
236 | }
237 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/bsc.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import (
4 | "fmt"
5 | "math/big"
6 |
7 | "github.com/ethereum/go-ethereum/core/types"
8 |
9 | tibcclient "github.com/bianjieai/tibc-sdk-go/modules/core/client"
10 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
11 |
12 | "github.com/ethereum/go-ethereum/common"
13 | )
14 |
15 | const (
16 | // Fixed number of extra-data prefix bytes reserved for signer vanity
17 | extraVanity = 32
18 |
19 | // Fixed number of extra-data suffix bytes reserved for signer seal
20 | extraSeal = 65
21 |
22 | // AddressLength is the expected length of the address
23 | addressLength = 20
24 |
25 | // BloomByteLength represents the number of bytes used in a header log bloom.
26 | bloomByteLength = 256
27 |
28 | // NonceByteLength represents the number of bytes used in a header log nonce.
29 | nonceByteLength = 8
30 |
31 | // The bound divisor of the gas limit, used in update calculations.
32 | gasLimitBoundDivisor uint64 = 256
33 | )
34 |
35 | var (
36 | // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
37 | uncleHash = types.CalcUncleHash(nil)
38 |
39 | // Block difficulty for in-turn signatures
40 | diffInTurn = big.NewInt(2)
41 |
42 | // Block difficulty for out-of-turn signatures
43 | diffNoTurn = big.NewInt(1)
44 | )
45 |
46 | // A BlockNonce is a 64-bit hash which proves (combined with the
47 | // mix-hash) that a sufficient amount of computation has been carried
48 | // out on a block.
49 | type BlockNonce [nonceByteLength]byte
50 |
51 | // BlockNonce converts a byte slice to a bloom filter.
52 | // It panics if b is not of suitable size.
53 | func BytesToBlockNonce(b []byte) BlockNonce {
54 | var nonce BlockNonce
55 | nonce.SetBytes(b)
56 | return nonce
57 | }
58 |
59 | // SetBytes sets the content of b to the given bytes.
60 | // It panics if d is not of suitable size.
61 | func (b *BlockNonce) SetBytes(d []byte) {
62 | if len(b) < len(d) {
63 | panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d)))
64 | }
65 | copy(b[nonceByteLength-len(d):], d)
66 | }
67 |
68 | // BscHeader represents a block header in the Ethereum blockchain.
69 | type BscHeader struct {
70 | ParentHash common.Hash `json:"parentHash" gencodec:"required"`
71 | UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
72 | Coinbase common.Address `json:"miner" gencodec:"required"`
73 | Root common.Hash `json:"stateRoot" gencodec:"required"`
74 | TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
75 | ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
76 | Bloom Bloom `json:"logsBloom" gencodec:"required"`
77 | Difficulty *big.Int `json:"difficulty" gencodec:"required"`
78 | Number *big.Int `json:"number" gencodec:"required"`
79 | GasLimit uint64 `json:"gasLimit" gencodec:"required"`
80 | GasUsed uint64 `json:"gasUsed" gencodec:"required"`
81 | Time uint64 `json:"timestamp" gencodec:"required"`
82 | Extra []byte `json:"extraData" gencodec:"required"`
83 | MixDigest common.Hash `json:"mixHash"`
84 | Nonce BlockNonce `json:"nonce"`
85 | }
86 |
87 | func (h BscHeader) ToHeader() Header {
88 | return Header{
89 | ParentHash: h.ParentHash[:],
90 | UncleHash: h.UncleHash[:],
91 | Coinbase: h.Coinbase[:],
92 | Root: h.Root[:],
93 | TxHash: h.TxHash[:],
94 | ReceiptHash: h.ReceiptHash[:],
95 | Bloom: h.Bloom[:],
96 | Difficulty: h.Difficulty.Uint64(),
97 | Height: tibcclient.NewHeight(0, h.Number.Uint64()),
98 | GasLimit: h.GasLimit,
99 | GasUsed: h.GasUsed,
100 | Time: h.Time,
101 | Extra: h.Extra,
102 | MixDigest: h.MixDigest[:],
103 | Nonce: h.Nonce[:],
104 | }
105 | }
106 |
107 | // Bloom represents a 2048 bit bloom filter.
108 | type Bloom [bloomByteLength]byte
109 |
110 | // BytesToBloom converts a byte slice to a bloom filter.
111 | // It panics if b is not of suitable size.
112 | func BytesToBloom(b []byte) Bloom {
113 | var bloom Bloom
114 | bloom.SetBytes(b)
115 | return bloom
116 | }
117 |
118 | // SetBytes sets the content of b to the given bytes.
119 | // It panics if d is not of suitable size.
120 | func (b *Bloom) SetBytes(d []byte) {
121 | if len(b) < len(d) {
122 | panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d)))
123 | }
124 | copy(b[bloomByteLength-len(d):], d)
125 | }
126 |
127 | // ProofAccount ...
128 | type ProofAccount struct {
129 | Nonce *big.Int
130 | Balance *big.Int
131 | Storage common.Hash
132 | Codehash common.Hash
133 | }
134 |
135 | func ParseValidators(extra []byte) ([][]byte, error) {
136 | validatorBytes := extra[extraVanity : len(extra)-extraSeal]
137 | if len(validatorBytes)%addressLength != 0 {
138 | return nil, tibctypes.Wrap(ErrInvalidLengthBsc, "(validatorsBytes % AddressLength) should bz zero")
139 | }
140 | n := len(validatorBytes) / addressLength
141 | result := make([][]byte, n)
142 | for i := 0; i < n; i++ {
143 | address := make([]byte, addressLength)
144 | copy(address, validatorBytes[i*addressLength:(i+1)*addressLength])
145 | result[i] = address
146 | }
147 | return result, nil
148 | }
149 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/client_state.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import (
4 | commitmenttypes "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | )
7 |
8 | var _ tibctypes.ClientState = (*ClientState)(nil)
9 |
10 | func (m ClientState) ClientType() string {
11 | return "008-bsc"
12 | }
13 |
14 | func (m ClientState) GetLatestHeight() tibctypes.Height {
15 | return m.Header.Height
16 | }
17 |
18 | func (m ClientState) Validate() error {
19 | return m.Header.ValidateBasic()
20 | }
21 |
22 | func (m ClientState) GetDelayTime() uint64 {
23 | return uint64(2*len(m.Validators)/3+1) * m.BlockInteval
24 | }
25 |
26 | func (m ClientState) GetDelayBlock() uint64 {
27 | return uint64(2*len(m.Validators)/3 + 1)
28 | }
29 |
30 | func (m ClientState) GetPrefix() tibctypes.Prefix {
31 | return commitmenttypes.MerklePrefix{}
32 | }
33 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/codec.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import (
4 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
5 | "github.com/irisnet/core-sdk-go/common/codec"
6 | "github.com/irisnet/core-sdk-go/common/codec/types"
7 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
8 | )
9 |
10 | var (
11 | amino = codec.NewLegacyAmino()
12 | ModuleCdc = codec.NewAminoCodec(amino)
13 | )
14 |
15 | func init() {
16 | cryptocodec.RegisterCrypto(amino)
17 | amino.Seal()
18 | }
19 |
20 | func RegisterInterfaces(registry types.InterfaceRegistry) {
21 | registry.RegisterImplementations(
22 | (*tibctypes.ClientState)(nil),
23 | &ClientState{},
24 | )
25 | registry.RegisterImplementations(
26 | (*tibctypes.ConsensusState)(nil),
27 | &ConsensusState{},
28 | )
29 | }
30 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/consensus_state.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import (
4 | commitmenttypes "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | )
7 |
8 | var _ tibctypes.ConsensusState = (*ConsensusState)(nil)
9 |
10 | func (m *ConsensusState) ClientType() string {
11 | return "008-bsc"
12 | }
13 |
14 | func (m *ConsensusState) GetRoot() tibctypes.Root {
15 | return commitmenttypes.MerkleRoot{
16 | Hash: m.Root,
17 | }
18 | }
19 |
20 | func (m *ConsensusState) GetTimestamp() uint64 {
21 | return m.Timestamp
22 | }
23 |
24 | func (m *ConsensusState) ValidateBasic() error {
25 | return nil
26 | }
27 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/errors.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
4 |
5 | const (
6 | SubModuleName = "bsc-client"
7 | moduleName = "tibc" + "-" + SubModuleName
8 | )
9 |
10 | // IBC bsc client sentinel errors
11 | var (
12 | ErrInvalidGenesisBlock = tibctypes.Register(moduleName, 2, "invalid genesis block")
13 | ErrInvalidValidatorBytes = tibctypes.Register(moduleName, 3, "invalid validators bytes length")
14 |
15 | // ErrUnknownBlock is returned when the list of validators is requested for a block
16 | // that is not part of the local blockchain.
17 | ErrUnknownBlock = tibctypes.Register(moduleName, 4, "unknown block")
18 | ErrFutureBlock = tibctypes.Register(moduleName, 5, "block in the future")
19 |
20 | // ErrMissingVanity is returned if a block's extra-data section is shorter than
21 | // 32 bytes, which is required to store the signer vanity.
22 | ErrMissingVanity = tibctypes.Register(moduleName, 6, "extra-data 32 byte vanity prefix missing")
23 |
24 | // ErrMissingSignature is returned if a block's extra-data section doesn't seem
25 | // to contain a 65 byte secp256k1 signature.
26 | ErrMissingSignature = tibctypes.Register(moduleName, 7, "extra-data 65 byte signature suffix missing")
27 |
28 | // ErrInvalidMixDigest is returned if a block's mix digest is non-zero.
29 | ErrInvalidMixDigest = tibctypes.Register(moduleName, 8, "non-zero mix digest")
30 |
31 | // ErrInvalidUncleHash is returned if a block contains an non-empty uncle list.
32 | ErrInvalidUncleHash = tibctypes.Register(moduleName, 9, "non empty uncle hash")
33 |
34 | // ErrInvalidDifficulty is returned if the difficulty of a block is missing.
35 | ErrInvalidDifficulty = tibctypes.Register(moduleName, 10, "invalid difficulty")
36 | ErrUnknownAncestor = tibctypes.Register(moduleName, 11, "unknown ancestor")
37 | // ErrCoinBaseMisMatch is returned if a header's coinbase do not match with signature
38 | ErrCoinBaseMisMatch = tibctypes.Register(moduleName, 12, "coinbase do not match with signature")
39 | // ErrUnauthorizedValidator is returned if a header is signed by a non-authorized entity.
40 | ErrUnauthorizedValidator = tibctypes.Register(moduleName, 13, "unauthorized validator")
41 | // ErrRecentlySigned is returned if a header is signed by an authorized entity
42 | // that already signed a header recently, thus is temporarily not allowed to.
43 | ErrRecentlySigned = tibctypes.Register(moduleName, 14, "recently signed")
44 | // ErrWrongDifficulty is returned if the difficulty of a block doesn't match the
45 | // turn of the signer.
46 | ErrWrongDifficulty = tibctypes.Register(moduleName, 15, "wrong difficulty")
47 | // ErrExtraValidators is returned if non-sprint-end block contain validator data in
48 | // their extra-data fields.
49 | ErrExtraValidators = tibctypes.Register(moduleName, 16, "non-sprint-end block contains extra validator list")
50 | // ErrInvalidSpanValidators is returned if a block contains an
51 | // invalid list of validators (i.e. non divisible by 20 bytes).
52 | ErrInvalidSpanValidators = tibctypes.Register(moduleName, 17, "invalid validator list on sprint end block")
53 |
54 | ErrInvalidProof = tibctypes.Register(moduleName, 18, "invalid proof")
55 | )
56 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/hashing.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package bsc
18 |
19 | import (
20 | "sync"
21 |
22 | "github.com/ethereum/go-ethereum/common"
23 | "github.com/ethereum/go-ethereum/crypto"
24 | "github.com/ethereum/go-ethereum/rlp"
25 | "golang.org/x/crypto/sha3"
26 | )
27 |
28 | // hasherPool holds LegacyKeccak256 hashers for rlpHash.
29 | var hasherPool = sync.Pool{
30 | New: func() interface{} { return sha3.NewLegacyKeccak256() },
31 | }
32 |
33 | // rlpHash encodes x and hashes the encoded bytes.
34 | func rlpHash(x interface{}) (h common.Hash) {
35 | sha := hasherPool.Get().(crypto.KeccakState)
36 | defer hasherPool.Put(sha)
37 | sha.Reset()
38 | _ = rlp.Encode(sha, x)
39 | _, _ = sha.Read(h[:])
40 | return h
41 | }
42 |
--------------------------------------------------------------------------------
/modules/light-clients/bsc/header.go:
--------------------------------------------------------------------------------
1 | package bsc
2 |
3 | import (
4 | "math/big"
5 |
6 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
7 | "github.com/ethereum/go-ethereum/common"
8 | )
9 |
10 | var _ tibctypes.Header = (*Header)(nil)
11 |
12 | func (h Header) ClientType() string {
13 | return "008-bsc"
14 | }
15 |
16 | func (h Header) GetHeight() tibctypes.Height {
17 | return h.Height
18 | }
19 |
20 | // Hash returns the block hash of the header, which is simply the keccak256 hash of its
21 | // RLP encoding.
22 | func (h *Header) Hash() common.Hash {
23 | return rlpHash(h.ToBscHeader())
24 | }
25 |
26 | func (h Header) ValidateBasic() error {
27 | number := h.Height.RevisionHeight
28 |
29 | // Check that the extra-data contains the vanity, validators and signature.
30 | if len(h.Extra) < extraVanity {
31 | return tibctypes.Wrap(ErrMissingVanity, "header Extra")
32 | }
33 | if len(h.Extra) < extraVanity+extraSeal {
34 | return tibctypes.Wrap(ErrMissingSignature, "header Extra")
35 | }
36 |
37 | // Ensure that the mix digest is zero as we don't have fork protection currently
38 | if common.BytesToHash(h.MixDigest) != (common.Hash{}) {
39 | return tibctypes.Wrap(ErrInvalidMixDigest, "header MixDigest")
40 | }
41 | // Ensure that the block doesn't contain any uncles which are meaningless in PoA
42 | if common.BytesToHash(h.UncleHash) != uncleHash {
43 | return tibctypes.Wrap(ErrInvalidUncleHash, "header UncleHash")
44 | }
45 | // Ensure that the block's difficulty is meaningful (may not be correct at this point)
46 | if number > 0 {
47 | if h.Difficulty == 0 {
48 | return tibctypes.Wrap(ErrInvalidDifficulty, "header Difficulty")
49 | }
50 | }
51 | return nil
52 | }
53 |
54 | func (h Header) ToBscHeader() BscHeader {
55 | return BscHeader{
56 | ParentHash: common.BytesToHash(h.ParentHash),
57 | UncleHash: common.BytesToHash(h.UncleHash),
58 | Coinbase: common.BytesToAddress(h.Coinbase),
59 | Root: common.BytesToHash(h.Root),
60 | TxHash: common.BytesToHash(h.TxHash),
61 | ReceiptHash: common.BytesToHash(h.ReceiptHash),
62 | Bloom: BytesToBloom(h.Bloom),
63 | Difficulty: big.NewInt(int64(h.Difficulty)),
64 | Number: big.NewInt(int64(h.Height.RevisionHeight)),
65 | GasLimit: h.GasLimit,
66 | GasUsed: h.GasUsed,
67 | Time: h.Time,
68 | Extra: h.Extra,
69 | MixDigest: common.BytesToHash(h.MixDigest),
70 | Nonce: BytesToBlockNonce(h.Nonce),
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/client_state.go:
--------------------------------------------------------------------------------
1 | package eth
2 |
3 | import (
4 | commitmenttypes "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | )
7 |
8 | var _ tibctypes.ClientState = (*ClientState)(nil)
9 |
10 | func (m ClientState) ClientType() string {
11 | return "009-eth"
12 | }
13 |
14 | func (m ClientState) GetLatestHeight() tibctypes.Height {
15 | return m.Header.Height
16 | }
17 |
18 | func (m ClientState) Validate() error {
19 | return m.Header.ValidateBasic()
20 | }
21 |
22 | func (m ClientState) GetDelayTime() uint64 {
23 | return m.TimeDelay
24 | }
25 |
26 | func (m ClientState) GetDelayBlock() uint64 {
27 | return m.BlockDelay
28 | }
29 |
30 | func (m ClientState) GetPrefix() tibctypes.Prefix {
31 | return commitmenttypes.MerklePrefix{}
32 | }
33 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/codec.go:
--------------------------------------------------------------------------------
1 | package eth
2 |
3 | import (
4 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
5 | "github.com/irisnet/core-sdk-go/common/codec"
6 | "github.com/irisnet/core-sdk-go/common/codec/types"
7 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
8 | )
9 |
10 | var (
11 | amino = codec.NewLegacyAmino()
12 | )
13 |
14 | func init() {
15 | cryptocodec.RegisterCrypto(amino)
16 | amino.Seal()
17 | }
18 |
19 | func RegisterInterfaces(registry types.InterfaceRegistry) {
20 | registry.RegisterImplementations(
21 | (*tibctypes.ClientState)(nil),
22 | &ClientState{},
23 | )
24 | registry.RegisterImplementations(
25 | (*tibctypes.ConsensusState)(nil),
26 | &ConsensusState{},
27 | )
28 | registry.RegisterImplementations(
29 | (*tibctypes.Header)(nil),
30 | &Header{},
31 | )
32 | }
33 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/consensus_state.go:
--------------------------------------------------------------------------------
1 | package eth
2 |
3 | import (
4 | tibccommitment "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | )
7 |
8 | var _ tibctypes.ConsensusState = (*ConsensusState)(nil)
9 |
10 | func (m *ConsensusState) ClientType() string {
11 | return "009-eth"
12 | }
13 |
14 | func (m *ConsensusState) GetRoot() tibctypes.Root {
15 | return tibccommitment.MerkleRoot{
16 | Hash: m.Root,
17 | }
18 | }
19 |
20 | func (m *ConsensusState) GetTimestamp() uint64 {
21 | return m.Timestamp
22 | }
23 |
24 | func (m *ConsensusState) ValidateBasic() error {
25 | return nil
26 | }
27 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/eth.go:
--------------------------------------------------------------------------------
1 | package eth
2 |
3 | import (
4 | "math/big"
5 |
6 | tibcclient "github.com/bianjieai/tibc-sdk-go/modules/core/client"
7 |
8 | "github.com/ethereum/go-ethereum/core/types"
9 |
10 | "github.com/ethereum/go-ethereum/common"
11 | )
12 |
13 | // EthHeader represents a block header in the Ethereum blockchain.
14 | type EthHeader struct {
15 | ParentHash common.Hash `json:"parentHash" gencodec:"required"`
16 | UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
17 | Coinbase common.Address `json:"miner" gencodec:"required"`
18 | Root common.Hash `json:"stateRoot" gencodec:"required"`
19 | TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
20 | ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
21 | Bloom types.Bloom `json:"logsBloom" gencodec:"required"`
22 | Difficulty *big.Int `json:"difficulty" gencodec:"required"`
23 | Number *big.Int `json:"number" gencodec:"required"`
24 | GasLimit uint64 `json:"gasLimit" gencodec:"required"`
25 | GasUsed uint64 `json:"gasUsed" gencodec:"required"`
26 | Time uint64 `json:"timestamp" gencodec:"required"`
27 | Extra []byte `json:"extraData" gencodec:"required"`
28 | MixDigest common.Hash `json:"mixHash"`
29 | Nonce types.BlockNonce `json:"nonce"`
30 |
31 | // BaseFee was added by EIP-1559 and is ignored in legacy headers.
32 | BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
33 | }
34 |
35 | func (h EthHeader) ToHeader() Header {
36 | return Header{
37 | ParentHash: h.ParentHash[:],
38 | UncleHash: h.UncleHash[:],
39 | Coinbase: h.Coinbase[:],
40 | Root: h.Root[:],
41 | TxHash: h.TxHash[:],
42 | ReceiptHash: h.ReceiptHash[:],
43 | Bloom: h.Bloom[:],
44 | Difficulty: h.Difficulty.String(),
45 | Height: tibcclient.NewHeight(0, h.Number.Uint64()),
46 | GasLimit: h.GasLimit,
47 | GasUsed: h.GasUsed,
48 | Time: h.Time,
49 | Extra: h.Extra,
50 | MixDigest: h.MixDigest[:],
51 | Nonce: h.Nonce.Uint64(),
52 | BaseFee: h.BaseFee.String(),
53 | }
54 | }
55 |
56 | // ProofAccount ...
57 | type ProofAccount struct {
58 | Nonce *big.Int
59 | Balance *big.Int
60 | Storage common.Hash
61 | Codehash common.Hash
62 | }
63 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/hashing.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package eth
18 |
19 | import (
20 | "sync"
21 |
22 | "github.com/ethereum/go-ethereum/common"
23 | "github.com/ethereum/go-ethereum/crypto"
24 | "github.com/ethereum/go-ethereum/rlp"
25 | "golang.org/x/crypto/sha3"
26 | )
27 |
28 | // hasherPool holds LegacyKeccak256 hashers for rlpHash.
29 | var hasherPool = sync.Pool{
30 | New: func() interface{} { return sha3.NewLegacyKeccak256() },
31 | }
32 |
33 | // rlpHash encodes x and hashes the encoded bytes.
34 | func rlpHash(x interface{}) (h common.Hash) {
35 | sha := hasherPool.Get().(crypto.KeccakState)
36 | defer hasherPool.Put(sha)
37 | sha.Reset()
38 | _ = rlp.Encode(sha, x)
39 | _, _ = sha.Read(h[:])
40 | return h
41 | }
42 |
--------------------------------------------------------------------------------
/modules/light-clients/eth/header.go:
--------------------------------------------------------------------------------
1 | package eth
2 |
3 | import (
4 | "fmt"
5 | "math/big"
6 | "time"
7 |
8 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
9 | "github.com/ethereum/go-ethereum/common"
10 | "github.com/ethereum/go-ethereum/consensus"
11 | "github.com/ethereum/go-ethereum/core/types"
12 | "github.com/ethereum/go-ethereum/params"
13 | )
14 |
15 | var (
16 | // Maximum number of uncles allowed in a single block
17 | allowedFutureBlockTimeSeconds = int64(15)
18 | )
19 | var _ tibctypes.Header = (*Header)(nil)
20 |
21 | func (h Header) ClientType() string {
22 | return "009-eth"
23 | }
24 |
25 | func (h Header) GetHeight() tibctypes.Height {
26 | return h.Height
27 | }
28 |
29 | // Hash returns the block hash of the header, which is simply the keccak256 hash of its
30 | // RLP encoding.
31 | func (h *Header) Hash() common.Hash {
32 | return rlpHash(h.ToEthHeader())
33 | }
34 |
35 | func (h Header) ValidateBasic() error {
36 | // Ensure that the header's extra-data section is of a reasonable size
37 | if uint64(len(h.Extra)) > params.MaximumExtraDataSize {
38 | return fmt.Errorf("extra-data too long: %d > %d", len(h.Extra), params.MaximumExtraDataSize)
39 | }
40 | if h.Time > uint64(time.Now().Unix()+allowedFutureBlockTimeSeconds) {
41 | return consensus.ErrFutureBlock
42 | }
43 | // Verify that the gas limit is <= 2^63-1
44 | cap := uint64(0x7fffffffffffffff)
45 | if h.GasLimit > cap {
46 | return fmt.Errorf("invalid gasLimit: have %v, max %v", h.GasLimit, cap)
47 | }
48 | // Verify that the gasUsed is <= gasLimit
49 | if h.GasUsed > h.GasLimit {
50 | return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", h.GasUsed, h.GasLimit)
51 | }
52 | // Ensure that the block's difficulty is meaningful (may not be correct at this point)
53 | number := h.Height.RevisionHeight
54 | if number > 0 {
55 | if h.ToEthHeader().Difficulty.Uint64() == 0 {
56 | return tibctypes.Wrap(ErrInvalidLengthEth, "header Difficulty")
57 | }
58 | }
59 | return nil
60 | }
61 |
62 | func (h Header) ToEthHeader() EthHeader {
63 | difficulty := new(big.Int)
64 | difficulty, ok := difficulty.SetString(h.Difficulty, 10)
65 | if !ok {
66 | return EthHeader{}
67 | }
68 | baseFee := new(big.Int)
69 | baseFee, ok = baseFee.SetString(h.BaseFee, 10)
70 | if !ok {
71 | return EthHeader{}
72 | }
73 | return EthHeader{
74 | ParentHash: common.BytesToHash(h.ParentHash),
75 | UncleHash: common.BytesToHash(h.UncleHash),
76 | Coinbase: common.BytesToAddress(h.Coinbase),
77 | Root: common.BytesToHash(h.Root),
78 | TxHash: common.BytesToHash(h.TxHash),
79 | ReceiptHash: common.BytesToHash(h.ReceiptHash),
80 | Bloom: types.BytesToBloom(h.Bloom),
81 | Difficulty: difficulty,
82 | Number: big.NewInt(int64(h.Height.RevisionHeight)),
83 | GasLimit: h.GasLimit,
84 | GasUsed: h.GasUsed,
85 | Time: h.Time,
86 | Extra: h.Extra,
87 | MixDigest: common.BytesToHash(h.MixDigest),
88 | Nonce: types.EncodeNonce(h.Nonce),
89 | BaseFee: baseFee,
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/client_state.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | import (
4 | "strings"
5 |
6 | "github.com/bianjieai/tibc-sdk-go/modules/types"
7 | tmmath "github.com/tendermint/tendermint/libs/math"
8 | "github.com/tendermint/tendermint/light"
9 | )
10 |
11 | func (cs ClientState) GetLatestHeight() types.Height {
12 | return cs.LatestHeight
13 | }
14 |
15 | // GetChainId returns the chain-id
16 | func (cs ClientState) GetChainId() string {
17 | return cs.ChainId
18 | }
19 |
20 | // ClientType is tendermint.
21 | func (cs ClientState) ClientType() string {
22 | return "007-tendermint"
23 | }
24 |
25 | // GetDelayBlock returns the number of blocks delayed in transaction confirmation.
26 | func (cs ClientState) GetDelayBlock() uint64 {
27 | return 0
28 | }
29 |
30 | // GetDelayTime returns the period of transaction confirmation delay.
31 | func (cs ClientState) GetDelayTime() uint64 {
32 | return cs.TimeDelay
33 | }
34 |
35 | // GetPrefix returns the prefix path for proof key.
36 | func (cs ClientState) GetPrefix() types.Prefix {
37 | return &cs.MerklePrefix
38 | }
39 |
40 | // Validate performs a basic validation of the client state fields.
41 | func (cs ClientState) Validate() error {
42 | if strings.TrimSpace(cs.ChainId) == "" {
43 | return types.Wrap(ErrInvalidChainID, "chain id cannot be empty string")
44 | }
45 | if err := light.ValidateTrustLevel(cs.TrustLevel.ToTendermint()); err != nil {
46 | return err
47 | }
48 | if cs.TrustingPeriod == 0 {
49 | return types.Wrap(ErrInvalidTrustingPeriod, "trusting period cannot be zero")
50 | }
51 | if cs.UnbondingPeriod == 0 {
52 | return types.Wrap(ErrInvalidUnbondingPeriod, "unbonding period cannot be zero")
53 | }
54 | if cs.MaxClockDrift == 0 {
55 | return types.Wrap(ErrInvalidMaxClockDrift, "max clock drift cannot be zero")
56 | }
57 | if cs.LatestHeight.RevisionHeight == 0 {
58 | return types.Wrapf(ErrInvalidHeaderHeight, "tendermint revision height cannot be zero")
59 | }
60 | if cs.TrustingPeriod >= cs.UnbondingPeriod {
61 | return types.Wrapf(
62 | ErrInvalidTrustingPeriod,
63 | "trusting period (%s) should be < unbonding period (%s)", cs.TrustingPeriod, cs.UnbondingPeriod,
64 | )
65 | }
66 | if cs.ProofSpecs == nil {
67 | return types.Wrap(ErrInvalidProofSpecs, "proof specs cannot be nil for tm client")
68 | }
69 | for i, spec := range cs.ProofSpecs {
70 | if spec == nil {
71 | return types.Wrapf(ErrInvalidProofSpecs, "proof spec cannot be nil at index: %d", i)
72 | }
73 | }
74 | return nil
75 | }
76 |
77 | // ToTendermint converts Fraction to tmmath.Fraction
78 | func (f Fraction) ToTendermint() tmmath.Fraction {
79 | return tmmath.Fraction{
80 | Numerator: f.Numerator,
81 | Denominator: f.Denominator,
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/codec.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | import (
4 | "github.com/bianjieai/tibc-sdk-go/modules/core/client"
5 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
6 | "github.com/irisnet/core-sdk-go/common/codec"
7 | "github.com/irisnet/core-sdk-go/common/codec/types"
8 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
9 | sdk "github.com/irisnet/core-sdk-go/types"
10 | )
11 |
12 | var (
13 | amino = codec.NewLegacyAmino()
14 | ModuleCdc = codec.NewAminoCodec(amino)
15 | )
16 |
17 | func init() {
18 | cryptocodec.RegisterCrypto(amino)
19 | amino.Seal()
20 | }
21 |
22 | func RegisterInterfaces(registry types.InterfaceRegistry) {
23 |
24 | registry.RegisterImplementations(
25 | (*tibctypes.ClientState)(nil),
26 | &ClientState{},
27 | )
28 | registry.RegisterImplementations(
29 | (*tibctypes.ConsensusState)(nil),
30 | &ConsensusState{},
31 | )
32 | registry.RegisterImplementations(
33 | (*sdk.Msg)(nil),
34 | &client.MsgUpdateClient{},
35 | )
36 | }
37 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/consensus_state.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
7 | "github.com/bianjieai/tibc-sdk-go/modules/types"
8 | tmbytes "github.com/tendermint/tendermint/libs/bytes"
9 | tmtypes "github.com/tendermint/tendermint/types"
10 | )
11 |
12 | // NewConsensusState creates a new ConsensusState instance.
13 | func NewConsensusState(
14 | timestamp time.Time, root commitment.MerkleRoot, nextValsHash tmbytes.HexBytes,
15 | ) *ConsensusState {
16 | return &ConsensusState{
17 | Timestamp: timestamp,
18 | Root: root,
19 | NextValidatorsHash: nextValsHash,
20 | }
21 | }
22 |
23 | // ClientType returns Tendermint
24 | func (ConsensusState) ClientType() string {
25 | return "007-tendermint"
26 | }
27 |
28 | // GetRoot returns the commitment Root for the specific
29 | func (cs ConsensusState) GetRoot() types.Root {
30 | return cs.Root
31 | }
32 |
33 | // GetTimestamp returns block time in nanoseconds of the header that created consensus state
34 | func (cs ConsensusState) GetTimestamp() uint64 {
35 | return uint64(cs.Timestamp.UnixNano())
36 | }
37 |
38 | // ValidateBasic defines a basic validation for the tendermint consensus state.
39 | // NOTE: ProcessedTimestamp may be zero if this is an initial consensus state passed in by relayer
40 | // as opposed to a consensus state constructed by the chain.
41 | func (cs ConsensusState) ValidateBasic() error {
42 | if cs.Root.Empty() {
43 | return types.Wrap(types.ErrInvalidConsensus, "root cannot be empty")
44 | }
45 | if err := tmtypes.ValidateHash(cs.NextValidatorsHash); err != nil {
46 | return types.Wrap(err, "next validators hash is invalid")
47 | }
48 | if cs.Timestamp.Unix() <= 0 {
49 | return types.Wrap(types.ErrInvalidConsensus, "timestamp must be a positive Unix time")
50 | }
51 | return nil
52 | }
53 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/errors.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | import (
4 | "github.com/bianjieai/tibc-sdk-go/modules/types"
5 | )
6 |
7 | const (
8 | SubModuleName = "tendermint-client"
9 | moduleName = "tibc" + "-" + SubModuleName
10 | )
11 |
12 | // IBC tendermint client sentinel errors
13 | var (
14 | ErrInvalidChainID = types.Register(moduleName, 2, "invalid chain-id")
15 | ErrInvalidTrustingPeriod = types.Register(moduleName, 3, "invalid trusting period")
16 | ErrInvalidUnbondingPeriod = types.Register(moduleName, 4, "invalid unbonding period")
17 | ErrInvalidHeaderHeight = types.Register(moduleName, 5, "invalid header height")
18 | ErrInvalidHeader = types.Register(moduleName, 6, "invalid header")
19 | ErrInvalidMaxClockDrift = types.Register(moduleName, 7, "invalid max clock drift")
20 | ErrProcessedTimeNotFound = types.Register(moduleName, 8, "processed time not found")
21 | ErrDelayPeriodNotPassed = types.Register(moduleName, 9, "packet-specified delay period has not been reached")
22 | ErrTrustingPeriodExpired = types.Register(moduleName, 10, "time since latest trusted state has passed the trusting period")
23 | ErrUnbondingPeriodExpired = types.Register(moduleName, 11, "time since latest trusted state has passed the unbonding period")
24 | ErrInvalidProofSpecs = types.Register(moduleName, 12, "invalid proof specs")
25 | ErrInvalidValidatorSet = types.Register(moduleName, 13, "invalid validator set")
26 | )
27 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/header.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "strconv"
7 | "strings"
8 | "time"
9 |
10 | "github.com/bianjieai/tibc-sdk-go/modules/core/client"
11 | commitmenttypes "github.com/bianjieai/tibc-sdk-go/modules/core/commitment"
12 | "github.com/bianjieai/tibc-sdk-go/modules/types"
13 |
14 | tmprtypes "github.com/tendermint/tendermint/proto/tendermint/types"
15 | tmtypes "github.com/tendermint/tendermint/types"
16 | )
17 |
18 | var _ types.Header = &Header{}
19 |
20 | func TmHeaderToPrHeader(h tmtypes.Header) Header {
21 | si := &tmprtypes.SignedHeader{
22 | Header: h.ToProto(),
23 | }
24 | return Header{
25 | SignedHeader: si,
26 | }
27 | }
28 |
29 | // ConsensusState returns the updated consensus state associated with the header
30 | func (h Header) ConsensusState() *ConsensusState {
31 | return &ConsensusState{
32 | Timestamp: h.GetTime(),
33 | Root: commitmenttypes.NewMerkleRoot(h.Header.GetAppHash()),
34 | NextValidatorsHash: h.Header.NextValidatorsHash,
35 | }
36 | }
37 |
38 | // ClientType defines that the Header is a Tendermint consensus algorithm
39 | func (h Header) ClientType() string {
40 | return "007-tendermint"
41 | }
42 |
43 | // GetHeight returns the current height. It returns 0 if the tendermint
44 | // header is nil.
45 | // NOTE: the header.Header is checked to be non nil in ValidateBasic.
46 | func (h Header) GetHeight() types.Height {
47 | if !client.IsRevisionFormat(h.Header.ChainID) {
48 | // chainID is not in revision format, return 0 as default
49 | return client.NewHeight(0, uint64(h.Header.Height))
50 | } else {
51 | splitStr := strings.Split(h.Header.ChainID, "-")
52 | revision, err := strconv.ParseUint(splitStr[len(splitStr)-1], 10, 64)
53 | // sanity check: error should always be nil since regex only allows numbers in last element
54 | if err != nil {
55 | panic(fmt.Sprintf("regex allowed non-number value as last split element for chainID: %s", h.Header.ChainID))
56 | }
57 | return client.NewHeight(revision, uint64(h.Header.Height))
58 | }
59 |
60 | }
61 |
62 | // GetTime returns the current block timestamp. It returns a zero time if
63 | // the tendermint header is nil.
64 | // NOTE: the header.Header is checked to be non nil in ValidateBasic.
65 | func (h Header) GetTime() time.Time {
66 | return h.Header.Time
67 | }
68 |
69 | // ValidateBasic calls the SignedHeader ValidateBasic function and checks
70 | // that validatorsets are not nil.
71 | // NOTE: TrustedHeight and TrustedValidators may be empty when creating client
72 | // with MsgCreateClient
73 | func (h Header) ValidateBasic() error {
74 | if h.SignedHeader == nil {
75 | return types.Wrap(types.ErrInvalidHeader, "tendermint signed header cannot be nil")
76 | }
77 | if h.Header == nil {
78 | return types.Wrap(types.ErrInvalidHeader, "tendermint header cannot be nil")
79 | }
80 | tmSignedHeader, err := tmtypes.SignedHeaderFromProto(h.SignedHeader)
81 | if err != nil {
82 | return types.Wrap(err, "header is not a tendermint header")
83 | }
84 | if err := tmSignedHeader.ValidateBasic(h.Header.GetChainID()); err != nil {
85 | return types.Wrap(err, "header failed basic validation")
86 | }
87 |
88 | if h.ValidatorSet == nil {
89 | return types.Wrap(types.ErrInvalidHeader, "validator set is nil")
90 | }
91 | tmValset, err := tmtypes.ValidatorSetFromProto(h.ValidatorSet)
92 | if err != nil {
93 | return types.Wrap(err, "validator set is not tendermint validator set")
94 | }
95 | if !bytes.Equal(h.Header.ValidatorsHash, tmValset.Hash()) {
96 | return types.Wrap(types.ErrInvalidHeader, "validator set does not match hash")
97 | }
98 | return nil
99 | }
100 |
--------------------------------------------------------------------------------
/modules/light-clients/tendermint/types.go:
--------------------------------------------------------------------------------
1 | package tendermint
2 |
3 | type EthermintConfig struct {
4 | Prefix []byte `json:"prefix"`
5 | ContractAddress string `json:"contract_address"`
6 | }
7 |
--------------------------------------------------------------------------------
/modules/types/errors.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/pkg/errors"
7 | )
8 |
9 | const RootCodeSpace = "tibc-sdk-go"
10 |
11 | var (
12 | ErrInternal = Register(RootCodeSpace, 1, "internal")
13 | ErrChainConn = Register(RootCodeSpace, 2, "connection chain failed")
14 | ErrGetLightClientState = Register(RootCodeSpace, 3, "failed to get light client state")
15 | ErrGetBlockHeader = Register(RootCodeSpace, 4, "failed to get block header")
16 | ErrUpdateClient = Register(RootCodeSpace, 5, "failed to update client")
17 | ErrGetPackets = Register(RootCodeSpace, 6, "failed to get packets")
18 | ErrGetCommitmentPacket = Register(RootCodeSpace, 7, "failed to get commitment packet")
19 | ErrGetAckPacket = Register(RootCodeSpace, 8, "failed to get ack packet")
20 | ErrGetReceiptPacket = Register(RootCodeSpace, 9, "failed to get receipt packet")
21 | ErrGetProof = Register(RootCodeSpace, 10, "failed to get proof")
22 | ErrGetLatestHeight = Register(RootCodeSpace, 11, "failed to get latest height")
23 | ErrRecvPacket = Register(RootCodeSpace, 12, "failed to recv packet")
24 | ErrNotProduced = Register(RootCodeSpace, 13, "failed to not produced")
25 | ErrUnknownMsg = Register(RootCodeSpace, 14, "failed to unknown msg type")
26 | ErrUnpackAny = Register(RootCodeSpace, 15, "failed to unpack any")
27 | ErrGetLightClientConsensusState = Register(RootCodeSpace, 16, "failed to light consensus state")
28 | ErrGetRelayer = Register(RootCodeSpace, 17, "failed to get relayer")
29 | ErrGetAddress = Register(RootCodeSpace, 18, "failed to get address")
30 | ErrPackAny = Register(RootCodeSpace, 19, "failed to pack any")
31 | ErrGetUnreceivedPacket = Register(RootCodeSpace, 20, "failed to get unreceived packet")
32 | ErrSendAckPacket = Register(RootCodeSpace, 21, "failed to send ack packet")
33 | ErrSendCleanPacket = Register(RootCodeSpace, 22, "failed to send clean packet")
34 | ErrRecvCleanPacket = Register(RootCodeSpace, 23, "failed to recv clean packet")
35 | ErrNftTransfer = Register(RootCodeSpace, 24, "failed to send nft transfer ")
36 | ErrInvalidConsensus = Register(RootCodeSpace, 25, "invalid consensus state")
37 | ErrInvalidHeader = Register(RootCodeSpace, 26, "invalid consensus state")
38 | ErrInvalidHeight = Register(RootCodeSpace, 27, "invalid height")
39 | ErrInvalidAddress = Register(RootCodeSpace, 28, "invalid address")
40 | ErrInvalidID = Register(RootCodeSpace, 29, "invalid identifier")
41 | )
42 |
43 | var usedCodes = map[string]*Error{}
44 |
45 | func getUsed(codespace string, code uint32) *Error {
46 | return usedCodes[errorID(codespace, code)]
47 | }
48 |
49 | func setUsed(err *Error) {
50 | usedCodes[errorID(err.codeSpace, err.code)] = err
51 | }
52 |
53 | func errorID(codespace string, code uint32) string {
54 | return fmt.Sprintf("%s:%d", codespace, code)
55 | }
56 |
57 | type IError interface {
58 | error
59 | Code() uint32
60 | Codespace() string
61 | }
62 |
63 | type Error struct {
64 | codeSpace string
65 | code uint32
66 | desc string
67 | }
68 |
69 | func (e Error) Codespace() string {
70 | return e.codeSpace
71 | }
72 |
73 | func New(codeSpace string, code uint32, desc string) *Error {
74 | return &Error{codeSpace: codeSpace, code: code, desc: desc}
75 | }
76 |
77 | func (e Error) Error() string {
78 | return e.desc
79 | }
80 |
81 | func (e Error) Code() uint32 {
82 | return e.code
83 | }
84 |
85 | func Register(codespace string, code uint32, description string) *Error {
86 | if e := getUsed(codespace, code); e != nil {
87 | panic(fmt.Sprintf("error with code %d is already registered: %q", code, e.desc))
88 | }
89 |
90 | err := New(codespace, code, description)
91 | setUsed(err)
92 |
93 | return err
94 | }
95 |
96 | type WrappedError struct {
97 | // This error layer description.
98 | msg string
99 | // The underlying error that triggered this one.
100 | parent error
101 | }
102 |
103 | func (e *WrappedError) Error() string {
104 | return fmt.Sprintf("%s: %s", e.msg, e.parent.Error())
105 | }
106 |
107 | func (e *WrappedError) Cause() error {
108 | return e.parent
109 | }
110 |
111 | // Is reports whether any error in e's chain matches a target.
112 | func (e *WrappedError) Is(target error) bool {
113 | if e == target {
114 | return true
115 | }
116 |
117 | w := e.Cause()
118 | for {
119 | if w == target {
120 | return true
121 | }
122 |
123 | x, ok := w.(causer)
124 | if ok {
125 | w = x.Cause()
126 | }
127 | if x == nil {
128 | return false
129 | }
130 | }
131 | }
132 |
133 | // Unwrap implements the built-in errors.Unwrap
134 | func (e *WrappedError) Unwrap() error {
135 | return e.parent
136 | }
137 |
138 | // causer is an interface implemented by an error that supports wrapping. Use
139 | // it to test if an error wraps another error instance.
140 | type causer interface {
141 | Cause() error
142 | }
143 |
144 | type unpacker interface {
145 | Unpack() []error
146 | }
147 |
148 | func IErrorWrap(err IError, description string) IError {
149 | if err == nil {
150 | return nil
151 | }
152 |
153 | errMsg := fmt.Sprintf("[%s,%s]", err.Error(), description)
154 |
155 | return &Error{
156 | codeSpace: err.Codespace(),
157 | code: err.Code(),
158 | desc: errMsg,
159 | }
160 | }
161 |
162 | func Wrap(err error, description string) error {
163 | if err == nil {
164 | return nil
165 | }
166 |
167 | // If this error does not carry the stacktrace information yet, attach
168 | // one. This should be done only once per error at the lowest frame
169 | // possible (most inner wrap).
170 | if stackTrace(err) == nil {
171 | err = errors.WithStack(err)
172 | }
173 |
174 | return &WrappedError{
175 | parent: err,
176 | msg: description,
177 | }
178 | }
179 |
180 | // stackTrace returns the first found stack trace frame carried by given error
181 | // or any wrapped error. It returns nil if no stack trace is found.
182 | func stackTrace(err error) errors.StackTrace {
183 | type stackTracer interface {
184 | StackTrace() errors.StackTrace
185 | }
186 |
187 | for {
188 | if st, ok := err.(stackTracer); ok {
189 | return st.StackTrace()
190 | }
191 |
192 | if c, ok := err.(causer); ok {
193 | err = c.Cause()
194 | } else {
195 | return nil
196 | }
197 | }
198 | }
199 | func Wrapf(err error, format string, args ...interface{}) error {
200 | desc := fmt.Sprintf(format, args...)
201 | return Wrap(err, desc)
202 | }
203 |
--------------------------------------------------------------------------------
/modules/types/exported.go:
--------------------------------------------------------------------------------
1 | package types
2 |
3 | import (
4 | "github.com/gogo/protobuf/proto"
5 | )
6 |
7 | // TODO:
8 | type UpdateClientRequest struct {
9 | ChainName string `json:"chain_name"`
10 | // header to update the light client
11 | Header Header `json:"header"`
12 | }
13 |
14 | // ClientState defines the required common functions for light clients.
15 | type ClientState interface {
16 | proto.Message
17 |
18 | ClientType() string
19 | GetLatestHeight() Height
20 | Validate() error
21 | GetDelayTime() uint64
22 | GetDelayBlock() uint64
23 | GetPrefix() Prefix
24 | }
25 |
26 | // ConsensusState is the state of the consensus process
27 | type ConsensusState interface {
28 | proto.Message
29 |
30 | ClientType() string // Consensus kind
31 |
32 | // GetRoot returns the commitment root of the consensus state,
33 | // which is used for key-value pair verification.
34 | GetRoot() Root
35 |
36 | // GetTimestamp returns the timestamp (in nanoseconds) of the consensus state
37 | GetTimestamp() uint64
38 |
39 | ValidateBasic() error
40 | }
41 |
42 | // Header is the consensus state update information
43 | type Header interface {
44 | proto.Message
45 |
46 | ClientType() string
47 | GetHeight() Height
48 | ValidateBasic() error
49 | }
50 |
51 | // Root implements spec:CommitmentRoot.
52 | // A root is constructed from a set of key-value pairs,
53 | // and the inclusion or non-inclusion of an arbitrary key-value pair
54 | // can be proven with the proof.
55 | type Root interface {
56 | GetHash() []byte
57 | Empty() bool
58 | }
59 |
60 | // Prefix implements spec:CommitmentPrefix.
61 | // Prefix represents the common "prefix" that a set of keys shares.
62 | type Prefix interface {
63 | Bytes() []byte
64 | Empty() bool
65 | }
66 |
67 | // Path implements spec:CommitmentPath.
68 | // A path is the additional information provided to the verification function.
69 | type Path interface {
70 | String() string
71 | Empty() bool
72 | }
73 |
74 | // Height is a wrapper interface over client.Height
75 | // all clients must use the concrete implementation in types
76 | type Height interface {
77 | IsZero() bool
78 | GetRevisionNumber() uint64
79 | GetRevisionHeight() uint64
80 | Increment() Height
81 | Decrement() (Height, bool)
82 | String() string
83 | }
84 |
85 | // PacketI defines the standard interface for IBC packets
86 | type PacketI interface {
87 | GetSequence() uint64
88 | GetPort() string
89 | GetSourceChain() string
90 | GetDestChain() string
91 | GetRelayChain() string
92 | GetData() []byte
93 | ValidateBasic() error
94 | }
95 |
96 | // CleanPacketI defines the standard interface for TIBC clean packets
97 | type CleanPacketI interface {
98 | GetSequence() uint64
99 | GetSourceChain() string
100 | GetDestChain() string
101 | GetRelayChain() string
102 | ValidateBasic() error
103 | }
104 |
--------------------------------------------------------------------------------
/proto/tibc/apps/mt_transfer/v1/mt_transfer.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tibc.apps.mt_transfer.v1;
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/apps/mt_transfer";
5 |
6 | message MultiTokenPacketData {
7 | // the class to which the Mt to be transferred belongs
8 | string class = 1;
9 | // the mt id
10 | string id = 2;
11 | // the address defined by MT outside the chain
12 | bytes data = 3;
13 | // the mt sender
14 | string sender = 4;
15 | // the mt receiver
16 | string receiver = 5;
17 | // identify whether it is far away from the source chain
18 | bool away_from_origin = 6;
19 | // the destination contract address to receive the nft
20 | string dest_contract = 7;
21 | // the amount defined by MT outside the chain
22 | uint64 amount = 8;
23 | }
24 | // ClassTrace contains the base class for Multi Token and the
25 | // source tracing information path.
26 | message ClassTrace {
27 | // path defines the chain of sourceChain/destChain
28 | // identifiers used for tracing the source of the Non fungible token.
29 | string path = 1;
30 | // base class of the relayed non fungible token.
31 | string base_class = 2;
32 | }
--------------------------------------------------------------------------------
/proto/tibc/apps/mt_transfer/v1/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.apps.mt_transfer.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/apps/mt_transfer";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | // Msg defines the tibc/MtTransfer Msg service.
9 | service Msg {
10 | // MtTransfer defines a rpc handler method for MsgMtTransfer.
11 | rpc MtTransfer(MsgMtTransfer) returns (MsgMtTransferResponse);
12 | }
13 |
14 | message MsgMtTransfer {
15 | option (gogoproto.equal) = false;
16 | option (gogoproto.goproto_getters) = false;
17 |
18 | // the class to which the mt to be transferred belongs
19 | string class = 1;
20 | // the mt id
21 | string id = 2;
22 | // the mt sender
23 | string sender = 3;
24 | // the mt receiver
25 | string receiver = 4;
26 | // target chain of transmission
27 | string dest_chain = 5;
28 | // relay chain during transmission
29 | string realay_chain = 6;
30 | // the destination contract address to receive the nft
31 | string dest_contract = 7;
32 | // the amount defined by MT outside the chain
33 | uint64 amount = 8;
34 | }
35 |
36 | // MsgMtTransferResponse defines the Msg/MtTransfer response type.
37 | message MsgMtTransferResponse {}
--------------------------------------------------------------------------------
/proto/tibc/apps/nft_transfer/v1/nft_transfer.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tibc.apps.nft_transfer.v1;
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/apps/nft_transfer";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | message NonFungibleTokenPacketData {
9 | // the class to which the NFT to be transferred belongs
10 | string class = 1;
11 | // the nft id
12 | string id = 2;
13 | // the address defined by NFT outside the chain
14 | string uri = 3;
15 | // the nft sender
16 | string sender = 4;
17 | // the nft receiver
18 | string receiver = 5;
19 | // identify whether it is far away from the source chain
20 | bool away_from_origin = 6;
21 | // the destination contract address to receive the nft
22 | string dest_contract = 7;
23 | }
24 | // ClassTrace contains the base class for TICS30 Non fungible tokens and the
25 | // source tracing information path.
26 | message ClassTrace {
27 | // path defines the chain of sourceChain/destChain
28 | // identifiers used for tracing the source of the Non fungible token.
29 | string path = 1;
30 | // base class of the relayed non fungible token.
31 | string base_class = 2;
32 | }
--------------------------------------------------------------------------------
/proto/tibc/apps/nft_transfer/v1/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.apps.nft_transfer.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/apps/nft_transfer";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | // Msg defines the ibc/nftTransfer Msg service.
9 | service Msg {
10 | // NftTransfer defines a rpc handler method for MsgNftTransfer.
11 | rpc NftTransfer(MsgNftTransfer) returns (MsgNftTransferResponse);
12 | }
13 |
14 | message MsgNftTransfer {
15 | option (gogoproto.equal) = false;
16 | option (gogoproto.goproto_getters) = false;
17 |
18 | // the class to which the NFT to be transferred belongs
19 | string class = 1;
20 | // the nft id
21 | string id = 2;
22 | // the nft sender
23 | string sender = 3;
24 | // the nft receiver
25 | string receiver = 4;
26 | // target chain of transmission
27 | string dest_chain = 5;
28 | // relay chain during transmission
29 | string realay_chain = 6;
30 | // the destination contract address to receive the nft
31 | string dest_contract = 7;
32 | }
33 |
34 | // MsgTransferResponse defines the Msg/NftTransfer response type.
35 | message MsgNftTransferResponse {}
--------------------------------------------------------------------------------
/proto/tibc/core/client/v1/client.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.client.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/client";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "google/protobuf/any.proto";
8 |
9 | // IdentifiedClientState defines a client state with an additional client
10 | // identifier field.
11 | message IdentifiedClientState {
12 | // client identifier
13 | string chain_name = 1;
14 | // client state
15 | google.protobuf.Any client_state = 2;
16 | }
17 |
18 | // IdentifiedRelayer defines a list of authorized relayers for the specified
19 | // client.
20 | message IdentifiedRelayers {
21 | // client identifier
22 | string chain_name = 1;
23 |
24 | // authorized relayer list
25 | repeated string relayers = 2;
26 | }
27 |
28 | // ConsensusStateWithHeight defines a consensus state with an additional height
29 | // field.
30 | message ConsensusStateWithHeight {
31 | // consensus state height
32 | Height height = 1 [(gogoproto.nullable) = false];
33 | // consensus state
34 | google.protobuf.Any consensus_state = 2;
35 | }
36 |
37 | // ClientConsensusStates defines all the stored consensus states for a given
38 | // client.
39 | message ClientConsensusStates {
40 | // client identifier
41 | string chain_name = 1;
42 | // consensus states and their heights associated with the client
43 | repeated ConsensusStateWithHeight consensus_states = 2
44 | [(gogoproto.nullable) = false];
45 | }
46 |
47 | // CreateClientProposal defines a overnance proposal to create an IBC client
48 | message CreateClientProposal {
49 | option (gogoproto.goproto_getters) = false;
50 | // the title of the update proposal
51 | string title = 1;
52 | // the description of the proposal
53 | string description = 2;
54 | // the client identifier for the client to be updated if the proposal passes
55 | string chain_name = 3;
56 | // light client state
57 | google.protobuf.Any client_state = 4;
58 | // consensus state associated with the client that corresponds to a given
59 | // height.
60 | google.protobuf.Any consensus_state = 5;
61 | }
62 |
63 | // UpgradeClientProposal defines a overnance proposal to overide an IBC client
64 | // state
65 | message UpgradeClientProposal {
66 | option (gogoproto.goproto_getters) = false;
67 | // the title of the update proposal
68 | string title = 1;
69 | // the description of the proposal
70 | string description = 2;
71 | // the client identifier for the client to be updated if the proposal passes
72 | string chain_name = 3;
73 | // client state
74 | google.protobuf.Any client_state = 4;
75 | // consensus state
76 | google.protobuf.Any consensus_state = 5;
77 | }
78 |
79 | // RegisterRelayerProposal defines a overnance proposal to register some
80 | // relayers for updating a client state.
81 | message RegisterRelayerProposal {
82 | option (gogoproto.goproto_getters) = false;
83 | // the title of the update proposal
84 | string title = 1;
85 | // the description of the proposal
86 | string description = 2;
87 | // the client identifier for the client to be updated if the proposal passes
88 | string chain_name = 3;
89 | // relayer address list
90 | repeated string relayers = 4;
91 | }
92 |
93 | // Height is a monotonically increasing data type
94 | // that can be compared against another Height for the purposes of updating and
95 | // freezing clients
96 | //
97 | // Normally the RevisionHeight is incremented at each height while keeping
98 | // RevisionNumber the same. However some consensus algorithms may choose to
99 | // reset the height in certain conditions e.g. hard forks, state-machine
100 | // breaking changes In these cases, the RevisionNumber is incremented so that
101 | // height continues to be monitonically increasing even as the RevisionHeight
102 | // gets reset
103 | message Height {
104 | option (gogoproto.goproto_getters) = false;
105 | option (gogoproto.goproto_stringer) = false;
106 |
107 | // the revision that the client is currently on
108 | uint64 revision_number = 1
109 | [(gogoproto.moretags) = "yaml:\"revision_number\""];
110 | // the height within the given revision
111 | uint64 revision_height = 2
112 | [(gogoproto.moretags) = "yaml:\"revision_height\""];
113 | }
114 |
--------------------------------------------------------------------------------
/proto/tibc/core/client/v1/genesis.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.client.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/client";
5 |
6 | import "tibc/core/client/v1/client.proto";
7 | import "gogoproto/gogo.proto";
8 |
9 | // GenesisState defines the ibc client submodule's genesis state.
10 | message GenesisState {
11 | // client states with their corresponding identifiers
12 | repeated IdentifiedClientState clients = 1 [
13 | (gogoproto.nullable) = false,
14 | (gogoproto.castrepeated) = "IdentifiedClientStates"
15 | ];
16 | // consensus states from each client
17 | repeated ClientConsensusStates clients_consensus = 2 [
18 | (gogoproto.nullable) = false,
19 | (gogoproto.castrepeated) = "ClientsConsensusStates"
20 | ];
21 | // metadata from each client
22 | repeated IdentifiedGenesisMetadata clients_metadata = 3
23 | [ (gogoproto.nullable) = false ];
24 | // the chain name of the current chain
25 | string native_chain_name = 5;
26 |
27 | // IdentifiedRelayer defines a list of authorized relayers for the specified
28 | // client.
29 | repeated IdentifiedRelayers relayers = 6 [ (gogoproto.nullable) = false ];
30 | }
31 |
32 | // GenesisMetadata defines the genesis type for metadata that clients may return
33 | // with ExportMetadata
34 | message GenesisMetadata {
35 | option (gogoproto.goproto_getters) = false;
36 |
37 | // store key of metadata without chainName-prefix
38 | bytes key = 1;
39 | // metadata value
40 | bytes value = 2;
41 | }
42 |
43 | // IdentifiedGenesisMetadata has the client metadata with the corresponding
44 | // chain name.
45 | message IdentifiedGenesisMetadata {
46 | string chain_name = 1;
47 | repeated GenesisMetadata metadata = 2 [ (gogoproto.nullable) = false ];
48 | }
--------------------------------------------------------------------------------
/proto/tibc/core/client/v1/query.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.client.v1;
3 |
4 | import "cosmos/base/query/v1beta1/pagination.proto";
5 | import "tibc/core/client/v1/client.proto";
6 | import "google/protobuf/any.proto";
7 | import "google/api/annotations.proto";
8 | import "gogoproto/gogo.proto";
9 |
10 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/client";
11 |
12 | // Query provides defines the gRPC querier service
13 | service Query {
14 | // ClientState queries an IBC light client.
15 | rpc ClientState(QueryClientStateRequest) returns (QueryClientStateResponse) {
16 | option (google.api.http).get =
17 | "/ibc/core/client/v1beta1/client_states/{chain_name}";
18 | }
19 |
20 | // ClientStates queries all the IBC light clients of a chain.
21 | rpc ClientStates(QueryClientStatesRequest)
22 | returns (QueryClientStatesResponse) {
23 | option (google.api.http).get = "/ibc/core/client/v1beta1/client_states";
24 | }
25 |
26 | // ConsensusState queries a consensus state associated with a client state at
27 | // a given height.
28 | rpc ConsensusState(QueryConsensusStateRequest)
29 | returns (QueryConsensusStateResponse) {
30 | option (google.api.http).get = "/ibc/core/client/v1beta1/consensus_states/"
31 | "{chain_name}/revision/{revision_number}/"
32 | "height/{revision_height}";
33 | }
34 |
35 | // ConsensusStates queries all the consensus state associated with a given
36 | // client.
37 | rpc ConsensusStates(QueryConsensusStatesRequest)
38 | returns (QueryConsensusStatesResponse) {
39 | option (google.api.http).get =
40 | "/ibc/core/client/v1beta1/consensus_states/{chain_name}";
41 | }
42 |
43 | // Relayers queries all the relayers associated with a given
44 | // client.
45 | rpc Relayers(QueryRelayersRequest) returns (QueryRelayersResponse) {
46 | option (google.api.http).get =
47 | "/ibc/core/client/v1beta1/relayers/{chain_name}";
48 | }
49 | }
50 |
51 | // QueryClientStateRequest is the request type for the Query/ClientState RPC
52 | // method
53 | message QueryClientStateRequest {
54 | // client state unique identifier
55 | string chain_name = 1;
56 | }
57 |
58 | // QueryClientStateResponse is the response type for the Query/ClientState RPC
59 | // method. Besides the client state, it includes a proof and the height from
60 | // which the proof was retrieved.
61 | message QueryClientStateResponse {
62 | // client state associated with the request identifier
63 | google.protobuf.Any client_state = 1;
64 | // merkle proof of existence
65 | bytes proof = 2;
66 | // height at which the proof was retrieved
67 | tibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
68 | }
69 |
70 | // QueryClientStatesRequest is the request type for the Query/ClientStates RPC
71 | // method
72 | message QueryClientStatesRequest {
73 | // pagination request
74 | cosmos.base.query.v1beta1.PageRequest pagination = 1;
75 | }
76 |
77 | // QueryClientStatesResponse is the response type for the Query/ClientStates RPC
78 | // method.
79 | message QueryClientStatesResponse {
80 | // list of stored ClientStates of the chain.
81 | repeated IdentifiedClientState client_states = 1 [
82 | (gogoproto.nullable) = false,
83 | (gogoproto.castrepeated) = "IdentifiedClientStates"
84 | ];
85 | // pagination response
86 | cosmos.base.query.v1beta1.PageResponse pagination = 2;
87 | }
88 |
89 | // QueryConsensusStateRequest is the request type for the Query/ConsensusState
90 | // RPC method. Besides the consensus state, it includes a proof and the height
91 | // from which the proof was retrieved.
92 | message QueryConsensusStateRequest {
93 | // client identifier
94 | string chain_name = 1;
95 | // consensus state revision number
96 | uint64 revision_number = 2;
97 | // consensus state revision height
98 | uint64 revision_height = 3;
99 | // latest_height overrrides the height field and queries the latest stored
100 | // ConsensusState
101 | bool latest_height = 4;
102 | }
103 |
104 | // QueryConsensusStateResponse is the response type for the Query/ConsensusState
105 | // RPC method
106 | message QueryConsensusStateResponse {
107 | // consensus state associated with the client identifier at the given height
108 | google.protobuf.Any consensus_state = 1;
109 | // merkle proof of existence
110 | bytes proof = 2;
111 | // height at which the proof was retrieved
112 | tibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
113 | }
114 |
115 | // QueryConsensusStatesRequest is the request type for the Query/ConsensusStates
116 | // RPC method.
117 | message QueryConsensusStatesRequest {
118 | // client identifier
119 | string chain_name = 1;
120 | // pagination request
121 | cosmos.base.query.v1beta1.PageRequest pagination = 2;
122 | }
123 |
124 | // QueryConsensusStatesResponse is the response type for the
125 | // Query/ConsensusStates RPC method
126 | message QueryConsensusStatesResponse {
127 | // consensus states associated with the identifier
128 | repeated ConsensusStateWithHeight consensus_states = 1
129 | [(gogoproto.nullable) = false];
130 | // pagination response
131 | cosmos.base.query.v1beta1.PageResponse pagination = 2;
132 | }
133 |
134 | // QueryRelayersRequest is the request type for the Query/Relayers
135 | // RPC method.
136 | message QueryRelayersRequest {
137 | // client identifier
138 | string chain_name = 1;
139 | }
140 |
141 | // QueryConsensusStatesResponse is the response type for the
142 | // Query/Relayers RPC method
143 | message QueryRelayersResponse {
144 | // relayers address associated with the client
145 | repeated string relayers = 1;
146 | }
147 |
--------------------------------------------------------------------------------
/proto/tibc/core/client/v1/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.client.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/client";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "google/protobuf/any.proto";
8 |
9 | // Msg defines the ibc/client Msg service.
10 | service Msg {
11 | // UpdateClient defines a rpc handler method for MsgUpdateClient.
12 | rpc UpdateClient(MsgUpdateClient) returns (MsgUpdateClientResponse);
13 | }
14 |
15 | // MsgUpdateClient defines an sdk.Msg to update a IBC client state using
16 | // the given header.
17 | message MsgUpdateClient {
18 | option (gogoproto.equal) = false;
19 | option (gogoproto.goproto_getters) = false;
20 |
21 | // client unique identifier
22 | string chain_name = 1;
23 | // header to update the light client
24 | google.protobuf.Any header = 2;
25 | // signer address
26 | string signer = 3;
27 | }
28 |
29 | // MsgUpdateClientResponse defines the Msg/UpdateClient response type.
30 | message MsgUpdateClientResponse {}
31 |
--------------------------------------------------------------------------------
/proto/tibc/core/commitment/v1/commitment.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.commitment.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/commitment";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "confio/proofs.proto";
8 |
9 | // MerkleRoot defines a merkle root hash.
10 | // In the Cosmos SDK, the AppHash of a block header becomes the root.
11 | message MerkleRoot {
12 | option (gogoproto.goproto_getters) = false;
13 |
14 | bytes hash = 1;
15 | }
16 |
17 | // MerklePrefix is merkle path prefixed to the key.
18 | // The constructed key from the Path and the key will be append(Path.KeyPath,
19 | // append(Path.KeyPrefix, key...))
20 | message MerklePrefix {
21 | bytes key_prefix = 1 [(gogoproto.moretags) = "yaml:\"key_prefix\""];
22 | }
23 |
24 | // MerklePath is the path used to verify commitment proofs, which can be an
25 | // arbitrary structured object (defined by a commitment type).
26 | // MerklePath is represented from root-to-leaf
27 | message MerklePath {
28 | option (gogoproto.goproto_stringer) = false;
29 |
30 | repeated string key_path = 1 [(gogoproto.moretags) = "yaml:\"key_path\""];
31 | }
32 |
33 | // MerkleProof is a wrapper type over a chain of CommitmentProofs.
34 | // It demonstrates membership or non-membership for an element or set of
35 | // elements, verifiable in conjunction with a known commitment root. Proofs
36 | // should be succinct.
37 | // MerkleProofs are ordered from leaf-to-root
38 | message MerkleProof {
39 | repeated ics23.CommitmentProof proofs = 1;
40 | }
--------------------------------------------------------------------------------
/proto/tibc/core/packet/v1/genesis.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.packet.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/packet";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tibc/core/packet/v1/packet.proto";
8 |
9 | // GenesisState defines the ibc channel submodule's genesis state.
10 | message GenesisState {
11 | repeated PacketState acknowledgements = 2 [(gogoproto.nullable) = false];
12 | repeated PacketState commitments = 3 [(gogoproto.nullable) = false];
13 | repeated PacketState receipts = 4 [(gogoproto.nullable) = false];
14 | repeated PacketSequence send_sequences = 5
15 | [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"send_sequences\""];
16 | repeated PacketSequence recv_sequences = 6
17 | [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"recv_sequences\""];
18 | repeated PacketSequence ack_sequences = 7
19 | [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"ack_sequences\""];
20 | // the sequence for the next generated channel identifier
21 | uint64 next_channel_sequence = 8 [(gogoproto.moretags) = "yaml:\"next_channel_sequence\""];
22 | }
23 |
24 | // PacketSequence defines the genesis type necessary to retrieve and store
25 | // next send and receive sequences.
26 | message PacketSequence {
27 | string source_chain = 1 [(gogoproto.moretags) = "yaml:\"source_chain\""];
28 | string destination_chain = 2 [(gogoproto.moretags) = "yaml:\"destination_chain\""];
29 | uint64 sequence = 3;
30 | }
31 |
--------------------------------------------------------------------------------
/proto/tibc/core/packet/v1/packet.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.packet.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/packet";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | // Packet defines a type that carries data across different chains through IBC
9 | message Packet {
10 | option (gogoproto.goproto_getters) = false;
11 |
12 | // number corresponds to the order of sends and receives, where a Packet
13 | // with an earlier sequence number must be sent and received before a Packet
14 | // with a later sequence number.
15 | uint64 sequence = 1;
16 | // identifies the port on the sending chain and destination chain.
17 | string port = 2;
18 | // identifies the chain id of the sending chain.
19 | string source_chain = 3 [(gogoproto.moretags) = "yaml:\"source_chain\""];
20 | // identifies the chain id of the receiving chain.
21 | string destination_chain = 4 [(gogoproto.moretags) = "yaml:\"destination_port\""];
22 | // identifies the chain id of the relay chain.
23 | string relay_chain = 5 [(gogoproto.moretags) = "yaml:\"relay_chain\""];
24 | // actual opaque bytes transferred directly to the application module
25 | bytes data = 6;
26 | }
27 |
28 | // CleanPacket defines a type that carries data across different chains through IBC
29 | message CleanPacket {
30 | option (gogoproto.goproto_getters) = false;
31 |
32 | // number corresponds to the order of sends and receives, where a Packet
33 | // with an earlier sequence number must be sent and received before a Packet
34 | // with a later sequence number.
35 | uint64 sequence = 1;
36 | // identifies the chain id of the sending chain.
37 | string source_chain = 3 [(gogoproto.moretags) = "yaml:\"source_chain\""];
38 | // identifies the chain id of the receiving chain.
39 | string destination_chain = 4 [(gogoproto.moretags) = "yaml:\"destination_port\""];
40 | // identifies the chain id of the relay chain.
41 | string relay_chain = 5 [(gogoproto.moretags) = "yaml:\"relay_chain\""];
42 | }
43 |
44 | // PacketState defines the generic type necessary to retrieve and store
45 | // packet commitments, acknowledgements, and receipts.
46 | // Caller is responsible for knowing the context necessary to interpret this
47 | // state as a commitment, acknowledgement, or a receipt.
48 | message PacketState {
49 | option (gogoproto.goproto_getters) = false;
50 |
51 | // the sending chain identifier.
52 | string source_chain = 1 [(gogoproto.moretags) = "yaml:\"source_chain\""];
53 | // the receiving chain identifier.
54 | string destination_chain = 2 [(gogoproto.moretags) = "yaml:\"source_chain\""];
55 | // packet sequence.
56 | uint64 sequence = 3;
57 | // embedded data that represents packet state.
58 | bytes data = 4;
59 | }
60 |
61 | // Acknowledgement is the recommended acknowledgement format to be used by
62 | // app-specific protocols.
63 | // NOTE: The field numbers 21 and 22 were explicitly chosen to avoid accidental
64 | // conflicts with other protobuf message formats used for acknowledgements.
65 | // The first byte of any message with this format will be the non-ASCII values
66 | // `0xaa` (result) or `0xb2` (error). Implemented as defined by ICS:
67 | // https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope
68 | message Acknowledgement {
69 | // response contains either a result or an error and must be non-empty
70 | oneof response {
71 | bytes result = 21;
72 | string error = 22;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/proto/tibc/core/packet/v1/query.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.packet.v1;
3 |
4 | import "tibc/core/client/v1/client.proto";
5 | import "cosmos/base/query/v1beta1/pagination.proto";
6 | import "tibc/core/packet/v1/packet.proto";
7 | import "google/api/annotations.proto";
8 | import "gogoproto/gogo.proto";
9 |
10 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/packet";
11 |
12 | // Query provides defines the gRPC querier service
13 | service Query {
14 | // PacketCommitment queries a stored packet commitment hash.
15 | rpc PacketCommitment(QueryPacketCommitmentRequest) returns (QueryPacketCommitmentResponse) {
16 | option (google.api.http).get =
17 | "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_commitments/{sequence}";
18 | }
19 |
20 | // PacketCommitments returns all the packet commitments hashes associated
21 | rpc PacketCommitments(QueryPacketCommitmentsRequest) returns (QueryPacketCommitmentsResponse) {
22 | option (google.api.http).get = "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_commitments";
23 | }
24 |
25 | // PacketReceipt queries if a given packet sequence has been received on the queried chain
26 | rpc PacketReceipt(QueryPacketReceiptRequest) returns (QueryPacketReceiptResponse) {
27 | option (google.api.http).get =
28 | "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_receipts/{sequence}";
29 | }
30 |
31 | // PacketAcknowledgement queries a stored packet acknowledgement hash.
32 | rpc PacketAcknowledgement(QueryPacketAcknowledgementRequest) returns (QueryPacketAcknowledgementResponse) {
33 | option (google.api.http).get =
34 | "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_acks/{sequence}";
35 | }
36 |
37 | // PacketAcknowledgements returns all the packet acknowledgements associated
38 | rpc PacketAcknowledgements(QueryPacketAcknowledgementsRequest) returns (QueryPacketAcknowledgementsResponse) {
39 | option (google.api.http).get =
40 | "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_acknowledgements";
41 | }
42 |
43 | // UnreceivedPackets returns all the unreceived TIBC packets associated with sequences.
44 | rpc UnreceivedPackets(QueryUnreceivedPacketsRequest) returns (QueryUnreceivedPacketsResponse) {
45 | option (google.api.http).get = "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_commitments/"
46 | "{packet_commitment_sequences}/unreceived_packets";
47 | }
48 |
49 | // UnreceivedAcks returns all the unreceived TIBC acknowledgements associated with sequences.
50 | rpc UnreceivedAcks(QueryUnreceivedAcksRequest) returns (QueryUnreceivedAcksResponse) {
51 | option (google.api.http).get = "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/packet_commitments/"
52 | "{packet_ack_sequences}/unreceived_acks";
53 | }
54 |
55 | // CleanPacketCommitment queries a stored packet commitment hash.
56 | rpc CleanPacketCommitment(QueryCleanPacketCommitmentRequest) returns (QueryCleanPacketCommitmentResponse) {
57 | option (google.api.http).get =
58 | "/tibc/core/packet/v1beta1/source_chains/{source_chain}/dest_chains/{dest_chain}/clean_packet_commitments";
59 | }
60 | }
61 |
62 | // QueryPacketCommitmentRequest is the request type for the
63 | // QueryPacketCommitment RPC method
64 | message QueryPacketCommitmentRequest {
65 | // dest chain name
66 | string dest_chain = 1;
67 | // source chain name
68 | string source_chain = 2;
69 | // packet sequence
70 | uint64 sequence = 3;
71 | }
72 |
73 | // QueryPacketCommitmentResponse defines the client query response for a packet
74 | // which also includes a proof and the height from which the proof was
75 | // retrieved
76 | message QueryPacketCommitmentResponse {
77 | // packet associated with the request fields
78 | bytes commitment = 1;
79 | // merkle proof of existence
80 | bytes proof = 2;
81 | // height at which the proof was retrieved
82 | tibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
83 | }
84 |
85 | // QueryPacketCommitmentsRequest is the request type for the
86 | // Query/QueryPacketCommitments RPC method
87 | message QueryPacketCommitmentsRequest {
88 | // dest chain name
89 | string dest_chain = 1;
90 | // source chain name
91 | string source_chain = 2;
92 | // pagination request
93 | cosmos.base.query.v1beta1.PageRequest pagination = 3;
94 | }
95 |
96 | // QueryPacketCommitmentsResponse is the request type for the
97 | // Query/QueryPacketCommitments RPC method
98 | message QueryPacketCommitmentsResponse {
99 | repeated tibc.core.packet.v1.PacketState commitments = 1;
100 | // pagination response
101 | cosmos.base.query.v1beta1.PageResponse pagination = 2;
102 | // query block height
103 | tibc.core.client.v1.Height height = 3 [(gogoproto.nullable) = false];
104 | }
105 |
106 | // QueryPacketReceiptRequest is the request type for the
107 | // Query/PacketReceipt RPC method
108 | message QueryPacketReceiptRequest {
109 | // dest chain name
110 | string dest_chain = 1;
111 | // source chain name
112 | string source_chain = 2;
113 | // packet sequence
114 | uint64 sequence = 3;
115 | }
116 |
117 | // QueryPacketReceiptResponse defines the client query response for a packet receipt
118 | // which also includes a proof, and the height from which the proof was
119 | // retrieved
120 | message QueryPacketReceiptResponse {
121 | // success flag for if receipt exists
122 | bool received = 2;
123 | // merkle proof of existence
124 | bytes proof = 3;
125 | // height at which the proof was retrieved
126 | tibc.core.client.v1.Height proof_height = 4 [(gogoproto.nullable) = false];
127 | }
128 |
129 | // QueryPacketAcknowledgementRequest is the request type for the
130 | // Query/PacketAcknowledgement RPC method
131 | message QueryPacketAcknowledgementRequest {
132 | // dest chain name
133 | string dest_chain = 1;
134 | // source chain name
135 | string source_chain = 2;
136 | // packet sequence
137 | uint64 sequence = 3;
138 | }
139 |
140 | // QueryPacketAcknowledgementResponse defines the client query response for a
141 | // packet which also includes a proof and the height from which the
142 | // proof was retrieved
143 | message QueryPacketAcknowledgementResponse {
144 | // packet associated with the request fields
145 | bytes acknowledgement = 1;
146 | // merkle proof of existence
147 | bytes proof = 2;
148 | // height at which the proof was retrieved
149 | tibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
150 | }
151 |
152 | // QueryPacketAcknowledgementsRequest is the request type for the
153 | // Query/QueryPacketCommitments RPC method
154 | message QueryPacketAcknowledgementsRequest {
155 | // dest chain name
156 | string dest_chain = 1;
157 | // source chain name
158 | string source_chain = 2;
159 | // pagination request
160 | cosmos.base.query.v1beta1.PageRequest pagination = 3;
161 | }
162 |
163 | // QueryPacketAcknowledgemetsResponse is the request type for the
164 | // Query/QueryPacketAcknowledgements RPC method
165 | message QueryPacketAcknowledgementsResponse {
166 | repeated tibc.core.packet.v1.PacketState acknowledgements = 1;
167 | // pagination response
168 | cosmos.base.query.v1beta1.PageResponse pagination = 2;
169 | // query block height
170 | tibc.core.client.v1.Height height = 3 [(gogoproto.nullable) = false];
171 | }
172 |
173 | // QueryUnreceivedPacketsRequest is the request type for the
174 | // Query/UnreceivedPackets RPC method
175 | message QueryUnreceivedPacketsRequest {
176 | // dest chain name
177 | string dest_chain = 1;
178 | // source chain name
179 | string source_chain = 2;
180 | // list of packet sequences
181 | repeated uint64 packet_commitment_sequences = 3;
182 | }
183 |
184 | // QueryUnreceivedPacketsResponse is the response type for the
185 | // Query/UnreceivedPacketCommitments RPC method
186 | message QueryUnreceivedPacketsResponse {
187 | // list of unreceived packet sequences
188 | repeated uint64 sequences = 1;
189 | // query block height
190 | tibc.core.client.v1.Height height = 2 [(gogoproto.nullable) = false];
191 | }
192 |
193 | // QueryUnreceivedAcks is the request type for the
194 | // Query/UnreceivedAcks RPC method
195 | message QueryUnreceivedAcksRequest {
196 | // dest chain name
197 | string dest_chain = 1;
198 | // source chain name
199 | string source_chain = 2;
200 | // list of acknowledgement sequences
201 | repeated uint64 packet_ack_sequences = 3;
202 | }
203 |
204 | // QueryUnreceivedAcksResponse is the response type for the
205 | // Query/UnreceivedAcks RPC method
206 | message QueryUnreceivedAcksResponse {
207 | // list of unreceived acknowledgement sequences
208 | repeated uint64 sequences = 1;
209 | // query block height
210 | tibc.core.client.v1.Height height = 2 [(gogoproto.nullable) = false];
211 | }
212 |
213 | // QueryCleanPacketCommitmentRequest is the request type for the
214 | // QueryCleanPacketCommitment RPC method
215 | message QueryCleanPacketCommitmentRequest {
216 | // dest chain name
217 | string dest_chain = 1;
218 | // source chain name
219 | string source_chain = 2;
220 | }
221 |
222 | // QueryCleanPacketCommitmentResponse defines the client query response for a packet
223 | // which also includes a proof and the height from which the proof was
224 | // retrieved
225 | message QueryCleanPacketCommitmentResponse {
226 | // packet associated with the request fields
227 | bytes commitment = 1;
228 | // merkle proof of existence
229 | bytes proof = 2;
230 | // height at which the proof was retrieved
231 | tibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false];
232 | }
--------------------------------------------------------------------------------
/proto/tibc/core/packet/v1/tx.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.core.packet.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/core/packet";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tibc/core/client/v1/client.proto";
8 | import "tibc/core/packet/v1/packet.proto";
9 |
10 | // Msg defines the tibc/packet Msg service.
11 | service Msg {
12 | // RecvPacket defines a rpc handler method for MsgRecvPacket.
13 | rpc RecvPacket(MsgRecvPacket) returns (MsgRecvPacketResponse);
14 |
15 | // Acknowledgement defines a rpc handler method for MsgAcknowledgement.
16 | rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse);
17 |
18 | // CleanPacket defines a rpc handler method for MsgCleanPacket.
19 | rpc CleanPacket(MsgCleanPacket) returns (MsgCleanPacketResponse);
20 |
21 | // RecvCleanPacket defines a rpc handler method for MsgRecvCleanPacket.
22 | rpc RecvCleanPacket(MsgRecvCleanPacket) returns (MsgRecvCleanPacketResponse);
23 | }
24 |
25 | // MsgRecvPacket receives incoming IBC packet
26 | message MsgRecvPacket {
27 | option (gogoproto.equal) = false;
28 | option (gogoproto.goproto_getters) = false;
29 |
30 | Packet packet = 1 [(gogoproto.nullable) = false];
31 | bytes proof_commitment = 2 [(gogoproto.moretags) = "yaml:\"proof_commitment\""];
32 | tibc.core.client.v1.Height proof_height = 3
33 | [(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
34 | string signer = 4;
35 | }
36 |
37 | // MsgRecvPacketResponse defines the Msg/RecvPacket response type.
38 | message MsgRecvPacketResponse {}
39 |
40 | // MsgAcknowledgement receives incoming IBC acknowledgement
41 | message MsgAcknowledgement {
42 | option (gogoproto.equal) = false;
43 | option (gogoproto.goproto_getters) = false;
44 |
45 | Packet packet = 1 [(gogoproto.nullable) = false];
46 | bytes acknowledgement = 2;
47 | bytes proof_acked = 3 [(gogoproto.moretags) = "yaml:\"proof_acked\""];
48 | tibc.core.client.v1.Height proof_height = 4
49 | [(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
50 | string signer = 5;
51 | }
52 |
53 | // MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.
54 | message MsgAcknowledgementResponse {}
55 |
56 | // MsgRecvPacket receives incoming IBC packet
57 | message MsgCleanPacket {
58 | option (gogoproto.equal) = false;
59 | option (gogoproto.goproto_getters) = false;
60 |
61 | CleanPacket clean_packet = 1 [(gogoproto.nullable) = false];
62 | string signer = 2;
63 | }
64 |
65 | // MsgRecvPacketResponse defines the Msg/RecvPacket response type.
66 | message MsgCleanPacketResponse {}
67 |
68 |
69 | // MsgRecvPacket receives incoming IBC packet
70 | message MsgRecvCleanPacket {
71 | option (gogoproto.equal) = false;
72 | option (gogoproto.goproto_getters) = false;
73 |
74 | CleanPacket clean_packet = 1 [(gogoproto.nullable) = false];
75 | bytes proof_commitment = 2 [(gogoproto.moretags) = "yaml:\"proof_commitment\""];
76 | tibc.core.client.v1.Height proof_height = 3
77 | [(gogoproto.moretags) = "yaml:\"proof_height\"", (gogoproto.nullable) = false];
78 | string signer = 4;
79 | }
80 |
81 | // MsgRecvPacketResponse defines the Msg/RecvPacket response type.
82 | message MsgRecvCleanPacketResponse {}
--------------------------------------------------------------------------------
/proto/tibc/lightclients/bsc/v1/bsc.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.lightclients.bsc.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/light-clients/bsc";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tibc/core/client/v1/client.proto";
8 |
9 | // Header defines the bsc client consensus Header.
10 | message Header {
11 | option (gogoproto.goproto_getters) = false;
12 |
13 | bytes parent_hash = 1;
14 | bytes uncle_hash = 2;
15 | bytes coinbase = 3;
16 | bytes root = 4;
17 | bytes tx_hash = 5;
18 | bytes receipt_hash = 6;
19 | bytes bloom = 7;
20 | uint64 difficulty = 8;
21 | tibc.core.client.v1.Height height = 9 [ (gogoproto.nullable) = false ];
22 | uint64 gas_limit = 10;
23 | uint64 gas_used = 11;
24 | uint64 time = 12;
25 | bytes extra = 13;
26 | bytes mix_digest = 14;
27 | bytes nonce = 15;
28 | }
29 |
30 | // ClientState from bsc tracks the current validator set, latest height,
31 | // and a possible frozen height.
32 | message ClientState {
33 | option (gogoproto.goproto_getters) = false;
34 |
35 | Header header = 1 [ (gogoproto.nullable) = false ];
36 | uint64 chain_id = 2;
37 | uint64 epoch = 3;
38 | uint64 block_inteval = 4;
39 | repeated bytes validators = 5;
40 | repeated Signer recent_signers = 6 [ (gogoproto.nullable) = false ];
41 | bytes contract_address = 7;
42 | uint64 trusting_period = 8;
43 | }
44 |
45 | message Signer {
46 | tibc.core.client.v1.Height height = 1 [ (gogoproto.nullable) = false ];
47 | bytes validator = 2;
48 | }
49 |
50 | message ValidatorSet { repeated bytes validators = 1; }
51 |
52 | // ConsensusState defines the consensus state from bsc.
53 | message ConsensusState {
54 | option (gogoproto.goproto_getters) = false;
55 |
56 | // timestamp that corresponds to the block height in which the ConsensusState
57 | // was stored.
58 | uint64 timestamp = 1;
59 | tibc.core.client.v1.Height number = 2 [ (gogoproto.nullable) = false ];
60 | bytes root = 3;
61 | }
62 |
63 | message StorageResult {
64 | option (gogoproto.goproto_getters) = false;
65 |
66 | string key = 1;
67 | string value = 2;
68 | repeated string proof = 3;
69 | }
70 |
71 | message Proof {
72 | option (gogoproto.goproto_getters) = false;
73 |
74 | string address = 1;
75 | string balance = 2;
76 | string code_hash = 3;
77 | string nonce = 4;
78 | string storage_hash = 5;
79 | repeated string account_proof = 6;
80 | repeated StorageResult storage_proof = 7;
81 | }
--------------------------------------------------------------------------------
/proto/tibc/lightclients/eth/v1/eth.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.lightclients.eth.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/light-clients/eth";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tibc/core/client/v1/client.proto";
8 |
9 | // Header defines the eth client consensus Header.
10 | message Header {
11 | option (gogoproto.goproto_getters) = false;
12 |
13 | bytes parent_hash = 1;
14 | bytes uncle_hash = 2;
15 | bytes coinbase = 3;
16 | bytes root = 4;
17 | bytes tx_hash = 5;
18 | bytes receipt_hash = 6;
19 | bytes bloom = 7;
20 | string difficulty = 8;
21 | tibc.core.client.v1.Height height = 9 [ (gogoproto.nullable) = false ];
22 | uint64 gas_limit = 10;
23 | uint64 gas_used = 11;
24 | uint64 time = 12;
25 | bytes extra = 13;
26 | bytes mix_digest = 14;
27 | uint64 nonce = 15;
28 | string baseFee=16;
29 | }
30 |
31 | // ClientState from eth tracks the current validator set, latest height,
32 | // and a possible frozen height.
33 | message ClientState {
34 | option (gogoproto.goproto_getters) = false;
35 |
36 | Header header = 1 [ (gogoproto.nullable) = false ];
37 | uint64 chain_id = 2;
38 | bytes contract_address = 3;
39 | uint64 trusting_period = 4;
40 | uint64 timeDelay = 5;
41 | uint64 blockDelay = 6;
42 | }
43 |
44 |
45 | // ConsensusState defines the consensus state from eth.
46 | message ConsensusState {
47 | option (gogoproto.goproto_getters) = false;
48 |
49 | // timestamp that corresponds to the block height in which the ConsensusState
50 | // was stored.
51 | uint64 timestamp = 1;
52 | tibc.core.client.v1.Height number = 2 [ (gogoproto.nullable) = false ];
53 | bytes root = 3;
54 | }
55 |
56 | message StorageResult {
57 | option (gogoproto.goproto_getters) = false;
58 |
59 | string key = 1;
60 | string value = 2;
61 | repeated string proof = 3;
62 | }
63 |
64 | message Proof {
65 | option (gogoproto.goproto_getters) = false;
66 |
67 | string address = 1;
68 | string balance = 2;
69 | string code_hash = 3;
70 | string nonce = 4;
71 | string storage_hash = 5;
72 | repeated string account_proof = 6;
73 | repeated StorageResult storage_proof = 7;
74 | }
--------------------------------------------------------------------------------
/proto/tibc/lightclients/tendermint/v1/tendermint.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tibc.lightclients.tendermint.v1;
3 |
4 | option go_package = "github.com/bianjieai/tibc-sdk-go/modules/light-clients/tendermint";
5 |
6 | import "tendermint/types/validator.proto";
7 | import "tendermint/types/types.proto";
8 | import "confio/proofs.proto";
9 | import "google/protobuf/duration.proto";
10 | import "google/protobuf/timestamp.proto";
11 | import "tibc/core/client/v1/client.proto";
12 | import "tibc/core/commitment/v1/commitment.proto";
13 | import "gogoproto/gogo.proto";
14 |
15 | // ClientState from Tendermint tracks the current validator set, latest height,
16 | // and a possible frozen height.
17 | message ClientState {
18 | option (gogoproto.goproto_getters) = false;
19 |
20 | string chain_id = 1;
21 | Fraction trust_level = 2 [ (gogoproto.nullable) = false ];
22 | // duration of the period since the LastestTimestamp during which the
23 | // submitted headers are valid for upgrade
24 | google.protobuf.Duration trusting_period = 3
25 | [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
26 | // duration of the staking unbonding period
27 | google.protobuf.Duration unbonding_period = 4
28 | [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
29 | // defines how much new (untrusted) header's Time can drift into the future.
30 | google.protobuf.Duration max_clock_drift = 5
31 | [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
32 | // latest height the client was updated to
33 | tibc.core.client.v1.Height latest_height = 6 [ (gogoproto.nullable) = false ];
34 | // proof specifications used in verifying counterparty state
35 | repeated ics23.ProofSpec proof_specs = 7;
36 | // commitment merkle prefix of the counterparty chain.
37 | tibc.core.commitment.v1.MerklePrefix MerklePrefix = 8
38 | [ (gogoproto.nullable) = false ];
39 | // period of transaction confirmation delay
40 | uint64 timeDelay = 9;
41 | // json structure, some additional options can be stored here
42 | bytes extra = 10;
43 | }
44 |
45 | // ConsensusState defines the consensus state from Tendermint.
46 | message ConsensusState {
47 | option (gogoproto.goproto_getters) = false;
48 |
49 | // timestamp that corresponds to the block height in which the ConsensusState
50 | // was stored.
51 | google.protobuf.Timestamp timestamp = 1
52 | [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
53 | // commitment root (i.e app hash)
54 | tibc.core.commitment.v1.MerkleRoot root = 2 [ (gogoproto.nullable) = false ];
55 | bytes next_validators_hash = 3
56 | [ (gogoproto.casttype) =
57 | "github.com/tendermint/tendermint/libs/bytes.HexBytes" ];
58 | }
59 |
60 | // Header defines the Tendermint client consensus Header.
61 | // It encapsulates all the information necessary to update from a trusted
62 | // Tendermint ConsensusState. The inclusion of TrustedHeight and
63 | // TrustedValidators allows this update to process correctly, so long as the
64 | // ConsensusState for the TrustedHeight exists, this removes race conditions
65 | // among relayers The SignedHeader and ValidatorSet are the new untrusted update
66 | // fields for the client. The TrustedHeight is the height of a stored
67 | // ConsensusState on the client that will be used to verify the new untrusted
68 | // header. The Trusted ConsensusState must be within the unbonding period of
69 | // current time in order to correctly verify, and the TrustedValidators must
70 | // hash to TrustedConsensusState.NextValidatorsHash since that is the last
71 | // trusted validator set at the TrustedHeight.
72 | message Header {
73 | .tendermint.types.SignedHeader signed_header = 1 [ (gogoproto.embed) = true ];
74 | .tendermint.types.ValidatorSet validator_set = 2;
75 | tibc.core.client.v1.Height trusted_height = 3
76 | [ (gogoproto.nullable) = false ];
77 | .tendermint.types.ValidatorSet trusted_validators = 4;
78 | }
79 |
80 | // Fraction defines the protobuf message type for tmmath.Fraction that only
81 | // supports positive values.
82 | message Fraction {
83 | uint64 numerator = 1;
84 | uint64 denominator = 2;
85 | }
86 |
--------------------------------------------------------------------------------
/scripts/Makefile:
--------------------------------------------------------------------------------
1 | all: get_tools
2 |
3 |
4 | ########################################
5 |
6 | GOLINT = github.com/tendermint/lint/golint
7 | GOMETALINTER = gopkg.in/alecthomas/gometalinter.v2
8 | UNCONVERT = github.com/mdempsky/unconvert
9 | INEFFASSIGN = github.com/gordonklaus/ineffassign
10 | MISSPELL = github.com/client9/misspell/cmd/misspell
11 | ERRCHECK = github.com/kisielk/errcheck
12 | UNPARAM = mvdan.cc/unparam
13 | STATIK = github.com/rakyll/statik
14 |
15 | GOLINT_CHECK := $(shell command -v golint 2> /dev/null)
16 | GOMETALINTER_CHECK := $(shell command -v gometalinter.v2 2> /dev/null)
17 | UNCONVERT_CHECK := $(shell command -v unconvert 2> /dev/null)
18 | INEFFASSIGN_CHECK := $(shell command -v ineffassign 2> /dev/null)
19 | MISSPELL_CHECK := $(shell command -v misspell 2> /dev/null)
20 | ERRCHECK_CHECK := $(shell command -v errcheck 2> /dev/null)
21 | UNPARAM_CHECK := $(shell command -v unparam 2> /dev/null)
22 | STATIK_CHECK := $(shell command -v statik 2> /dev/null)
23 |
24 |
25 | check_tools:
26 | ifndef STATIK_CHECK
27 | @echo "No statik in path. Install with 'make get_tools'."
28 | else
29 | @echo "Found statik in path."
30 | endif
31 |
32 | check_dev_tools:
33 | $(MAKE) check_tools
34 | ifndef GOLINT_CHECK
35 | @echo "No golint in path. Install with 'make get_dev_tools'."
36 | else
37 | @echo "Found golint in path."
38 | endif
39 | ifndef GOMETALINTER_CHECK
40 | @echo "No gometalinter in path. Install with 'make get_dev_tools'."
41 | else
42 | @echo "Found gometalinter in path."
43 | endif
44 | ifndef UNCONVERT_CHECK
45 | @echo "No unconvert in path. Install with 'make get_dev_tools'."
46 | else
47 | @echo "Found unconvert in path."
48 | endif
49 | ifndef INEFFASSIGN_CHECK
50 | @echo "No ineffassign in path. Install with 'make get_dev_tools'."
51 | else
52 | @echo "Found ineffassign in path."
53 | endif
54 | ifndef MISSPELL_CHECK
55 | @echo "No misspell in path. Install with 'make get_dev_tools'."
56 | else
57 | @echo "Found misspell in path."
58 | endif
59 | ifndef ERRCHECK_CHECK
60 | @echo "No errcheck in path. Install with 'make get_dev_tools'."
61 | else
62 | @echo "Found errcheck in path."
63 | endif
64 | ifndef UNPARAM_CHECK
65 | @echo "No unparam in path. Install with 'make get_dev_tools'."
66 | else
67 | @echo "Found unparam in path."
68 | endif
69 |
70 | get_tools:
71 | ifdef STATIK_CHECK
72 | @echo "Statik is already installed. Run 'make update_tools' to update."
73 | else
74 | @echo "Installing statik"
75 | go version
76 | go get -v $(STATIK)
77 | endif
78 |
79 | get_dev_tools:
80 | $(MAKE) get_tools
81 | ifdef GOLINT_CHECK
82 | @echo "Golint is already installed. Run 'make update_tools' to update."
83 | else
84 | @echo "Installing golint"
85 | go get -v $(GOLINT)
86 | endif
87 | ifdef GOMETALINTER_CHECK
88 | @echo "Gometalinter.v2 is already installed. Run 'make update_tools' to update."
89 | else
90 | @echo "Installing gometalinter.v2"
91 | go get -v $(GOMETALINTER)
92 | endif
93 | ifdef UNCONVERT_CHECK
94 | @echo "Unconvert is already installed. Run 'make update_tools' to update."
95 | else
96 | @echo "Installing unconvert"
97 | go get -v $(UNCONVERT)
98 | endif
99 | ifdef INEFFASSIGN_CHECK
100 | @echo "Ineffassign is already installed. Run 'make update_tools' to update."
101 | else
102 | @echo "Installing ineffassign"
103 | go get -v $(INEFFASSIGN)
104 | endif
105 | ifdef MISSPELL_CHECK
106 | @echo "misspell is already installed. Run 'make update_tools' to update."
107 | else
108 | @echo "Installing misspell"
109 | go get -v $(MISSPELL)
110 | endif
111 | ifdef ERRCHECK_CHECK
112 | @echo "errcheck is already installed. Run 'make update_tools' to update."
113 | else
114 | @echo "Installing errcheck"
115 | go get -v $(ERRCHECK)
116 | endif
117 | ifdef UNPARAM_CHECK
118 | @echo "unparam is already installed. Run 'make update_tools' to update."
119 | else
120 | @echo "Installing unparam"
121 | go get -v $(UNPARAM)
122 | endif
123 | ifdef STATIK_CHECK
124 | @echo "statik is already installed. Run 'make update_tools' to update."
125 | else
126 | @echo "Installing statik"
127 | go get -v $(STATIK)
128 | endif
129 |
130 | update_dev_tools:
131 | $(MAKE) update_tools
132 | @echo "Updating tendermint/golint"
133 | go get -u -v $(GOLINT)
134 | @echo "Updating gometalinter.v2"
135 | go get -u -v $(GOMETALINTER)
136 | @echo "Updating unconvert"
137 | go get -u -v $(UNCONVERT)
138 | @echo "Updating ineffassign"
139 | go get -u -v $(INEFFASSIGN)
140 | @echo "Updating misspell"
141 | go get -u -v $(MISSPELL)
142 | @echo "Updating errcheck"
143 | go get -u -v $(ERRCHECK)
144 | @echo "Updating unparam"
145 | go get -u -v $(UNPARAM)
146 | @echo "Updating statik"
147 | go get -u -v $(STATIK)
148 |
149 | # To avoid unintended conflicts with file names, always add to .PHONY
150 | # unless there is a reason not to.
151 | # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
152 | .PHONY: check_tools get_tools update_tools check_dev_tools get_dev_tools update_dev_tools
--------------------------------------------------------------------------------
/scripts/protocgen.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -eo pipefail
4 |
5 | proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
6 | for dir in $proto_dirs; do
7 | protoc \
8 | -I "proto" \
9 | -I "third_party/proto" \
10 | --gocosmos_out=plugins=interfacetype+grpc,\
11 | Mgoogle/protobuf/any.proto=github.com/irisnet/core-sdk-go/common/codec/types:. \
12 | $(find "${dir}" -maxdepth 1 -name '*.proto')
13 |
14 | # command to generate gRPC gateway (*.pb.gw.go in respective modules) files
15 | protoc \
16 | -I "proto" \
17 | -I "third_party/proto" \
18 | --grpc-gateway_out=logtostderr=true:. \
19 | $(find "${dir}" -maxdepth 1 -name '*.proto')
20 |
21 | done
22 |
23 | # move proto files to the right places
24 | cp -r github.com/bianjieai/tibc-sdk-go/* ./
25 | rm -rf github.com
26 |
--------------------------------------------------------------------------------
/testing/integration_test/Tendermit_lightClient.go:
--------------------------------------------------------------------------------
1 | package integration
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "io/ioutil"
7 | "os"
8 | "time"
9 |
10 | tibc "github.com/bianjieai/tibc-sdk-go"
11 | tibcclient "github.com/bianjieai/tibc-sdk-go/modules/core/client"
12 | "github.com/bianjieai/tibc-sdk-go/modules/light-clients/tendermint"
13 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
14 | "github.com/irisnet/core-sdk-go/types"
15 | tenderminttypes "github.com/tendermint/tendermint/proto/tendermint/types"
16 | tmtypes "github.com/tendermint/tendermint/types"
17 | )
18 |
19 | func getClientState(client tibc.Client, clientName string) {
20 | clientState1, err := client.GetClientState(clientName)
21 | if err != nil {
22 | panic(err)
23 | }
24 | fmt.Println(clientState1.String())
25 | }
26 | func getClientStates(client tibc.Client) {
27 | clientState1, err := client.GetClientStates()
28 | if err != nil {
29 | panic(err)
30 | }
31 | for _, value := range clientState1 {
32 | if value == nil {
33 | break
34 | }
35 | fmt.Println(value.String())
36 | }
37 | }
38 | func getheader(client Client, height int64, trustHeight tibcclient.Height, clientState tibctypes.ClientState) {
39 | res, err := client.QueryBlock(height)
40 | if err != nil {
41 | fmt.Println("QueryBlock fail: ", err)
42 | }
43 | tmHeader := res.Block.Header
44 |
45 | rescommit, err := client.Commit(context.Background(), &res.BlockResult.Height)
46 | commit := rescommit.Commit
47 | signedHeader := &tenderminttypes.SignedHeader{
48 | Header: tmHeader.ToProto(),
49 | Commit: commit.ToProto(),
50 | }
51 | fmtheader := &tendermint.Header{
52 | SignedHeader: signedHeader,
53 | ValidatorSet: queryValidatorSet(height, client.Tendermint),
54 | TrustedHeight: trustHeight,
55 | TrustedValidators: queryValidatorSet(int64(clientState.GetLatestHeight().GetRevisionHeight()), client.Tendermint),
56 | }
57 | b0, err := client.Tendermint.Marshaler.MarshalJSON(fmtheader)
58 | if err != nil {
59 | panic(err)
60 | }
61 | b0 = []byte(TenStaType + string(b0)[1:])
62 | clientStateName := tmHeader.ChainID + "_client_header.json"
63 | err = ioutil.WriteFile(clientStateName, b0, os.ModeAppend)
64 | }
65 |
66 | func getConsensusState(client tibc.Client, clientName string, height uint64) {
67 | consensusState1, err := client.GetConsensusState(clientName, height)
68 | if err != nil {
69 | panic(err)
70 | }
71 | fmt.Println(consensusState1.String())
72 |
73 | }
74 | func getConsensusStates(client tibc.Client) {
75 | consensusState1, err := client.GetConsensusStates("testCreateClient")
76 | if err != nil {
77 | panic(err)
78 | }
79 | fmt.Println("consensusState: ")
80 | for _, value := range consensusState1 {
81 | if value == nil {
82 | break
83 | }
84 | fmt.Println(value.String())
85 | }
86 | }
87 |
88 | func updateRinkebyEthClientTest(sourceClient Client, chainName, keyName, url string) {
89 | baseTx := types.BaseTx{
90 | From: keyName,
91 | Gas: 0,
92 | Memo: "TEST",
93 | Mode: types.Commit,
94 | Password: "12345678",
95 | SimulateAndExecute: false,
96 | GasAdjustment: 1.5,
97 | }
98 | lightClientState, err := sourceClient.Tendermint.GetClientState(chainName)
99 | if err != nil {
100 | fmt.Println("GetClientState fail :", err, lightClientState)
101 | return
102 | }
103 | height := lightClientState.GetLatestHeight()
104 | ethHeader, err1 := GetRinkeyEthNodeHeader(url, height.GetRevisionHeight()+1)
105 | if err1 != nil {
106 | fmt.Println("GetEthNodeHeader fail :", err1, lightClientState)
107 | return
108 | }
109 | header := ethHeader.ToHeader()
110 | request := tibctypes.UpdateClientRequest{
111 | ChainName: chainName,
112 | Header: &header,
113 | }
114 | fmt.Println("run : update client ", sourceClient.ChainName, ".", chainName, "start height : ", height, "want height:", height.GetRevisionHeight()+1)
115 | _, err = sourceClient.Tendermint.UpdateClient(request, baseTx)
116 | if err != nil {
117 | time.Sleep(time.Second * 5)
118 | }
119 | fmt.Println(" success : update client ", sourceClient.ChainName, ".", chainName, "end height : ", header.Height.RevisionHeight)
120 | }
121 |
122 | func updateEthClientTest(sourceClient Client, chainName, keyName, url string) {
123 | baseTx := types.BaseTx{
124 | From: keyName,
125 | Gas: 0,
126 | Memo: "TEST",
127 | Mode: types.Commit,
128 | Password: "12345678",
129 | SimulateAndExecute: false,
130 | GasAdjustment: 1.5,
131 | }
132 | lightClientState, err := sourceClient.Tendermint.GetClientState(chainName)
133 | if err != nil {
134 | fmt.Println("GetClientState fail :", err, lightClientState)
135 | return
136 | }
137 | height := lightClientState.GetLatestHeight()
138 | ethHeader, err1 := GetEthNodeHeader(url, height.GetRevisionHeight()+1)
139 | if err1 != nil {
140 | fmt.Println("GetEthNodeHeader fail :", err1, lightClientState)
141 | return
142 | }
143 | header := ethHeader.ToHeader()
144 | request := tibctypes.UpdateClientRequest{
145 | ChainName: chainName,
146 | Header: &header,
147 | }
148 | wantHeight := height.GetRevisionHeight() + 1
149 | fmt.Println("run : update client ", sourceClient.ChainName, ".", chainName, "start height : ", height, "want height:", wantHeight)
150 | _, err = sourceClient.Tendermint.UpdateClient(request, baseTx)
151 | if err != nil {
152 | time.Sleep(time.Second * 6)
153 | lightClientState, _ = sourceClient.Tendermint.GetClientState(chainName)
154 | height = lightClientState.GetLatestHeight()
155 | if height.GetRevisionHeight() != wantHeight {
156 | fmt.Println("update filed")
157 | return
158 | }
159 | }
160 | fmt.Println(" success : update client ", sourceClient.ChainName, ".", chainName, "end height : ", header.Height.RevisionHeight)
161 | }
162 |
163 | //destClient tibc.Client,
164 | func updatetendetmintclientTest(sourceClient Client, destClient Client, chainName, keyName string) {
165 | baseTx := types.BaseTx{
166 | From: keyName,
167 | Gas: 0,
168 | Memo: "TEST",
169 | Mode: types.Commit,
170 | Password: "12345678",
171 | SimulateAndExecute: false,
172 | GasAdjustment: 1.5,
173 | }
174 | lightClientState, err := sourceClient.Tendermint.GetClientState(chainName)
175 | if err != nil {
176 | fmt.Println("UpdateClient fail :", err)
177 | return
178 | }
179 | height := int64(lightClientState.GetLatestHeight().GetRevisionHeight())
180 | stat, err1 := destClient.Status(context.Background())
181 | if err1 != nil {
182 | fmt.Println("get Status fail :", err1)
183 | return
184 | }
185 | height1 := stat.SyncInfo.LatestBlockHeight
186 | request := tibctypes.UpdateClientRequest{
187 | ChainName: chainName,
188 | Header: CreateTenderrmintHeader(destClient, height1, tibcclient.NewHeight(lightClientState.GetLatestHeight().GetRevisionNumber(), uint64(height)), lightClientState),
189 | }
190 | fmt.Println("run : update client ", sourceClient.ChainName, ".", destClient.ChainName)
191 | _, err = sourceClient.Tendermint.UpdateClient(request, baseTx)
192 | if err != nil {
193 | fmt.Println("UpdateClient fail :", err)
194 | return
195 | }
196 | fmt.Println(" success : update client ", sourceClient.ChainName, ".", destClient.ChainName)
197 | }
198 |
199 | func CreateTenderrmintHeader(client Client, height int64, trustHeight tibcclient.Height, clientState tibctypes.ClientState) *tendermint.Header {
200 |
201 | res, err := client.QueryBlock(height)
202 | if err != nil {
203 | fmt.Println("QueryBlock fail: ", err)
204 | }
205 | tmHeader := res.Block.Header
206 |
207 | rescommit, err := client.Commit(context.Background(), &res.BlockResult.Height)
208 | commit := rescommit.Commit
209 | signedHeader := &tenderminttypes.SignedHeader{
210 | Header: tmHeader.ToProto(),
211 | Commit: commit.ToProto(),
212 | }
213 | // print header json
214 | //ehdaer := tendermint.Header{
215 | // SignedHeader: signedHeader,
216 | // ValidatorSet: queryValidatorSet(height, client.Tendermint),
217 | // TrustedHeight: trustHeight,
218 | // TrustedValidators: queryValidatorSet(int64(clientState.GetLatestHeight().GetRevisionHeight()), client.Tendermint),
219 | //}
220 | //
221 | //b0, err := json.Marshal(ehdaer)
222 | //if err != nil {
223 | // panic(err)
224 | //}
225 | //
226 | //b0 = []byte(TenStaType + string(b0)[1:])
227 | //clientStateName := "client_header.json"
228 | //err = ioutil.WriteFile(clientStateName, b0, os.ModeAppend)
229 |
230 | return &tendermint.Header{
231 | SignedHeader: signedHeader,
232 | ValidatorSet: queryValidatorSet(height, client.Tendermint),
233 | TrustedHeight: trustHeight,
234 | TrustedValidators: queryValidatorSet(int64(clientState.GetLatestHeight().GetRevisionHeight()), client.Tendermint),
235 | }
236 |
237 | }
238 |
239 | func queryValidatorSet(height int64, client tibc.Client) *tenderminttypes.ValidatorSet {
240 | page := 1
241 | prepage := 200
242 | validators, err := client.Validators(context.Background(), &height, &page, &prepage)
243 | if err != nil {
244 | fmt.Println("queryValidatorSet fail :", err)
245 | }
246 | fmt.Println(len(validators.Validators))
247 | validatorSet, err := tmtypes.NewValidatorSet(validators.Validators[:20]).ToProto()
248 | if err != nil {
249 | fmt.Println("queryValidatorSet fail :", err)
250 | }
251 | return validatorSet
252 | }
253 |
254 | func updatebscclientTest(sourceClient Client, destchainUrl, chainName, keyname string) {
255 | baseTx := types.BaseTx{
256 | From: keyname,
257 | Gas: 0,
258 | Memo: "TEST",
259 | Mode: types.Commit,
260 | Password: "12345678",
261 | SimulateAndExecute: false,
262 | GasAdjustment: 1.5,
263 | }
264 | lightClientState, err := sourceClient.Tendermint.GetClientState(chainName)
265 | if err != nil {
266 | fmt.Println("GetClientState fail :", err, lightClientState)
267 | return
268 | }
269 | height := lightClientState.GetLatestHeight()
270 | bscHeader, err1 := GetNodeHeader(destchainUrl, height.GetRevisionHeight()+1)
271 | if err1 != nil {
272 | fmt.Println("GetClientState fail :", err1, lightClientState)
273 | return
274 | }
275 | header := bscHeader.ToHeader()
276 | request := tibctypes.UpdateClientRequest{
277 | ChainName: chainName,
278 | Header: &header,
279 | }
280 | fmt.Println("run : update client ", sourceClient.ChainName, ".", chainName, "start height : ", header.Height.RevisionHeight)
281 | _, err = sourceClient.Tendermint.UpdateClient(request, baseTx)
282 | if err != nil {
283 | fmt.Println("UpdateClient fail :", err)
284 | return
285 | }
286 | fmt.Println(" success : update client ", sourceClient.ChainName, ".", chainName, "end height : ", header.Height.RevisionHeight+1)
287 |
288 | }
289 |
--------------------------------------------------------------------------------
/testing/integration_test/Tendermit_lightClient_test.go:
--------------------------------------------------------------------------------
1 | package integration
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "testing"
7 |
8 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
9 | "github.com/irisnet/core-sdk-go/common/crypto"
10 | "github.com/irisnet/core-sdk-go/types"
11 | "github.com/irisnet/core-sdk-go/types/store"
12 | )
13 |
14 | const (
15 | nodeURIiris = "tcp://sentry-1.mainnet.irisnet.org:26657"
16 | grpcAddriris = "sentry-1.mainnet.irisnet.org:9090"
17 | chainIDiris = "testA"
18 | keyNameiris = "chainANode0"
19 | passwordiris = "12345678"
20 | keyStoreiris = `-----BEGIN TENDERMINT PRIVATE KEY-----
21 | kdf: bcrypt
22 | salt: 3DD1ADDB1389FD5F06010321A9FB8230
23 | type: sm2
24 |
25 | 1wD0rJf9qu0MMVPGqpo/fXa5VynSajIyskmhJLAkjMsWc2ssO5tSNQ0ENgTbGZbp
26 | I6OtbT8H4FBJEH/g4aopJ+9l+zSGogNrylXlDD8=
27 | =+MfP
28 | -----END TENDERMINT PRIVATE KEY-----`
29 | chainirisLightClientName = "testCreateClientA"
30 | addressiris = "iaa12z75qgsrn26cs99gvu2fq44p3ehezwdzt4durm"
31 | )
32 | const (
33 | nodeURIlocal = "tcp://localhost:26657"
34 | grpcAddrlocal = "localhost:9090"
35 | chainIDlocal = "testC"
36 | keyNamelocal = "chainCNode0"
37 | passwordlocal = "12345678"
38 | keyStorelocal = `-----BEGIN TENDERMINT PRIVATE KEY-----
39 | kdf: bcrypt
40 | salt: F248AB34AE4BED4B4A5DD10E34C8BAFA
41 | type: secp256k1
42 |
43 | xqzXVX8JXYQWj/aJmH3hNfEqlO3IAM35C+oXkys02KfXcHZm+LDBVTRUFpONV3iB
44 | C8FzpKaS8W69qqXhNP2sLBtHrGIk8L3T0wAVM3Q=
45 | =2BeH
46 | -----END TENDERMINT PRIVATE KEY-----`
47 | chainlocalLightClientName = "testCreateClientC"
48 | addresslocal = "iaa10nfdefym9vg7c288fm4790833ee5f4p0g8w3ej"
49 | )
50 | const (
51 | nodeURI0 = "tcp://192.168.232.133:26657"
52 | grpcAddr0 = "192.168.232.133:9090"
53 | chainID0 = "testA"
54 | keyName0 = "chainANode0"
55 | password0 = "12345678"
56 | keyStore0 = `-----BEGIN TENDERMINT PRIVATE KEY-----
57 | kdf: bcrypt
58 | salt: 0CDF9AFE4EF0002010ABD3E01CBAE7E8
59 | type: secp256k1
60 |
61 | BNeeN1PaoRmu8jjpqA2X2EjwP6I+j02tTxU1/Z3kCijd04CV/0C28IJ3DTX/d0vN
62 | kZkaKvjE995Gamdow95b872Sen0IyFP6FXdTbis=
63 | =qpfu
64 | -----END TENDERMINT PRIVATE KEY-----`
65 | chainALightClientName = "testCreateClientA"
66 | addressA = "iaa12z75qgsrn26cs99gvu2fq44p3ehezwdzt4durm"
67 | )
68 |
69 | const (
70 | nodeURI1 = "tcp://192.168.232.135:26657"
71 | grpcAddr1 = "192.168.232.135:9090"
72 | chainID1 = "testB"
73 | keyName1 = "chainBNode0"
74 | password1 = "12345678"
75 | keyStore1 = `-----BEGIN TENDERMINT PRIVATE KEY-----
76 | kdf: bcrypt
77 | salt: 4EAEB42D9AEED740C5F9FEDA569F346C
78 | type: secp256k1
79 |
80 | RpPG2Ow32xTN7P3Hro34lVK8WGizKhjfyyU9QgHWFlN5Fv8zIhYeBCRsxI9QzKDX
81 | lknIkHf36F6t06zwzYb3+ReT8cQeowsgHwOS7c8=
82 | =YqMi
83 | -----END TENDERMINT PRIVATE KEY-----`
84 | chainBLightClientName = "testCreateClientB"
85 | addressB = "iaa1twsrmhpmg6rkc6l5r7rcanxeelhylxlnsw6g0l"
86 | )
87 | const (
88 | nodeURI2 = "tcp://192.168.47.128:26657"
89 | grpcAddr2 = "192.168.47.128:9090"
90 | chainID2 = "testC"
91 | keyName2 = "chainCNode0"
92 | password2 = "12345678"
93 | keyStore2 = `-----BEGIN TENDERMINT PRIVATE KEY-----
94 | kdf: bcrypt
95 | salt: B8113AE06ACB73701FBCA453D7C7AFAB
96 | type: secp256k1
97 |
98 | brg7lUm30ZDPDhHmSbDFWw+/pMr09rZnnUFYGiBZX2l0kG9t50Q3UkNuqxZYBdd7
99 | MvIhB6q/n3lFY7gykW1mPi6zD6dZsgIeHK/CknY=
100 | =6sV2
101 | -----END TENDERMINT PRIVATE KEY-----`
102 | chainCLightClientName = "testCreateClientC"
103 | addressC = "iaa1zvf654uuamjgecucaeklwsqeqxjguhv26f0n2g"
104 | )
105 |
106 | func Test_updateRinkebyEth(t *testing.T) {
107 | clientC, err := getIntegrationClient(nodeURI2, grpcAddr2, chainID2, keyName2, password2, keyStore2, chainCLightClientName)
108 | if err != nil {
109 | fmt.Println(err.Codespace(), err.Code(), err.Error(), clientC)
110 | return
111 | }
112 | //getRinkebyETHjson(clientC.Tendermint)
113 | updateRinkebyEthClientTest(clientC, "rinkebyeth", keyName2, rinkeby)
114 | }
115 |
116 | func Test_getHashLen(t *testing.T) {
117 | header, err := GetEthNodeHeader(ethurl, 13287800)
118 | if err != nil {
119 | return
120 | }
121 | toHeader := header.ToHeader()
122 | fmt.Println(len(toHeader.Hash().Bytes()))
123 | }
124 | func Test_LocalTest(t *testing.T) {
125 | localClient, err := getIntegrationClient(nodeURIlocal, grpcAddrlocal, chainIDlocal, keyNamelocal, passwordlocal, keyStorelocal, chainlocalLightClientName)
126 | if err != nil {
127 | fmt.Println(err.Codespace(), err.Code(), err.Error(), localClient)
128 | return
129 | }
130 | fmt.Println(localClient.Status(context.Background()))
131 | }
132 | func Test_GetIrisNetJson(t *testing.T) {
133 | irisClient, err := getIntegrationClient(nodeURIiris, grpcAddriris, chainIDiris, keyNameiris, passwordiris, keyStoreiris, chainALightClientName)
134 | if err != nil {
135 | fmt.Println(err.Codespace(), err.Code(), err.Error(), irisClient)
136 | return
137 | }
138 | //getTendermintjson(irisClient.Tendermint, 11762491)
139 | }
140 |
141 | func Test_integrationClientTen(t *testing.T) {
142 |
143 | clientA, err := getIntegrationClient(nodeURI0, grpcAddr0, chainID0, keyName0, password0, keyStore0, chainALightClientName)
144 | if err != nil {
145 | fmt.Println(err.Codespace(), err.Code(), err.Error(), clientA)
146 | return
147 | }
148 | address, err := clientA.QueryAddress(keyName0, password0)
149 | if err != nil {
150 | fmt.Println(err)
151 | return
152 | }
153 | fmt.Println(address)
154 | baseTx := types.BaseTx{
155 | From: keyName0,
156 | Gas: 0,
157 | Memo: "TEST",
158 | Mode: types.Commit,
159 | Password: "12345678",
160 | SimulateAndExecute: false,
161 | GasAdjustment: 1.5,
162 | }
163 | dec := types.NewDec(1000)
164 | deccoin := types.DecCoin{
165 | Denom: "upoint",
166 | Amount: dec,
167 | }
168 | amount := types.DecCoins{deccoin}
169 | resu, err := clientA.Bank.Send("cosmos1mzzl97r8zkst5rgz2fyja99f3m9wh50hxg0ct9", amount, baseTx)
170 |
171 | if err != nil {
172 | fmt.Println(err)
173 | return
174 | }
175 |
176 | fmt.Println(resu)
177 |
178 | }
179 |
180 | func Test_integrationClientBsc(t *testing.T) {
181 | clientA, err := getIntegrationClient(nodeURI0, grpcAddr0, chainID0, keyName0, password0, keyStore0, chainALightClientName)
182 | if err != nil {
183 | fmt.Println(err.Codespace(), err.Code(), err.Error(), clientA)
184 | return
185 | }
186 | clientC, err := getIntegrationClient(nodeURI2, grpcAddr2, chainID2, keyName2, password2, keyStore2, chainCLightClientName)
187 | if err != nil {
188 | fmt.Println(err.Codespace(), err.Code(), err.Error(), clientC)
189 | return
190 | }
191 | //getBSCjson(clientC.Tendermint)
192 | for i := 1; i < 500; i++ {
193 | fmt.Println("----------------------------------")
194 | updatebscclientTest(clientC, testneturl, "bsctestnet", keyName2)
195 | }
196 | }
197 |
198 | func Test_integrationClientETH(t *testing.T) {
199 | clientC, err := getIntegrationClient(nodeURI2, grpcAddr2, chainID2, keyName2, password2, keyStore2, chainCLightClientName)
200 | if err != nil {
201 | fmt.Println(err.Codespace(), err.Code(), err.Error(), clientC)
202 | return
203 | }
204 | //getETHjson(clientC.Tendermint)
205 | //updateEthClientTest(clientC, "ethclient", keyName2, ethurl)
206 | for i := 1; i < 50; i++ {
207 | updateEthClientTest(clientC, "ethclient", keyName2, ethurl)
208 | }
209 | }
210 |
211 | func updateAllCient(clientA, clientB, clientC Client) {
212 | updatetendetmintclientTest(clientA, clientB, chainBLightClientName, keyName0)
213 | updatetendetmintclientTest(clientA, clientC, chainCLightClientName, keyName0)
214 | updatetendetmintclientTest(clientB, clientA, chainALightClientName, keyName1)
215 | updatetendetmintclientTest(clientC, clientA, chainALightClientName, keyName2)
216 | }
217 |
218 | func getIntegrationClient(nodeURI, grpcAddr, chainID, keyName, password, keyStore, chainName string) (Client, tibctypes.IError) {
219 | feeCoin, err := types.ParseDecCoins("1000upoint")
220 | options := []types.Option{
221 | types.KeyDAOOption(store.NewMemory(nil)),
222 | types.TimeoutOption(3000),
223 | types.KeyManagerOption(crypto.NewKeyManager()),
224 | types.BIP44PathOption(""),
225 | // only for irita sm2
226 | types.AlgoOption("sm2"),
227 | types.FeeOption(feeCoin),
228 | }
229 | cfg, err := types.NewClientConfig(nodeURI, grpcAddr, chainID, options...)
230 | if err != nil {
231 | return Client{}, tibctypes.New("config", 0, "error get config")
232 | }
233 | client := NewClient(cfg, chainName)
234 | _, err = client.Import(keyName, password, keyStore)
235 | if err != nil {
236 | return Client{}, tibctypes.New("importkey", 0, "error import key")
237 | }
238 | return client, nil
239 | }
240 |
--------------------------------------------------------------------------------
/testing/integration_test/client.go:
--------------------------------------------------------------------------------
1 | package integration
2 |
3 | import (
4 | tibc "github.com/bianjieai/tibc-sdk-go"
5 | "github.com/irisnet/core-sdk-go/bank"
6 | "github.com/irisnet/core-sdk-go/client"
7 | "github.com/irisnet/core-sdk-go/common/codec"
8 | cdctypes "github.com/irisnet/core-sdk-go/common/codec/types"
9 | cryptocodec "github.com/irisnet/core-sdk-go/common/crypto/codec"
10 | "github.com/irisnet/core-sdk-go/gov"
11 | "github.com/irisnet/core-sdk-go/staking"
12 | "github.com/irisnet/core-sdk-go/types"
13 | txtypes "github.com/irisnet/core-sdk-go/types/tx"
14 | )
15 |
16 | type Client struct {
17 | encodingConfig types.EncodingConfig
18 | types.BaseClient
19 | Bank bank.Client
20 | Staking staking.Client
21 | Gov gov.Client
22 | Tendermint tibc.Client
23 | ChainName string
24 | }
25 |
26 | func NewClient(cfg types.ClientConfig, chainName string) Client {
27 | encodingConfig := makeEncodingConfig()
28 | // create a instance of baseClient
29 | baseClient := client.NewBaseClient(cfg, encodingConfig, nil)
30 | bankClient := bank.NewClient(baseClient, encodingConfig.Marshaler)
31 | stakingClient := staking.NewClient(baseClient, encodingConfig.Marshaler)
32 | govClient := gov.NewClient(baseClient, encodingConfig.Marshaler)
33 | tendermint := tibc.NewClient(baseClient, encodingConfig)
34 |
35 | client := &Client{
36 | encodingConfig: encodingConfig,
37 | BaseClient: baseClient,
38 | Bank: bankClient,
39 | Staking: stakingClient,
40 | Gov: govClient,
41 | Tendermint: tendermint,
42 | ChainName: chainName,
43 | }
44 |
45 | client.RegisterModule(
46 | bankClient,
47 | stakingClient,
48 | govClient,
49 | )
50 | return *client
51 | }
52 |
53 | func (client Client) Manager() types.BaseClient {
54 | return client.BaseClient
55 | }
56 |
57 | func (client Client) RegisterModule(ms ...types.Module) {
58 | for _, m := range ms {
59 | m.RegisterInterfaceTypes(client.encodingConfig.InterfaceRegistry)
60 | }
61 | }
62 |
63 | func makeEncodingConfig() types.EncodingConfig {
64 | amino := codec.NewLegacyAmino()
65 | interfaceRegistry := cdctypes.NewInterfaceRegistry()
66 | marshaler := codec.NewProtoCodec(interfaceRegistry)
67 | txCfg := txtypes.NewTxConfig(marshaler, txtypes.DefaultSignModes)
68 |
69 | encodingConfig := types.EncodingConfig{
70 | InterfaceRegistry: interfaceRegistry,
71 | Marshaler: marshaler,
72 | TxConfig: txCfg,
73 | Amino: amino,
74 | }
75 | RegisterLegacyAminoCodec(encodingConfig.Amino)
76 | RegisterInterfaces(encodingConfig.InterfaceRegistry)
77 | return encodingConfig
78 | }
79 |
80 | // RegisterLegacyAminoCodec registers the sdk message type.
81 | func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
82 | cdc.RegisterInterface((*types.Msg)(nil), nil)
83 | cdc.RegisterInterface((*types.Tx)(nil), nil)
84 | cryptocodec.RegisterCrypto(cdc)
85 | }
86 |
87 | // RegisterInterfaces registers the sdk message type.
88 | func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
89 | registry.RegisterInterface("cosmos.v1beta1.Msg", (*types.Msg)(nil))
90 | txtypes.RegisterInterfaces(registry)
91 | cryptocodec.RegisterInterfaces(registry)
92 | }
93 |
--------------------------------------------------------------------------------
/testing/integration_test/packet.go:
--------------------------------------------------------------------------------
1 | package integration
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 |
7 | tibc "github.com/bianjieai/tibc-sdk-go"
8 | "github.com/bianjieai/tibc-sdk-go/modules/core/packet"
9 | tibctypes "github.com/bianjieai/tibc-sdk-go/modules/types"
10 | "github.com/irisnet/core-sdk-go/types"
11 | )
12 |
13 | func queryCommitment(client tibc.Client, destName string, sourceName string, seq uint64) *packet.QueryPacketCommitmentResponse {
14 | res, err := client.PacketCommitment(destName, sourceName, seq)
15 | if err != nil {
16 | fmt.Println(err)
17 | return nil
18 | }
19 | fmt.Println(res.String())
20 | return res
21 | }
22 |
23 | func packetReceipt(client tibc.Client) {
24 | res, err := client.PacketReceipt("testCreateClientC", "testCreateClientA", 1)
25 | if err != nil {
26 | fmt.Println(err)
27 | return
28 | }
29 | fmt.Println(res.Received)
30 | }
31 | func queryack(client tibc.Client) {
32 | res, err := client.PacketAcknowledgement("testCreateClientC", "testCreateClientA", 1)
33 | if err != nil {
34 | fmt.Println(err)
35 | return
36 | }
37 | res1, err := client.PacketAcknowledgements("testCreateClientC", "testCreateClientA", nil)
38 | if err != nil {
39 | fmt.Println(err)
40 | return
41 | }
42 | fmt.Println(res.String())
43 | fmt.Println(res1.String())
44 | }
45 | func queryUnreceivedPacketsAndAcks(client tibc.Client) {
46 | res, err := client.UnreceivedPackets("testCreateClientA", "testCreateClientC", nil)
47 | if err != nil {
48 | fmt.Println(err)
49 | return
50 | }
51 | fmt.Println("packets :", res.String())
52 | res1, err := client.UnreceivedAcks("testCreateClientA", "testCreateClientC", nil)
53 | if err != nil {
54 | fmt.Println(err)
55 | return
56 | }
57 | fmt.Println("acks ", res1.String())
58 |
59 | }
60 | func getpacket(tx types.ResultQueryTx) (packet.Packet, error) {
61 | sequence, err := tx.Result.Events.GetValue("send_packet", "packet_sequence")
62 | if err != nil {
63 | fmt.Println(err)
64 | return packet.Packet{}, err
65 | }
66 | sourceChain, err := tx.Result.Events.GetValue("send_packet", "packet_src_chain")
67 | if err != nil {
68 | fmt.Println(err)
69 | return packet.Packet{}, err
70 | }
71 | destinationChain, err := tx.Result.Events.GetValue("send_packet", "packet_dst_port")
72 | if err != nil {
73 | fmt.Println(err)
74 | return packet.Packet{}, err
75 | }
76 | port, err := tx.Result.Events.GetValue("send_packet", "packet_port")
77 | if err != nil {
78 | fmt.Println(err)
79 | return packet.Packet{}, err
80 | }
81 | relayChain, err := tx.Result.Events.GetValue("send_packet", "packet_relay_channel")
82 | if err != nil {
83 | fmt.Println(err)
84 | return packet.Packet{}, err
85 | }
86 | data, err := tx.Result.Events.GetValue("send_packet", "packet_data")
87 | if err != nil {
88 | fmt.Println(err)
89 | return packet.Packet{}, err
90 | }
91 | num, err := strconv.Atoi(sequence)
92 | if err != nil {
93 | fmt.Println(err)
94 | return packet.Packet{}, err
95 | }
96 | return packet.Packet{
97 | Sequence: uint64(num),
98 | SourceChain: sourceChain,
99 | DestinationChain: destinationChain,
100 | Port: port,
101 | RelayChain: relayChain,
102 | Data: []byte(data),
103 | }, nil
104 | }
105 | func getpacketAndAck(tx types.ResultQueryTx) (packet.Packet, []byte, error) {
106 | sequence, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_sequence")
107 | if err != nil {
108 | fmt.Println(err)
109 | return packet.Packet{}, nil, err
110 | }
111 | sourceChain, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_src_chain")
112 | if err != nil {
113 | fmt.Println(err)
114 | return packet.Packet{}, nil, err
115 | }
116 | destinationChain, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_dst_port")
117 | if err != nil {
118 | fmt.Println(err)
119 | return packet.Packet{}, nil, err
120 | }
121 | port, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_port")
122 | if err != nil {
123 | fmt.Println(err)
124 | return packet.Packet{}, nil, err
125 | }
126 | relayChain, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_relay_channel")
127 | if err != nil {
128 | fmt.Println(err)
129 | return packet.Packet{}, nil, err
130 | }
131 | data, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_data")
132 | if err != nil {
133 | fmt.Println(err)
134 | return packet.Packet{}, nil, err
135 | }
136 | ack, err := tx.Result.Events.GetValue("write_acknowledgement", "packet_ack")
137 | if err != nil {
138 | fmt.Println(err)
139 | return packet.Packet{}, nil, err
140 | }
141 | num, err := strconv.Atoi(sequence)
142 | if err != nil {
143 | fmt.Println(err)
144 | return packet.Packet{}, nil, err
145 | }
146 | return packet.Packet{
147 | Sequence: uint64(num),
148 | SourceChain: sourceChain,
149 | DestinationChain: destinationChain,
150 | Port: port,
151 | RelayChain: relayChain,
152 | Data: []byte(data),
153 | }, []byte(ack), nil
154 | }
155 | func sendAck(sourceClient Client, destClient Client, keyname string, txhash string) (string, tibctypes.IError) {
156 | tx, err := destClient.QueryTx(txhash)
157 | if err != nil {
158 | return "", tibctypes.New("querytx", 0, "error query tx")
159 | }
160 | clients, err := sourceClient.Tendermint.GetClientState(destClient.ChainName)
161 | height := clients.GetLatestHeight()
162 | packet1, ack, err := getpacketAndAck(tx)
163 | baseTx := types.BaseTx{
164 | From: keyname,
165 | Gas: 0,
166 | Memo: "TEST",
167 | Mode: types.Commit,
168 | Password: "12345678",
169 | SimulateAndExecute: false,
170 | GasAdjustment: 1.5,
171 | }
172 | // ProofCommitment and ProofHeight are derived from the packet
173 | key := packet.PacketAcknowledgementKey(packet1.GetSourceChain(), packet1.GetDestChain(), packet1.GetSequence())
174 | _, proofBz, _, err1 := destClient.Tendermint.QueryTendermintProof(int64(height.GetRevisionHeight()), key)
175 |
176 | if err1 != nil {
177 | fmt.Println(err1)
178 | return "", tibctypes.New("queryProof", 0, "error query proof")
179 |
180 | }
181 | ress, err := sourceClient.Tendermint.Acknowledgement(proofBz, ack, packet1, int64(height.GetRevisionHeight()), clients.GetLatestHeight().GetRevisionNumber(), baseTx)
182 | if err != nil {
183 | fmt.Println(err)
184 | return "", tibctypes.New("queryProof", 0, "error send acknowledgement")
185 | }
186 | fmt.Println(ress)
187 | return ress.Hash, nil
188 | }
189 |
190 | func packetRecive(sourceClient Client, destClient Client, keyname string, txHash string) (string, tibctypes.IError) {
191 | tx, err := sourceClient.QueryTx(txHash)
192 | if err != nil {
193 | fmt.Println(err)
194 | return "", tibctypes.New("querytx", 0, "error query tx")
195 | }
196 | clients, err := destClient.Tendermint.GetClientState(sourceClient.ChainName)
197 |
198 | height := clients.GetLatestHeight()
199 | packet1, err := getpacket(tx)
200 | //fmt.Println(packet1.String())
201 | baseTx := types.BaseTx{
202 | From: keyname,
203 | Gas: 0,
204 | Memo: "TEST",
205 | Mode: types.Commit,
206 | Password: "12345678",
207 | SimulateAndExecute: false,
208 | GasAdjustment: 1.5,
209 | }
210 | // ProofCommitment and ProofHeight are derived from the packet
211 | key := packet.PacketCommitmentKey(packet1.GetSourceChain(), packet1.GetDestChain(), packet1.GetSequence())
212 | _, proofBz, _, err1 := sourceClient.Tendermint.QueryTendermintProof(int64(height.GetRevisionHeight()), key)
213 | if err1 != nil {
214 | fmt.Println(err1)
215 | return "", tibctypes.New("queryProof", 0, "error query proof")
216 | }
217 | ress, err := destClient.Tendermint.RecvPacket(proofBz, packet1, int64(height.GetRevisionHeight()), clients.GetLatestHeight().GetRevisionNumber(), baseTx)
218 | if err != nil {
219 | return "", tibctypes.New("recvPacket", 0, "error recive packet")
220 | }
221 | fmt.Println(ress)
222 | return ress.Hash, nil
223 | }
224 | func cleanPacket(sourceClient, destClient Client, seq uint64, keyname string) (string, tibctypes.IError) {
225 | cleanpacket := packet.CleanPacket{
226 | Sequence: seq,
227 | SourceChain: sourceClient.ChainName,
228 | DestinationChain: destClient.ChainName,
229 | RelayChain: "",
230 | }
231 | baseTx := types.BaseTx{
232 | From: keyname,
233 | Gas: 0,
234 | Memo: "TEST",
235 | Mode: types.Commit,
236 | Password: "12345678",
237 | SimulateAndExecute: false,
238 | GasAdjustment: 1.5,
239 | }
240 | res, err := sourceClient.Tendermint.CleanPacket(cleanpacket, baseTx)
241 | if err != nil {
242 | fmt.Println(err)
243 | return "", err
244 | }
245 | fmt.Println(res)
246 | return res.Hash, nil
247 | }
248 | func recvCleanPacket(sourceClient, destClient Client, keyname string, txhash string) (string, tibctypes.IError) {
249 | tx, err := sourceClient.QueryTx(txhash)
250 | if err != nil {
251 | fmt.Println(err)
252 | return "", tibctypes.New("querytx", 0, "error query tx")
253 | }
254 | clients, err := destClient.Tendermint.GetClientState(sourceClient.ChainName)
255 | height := clients.GetLatestHeight()
256 | cleanpack, err := getcleanpack(tx)
257 | if err != nil {
258 | fmt.Println("getcleanpack error")
259 | }
260 | baseTx := types.BaseTx{
261 | From: keyname,
262 | Gas: 0,
263 | Memo: "TEST",
264 | Mode: types.Commit,
265 | Password: "12345678",
266 | SimulateAndExecute: false,
267 | GasAdjustment: 1.5,
268 | }
269 | // ProofCommitment and ProofHeight are derived from the packet
270 | key := packet.CleanPacketCommitmentKey(cleanpack.GetSourceChain(), cleanpack.GetDestChain())
271 | _, proofBz, _, err1 := sourceClient.Tendermint.QueryTendermintProof(int64(height.GetRevisionHeight()), key)
272 | if err1 != nil {
273 | fmt.Println(err1)
274 | return "", tibctypes.New("queryProof", 0, "error query proof")
275 | }
276 | ress, err := destClient.Tendermint.RecvCleanPacket(proofBz, cleanpack, int64(height.GetRevisionHeight()), clients.GetLatestHeight().GetRevisionNumber(), baseTx)
277 | if err != nil {
278 | fmt.Println(err)
279 | return "", tibctypes.New("recvcleanpacket", 0, "error Recv CleanPacket")
280 | }
281 | fmt.Println(ress)
282 | return ress.Hash, nil
283 | }
284 |
285 | func getcleanpack(tx types.ResultQueryTx) (packet.CleanPacket, error) {
286 | sequence, err := tx.Result.Events.GetValue("send_clean_packet", "packet_sequence")
287 | if err != nil {
288 | fmt.Println(err)
289 | return packet.CleanPacket{}, nil
290 | }
291 | sourceChain, err := tx.Result.Events.GetValue("send_clean_packet", "packet_src_chain")
292 | if err != nil {
293 | fmt.Println(err)
294 | return packet.CleanPacket{}, nil
295 | }
296 | destinationChain, err := tx.Result.Events.GetValue("send_clean_packet", "packet_dst_port")
297 | if err != nil {
298 | fmt.Println(err)
299 | return packet.CleanPacket{}, nil
300 | }
301 | relayChain, err := tx.Result.Events.GetValue("send_clean_packet", "packet_relay_channel")
302 | if err != nil {
303 | fmt.Println(err)
304 | return packet.CleanPacket{}, nil
305 | }
306 | num, err := strconv.Atoi(sequence)
307 | if err != nil {
308 | fmt.Println(err)
309 | return packet.CleanPacket{}, nil
310 | }
311 | return packet.CleanPacket{
312 | Sequence: uint64(num),
313 | SourceChain: sourceChain,
314 | DestinationChain: destinationChain,
315 | RelayChain: relayChain,
316 | }, nil
317 |
318 | }
319 |
--------------------------------------------------------------------------------
/third_party/proto/confio/proofs.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package ics23;
4 | option go_package = "github.com/confio/ics23/go";
5 |
6 | enum HashOp {
7 | // NO_HASH is the default if no data passed. Note this is an illegal argument some places.
8 | NO_HASH = 0;
9 | SHA256 = 1;
10 | SHA512 = 2;
11 | KECCAK = 3;
12 | RIPEMD160 = 4;
13 | BITCOIN = 5; // ripemd160(sha256(x))
14 | }
15 |
16 | /**
17 | LengthOp defines how to process the key and value of the LeafOp
18 | to include length information. After encoding the length with the given
19 | algorithm, the length will be prepended to the key and value bytes.
20 | (Each one with it's own encoded length)
21 | */
22 | enum LengthOp {
23 | // NO_PREFIX don't include any length info
24 | NO_PREFIX = 0;
25 | // VAR_PROTO uses protobuf (and go-amino) varint encoding of the length
26 | VAR_PROTO = 1;
27 | // VAR_RLP uses rlp int encoding of the length
28 | VAR_RLP = 2;
29 | // FIXED32_BIG uses big-endian encoding of the length as a 32 bit integer
30 | FIXED32_BIG = 3;
31 | // FIXED32_LITTLE uses little-endian encoding of the length as a 32 bit integer
32 | FIXED32_LITTLE = 4;
33 | // FIXED64_BIG uses big-endian encoding of the length as a 64 bit integer
34 | FIXED64_BIG = 5;
35 | // FIXED64_LITTLE uses little-endian encoding of the length as a 64 bit integer
36 | FIXED64_LITTLE = 6;
37 | // REQUIRE_32_BYTES is like NONE, but will fail if the input is not exactly 32 bytes (sha256 output)
38 | REQUIRE_32_BYTES = 7;
39 | // REQUIRE_64_BYTES is like NONE, but will fail if the input is not exactly 64 bytes (sha512 output)
40 | REQUIRE_64_BYTES = 8;
41 | }
42 |
43 | /**
44 | ExistenceProof takes a key and a value and a set of steps to perform on it.
45 | The result of peforming all these steps will provide a "root hash", which can
46 | be compared to the value in a header.
47 |
48 | Since it is computationally infeasible to produce a hash collission for any of the used
49 | cryptographic hash functions, if someone can provide a series of operations to transform
50 | a given key and value into a root hash that matches some trusted root, these key and values
51 | must be in the referenced merkle tree.
52 |
53 | The only possible issue is maliablity in LeafOp, such as providing extra prefix data,
54 | which should be controlled by a spec. Eg. with lengthOp as NONE,
55 | prefix = FOO, key = BAR, value = CHOICE
56 | and
57 | prefix = F, key = OOBAR, value = CHOICE
58 | would produce the same value.
59 |
60 | With LengthOp this is tricker but not impossible. Which is why the "leafPrefixEqual" field
61 | in the ProofSpec is valuable to prevent this mutability. And why all trees should
62 | length-prefix the data before hashing it.
63 | */
64 | message ExistenceProof {
65 | bytes key = 1;
66 | bytes value = 2;
67 | LeafOp leaf = 3;
68 | repeated InnerOp path = 4;
69 | }
70 |
71 | /*
72 | NonExistenceProof takes a proof of two neighbors, one left of the desired key,
73 | one right of the desired key. If both proofs are valid AND they are neighbors,
74 | then there is no valid proof for the given key.
75 | */
76 | message NonExistenceProof {
77 | bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
78 | ExistenceProof left = 2;
79 | ExistenceProof right = 3;
80 | }
81 |
82 | /*
83 | CommitmentProof is either an ExistenceProof or a NonExistenceProof, or a Batch of such messages
84 | */
85 | message CommitmentProof {
86 | oneof proof {
87 | ExistenceProof exist = 1;
88 | NonExistenceProof nonexist = 2;
89 | BatchProof batch = 3;
90 | CompressedBatchProof compressed = 4;
91 | }
92 | }
93 |
94 | /**
95 | LeafOp represents the raw key-value data we wish to prove, and
96 | must be flexible to represent the internal transformation from
97 | the original key-value pairs into the basis hash, for many existing
98 | merkle trees.
99 |
100 | key and value are passed in. So that the signature of this operation is:
101 | leafOp(key, value) -> output
102 |
103 | To process this, first prehash the keys and values if needed (ANY means no hash in this case):
104 | hkey = prehashKey(key)
105 | hvalue = prehashValue(value)
106 |
107 | Then combine the bytes, and hash it
108 | output = hash(prefix || length(hkey) || hkey || length(hvalue) || hvalue)
109 | */
110 | message LeafOp {
111 | HashOp hash = 1;
112 | HashOp prehash_key = 2;
113 | HashOp prehash_value = 3;
114 | LengthOp length = 4;
115 | // prefix is a fixed bytes that may optionally be included at the beginning to differentiate
116 | // a leaf node from an inner node.
117 | bytes prefix = 5;
118 | }
119 |
120 | /**
121 | InnerOp represents a merkle-proof step that is not a leaf.
122 | It represents concatenating two children and hashing them to provide the next result.
123 |
124 | The result of the previous step is passed in, so the signature of this op is:
125 | innerOp(child) -> output
126 |
127 | The result of applying InnerOp should be:
128 | output = op.hash(op.prefix || child || op.suffix)
129 |
130 | where the || operator is concatenation of binary data,
131 | and child is the result of hashing all the tree below this step.
132 |
133 | Any special data, like prepending child with the length, or prepending the entire operation with
134 | some value to differentiate from leaf nodes, should be included in prefix and suffix.
135 | If either of prefix or suffix is empty, we just treat it as an empty string
136 | */
137 | message InnerOp {
138 | HashOp hash = 1;
139 | bytes prefix = 2;
140 | bytes suffix = 3;
141 | }
142 |
143 |
144 | /**
145 | ProofSpec defines what the expected parameters are for a given proof type.
146 | This can be stored in the client and used to validate any incoming proofs.
147 |
148 | verify(ProofSpec, Proof) -> Proof | Error
149 |
150 | As demonstrated in tests, if we don't fix the algorithm used to calculate the
151 | LeafHash for a given tree, there are many possible key-value pairs that can
152 | generate a given hash (by interpretting the preimage differently).
153 | We need this for proper security, requires client knows a priori what
154 | tree format server uses. But not in code, rather a configuration object.
155 | */
156 | message ProofSpec {
157 | // any field in the ExistenceProof must be the same as in this spec.
158 | // except Prefix, which is just the first bytes of prefix (spec can be longer)
159 | LeafOp leaf_spec = 1;
160 | InnerSpec inner_spec = 2;
161 | // max_depth (if > 0) is the maximum number of InnerOps allowed (mainly for fixed-depth tries)
162 | int32 max_depth = 3;
163 | // min_depth (if > 0) is the minimum number of InnerOps allowed (mainly for fixed-depth tries)
164 | int32 min_depth = 4;
165 | }
166 |
167 | /*
168 | InnerSpec contains all store-specific structure info to determine if two proofs from a
169 | given store are neighbors.
170 |
171 | This enables:
172 |
173 | isLeftMost(spec: InnerSpec, op: InnerOp)
174 | isRightMost(spec: InnerSpec, op: InnerOp)
175 | isLeftNeighbor(spec: InnerSpec, left: InnerOp, right: InnerOp)
176 | */
177 | message InnerSpec {
178 | // Child order is the ordering of the children node, must count from 0
179 | // iavl tree is [0, 1] (left then right)
180 | // merk is [0, 2, 1] (left, right, here)
181 | repeated int32 child_order = 1;
182 | int32 child_size = 2;
183 | int32 min_prefix_length = 3;
184 | int32 max_prefix_length = 4;
185 | // empty child is the prehash image that is used when one child is nil (eg. 20 bytes of 0)
186 | bytes empty_child = 5;
187 | // hash is the algorithm that must be used for each InnerOp
188 | HashOp hash = 6;
189 | }
190 |
191 | /*
192 | BatchProof is a group of multiple proof types than can be compressed
193 | */
194 | message BatchProof {
195 | repeated BatchEntry entries = 1;
196 | }
197 |
198 | // Use BatchEntry not CommitmentProof, to avoid recursion
199 | message BatchEntry {
200 | oneof proof {
201 | ExistenceProof exist = 1;
202 | NonExistenceProof nonexist = 2;
203 | }
204 | }
205 |
206 |
207 | /****** all items here are compressed forms *******/
208 |
209 | message CompressedBatchProof {
210 | repeated CompressedBatchEntry entries = 1;
211 | repeated InnerOp lookup_inners = 2;
212 | }
213 |
214 | // Use BatchEntry not CommitmentProof, to avoid recursion
215 | message CompressedBatchEntry {
216 | oneof proof {
217 | CompressedExistenceProof exist = 1;
218 | CompressedNonExistenceProof nonexist = 2;
219 | }
220 | }
221 |
222 | message CompressedExistenceProof {
223 | bytes key = 1;
224 | bytes value = 2;
225 | LeafOp leaf = 3;
226 | // these are indexes into the lookup_inners table in CompressedBatchProof
227 | repeated int32 path = 4;
228 | }
229 |
230 | message CompressedNonExistenceProof {
231 | bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
232 | CompressedExistenceProof left = 2;
233 | CompressedExistenceProof right = 3;
234 | }
235 |
--------------------------------------------------------------------------------
/third_party/proto/cosmos/base/query/v1beta1/pagination.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package cosmos.base.query.v1beta1;
3 |
4 | option go_package = "github.com/irisnet/core-sdk-go/types/query";
5 |
6 | // PageRequest is to be embedded in gRPC request messages for efficient
7 | // pagination. Ex:
8 | //
9 | // message SomeRequest {
10 | // Foo some_parameter = 1;
11 | // PageRequest page = 2;
12 | // }
13 | message PageRequest {
14 | // key is a value returned in PageResponse.next_key to begin
15 | // querying the next page most efficiently. Only one of offset or key
16 | // should be set.
17 | bytes key = 1;
18 |
19 | // offset is a numeric offset that can be used when key is unavailable.
20 | // It is less efficient than using key. Only one of offset or key should
21 | // be set.
22 | uint64 offset = 2;
23 |
24 | // limit is the total number of results to be returned in the result page.
25 | // If left empty it will default to a value to be set by each app.
26 | uint64 limit = 3;
27 |
28 | // count_total is set to true to indicate that the result set should include
29 | // a count of the total number of items available for pagination in UIs. count_total
30 | // is only respected when offset is used. It is ignored when key is set.
31 | bool count_total = 4;
32 | }
33 |
34 | // PageResponse is to be embedded in gRPC response messages where the corresponding
35 | // request message has used PageRequest
36 | //
37 | // message SomeResponse {
38 | // repeated Bar results = 1;
39 | // PageResponse page = 2;
40 | // }
41 | message PageResponse {
42 | // next_key is the key to be passed to PageRequest.key to
43 | // query the next page most efficiently
44 | bytes next_key = 1;
45 |
46 | // total is total number of results available if PageRequest.count_total
47 | // was set, its value is undefined otherwise
48 | uint64 total = 2;
49 | }
50 |
--------------------------------------------------------------------------------
/third_party/proto/cosmos/base/v1beta1/coin.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package cosmos.base.v1beta1;
3 |
4 | import "gogoproto/gogo.proto";
5 |
6 | option go_package = "github.com/irisnet/core-sdk-go/types";
7 | option (gogoproto.goproto_stringer_all) = false;
8 | option (gogoproto.stringer_all) = false;
9 |
10 | // Coin defines a token with a denomination and an amount.
11 | //
12 | // NOTE: The amount field is an Int which implements the custom method
13 | // signatures required by gogoproto.
14 | message Coin {
15 | option (gogoproto.equal) = true;
16 |
17 | string denom = 1;
18 | string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false];
19 | }
20 |
21 | // DecCoin defines a token with a denomination and a decimal amount.
22 | //
23 | // NOTE: The amount field is an Dec which implements the custom method
24 | // signatures required by gogoproto.
25 | message DecCoin {
26 | option (gogoproto.equal) = true;
27 |
28 | string denom = 1;
29 | string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false];
30 | }
31 |
32 | // IntProto defines a Protobuf wrapper around an Int object.
33 | message IntProto {
34 | string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false];
35 | }
36 |
37 | // DecProto defines a Protobuf wrapper around a Dec object.
38 | message DecProto {
39 | string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false];
40 | }
41 |
--------------------------------------------------------------------------------
/third_party/proto/cosmos_proto/cosmos.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package cosmos_proto;
3 |
4 | import "google/protobuf/descriptor.proto";
5 |
6 | option go_package = "github.com/regen-network/cosmos-proto";
7 |
8 | extend google.protobuf.MessageOptions {
9 | string interface_type = 93001;
10 |
11 | string implements_interface = 93002;
12 | }
13 |
14 | extend google.protobuf.FieldOptions {
15 | string accepts_interface = 93001;
16 | }
17 |
--------------------------------------------------------------------------------
/third_party/proto/gogoproto/gogo.proto:
--------------------------------------------------------------------------------
1 | // Protocol Buffers for Go with Gadgets
2 | //
3 | // Copyright (c) 2013, The GoGo Authors. All rights reserved.
4 | // http://github.com/gogo/protobuf
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | syntax = "proto2";
30 | package gogoproto;
31 |
32 | import "google/protobuf/descriptor.proto";
33 |
34 | option java_package = "com.google.protobuf";
35 | option java_outer_classname = "GoGoProtos";
36 | option go_package = "github.com/gogo/protobuf/gogoproto";
37 |
38 | extend google.protobuf.EnumOptions {
39 | optional bool goproto_enum_prefix = 62001;
40 | optional bool goproto_enum_stringer = 62021;
41 | optional bool enum_stringer = 62022;
42 | optional string enum_customname = 62023;
43 | optional bool enumdecl = 62024;
44 | }
45 |
46 | extend google.protobuf.EnumValueOptions {
47 | optional string enumvalue_customname = 66001;
48 | }
49 |
50 | extend google.protobuf.FileOptions {
51 | optional bool goproto_getters_all = 63001;
52 | optional bool goproto_enum_prefix_all = 63002;
53 | optional bool goproto_stringer_all = 63003;
54 | optional bool verbose_equal_all = 63004;
55 | optional bool face_all = 63005;
56 | optional bool gostring_all = 63006;
57 | optional bool populate_all = 63007;
58 | optional bool stringer_all = 63008;
59 | optional bool onlyone_all = 63009;
60 |
61 | optional bool equal_all = 63013;
62 | optional bool description_all = 63014;
63 | optional bool testgen_all = 63015;
64 | optional bool benchgen_all = 63016;
65 | optional bool marshaler_all = 63017;
66 | optional bool unmarshaler_all = 63018;
67 | optional bool stable_marshaler_all = 63019;
68 |
69 | optional bool sizer_all = 63020;
70 |
71 | optional bool goproto_enum_stringer_all = 63021;
72 | optional bool enum_stringer_all = 63022;
73 |
74 | optional bool unsafe_marshaler_all = 63023;
75 | optional bool unsafe_unmarshaler_all = 63024;
76 |
77 | optional bool goproto_extensions_map_all = 63025;
78 | optional bool goproto_unrecognized_all = 63026;
79 | optional bool gogoproto_import = 63027;
80 | optional bool protosizer_all = 63028;
81 | optional bool compare_all = 63029;
82 | optional bool typedecl_all = 63030;
83 | optional bool enumdecl_all = 63031;
84 |
85 | optional bool goproto_registration = 63032;
86 | optional bool messagename_all = 63033;
87 |
88 | optional bool goproto_sizecache_all = 63034;
89 | optional bool goproto_unkeyed_all = 63035;
90 | }
91 |
92 | extend google.protobuf.MessageOptions {
93 | optional bool goproto_getters = 64001;
94 | optional bool goproto_stringer = 64003;
95 | optional bool verbose_equal = 64004;
96 | optional bool face = 64005;
97 | optional bool gostring = 64006;
98 | optional bool populate = 64007;
99 | optional bool stringer = 67008;
100 | optional bool onlyone = 64009;
101 |
102 | optional bool equal = 64013;
103 | optional bool description = 64014;
104 | optional bool testgen = 64015;
105 | optional bool benchgen = 64016;
106 | optional bool marshaler = 64017;
107 | optional bool unmarshaler = 64018;
108 | optional bool stable_marshaler = 64019;
109 |
110 | optional bool sizer = 64020;
111 |
112 | optional bool unsafe_marshaler = 64023;
113 | optional bool unsafe_unmarshaler = 64024;
114 |
115 | optional bool goproto_extensions_map = 64025;
116 | optional bool goproto_unrecognized = 64026;
117 |
118 | optional bool protosizer = 64028;
119 | optional bool compare = 64029;
120 |
121 | optional bool typedecl = 64030;
122 |
123 | optional bool messagename = 64033;
124 |
125 | optional bool goproto_sizecache = 64034;
126 | optional bool goproto_unkeyed = 64035;
127 | }
128 |
129 | extend google.protobuf.FieldOptions {
130 | optional bool nullable = 65001;
131 | optional bool embed = 65002;
132 | optional string customtype = 65003;
133 | optional string customname = 65004;
134 | optional string jsontag = 65005;
135 | optional string moretags = 65006;
136 | optional string casttype = 65007;
137 | optional string castkey = 65008;
138 | optional string castvalue = 65009;
139 |
140 | optional bool stdtime = 65010;
141 | optional bool stdduration = 65011;
142 | optional bool wktpointer = 65012;
143 |
144 | optional string castrepeated = 65013;
145 | }
146 |
--------------------------------------------------------------------------------
/third_party/proto/google/api/annotations.proto:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015, Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | syntax = "proto3";
16 |
17 | package google.api;
18 |
19 | import "google/api/http.proto";
20 | import "google/protobuf/descriptor.proto";
21 |
22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
23 | option java_multiple_files = true;
24 | option java_outer_classname = "AnnotationsProto";
25 | option java_package = "com.google.api";
26 | option objc_class_prefix = "GAPI";
27 |
28 | extend google.protobuf.MethodOptions {
29 | // See `HttpRule`.
30 | HttpRule http = 72295728;
31 | }
32 |
--------------------------------------------------------------------------------
/third_party/proto/google/api/httpbody.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Google LLC.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | //
15 |
16 | syntax = "proto3";
17 |
18 | package google.api;
19 |
20 | import "google/protobuf/any.proto";
21 |
22 | option cc_enable_arenas = true;
23 | option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody";
24 | option java_multiple_files = true;
25 | option java_outer_classname = "HttpBodyProto";
26 | option java_package = "com.google.api";
27 | option objc_class_prefix = "GAPI";
28 |
29 | // Message that represents an arbitrary HTTP body. It should only be used for
30 | // payload formats that can't be represented as JSON, such as raw binary or
31 | // an HTML page.
32 | //
33 | //
34 | // This message can be used both in streaming and non-streaming API methods in
35 | // the request as well as the response.
36 | //
37 | // It can be used as a top-level request field, which is convenient if one
38 | // wants to extract parameters from either the URL or HTTP template into the
39 | // request fields and also want access to the raw HTTP body.
40 | //
41 | // Example:
42 | //
43 | // message GetResourceRequest {
44 | // // A unique request id.
45 | // string request_id = 1;
46 | //
47 | // // The raw HTTP body is bound to this field.
48 | // google.api.HttpBody http_body = 2;
49 | // }
50 | //
51 | // service ResourceService {
52 | // rpc GetResource(GetResourceRequest) returns (google.api.HttpBody);
53 | // rpc UpdateResource(google.api.HttpBody) returns
54 | // (google.protobuf.Empty);
55 | // }
56 | //
57 | // Example with streaming methods:
58 | //
59 | // service CaldavService {
60 | // rpc GetCalendar(stream google.api.HttpBody)
61 | // returns (stream google.api.HttpBody);
62 | // rpc UpdateCalendar(stream google.api.HttpBody)
63 | // returns (stream google.api.HttpBody);
64 | // }
65 | //
66 | // Use of this type only changes how the request and response bodies are
67 | // handled, all other features will continue to work unchanged.
68 | message HttpBody {
69 | // The HTTP Content-Type header value specifying the content type of the body.
70 | string content_type = 1;
71 |
72 | // The HTTP request/response body as raw binary.
73 | bytes data = 2;
74 |
75 | // Application specific response metadata. Must be set in the first response
76 | // for streaming APIs.
77 | repeated google.protobuf.Any extensions = 3;
78 | }
--------------------------------------------------------------------------------
/third_party/proto/google/protobuf/any.proto:
--------------------------------------------------------------------------------
1 | // Protocol Buffers - Google's data interchange format
2 | // Copyright 2008 Google Inc. All rights reserved.
3 | // https://developers.google.com/protocol-buffers/
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions are
7 | // met:
8 | //
9 | // * Redistributions of source code must retain the above copyright
10 | // notice, this list of conditions and the following disclaimer.
11 | // * Redistributions in binary form must reproduce the above
12 | // copyright notice, this list of conditions and the following disclaimer
13 | // in the documentation and/or other materials provided with the
14 | // distribution.
15 | // * Neither the name of Google Inc. nor the names of its
16 | // contributors may be used to endorse or promote products derived from
17 | // this software without specific prior written permission.
18 | //
19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
31 | syntax = "proto3";
32 |
33 | package google.protobuf;
34 |
35 | import "gogoproto/gogo.proto";
36 |
37 | option csharp_namespace = "Google.Protobuf.WellKnownTypes";
38 | option go_package = "types";
39 | option java_package = "com.google.protobuf";
40 | option java_outer_classname = "AnyProto";
41 | option java_multiple_files = true;
42 | option objc_class_prefix = "GPB";
43 |
44 | // `Any` contains an arbitrary serialized protocol buffer message along with a
45 | // URL that describes the type of the serialized message.
46 | //
47 | // Protobuf library provides support to pack/unpack Any values in the form
48 | // of utility functions or additional generated methods of the Any type.
49 | //
50 | // Example 1: Pack and unpack a message in C++.
51 | //
52 | // Foo foo = ...;
53 | // Any any;
54 | // any.PackFrom(foo);
55 | // ...
56 | // if (any.UnpackTo(&foo)) {
57 | // ...
58 | // }
59 | //
60 | // Example 2: Pack and unpack a message in Java.
61 | //
62 | // Foo foo = ...;
63 | // Any any = Any.pack(foo);
64 | // ...
65 | // if (any.is(Foo.class)) {
66 | // foo = any.unpack(Foo.class);
67 | // }
68 | //
69 | // Example 3: Pack and unpack a message in Python.
70 | //
71 | // foo = Foo(...)
72 | // any = Any()
73 | // any.Pack(foo)
74 | // ...
75 | // if any.Is(Foo.DESCRIPTOR):
76 | // any.Unpack(foo)
77 | // ...
78 | //
79 | // Example 4: Pack and unpack a message in Go
80 | //
81 | // foo := &pb.Foo{...}
82 | // any, err := ptypes.MarshalAny(foo)
83 | // ...
84 | // foo := &pb.Foo{}
85 | // if err := ptypes.UnmarshalAny(any, foo); err != nil {
86 | // ...
87 | // }
88 | //
89 | // The pack methods provided by protobuf library will by default use
90 | // 'type.googleapis.com/full.type.name' as the type URL and the unpack
91 | // methods only use the fully qualified type name after the last '/'
92 | // in the type URL, for example "foo.bar.com/x/y.z" will yield type
93 | // name "y.z".
94 | //
95 | //
96 | // JSON
97 | // ====
98 | // The JSON representation of an `Any` value uses the regular
99 | // representation of the deserialized, embedded message, with an
100 | // additional field `@type` which contains the type URL. Example:
101 | //
102 | // package google.profile;
103 | // message Person {
104 | // string first_name = 1;
105 | // string last_name = 2;
106 | // }
107 | //
108 | // {
109 | // "@type": "type.googleapis.com/google.profile.Person",
110 | // "firstName": ,
111 | // "lastName":
112 | // }
113 | //
114 | // If the embedded message type is well-known and has a custom JSON
115 | // representation, that representation will be embedded adding a field
116 | // `value` which holds the custom JSON in addition to the `@type`
117 | // field. Example (for message [google.protobuf.Duration][]):
118 | //
119 | // {
120 | // "@type": "type.googleapis.com/google.protobuf.Duration",
121 | // "value": "1.212s"
122 | // }
123 | //
124 | message Any {
125 | // A URL/resource name that uniquely identifies the type of the serialized
126 | // protocol buffer message. This string must contain at least
127 | // one "/" character. The last segment of the URL's path must represent
128 | // the fully qualified name of the type (as in
129 | // `path/google.protobuf.Duration`). The name should be in a canonical form
130 | // (e.g., leading "." is not accepted).
131 | //
132 | // In practice, teams usually precompile into the binary all types that they
133 | // expect it to use in the context of Any. However, for URLs which use the
134 | // scheme `http`, `https`, or no scheme, one can optionally set up a type
135 | // server that maps type URLs to message definitions as follows:
136 | //
137 | // * If no scheme is provided, `https` is assumed.
138 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][]
139 | // value in binary format, or produce an error.
140 | // * Applications are allowed to cache lookup results based on the
141 | // URL, or have them precompiled into a binary to avoid any
142 | // lookup. Therefore, binary compatibility needs to be preserved
143 | // on changes to types. (Use versioned type names to manage
144 | // breaking changes.)
145 | //
146 | // Note: this functionality is not currently available in the official
147 | // protobuf release, and it is not used for type URLs beginning with
148 | // type.googleapis.com.
149 | //
150 | // Schemes other than `http`, `https` (or the empty scheme) might be
151 | // used with implementation specific semantics.
152 | //
153 | string type_url = 1;
154 |
155 | // Must be a valid serialized protocol buffer of the above specified type.
156 | bytes value = 2;
157 |
158 | option (gogoproto.typedecl) = false;
159 | }
160 |
161 | option (gogoproto.goproto_registration) = false;
162 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/crypto/keys.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.crypto;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | // PublicKey defines the keys available for use with Tendermint Validators
9 | message PublicKey {
10 | option (gogoproto.compare) = true;
11 | option (gogoproto.equal) = true;
12 |
13 | oneof sum {
14 | bytes ed25519 = 1;
15 | bytes secp256k1 = 2;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/crypto/proof.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.crypto;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/crypto";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | message Proof {
9 | int64 total = 1;
10 | int64 index = 2;
11 | bytes leaf_hash = 3;
12 | repeated bytes aunts = 4;
13 | }
14 |
15 | message ValueOp {
16 | // Encoded in ProofOp.Key.
17 | bytes key = 1;
18 |
19 | // To encode in ProofOp.Data
20 | Proof proof = 2;
21 | }
22 |
23 | message DominoOp {
24 | string key = 1;
25 | string input = 2;
26 | string output = 3;
27 | }
28 |
29 | // ProofOp defines an operation used for calculating Merkle root
30 | // The data could be arbitrary format, providing nessecary data
31 | // for example neighbouring node hash
32 | message ProofOp {
33 | string type = 1;
34 | bytes key = 2;
35 | bytes data = 3;
36 | }
37 |
38 | // ProofOps is Merkle proof defined by the list of ProofOps
39 | message ProofOps {
40 | repeated ProofOp ops = 1 [(gogoproto.nullable) = false];
41 | }
42 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/libs/bits/types.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.libs.bits;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/libs/bits";
5 |
6 | message BitArray {
7 | int64 bits = 1;
8 | repeated uint64 elems = 2;
9 | }
10 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/p2p/types.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.p2p;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/p2p";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | message NetAddress {
9 | string id = 1 [(gogoproto.customname) = "ID"];
10 | string ip = 2 [(gogoproto.customname) = "IP"];
11 | uint32 port = 3;
12 | }
13 |
14 | message ProtocolVersion {
15 | uint64 p2p = 1 [(gogoproto.customname) = "P2P"];
16 | uint64 block = 2;
17 | uint64 app = 3;
18 | }
19 |
20 | message DefaultNodeInfo {
21 | ProtocolVersion protocol_version = 1 [(gogoproto.nullable) = false];
22 | string default_node_id = 2 [(gogoproto.customname) = "DefaultNodeID"];
23 | string listen_addr = 3;
24 | string network = 4;
25 | string version = 5;
26 | bytes channels = 6;
27 | string moniker = 7;
28 | DefaultNodeInfoOther other = 8 [(gogoproto.nullable) = false];
29 | }
30 |
31 | message DefaultNodeInfoOther {
32 | string tx_index = 1;
33 | string rpc_address = 2 [(gogoproto.customname) = "RPCAddress"];
34 | }
35 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/types/block.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.types;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tendermint/types/types.proto";
8 | import "tendermint/types/evidence.proto";
9 |
10 | message Block {
11 | Header header = 1 [(gogoproto.nullable) = false];
12 | Data data = 2 [(gogoproto.nullable) = false];
13 | tendermint.types.EvidenceList evidence = 3 [(gogoproto.nullable) = false];
14 | Commit last_commit = 4;
15 | }
16 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/types/evidence.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.types;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "google/protobuf/timestamp.proto";
8 | import "tendermint/types/types.proto";
9 | import "tendermint/types/validator.proto";
10 |
11 | message Evidence {
12 | oneof sum {
13 | DuplicateVoteEvidence duplicate_vote_evidence = 1;
14 | LightClientAttackEvidence light_client_attack_evidence = 2;
15 | }
16 | }
17 |
18 | // DuplicateVoteEvidence contains evidence of a validator signed two conflicting votes.
19 | message DuplicateVoteEvidence {
20 | tendermint.types.Vote vote_a = 1;
21 | tendermint.types.Vote vote_b = 2;
22 | int64 total_voting_power = 3;
23 | int64 validator_power = 4;
24 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
25 | }
26 |
27 | // LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client.
28 | message LightClientAttackEvidence {
29 | tendermint.types.LightBlock conflicting_block = 1;
30 | int64 common_height = 2;
31 | repeated tendermint.types.Validator byzantine_validators = 3;
32 | int64 total_voting_power = 4;
33 | google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
34 | }
35 |
36 | message EvidenceList {
37 | repeated Evidence evidence = 1 [(gogoproto.nullable) = false];
38 | }
39 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/types/params.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.types;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "google/protobuf/duration.proto";
8 |
9 | option (gogoproto.equal_all) = true;
10 |
11 | // ConsensusParams contains consensus critical parameters that determine the
12 | // validity of blocks.
13 | message ConsensusParams {
14 | BlockParams block = 1 [(gogoproto.nullable) = false];
15 | EvidenceParams evidence = 2 [(gogoproto.nullable) = false];
16 | ValidatorParams validator = 3 [(gogoproto.nullable) = false];
17 | VersionParams version = 4 [(gogoproto.nullable) = false];
18 | }
19 |
20 | // BlockParams contains limits on the block size.
21 | message BlockParams {
22 | // Max block size, in bytes.
23 | // Note: must be greater than 0
24 | int64 max_bytes = 1;
25 | // Max gas per block.
26 | // Note: must be greater or equal to -1
27 | int64 max_gas = 2;
28 | // Minimum time increment between consecutive blocks (in milliseconds) If the
29 | // block header timestamp is ahead of the system clock, decrease this value.
30 | //
31 | // Not exposed to the application.
32 | int64 time_iota_ms = 3;
33 | }
34 |
35 | // EvidenceParams determine how we handle evidence of malfeasance.
36 | message EvidenceParams {
37 | // Max age of evidence, in blocks.
38 | //
39 | // The basic formula for calculating this is: MaxAgeDuration / {average block
40 | // time}.
41 | int64 max_age_num_blocks = 1;
42 |
43 | // Max age of evidence, in time.
44 | //
45 | // It should correspond with an app's "unbonding period" or other similar
46 | // mechanism for handling [Nothing-At-Stake
47 | // attacks](https://github.com/ethereum/wiki/wiki/Proof-of-Stake-FAQ#what-is-the-nothing-at-stake-problem-and-how-can-it-be-fixed).
48 | google.protobuf.Duration max_age_duration = 2
49 | [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
50 |
51 | // This sets the maximum size of total evidence in bytes that can be committed in a single block.
52 | // and should fall comfortably under the max block bytes.
53 | // Default is 1048576 or 1MB
54 | int64 max_bytes = 3;
55 | }
56 |
57 | // ValidatorParams restrict the public key types validators can use.
58 | // NOTE: uses ABCI pubkey naming, not Amino names.
59 | message ValidatorParams {
60 | option (gogoproto.populate) = true;
61 | option (gogoproto.equal) = true;
62 |
63 | repeated string pub_key_types = 1;
64 | }
65 |
66 | // VersionParams contains the ABCI application version.
67 | message VersionParams {
68 | option (gogoproto.populate) = true;
69 | option (gogoproto.equal) = true;
70 |
71 | uint64 app_version = 1;
72 | }
73 |
74 | // HashedParams is a subset of ConsensusParams.
75 | //
76 | // It is hashed into the Header.ConsensusHash.
77 | message HashedParams {
78 | int64 block_max_bytes = 1;
79 | int64 block_max_gas = 2;
80 | }
81 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/types/types.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.types;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "google/protobuf/timestamp.proto";
8 | import "tendermint/crypto/proof.proto";
9 | import "tendermint/version/types.proto";
10 | import "tendermint/types/validator.proto";
11 |
12 | // BlockIdFlag indicates which BlcokID the signature is for
13 | enum BlockIDFlag {
14 | option (gogoproto.goproto_enum_stringer) = true;
15 | option (gogoproto.goproto_enum_prefix) = false;
16 |
17 | BLOCK_ID_FLAG_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "BlockIDFlagUnknown"];
18 | BLOCK_ID_FLAG_ABSENT = 1 [(gogoproto.enumvalue_customname) = "BlockIDFlagAbsent"];
19 | BLOCK_ID_FLAG_COMMIT = 2 [(gogoproto.enumvalue_customname) = "BlockIDFlagCommit"];
20 | BLOCK_ID_FLAG_NIL = 3 [(gogoproto.enumvalue_customname) = "BlockIDFlagNil"];
21 | }
22 |
23 | // SignedMsgType is a type of signed message in the consensus.
24 | enum SignedMsgType {
25 | option (gogoproto.goproto_enum_stringer) = true;
26 | option (gogoproto.goproto_enum_prefix) = false;
27 |
28 | SIGNED_MSG_TYPE_UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "UnknownType"];
29 | // Votes
30 | SIGNED_MSG_TYPE_PREVOTE = 1 [(gogoproto.enumvalue_customname) = "PrevoteType"];
31 | SIGNED_MSG_TYPE_PRECOMMIT = 2 [(gogoproto.enumvalue_customname) = "PrecommitType"];
32 |
33 | // Proposals
34 | SIGNED_MSG_TYPE_PROPOSAL = 32 [(gogoproto.enumvalue_customname) = "ProposalType"];
35 | }
36 |
37 | // PartsetHeader
38 | message PartSetHeader {
39 | uint32 total = 1;
40 | bytes hash = 2;
41 | }
42 |
43 | message Part {
44 | uint32 index = 1;
45 | bytes bytes = 2;
46 | tendermint.crypto.Proof proof = 3 [(gogoproto.nullable) = false];
47 | }
48 |
49 | // BlockID
50 | message BlockID {
51 | bytes hash = 1;
52 | PartSetHeader part_set_header = 2 [(gogoproto.nullable) = false];
53 | }
54 |
55 | // --------------------------------
56 |
57 | // Header defines the structure of a Tendermint block header.
58 | message Header {
59 | // basic block info
60 | tendermint.version.Consensus version = 1 [(gogoproto.nullable) = false];
61 | string chain_id = 2 [(gogoproto.customname) = "ChainID"];
62 | int64 height = 3;
63 | google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
64 |
65 | // prev block info
66 | BlockID last_block_id = 5 [(gogoproto.nullable) = false];
67 |
68 | // hashes of block data
69 | bytes last_commit_hash = 6; // commit from validators from the last block
70 | bytes data_hash = 7; // transactions
71 |
72 | // hashes from the app output from the prev block
73 | bytes validators_hash = 8; // validators for the current block
74 | bytes next_validators_hash = 9; // validators for the next block
75 | bytes consensus_hash = 10; // consensus params for current block
76 | bytes app_hash = 11; // state after txs from the previous block
77 | bytes last_results_hash = 12; // root hash of all results from the txs from the previous block
78 |
79 | // consensus info
80 | bytes evidence_hash = 13; // evidence included in the block
81 | bytes proposer_address = 14; // original proposer of the block
82 | }
83 |
84 | // Data contains the set of transactions included in the block
85 | message Data {
86 | // Txs that will be applied by state @ block.Height+1.
87 | // NOTE: not all txs here are valid. We're just agreeing on the order first.
88 | // This means that block.AppHash does not include these txs.
89 | repeated bytes txs = 1;
90 | }
91 |
92 | // Vote represents a prevote, precommit, or commit vote from validators for
93 | // consensus.
94 | message Vote {
95 | SignedMsgType type = 1;
96 | int64 height = 2;
97 | int32 round = 3;
98 | BlockID block_id = 4
99 | [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"]; // zero if vote is nil.
100 | google.protobuf.Timestamp timestamp = 5
101 | [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
102 | bytes validator_address = 6;
103 | int32 validator_index = 7;
104 | bytes signature = 8;
105 | }
106 |
107 | // Commit contains the evidence that a block was committed by a set of validators.
108 | message Commit {
109 | int64 height = 1;
110 | int32 round = 2;
111 | BlockID block_id = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"];
112 | repeated CommitSig signatures = 4 [(gogoproto.nullable) = false];
113 | }
114 |
115 | // CommitSig is a part of the Vote included in a Commit.
116 | message CommitSig {
117 | BlockIDFlag block_id_flag = 1;
118 | bytes validator_address = 2;
119 | google.protobuf.Timestamp timestamp = 3
120 | [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
121 | bytes signature = 4;
122 | }
123 |
124 | message Proposal {
125 | SignedMsgType type = 1;
126 | int64 height = 2;
127 | int32 round = 3;
128 | int32 pol_round = 4;
129 | BlockID block_id = 5 [(gogoproto.customname) = "BlockID", (gogoproto.nullable) = false];
130 | google.protobuf.Timestamp timestamp = 6
131 | [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
132 | bytes signature = 7;
133 | }
134 |
135 | message SignedHeader {
136 | Header header = 1;
137 | Commit commit = 2;
138 | }
139 |
140 | message LightBlock {
141 | SignedHeader signed_header = 1;
142 | tendermint.types.ValidatorSet validator_set = 2;
143 | }
144 |
145 | message BlockMeta {
146 | BlockID block_id = 1 [(gogoproto.customname) = "BlockID", (gogoproto.nullable) = false];
147 | int64 block_size = 2;
148 | Header header = 3 [(gogoproto.nullable) = false];
149 | int64 num_txs = 4;
150 | }
151 |
152 | // TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.
153 | message TxProof {
154 | bytes root_hash = 1;
155 | bytes data = 2;
156 | tendermint.crypto.Proof proof = 3;
157 | }
158 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/types/validator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.types;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/types";
5 |
6 | import "gogoproto/gogo.proto";
7 | import "tendermint/crypto/keys.proto";
8 |
9 | message ValidatorSet {
10 | repeated Validator validators = 1;
11 | Validator proposer = 2;
12 | int64 total_voting_power = 3;
13 | }
14 |
15 | message Validator {
16 | bytes address = 1;
17 | tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false];
18 | int64 voting_power = 3;
19 | int64 proposer_priority = 4;
20 | }
21 |
22 | message SimpleValidator {
23 | tendermint.crypto.PublicKey pub_key = 1;
24 | int64 voting_power = 2;
25 | }
26 |
--------------------------------------------------------------------------------
/third_party/proto/tendermint/version/types.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package tendermint.version;
3 |
4 | option go_package = "github.com/tendermint/tendermint/proto/tendermint/version";
5 |
6 | import "gogoproto/gogo.proto";
7 |
8 | // App includes the protocol and software version for the application.
9 | // This information is included in ResponseInfo. The App.Protocol can be
10 | // updated in ResponseEndBlock.
11 | message App {
12 | uint64 protocol = 1;
13 | string software = 2;
14 | }
15 |
16 | // Consensus captures the consensus rules for processing a block in the blockchain,
17 | // including all blockchain data structures and the rules of the application's
18 | // state transition machine.
19 | message Consensus {
20 | option (gogoproto.equal) = true;
21 |
22 | uint64 block = 1;
23 | uint64 app = 2;
24 | }
25 |
--------------------------------------------------------------------------------