cosmos-sdk/client/context/types.go

76 lines
2.1 KiB
Go
Raw Normal View History

2018-04-18 12:39:32 -07:00
package context
2018-03-30 05:57:53 -07:00
import (
rpcclient "github.com/tendermint/tendermint/rpc/client"
sdk "github.com/cosmos/cosmos-sdk/types"
)
2018-04-18 12:39:32 -07:00
// typical context created in sdk modules for transactions/queries
2018-03-30 05:57:53 -07:00
type CoreContext struct {
ChainID string
Height int64
TrustNode bool
NodeURI string
FromAddressName string
Sequence int64
Client rpcclient.Client
Decoder sdk.AccountDecoder
AccountStore string
2018-03-30 05:57:53 -07:00
}
2018-04-10 02:15:34 -07:00
// WithChainID - return a copy of the context with an updated chainID
func (c CoreContext) WithChainID(chainID string) CoreContext {
c.ChainID = chainID
return c
}
2018-04-11 08:47:56 -07:00
// WithHeight - return a copy of the context with an updated height
func (c CoreContext) WithHeight(height int64) CoreContext {
c.Height = height
return c
}
2018-04-10 02:15:34 -07:00
// WithTrustNode - return a copy of the context with an updated TrustNode flag
func (c CoreContext) WithTrustNode(trustNode bool) CoreContext {
c.TrustNode = trustNode
return c
}
2018-04-10 02:15:34 -07:00
// WithNodeURI - return a copy of the context with an updated node URI
func (c CoreContext) WithNodeURI(nodeURI string) CoreContext {
c.NodeURI = nodeURI
2018-04-11 02:25:52 -07:00
c.Client = rpcclient.NewHTTP(nodeURI, "/websocket")
return c
}
2018-04-10 02:15:34 -07:00
// WithFromAddressName - return a copy of the context with an updated from address
func (c CoreContext) WithFromAddressName(fromAddressName string) CoreContext {
c.FromAddressName = fromAddressName
return c
}
2018-04-10 02:15:34 -07:00
// WithSequence - return a copy of the context with an updated sequence number
func (c CoreContext) WithSequence(sequence int64) CoreContext {
c.Sequence = sequence
return c
}
2018-04-10 02:15:34 -07:00
// WithClient - return a copy of the context with an updated RPC client instance
func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
c.Client = client
return c
}
2018-04-10 02:15:34 -07:00
// WithDecoder - return a copy of the context with an updated Decoder
func (c CoreContext) WithDecoder(decoder sdk.AccountDecoder) CoreContext {
c.Decoder = decoder
return c
}
2018-04-10 02:15:34 -07:00
// WithAccountStore - return a copy of the context with an updated AccountStore
func (c CoreContext) WithAccountStore(accountStore string) CoreContext {
c.AccountStore = accountStore
return c
}