Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/cli/auth_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (s *AuthCLITestSuite) TestCLISendGenerateSignAndBroadcast() {
With(signedTxFile.Name()).
WithFrom(s.val.String()).
WithOffline()...)
s.Require().EqualError(err, "cannot broadcast tx during offline mode")
s.Require().EqualError(err, "context does not have value set: context-client")

// Broadcast correct transaction.
_, err = clitestutil.TxBroadcastExec(
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func (s *AuthCLITestSuite) TestGetBroadcastCommandOfflineFlag() {
With("fsdf").
WithOffline()...,
)
s.Require().EqualError(err, "cannot broadcast tx during offline mode")
s.Require().EqualError(err, "context does not have value set: context-client")
}

func (s *AuthCLITestSuite) TestQueryParamsCmd() {
Expand Down
10 changes: 4 additions & 6 deletions go/cli/broadcast.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"errors"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -28,12 +27,11 @@ $ <appd> tx broadcast ./mytxn.json
PreRunE: TxPersistentPreRunE,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
cl := MustClientFromContext(ctx)
cctx := cl.ClientContext()

if cctx.Offline {
return errors.New("cannot broadcast tx during offline mode")
cl, err := ClientFromContext(ctx)
if err != nil {
return err
}
cctx := cl.ClientContext()

stdTx, err := authclient.ReadTxFromFile(cctx, args[0])
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions go/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const (
ContextTypeRPCClient = ContextType("rpc-client")
)

var ErrContextValueNotSet = errors.New("context does not have value set")

func ClientFromContext(ctx context.Context) (aclient.Client, error) {
val := ctx.Value(ContextTypeClient)
if val == nil {
return nil, errors.New("context does not have client set")
return nil, fmt.Errorf("%w: %s", ErrContextValueNotSet, ContextTypeClient)
}

res, valid := val.(aclient.Client)
Expand All @@ -56,7 +58,7 @@ func LightClientFromContext(ctx context.Context) (aclient.LightClient, error) {
if val == nil {
val = ctx.Value(ContextTypeClient)
if val == nil {
return nil, errors.New("context does not have client set")
return nil, fmt.Errorf("%w: %s", ErrContextValueNotSet, ContextTypeClient)
}
}

Expand All @@ -82,7 +84,7 @@ func MustLightClientFromContext(ctx context.Context) aclient.LightClient {
func MustAddressCodecFromContext(ctx context.Context) address.Codec {
val := ctx.Value(ContextTypeAddressCodec)
if val == nil {
panic("context does not have address codec set")
panic(fmt.Errorf("%w: %s", ErrContextValueNotSet, ContextTypeAddressCodec))
}

res, valid := val.(address.Codec)
Expand All @@ -96,7 +98,7 @@ func MustAddressCodecFromContext(ctx context.Context) address.Codec {
func MustValidatorCodecFromContext(ctx context.Context) address.Codec {
val := ctx.Value(ContextTypeValidatorCodec)
if val == nil {
panic("context does not have validator codec set")
panic(fmt.Errorf("%w: %s", ErrContextValueNotSet, ContextTypeValidatorCodec))
}

res, valid := val.(address.Codec)
Expand Down
13 changes: 9 additions & 4 deletions go/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"github.com/spf13/cobra"

cflags "pkg.akt.dev/go/cli/flags"
aclient "pkg.akt.dev/go/node/client/discovery"
aclient "pkg.akt.dev/go/node/client"
discovery "pkg.akt.dev/go/node/client/discovery"
)

func TxPersistentPreRunE(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -38,9 +39,13 @@ func TxPersistentPreRunE(cmd *cobra.Command, _ []string) error {
return err
}

cl, err := aclient.DiscoverClient(ctx, cctx, opts...)
if err != nil {
return err
var cl aclient.Client
if !cctx.Offline {
cl, err = discovery.DiscoverClient(ctx, cctx, opts...)
if err != nil {
return err
}

}

ctx = context.WithValue(ctx, ContextTypeClient, cl)
Expand Down
3 changes: 3 additions & 0 deletions go/node/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func DiscoverLightClient(ctx context.Context, cctx sdkclient.Context, setup Setu
// An error is returned if client discovery is not successful.
func DiscoverQueryClient(ctx context.Context, cctx sdkclient.Context, setup SetupFn) error {
result, err := queryClientInfo(ctx, cctx)
if err != nil {
return err
}

var cl interface{}

Expand Down
Loading