Move client context initialization from viper to separate package

This commit is contained in:
Christopher Goes
2018-04-03 22:16:03 +02:00
parent 0888096677
commit 7214149f1d
19 changed files with 67 additions and 68 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
@@ -64,7 +64,7 @@ func (c commander) getAccountCmd(cmd *cobra.Command, args []string) error {
}
key := sdk.Address(bz)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.Query(key, c.storeName)
if err != nil {
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
)
@@ -33,7 +33,7 @@ func QueryAccountRequestHandler(storeName string, cdc *wire.Codec, decoder sdk.A
}
key := sdk.Address(bz)
res, err := core.NewCoreContextFromViper().Query(key, c.storeName)
res, err := context.NewCoreContextFromViper().Query(key, c.storeName)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Could't query account. Error: %s", err.Error())))
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/bank"
@@ -38,7 +38,7 @@ type Commander struct {
}
func (c Commander) sendTxCmd(cmd *cobra.Command, args []string) error {
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
// get the from address
from, err := ctx.GetFromAddress()
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/gorilla/mux"
"github.com/tendermint/go-crypto/keys"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/bank/commands"
@@ -71,7 +71,7 @@ func SendRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.ResponseWrit
}
// sign
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
ctx.Sequence = m.Sequence
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
if err != nil {
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
wire "github.com/cosmos/cosmos-sdk/wire"
@@ -39,7 +39,7 @@ type sendCommander struct {
}
func (c sendCommander) sendIBCTransfer(cmd *cobra.Command, args []string) error {
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
// get the from address
from, err := ctx.GetFromAddress()
+6 -6
View File
@@ -9,7 +9,7 @@ import (
"github.com/tendermint/tmlibs/log"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
wire "github.com/cosmos/cosmos-sdk/wire"
@@ -73,7 +73,7 @@ func (c relayCommander) runIBCRelay(cmd *cobra.Command, args []string) {
fromChainNode := viper.GetString(FlagFromChainNode)
toChainID := viper.GetString(FlagToChainID)
toChainNode := viper.GetString(FlagToChainNode)
address, err := core.NewCoreContextFromViper().GetFromAddress()
address, err := context.NewCoreContextFromViper().GetFromAddress()
if err != nil {
panic(err)
}
@@ -83,7 +83,7 @@ func (c relayCommander) runIBCRelay(cmd *cobra.Command, args []string) {
}
func (c relayCommander) loop(fromChainID, fromChainNode, toChainID, toChainNode string) {
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
// get password
passphrase, err := ctx.GetPassphraseFromStdin(ctx.FromAddressName)
if err != nil {
@@ -147,11 +147,11 @@ OUTER:
}
func query(node string, key []byte, storeName string) (res []byte, err error) {
return core.NewCoreContextFromViper().WithNodeURI(node).Query(key, storeName)
return context.NewCoreContextFromViper().WithNodeURI(node).Query(key, storeName)
}
func (c relayCommander) broadcastTx(node string, tx []byte) error {
_, err := core.NewCoreContextFromViper().WithNodeURI(node).WithSequence(c.getSequence(node) + 1).BroadcastTx(tx)
_, err := context.NewCoreContextFromViper().WithNodeURI(node).WithSequence(c.getSequence(node) + 1).BroadcastTx(tx)
return err
}
@@ -185,7 +185,7 @@ func (c relayCommander) refine(bz []byte, sequence int64, passphrase string) []b
Sequence: sequence,
}
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.SignAndBuild(ctx.FromAddressName, passphrase, msg, c.cdc)
if err != nil {
panic(err)
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/gorilla/mux"
"github.com/tendermint/go-crypto/keys"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/bank/commands"
@@ -70,7 +70,7 @@ func TransferRequestHandler(cdc *wire.Codec, kb keys.Keybase) func(http.Response
// sign
// XXX: OMG
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
ctx.Sequence = m.Sequence
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, msg, c.Cdc)
if err != nil {
+4 -4
View File
@@ -10,7 +10,7 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/simplestake"
@@ -48,7 +48,7 @@ type commander struct {
}
func (co commander) bondTxCmd(cmd *cobra.Command, args []string) error {
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
from, err := ctx.GetFromAddress()
if err != nil {
@@ -84,7 +84,7 @@ func (co commander) bondTxCmd(cmd *cobra.Command, args []string) error {
}
func (co commander) unbondTxCmd(cmd *cobra.Command, args []string) error {
from, err := core.NewCoreContextFromViper().GetFromAddress()
from, err := context.NewCoreContextFromViper().GetFromAddress()
if err != nil {
return err
}
@@ -96,7 +96,7 @@ func (co commander) unbondTxCmd(cmd *cobra.Command, args []string) error {
func (co commander) sendMsg(msg sdk.Msg) error {
name := viper.GetString(client.FlagName)
res, err := core.NewCoreContextFromViper().SignBuildBroadcast(name, msg, co.cdc)
res, err := context.NewCoreContextFromViper().SignBuildBroadcast(name, msg, co.cdc)
if err != nil {
return err
}
+5 -5
View File
@@ -11,7 +11,7 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" // XXX fix
"github.com/cosmos/cosmos-sdk/x/stake"
@@ -47,7 +47,7 @@ func GetCmdQueryCandidates(cdc *wire.Codec, storeName string) *cobra.Command {
key := PrefixedKey(stake.MsgType, stake.CandidatesKey)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.Query(key, storeName)
if err != nil {
return err
@@ -88,7 +88,7 @@ func GetCmdQueryCandidate(cdc *wire.Codec, storeName string) *cobra.Command {
key := PrefixedKey(stake.MsgType, stake.GetCandidateKey(addr))
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.Query(key, storeName)
if err != nil {
@@ -136,7 +136,7 @@ func GetCmdQueryDelegatorBond(cdc *wire.Codec, storeName string) *cobra.Command
key := PrefixedKey(stake.MsgType, stake.GetDelegatorBondKey(delegator, addr, cdc))
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.Query(key, storeName)
if err != nil {
@@ -180,7 +180,7 @@ func GetCmdQueryDelegatorBonds(cdc *wire.Codec, storeName string) *cobra.Command
key := PrefixedKey(stake.MsgType, stake.GetDelegatorBondsKey(delegator, cdc))
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.Query(key, storeName)
if err != nil {
+5 -5
View File
@@ -11,7 +11,7 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/core"
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/stake"
@@ -93,7 +93,7 @@ func GetCmdDeclareCandidacy(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
name := viper.GetString(client.FlagName)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.SignBuildBroadcast(name, msg, cdc)
if err != nil {
return err
@@ -131,7 +131,7 @@ func GetCmdEditCandidacy(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
name := viper.GetString(client.FlagName)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.SignBuildBroadcast(name, msg, cdc)
if err != nil {
return err
@@ -168,7 +168,7 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
name := viper.GetString(client.FlagName)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.SignBuildBroadcast(name, msg, cdc)
if err != nil {
return err
@@ -216,7 +216,7 @@ func GetCmdUnbond(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
name := viper.GetString(client.FlagName)
ctx := core.NewCoreContextFromViper()
ctx := context.NewCoreContextFromViper()
res, err := ctx.SignBuildBroadcast(name, msg, cdc)
if err != nil {
return err