Change CoreContext parameters instead of using viper.Set
This commit is contained in:
parent
579e5d4cdc
commit
7a8e00dbb9
|
@ -28,3 +28,33 @@ func NewCoreContextFromViper() CoreContext {
|
||||||
Sequence: viper.GetInt64(client.FlagSequence),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -73,9 +73,8 @@ func SendRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWrit
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign
|
// sign
|
||||||
// XXX: OMG
|
|
||||||
viper.Set(client.FlagSequence, m.Sequence)
|
|
||||||
ctx := core.NewCoreContextFromViper()
|
ctx := core.NewCoreContextFromViper()
|
||||||
|
ctx.Sequence = m.Sequence
|
||||||
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
|
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
|
|
@ -86,8 +86,7 @@ func (c relayCommander) runIBCRelay(cmd *cobra.Command, args []string) {
|
||||||
func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode string) {
|
func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode string) {
|
||||||
ctx := core.NewCoreContextFromViper()
|
ctx := core.NewCoreContextFromViper()
|
||||||
// get password
|
// get password
|
||||||
name := viper.GetString(client.FlagName)
|
passphrase, err := ctx.GetPassphraseFromStdin(ctx.FromAddressName)
|
||||||
passphrase, err := ctx.GetPassphraseFromStdin(name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -149,15 +148,11 @@ OUTER:
|
||||||
}
|
}
|
||||||
|
|
||||||
func query(node string, key []byte, storeName string) (res []byte, err error) {
|
func query(node string, key []byte, storeName string) (res []byte, err error) {
|
||||||
orig := viper.GetString(client.FlagNode)
|
return core.NewCoreContextFromViper().WithNodeURI(node).Query(key, storeName)
|
||||||
viper.Set(client.FlagNode, node)
|
|
||||||
res, err = core.NewCoreContextFromViper().Query(key, storeName)
|
|
||||||
viper.Set(client.FlagNode, orig)
|
|
||||||
return res, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c relayCommander) broadcastTx(node string, tx []byte) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +186,8 @@ func (c relayCommander) refine(bz []byte, sequence int64, passphrase string) []b
|
||||||
Sequence: sequence,
|
Sequence: sequence,
|
||||||
}
|
}
|
||||||
|
|
||||||
name := viper.GetString(client.FlagName)
|
ctx := core.NewCoreContextFromViper()
|
||||||
res, err := core.NewCoreContextFromViper().SignAndBuild(name, passphrase, msg, c.cdc)
|
res, err := ctx.SignAndBuild(ctx.FromAddressName, passphrase, msg, c.cdc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/tendermint/go-crypto/keys"
|
"github.com/tendermint/go-crypto/keys"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
@ -72,8 +71,8 @@ func TransferRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.Response
|
||||||
|
|
||||||
// sign
|
// sign
|
||||||
// XXX: OMG
|
// XXX: OMG
|
||||||
viper.Set(client.FlagSequence, m.Sequence)
|
|
||||||
ctx := core.NewCoreContextFromViper()
|
ctx := core.NewCoreContextFromViper()
|
||||||
|
ctx.Sequence = m.Sequence
|
||||||
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
|
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
|
Loading…
Reference in New Issue