From 8c2852e8cd2a7721897de095d6394b41322e8a98 Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:07:44 +0100 Subject: [PATCH] lets give the relayer a shot --- relayer/chains/cosmos/query.go | 35 ++++++++++++++++++++++++++++++++-- relayer/channel.go | 4 ++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index f2bf8d56b..d83e2e5aa 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -4,8 +4,11 @@ import ( "context" "encoding/binary" "encoding/hex" + "encoding/json" "errors" "fmt" + "io" + "net/http" "strconv" "strings" "sync" @@ -339,8 +342,36 @@ func (cc *CosmosProvider) queryParamsSubspaceTime(ctx context.Context, subspace } func (pc CosmosProviderConfig) QueryCanonicalLightClient(ctx context.Context, rollappID string) (string, error) { - // TODO implement me - panic("implement me") + // Define the URL for the GET request + template := "http://localhost:1318/dymensionxyz/dymension/lightclient/lightclient/%s" + url := fmt.Sprintf(template, rollappID) + + // Create a new HTTP GET request + resp, err := http.Get(url) + if err != nil { + return "", fmt.Errorf("get: %w", err) + } + defer resp.Body.Close() + + // Read the response body + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", fmt.Errorf("read: %w", err) + } + + type Response struct { + ClientID string `json:"client_id"` + } + + // Create an instance of the Response struct + var response Response + + // Decode the JSON data into the struct + err = json.Unmarshal(body, &response) + if err != nil { + return "", fmt.Errorf("unmarshal: body: %s: %w", body, err) + } + return response.ClientID, nil } // QueryUnbondingPeriod returns the unbonding period of the chain diff --git a/relayer/channel.go b/relayer/channel.go index 5b4608445..95b286728 100644 --- a/relayer/channel.go +++ b/relayer/channel.go @@ -34,7 +34,7 @@ func (c *Chain) blockUntilClientIsCanonical(ctx context.Context) error { retry.Attempts(0), // forever retry.Delay(20*time.Second), retry.OnRetry(func(n uint, err error) { - // TODO: log + c.log.Info("Query canonical client", zap.Any("attempt", n), zap.Error(err)) }), ) } @@ -74,7 +74,7 @@ func (c *Chain) CreateOpenChannels( err := c.blockUntilClientIsCanonical(ctx) if err != nil { - return err + return fmt.Errorf("blockUntilClientIsCanonical: %w", err) } // Timeout is per message. Four channel handshake messages, allowing maxRetries for each.