Reuse Tendermint client instance (closes #671)
This commit is contained in:
@@ -3,17 +3,25 @@ package context
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/core"
|
||||
)
|
||||
|
||||
func NewCoreContextFromViper() core.CoreContext {
|
||||
nodeURI := viper.GetString(client.FlagNode)
|
||||
var rpc rpcclient.Client
|
||||
if nodeURI != "" {
|
||||
rpc = rpcclient.NewHTTP(nodeURI, "/websocket")
|
||||
}
|
||||
return core.CoreContext{
|
||||
ChainID: viper.GetString(client.FlagChainID),
|
||||
Height: viper.GetInt64(client.FlagHeight),
|
||||
TrustNode: viper.GetBool(client.FlagTrustNode),
|
||||
NodeURI: viper.GetString(client.FlagNode),
|
||||
FromAddressName: viper.GetString(client.FlagName),
|
||||
NodeURI: nodeURI,
|
||||
Sequence: viper.GetInt64(client.FlagSequence),
|
||||
Client: rpc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
)
|
||||
|
||||
type CoreContext struct {
|
||||
ChainID string
|
||||
Height int64
|
||||
@@ -7,6 +11,7 @@ type CoreContext struct {
|
||||
NodeURI string
|
||||
FromAddressName string
|
||||
Sequence int64
|
||||
Client rpcclient.Client
|
||||
}
|
||||
|
||||
func (c CoreContext) WithChainID(chainID string) CoreContext {
|
||||
@@ -38,3 +43,8 @@ func (c CoreContext) WithSequence(sequence int64) CoreContext {
|
||||
c.Sequence = sequence
|
||||
return c
|
||||
}
|
||||
|
||||
func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
|
||||
c.Client = client
|
||||
return c
|
||||
}
|
||||
|
||||
+2
-2
@@ -146,8 +146,8 @@ func (ctx CoreContext) GetPassphraseFromStdin(name string) (pass string, err err
|
||||
|
||||
// GetNode prepares a simple rpc.Client
|
||||
func (ctx CoreContext) GetNode() (rpcclient.Client, error) {
|
||||
if ctx.NodeURI == "" {
|
||||
if ctx.Client == nil {
|
||||
return nil, errors.New("Must define node URI")
|
||||
}
|
||||
return rpcclient.NewHTTP(ctx.NodeURI, "/websocket"), nil
|
||||
return ctx.Client, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user