query.gno
1.68 Kb · 70 lines
1package core
2
3import (
4 "strconv"
5
6 "gno.land/p/onbloc/ibc/union/types"
7)
8
9// QueryClientState returns the client state bytes as a hex string, or an empty
10// string when the client is missing.
11func QueryClientState(clientId types.ClientId) string {
12 bz, ok := store.ClientStateBytes(clientId)
13 if !ok {
14 return ""
15 }
16
17 return hexString(bz)
18}
19
20// QueryConsensusState returns the consensus state bytes at a given height as a
21// hex string, or an empty string when missing.
22func QueryConsensusState(clientId types.ClientId, height uint64) string {
23 bz, ok := store.ConsensusStateBytes(clientId, types.NewHeight(height))
24 if !ok {
25 return ""
26 }
27
28 return hexString(bz)
29}
30
31// QueryConnection returns the ABI-encoded connection as a hex string, or an
32// empty string when the connection is missing.
33func QueryConnection(connectionId types.ConnectionId) string {
34 conn, ok := store.GetConnection(connectionId)
35 if !ok {
36 return ""
37 }
38 bz, err := conn.EncodeABI()
39 if err != nil {
40 return ""
41 }
42
43 return hexString(bz)
44}
45
46// QueryChannel returns the ABI-encoded channel as a hex string, or an empty
47// string when the channel is missing.
48func QueryChannel(channelId types.ChannelId) string {
49 channel, ok := store.GetChannel(channelId)
50 if !ok {
51 return ""
52 }
53 bz, err := channel.EncodeABI()
54 if err != nil {
55 return ""
56 }
57
58 return hexString(bz)
59}
60
61// GetClientStatus returns the client status as a uint8 string ("1"=Active,
62// "2"=Expired, "3"=Frozen), or "0" when the client is missing.
63func GetClientStatus(clientId types.ClientId) string {
64 lc, ok := store.GetLightClient(clientId)
65 if !ok {
66 return strconv.FormatUint(uint64(types.StatusUnknown), 10)
67 }
68
69 return strconv.FormatUint(uint64(lc.Status().ToType()), 10)
70}