github.com/lino-network/lino@v0.6.11/client/core/context.go (about)

     1  package core
     2  
     3  import (
     4  	sdk "github.com/cosmos/cosmos-sdk/types"
     5  	"github.com/tendermint/tendermint/crypto"
     6  	rpcclient "github.com/tendermint/tendermint/rpc/client"
     7  
     8  	linotypes "github.com/lino-network/lino/types"
     9  )
    10  
    11  // CoreContext - context used in terminal
    12  type CoreContext struct {
    13  	ChainID         string
    14  	Height          int64
    15  	TrustNode       bool
    16  	NodeURI         string
    17  	FromAddressName string
    18  	Sequence        uint64
    19  	Memo            string
    20  	Offline         bool
    21  	Client          rpcclient.Client
    22  	PrivKey         crypto.PrivKey
    23  	Fees            sdk.Coins
    24  	TxEncoder       sdk.TxEncoder
    25  }
    26  
    27  // WithChainID - mount chain id on context
    28  func (c CoreContext) WithChainID(chainID string) CoreContext {
    29  	c.ChainID = chainID
    30  	return c
    31  }
    32  
    33  // WithHeight - mount height on context
    34  func (c CoreContext) WithHeight(height int64) CoreContext {
    35  	c.Height = height
    36  	return c
    37  }
    38  
    39  // WithTrustNode - mount trust node on context
    40  func (c CoreContext) WithTrustNode(trustNode bool) CoreContext {
    41  	c.TrustNode = trustNode
    42  	return c
    43  }
    44  
    45  // WithNodeURI - mount node uri on context
    46  func (c CoreContext) WithNodeURI(nodeURI string) CoreContext {
    47  	c.NodeURI = nodeURI
    48  	return c
    49  }
    50  
    51  // WithFromAddressName - mount from address on context
    52  func (c CoreContext) WithFromAddressName(fromAddressName string) CoreContext {
    53  	c.FromAddressName = fromAddressName
    54  	return c
    55  }
    56  
    57  // WithSequence - mount sequence number on context
    58  func (c CoreContext) WithSequence(sequence uint64) CoreContext {
    59  	c.Sequence = sequence
    60  	return c
    61  }
    62  
    63  // WithClient - mount client on context
    64  func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
    65  	c.Client = client
    66  	return c
    67  }
    68  
    69  // WithPrivKey - mount private key on context
    70  func (c CoreContext) WithPrivKey(privKey crypto.PrivKey) CoreContext {
    71  	c.PrivKey = privKey
    72  	return c
    73  }
    74  
    75  // WithFees - mount fees
    76  func (c CoreContext) WithFees(fees string) CoreContext {
    77  	parsedFees, err := sdk.ParseCoins(fees)
    78  	if err != nil {
    79  		panic(err)
    80  	}
    81  	if parsedFees.Len() != 1 || parsedFees[0].Denom != linotypes.LinoCoinDenom {
    82  		panic("invalid tx fees, unit must be: " + linotypes.LinoCoinDenom)
    83  	}
    84  	c.Fees = parsedFees
    85  	return c
    86  }
    87  
    88  // WithCodec - mount cdc on context.
    89  func (c CoreContext) WithTxEncoder(encoder sdk.TxEncoder) CoreContext {
    90  	c.TxEncoder = encoder
    91  	return c
    92  }