2018-04-18 12:39:32 -07:00
|
|
|
package context
|
2018-03-30 05:57:53 -07:00
|
|
|
|
2018-04-03 05:11:49 -07:00
|
|
|
import (
|
|
|
|
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
2018-04-09 07:06:24 -07:00
|
|
|
|
2018-05-23 19:26:54 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
2018-04-03 05:11:49 -07:00
|
|
|
)
|
|
|
|
|
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
|
2018-06-08 21:44:08 -07:00
|
|
|
Gas int64
|
2018-06-29 06:37:14 -07:00
|
|
|
Fee string
|
2018-03-30 05:57:53 -07:00
|
|
|
TrustNode bool
|
|
|
|
NodeURI string
|
|
|
|
FromAddressName string
|
2018-06-11 19:30:54 -07:00
|
|
|
AccountNumber int64
|
2018-03-30 05:57:53 -07:00
|
|
|
Sequence int64
|
2018-06-20 12:27:36 -07:00
|
|
|
Memo string
|
2018-04-03 05:11:49 -07:00
|
|
|
Client rpcclient.Client
|
2018-05-23 19:26:54 -07:00
|
|
|
Decoder auth.AccountDecoder
|
2018-04-09 07:06:24 -07:00
|
|
|
AccountStore string
|
2018-06-28 17:54:47 -07:00
|
|
|
UseLedger bool
|
2018-07-05 20:05:17 -07:00
|
|
|
Async bool
|
2018-07-05 20:42:41 -07:00
|
|
|
JSON bool
|
2018-07-05 22:19:50 -07:00
|
|
|
PrintResponse bool
|
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
|
2018-03-30 06:12:50 -07:00
|
|
|
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
|
2018-03-30 06:12:50 -07:00
|
|
|
func (c CoreContext) WithHeight(height int64) CoreContext {
|
|
|
|
c.Height = height
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-06-08 21:44:08 -07:00
|
|
|
// WithGas - return a copy of the context with an updated gas
|
|
|
|
func (c CoreContext) WithGas(gas int64) CoreContext {
|
|
|
|
c.Gas = gas
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-06-29 06:37:14 -07:00
|
|
|
// WithFee - return a copy of the context with an updated fee
|
|
|
|
func (c CoreContext) WithFee(fee string) CoreContext {
|
|
|
|
c.Fee = fee
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithTrustNode - return a copy of the context with an updated TrustNode flag
|
2018-03-30 06:12:50 -07:00
|
|
|
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
|
2018-03-30 06:12:50 -07:00
|
|
|
func (c CoreContext) WithNodeURI(nodeURI string) CoreContext {
|
|
|
|
c.NodeURI = nodeURI
|
2018-04-11 02:25:52 -07:00
|
|
|
c.Client = rpcclient.NewHTTP(nodeURI, "/websocket")
|
2018-03-30 06:12:50 -07:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithFromAddressName - return a copy of the context with an updated from address
|
2018-03-30 06:12:50 -07:00
|
|
|
func (c CoreContext) WithFromAddressName(fromAddressName string) CoreContext {
|
|
|
|
c.FromAddressName = fromAddressName
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:30:54 -07:00
|
|
|
// WithSequence - return a copy of the context with an account number
|
|
|
|
func (c CoreContext) WithAccountNumber(accnum int64) CoreContext {
|
|
|
|
c.AccountNumber = accnum
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithSequence - return a copy of the context with an updated sequence number
|
2018-03-30 06:12:50 -07:00
|
|
|
func (c CoreContext) WithSequence(sequence int64) CoreContext {
|
|
|
|
c.Sequence = sequence
|
|
|
|
return c
|
|
|
|
}
|
2018-04-03 05:11:49 -07:00
|
|
|
|
2018-06-20 12:27:36 -07:00
|
|
|
// WithMemo - return a copy of the context with an updated memo
|
|
|
|
func (c CoreContext) WithMemo(memo string) CoreContext {
|
|
|
|
c.Memo = memo
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithClient - return a copy of the context with an updated RPC client instance
|
2018-04-03 05:11:49 -07:00
|
|
|
func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
|
|
|
|
c.Client = client
|
|
|
|
return c
|
|
|
|
}
|
2018-04-09 07:06:24 -07:00
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithDecoder - return a copy of the context with an updated Decoder
|
2018-05-23 19:26:54 -07:00
|
|
|
func (c CoreContext) WithDecoder(decoder auth.AccountDecoder) CoreContext {
|
2018-04-09 07:06:24 -07:00
|
|
|
c.Decoder = decoder
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2018-04-10 02:15:34 -07:00
|
|
|
// WithAccountStore - return a copy of the context with an updated AccountStore
|
2018-04-09 07:06:24 -07:00
|
|
|
func (c CoreContext) WithAccountStore(accountStore string) CoreContext {
|
|
|
|
c.AccountStore = accountStore
|
|
|
|
return c
|
|
|
|
}
|
2018-06-28 17:54:47 -07:00
|
|
|
|
|
|
|
// WithUseLedger - return a copy of the context with an updated UseLedger
|
|
|
|
func (c CoreContext) WithUseLedger(useLedger bool) CoreContext {
|
|
|
|
c.UseLedger = useLedger
|
|
|
|
return c
|
|
|
|
}
|