Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

query.gno

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