diff --git a/client/core/context.go b/client/core/context.go index 5a35ea533..b3ae1f4f0 100644 --- a/client/core/context.go +++ b/client/core/context.go @@ -28,3 +28,33 @@ func NewCoreContextFromViper() CoreContext { Sequence: viper.GetInt64(client.FlagSequence), } } + +func (c CoreContext) WithChainID(chainID string) CoreContext { + c.ChainID = chainID + return c +} + +func (c CoreContext) WithHeight(height int64) CoreContext { + c.Height = height + return c +} + +func (c CoreContext) WithTrustNode(trustNode bool) CoreContext { + c.TrustNode = trustNode + return c +} + +func (c CoreContext) WithNodeURI(nodeURI string) CoreContext { + c.NodeURI = nodeURI + return c +} + +func (c CoreContext) WithFromAddressName(fromAddressName string) CoreContext { + c.FromAddressName = fromAddressName + return c +} + +func (c CoreContext) WithSequence(sequence int64) CoreContext { + c.Sequence = sequence + return c +} diff --git a/x/bank/rest/sendtx.go b/x/bank/rest/sendtx.go index faa82f018..59870d0f2 100644 --- a/x/bank/rest/sendtx.go +++ b/x/bank/rest/sendtx.go @@ -73,9 +73,8 @@ func SendRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWrit } // sign - // XXX: OMG - viper.Set(client.FlagSequence, m.Sequence) ctx := core.NewCoreContextFromViper() + ctx.Sequence = m.Sequence txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc) if err != nil { w.WriteHeader(http.StatusUnauthorized) diff --git a/x/ibc/commands/relay.go b/x/ibc/commands/relay.go index c3000df8d..04864ca8a 100644 --- a/x/ibc/commands/relay.go +++ b/x/ibc/commands/relay.go @@ -86,8 +86,7 @@ func (c relayCommander) runIBCRelay(cmd *cobra.Command, args []string) { func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode string) { ctx := core.NewCoreContextFromViper() // get password - name := viper.GetString(client.FlagName) - passphrase, err := ctx.GetPassphraseFromStdin(name) + passphrase, err := ctx.GetPassphraseFromStdin(ctx.FromAddressName) if err != nil { panic(err) } @@ -149,15 +148,11 @@ OUTER: } func query(node string, key []byte, storeName string) (res []byte, err error) { - orig := viper.GetString(client.FlagNode) - viper.Set(client.FlagNode, node) - res, err = core.NewCoreContextFromViper().Query(key, storeName) - viper.Set(client.FlagNode, orig) - return res, err + return core.NewCoreContextFromViper().WithNodeURI(node).Query(key, storeName) } func (c relayCommander) broadcastTx(node string, tx []byte) error { - _, err := core.NewCoreContextFromViper().WithSequence(c.getSequence(node) + 1).WithNodeURI(node).BroadcastTx(tx) + _, err := core.NewCoreContextFromViper().WithNodeURI(node).WithSequence(c.getSequence(node) + 1).BroadcastTx(tx) return err } @@ -191,8 +186,8 @@ func (c relayCommander) refine(bz []byte, sequence int64, passphrase string) []b Sequence: sequence, } - name := viper.GetString(client.FlagName) - res, err := core.NewCoreContextFromViper().SignAndBuild(name, passphrase, msg, c.cdc) + ctx := core.NewCoreContextFromViper() + res, err := ctx.SignAndBuild(ctx.FromAddressName, passphrase, msg, c.cdc) if err != nil { panic(err) } diff --git a/x/ibc/rest/transfer.go b/x/ibc/rest/transfer.go index 308e7c0a6..fcfe40d51 100644 --- a/x/ibc/rest/transfer.go +++ b/x/ibc/rest/transfer.go @@ -7,7 +7,6 @@ import ( "net/http" "github.com/gorilla/mux" - "github.com/spf13/viper" "github.com/tendermint/go-crypto/keys" "github.com/cosmos/cosmos-sdk/client" @@ -72,8 +71,8 @@ func TransferRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.Response // sign // XXX: OMG - viper.Set(client.FlagSequence, m.Sequence) ctx := core.NewCoreContextFromViper() + ctx.Sequence = m.Sequence txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc) if err != nil { w.WriteHeader(http.StatusUnauthorized)