/
querier.go
114 lines (99 loc) · 4.47 KB
/
querier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package types
import (
"strings"
"github.com/tendermint/tendermint/crypto/merkle"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// query routes supported by the IBC channel Querier
const (
QueryAllChannels = "channels"
QueryChannel = "channel"
QueryConnectionChannels = "connection-channels"
)
// ChannelResponse defines the client query response for a channel which also
// includes a proof,its path and the height from which the proof was retrieved.
type ChannelResponse struct {
Channel IdentifiedChannel `json:"channel" yaml:"channel"`
Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"`
ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"`
ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"`
}
// NewChannelResponse creates a new ChannelResponse instance
func NewChannelResponse(
portID, channelID string, channel Channel, proof *merkle.Proof, height int64,
) ChannelResponse {
return ChannelResponse{
Channel: NewIdentifiedChannel(portID, channelID, channel),
Proof: commitmenttypes.MerkleProof{Proof: proof},
ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.ChannelPath(portID, channelID), "/")),
ProofHeight: uint64(height),
}
}
// QueryAllChannelsParams defines the parameters necessary for querying for all
// channels.
type QueryAllChannelsParams struct {
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
}
// NewQueryAllChannelsParams creates a new QueryAllChannelsParams instance.
func NewQueryAllChannelsParams(page, limit int) QueryAllChannelsParams {
return QueryAllChannelsParams{
Page: page,
Limit: limit,
}
}
// QueryConnectionChannelsParams defines the parameters necessary for querying
// for all channels associated with a given connection.
type QueryConnectionChannelsParams struct {
Connection string `json:"connection" yaml:"connection"`
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
}
// NewQueryConnectionChannelsParams creates a new QueryConnectionChannelsParams instance.
func NewQueryConnectionChannelsParams(connection string, page, limit int) QueryConnectionChannelsParams {
return QueryConnectionChannelsParams{
Connection: connection,
Page: page,
Limit: limit,
}
}
// PacketResponse defines the client query response for a packet which also
// includes a proof, its path and the height form which the proof was retrieved
type PacketResponse struct {
Packet Packet `json:"packet" yaml:"packet"`
Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"`
ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"`
ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"`
}
// NewPacketResponse creates a new PacketResponswe instance
func NewPacketResponse(
portID, channelID string, sequence uint64, packet Packet, proof *merkle.Proof, height int64,
) PacketResponse {
return PacketResponse{
Packet: packet,
Proof: commitmenttypes.MerkleProof{Proof: proof},
ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.PacketCommitmentPath(portID, channelID, sequence), "/")),
ProofHeight: uint64(height),
}
}
// RecvResponse defines the client query response for the next receive sequence
// number which also includes a proof, its path and the height form which the
// proof was retrieved
type RecvResponse struct {
NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"`
Proof commitmenttypes.MerkleProof `json:"proof,omitempty" yaml:"proof,omitempty"`
ProofPath commitmenttypes.MerklePath `json:"proof_path,omitempty" yaml:"proof_path,omitempty"`
ProofHeight uint64 `json:"proof_height,omitempty" yaml:"proof_height,omitempty"`
}
// NewRecvResponse creates a new RecvResponse instance
func NewRecvResponse(
portID, channelID string, sequenceRecv uint64, proof *merkle.Proof, height int64,
) RecvResponse {
return RecvResponse{
NextSequenceRecv: sequenceRecv,
Proof: commitmenttypes.MerkleProof{Proof: proof},
ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.NextSequenceRecvPath(portID, channelID), "/")),
ProofHeight: uint64(height),
}
}