github.com/InjectiveLabs/sdk-go@v1.53.0/client/common/options.go (about)

     1  package common
     2  
     3  import (
     4  	ctypes "github.com/InjectiveLabs/sdk-go/chain/types"
     5  	log "github.com/InjectiveLabs/suplog"
     6  	"github.com/cosmos/cosmos-sdk/client/tx"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	"github.com/pkg/errors"
     9  	"google.golang.org/grpc/credentials"
    10  )
    11  
    12  func init() {
    13  	// set the address prefixes
    14  	config := sdk.GetConfig()
    15  
    16  	// This is specific to Injective chain
    17  	ctypes.SetBech32Prefixes(config)
    18  	ctypes.SetBip44CoinType(config)
    19  }
    20  
    21  type ClientOptions struct {
    22  	GasPrices                 string
    23  	TLSCert                   credentials.TransportCredentials
    24  	TxFactory                 *tx.Factory
    25  	ShouldFixSequenceMismatch bool
    26  }
    27  
    28  type ClientOption func(opts *ClientOptions) error
    29  
    30  func DefaultClientOptions() *ClientOptions {
    31  	return &ClientOptions{
    32  		ShouldFixSequenceMismatch: true,
    33  	}
    34  }
    35  
    36  func OptionGasPrices(gasPrices string) ClientOption {
    37  	return func(opts *ClientOptions) error {
    38  		_, err := sdk.ParseDecCoins(gasPrices)
    39  		if err != nil {
    40  			err = errors.Wrapf(err, "failed to ParseDecCoins %s", gasPrices)
    41  			return err
    42  		}
    43  
    44  		opts.GasPrices = gasPrices
    45  		return nil
    46  	}
    47  }
    48  
    49  func OptionTLSCert(tlsCert credentials.TransportCredentials) ClientOption {
    50  	return func(opts *ClientOptions) error {
    51  		if tlsCert == nil {
    52  			log.Infoln("client does not use grpc secure transport")
    53  		} else {
    54  			log.Infoln("successfully load server TLS cert")
    55  		}
    56  		opts.TLSCert = tlsCert
    57  		return nil
    58  	}
    59  }
    60  
    61  func OptionTxFactory(txFactory *tx.Factory) ClientOption {
    62  	return func(opts *ClientOptions) error {
    63  		opts.TxFactory = txFactory
    64  		return nil
    65  	}
    66  }