Skip to content

Commit

Permalink
lets give the relayer a shot
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt committed Aug 30, 2024
1 parent d77cd9c commit 8c2852e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"context"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions relayer/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}),
)
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8c2852e

Please sign in to comment.