Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supply refactors #4604

Merged
merged 19 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ linters:
- unconvert
- misspell
- govet
- unused
- deadcode
- goconst
linters-settings:
gocyclo:
min-complexity: 11
Expand Down
2 changes: 2 additions & 0 deletions .pending/breaking/sdk/4543-Account-getters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#4543 Account getters are no longer part of client.CLIContext() and have now moved
to reside in the auth-specific AccountRetriever.
6 changes: 6 additions & 0 deletions .pending/breaking/sdk/4588-Context-does-no
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#4588 Context does not depend on x/auth anymore. client/context is stripped out of the following features:
- GetAccountDecoder()
- CLIContext.WithAccountDecoder()
- CLIContext.WithAccountStore()

x/auth.AccountDecoder is unnecessary and consequently removed.
1 change: 1 addition & 0 deletions .pending/breaking/sdk/4602-client-input-Bu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4602 client/input.{Buffer,Override}Stdin() functions are removed. Thanks to cobra's new release they are now redundant.
1 change: 1 addition & 0 deletions .pending/bugfixes/sdk/4598-fix-check-bond-
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4598 Fix redelegation and undelegation txs that were not checking for the correct bond denomination.
2 changes: 2 additions & 0 deletions .pending/improvements/sdk/4584-Update-bank-Kee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#4584 Update bank Keeper to use expected keeper interface of the AccountKeeper.
#4584 Move `Account` and `VestingAccount` interface types to `x/auth/exported`.
1 change: 1 addition & 0 deletions .pending/improvements/sdk/Remove---print-respo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `--print-response` flag as it is no longer used.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
SIMAPP = github.com/cosmos/cosmos-sdk/simapp
MOCKS_DIR = $(CURDIR)/tests/mocks

export GO111MODULE = on

Expand All @@ -33,6 +34,12 @@ dist:
@bash publish/dist.sh
@bash publish/publish.sh

mocks: $(MOCKS_DIR)
mockgen -source=x/auth/types/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go

$(MOCKS_DIR):
mkdir -p $(MOCKS_DIR)

########################################
### Tools & dependencies

Expand Down Expand Up @@ -186,7 +193,7 @@ snapcraft-local.yaml: snapcraft-local.yaml.in
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: build dist clean test test_unit test_cover lint \
.PHONY: build dist clean test test_unit test_cover lint mocks \
benchmark devdoc_init devdoc devdoc_save devdoc_update runsim \
format test_sim_app_nondeterminism test_sim_modules test_sim_app_fast \
test_sim_app_custom_genesis_fast test_sim_app_custom_genesis_multi_seed \
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

[![version](https://img.shields.io/github/tag/cosmos/cosmos-sdk.svg)](https://github.com/cosmos/cosmos-sdk/releases/latest)
[![CircleCI](https://circleci.com/gh/cosmos/cosmos-sdk/tree/master.svg?style=shield)](https://circleci.com/gh/cosmos/cosmos-sdk/tree/master)
[![Snap Status](https://build.snapcraft.io/badge/cosmos/cosmos-sdk.svg)](https://build.snapcraft.io/user/cosmos/cosmos-sdk)
[![codecov](https://codecov.io/gh/cosmos/cosmos-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/cosmos/cosmos-sdk)
[![Go Report Card](https://goreportcard.com/badge/github.com/cosmos/cosmos-sdk)](https://goreportcard.com/report/github.com/cosmos/cosmos-sdk)
[![license](https://img.shields.io/github/license/cosmos/cosmos-sdk.svg)](https://github.com/cosmos/cosmos-sdk/blob/master/LICENSE)
Expand Down
4 changes: 0 additions & 4 deletions client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
FlagFees = flags.FlagFees
FlagGasPrices = flags.FlagGasPrices
FlagBroadcastMode = flags.FlagBroadcastMode
FlagPrintResponse = flags.FlagPrintResponse
FlagDryRun = flags.FlagDryRun
FlagGenerateOnly = flags.FlagGenerateOnly
FlagIndentResponse = flags.FlagIndentResponse
Expand All @@ -67,7 +66,6 @@ var (
// functions aliases
NewCLIContextWithFrom = context.NewCLIContextWithFrom
NewCLIContext = context.NewCLIContext
GetAccountDecoder = context.GetAccountDecoder
GetFromFields = context.GetFromFields
ErrInvalidAccount = context.ErrInvalidAccount
ErrVerifyCommit = context.ErrVerifyCommit
Expand Down Expand Up @@ -105,8 +103,6 @@ var (
GetValidators = rpc.GetValidators
ValidatorSetRequestHandlerFn = rpc.ValidatorSetRequestHandlerFn
LatestValidatorSetRequestHandlerFn = rpc.LatestValidatorSetRequestHandlerFn
BufferStdin = input.BufferStdin
OverrideStdin = input.OverrideStdin
GetPassword = input.GetPassword
GetCheckPassword = input.GetCheckPassword
GetConfirmation = input.GetConfirmation
Expand Down
31 changes: 0 additions & 31 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

var (
Expand All @@ -34,19 +33,16 @@ var (
// transaction handling and queries.
type CLIContext struct {
Codec *codec.Codec
AccDecoder authtypes.AccountDecoder
Client rpcclient.Client
Keybase cryptokeys.Keybase
Output io.Writer
OutputFormat string
Height int64
NodeURI string
From string
AccountStore string
TrustNode bool
UseLedger bool
BroadcastMode string
PrintResponse bool
Verifier tmlite.Verifier
VerifierHome string
Simulate bool
Expand Down Expand Up @@ -88,14 +84,12 @@ func NewCLIContextWithFrom(from string) CLIContext {
Client: rpc,
Output: os.Stdout,
NodeURI: nodeURI,
AccountStore: authtypes.StoreKey,
From: viper.GetString(flags.FlagFrom),
OutputFormat: viper.GetString(cli.OutputFlag),
Height: viper.GetInt64(flags.FlagHeight),
TrustNode: viper.GetBool(flags.FlagTrustNode),
UseLedger: viper.GetBool(flags.FlagUseLedger),
BroadcastMode: viper.GetString(flags.FlagBroadcastMode),
PrintResponse: viper.GetBool(flags.FlagPrintResponse),
Verifier: verifier,
Simulate: viper.GetBool(flags.FlagDryRun),
GenerateOnly: genOnly,
Expand Down Expand Up @@ -162,37 +156,12 @@ func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext {
return ctx
}

// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
func GetAccountDecoder(cdc *codec.Codec) authtypes.AccountDecoder {
return func(accBytes []byte) (acct authtypes.Account, err error) {
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
if err != nil {
panic(err)
}

return acct, err
}
}

// WithAccountDecoder returns a copy of the context with an updated account
// decoder.
func (ctx CLIContext) WithAccountDecoder(cdc *codec.Codec) CLIContext {
ctx.AccDecoder = GetAccountDecoder(cdc)
return ctx
}

// WithOutput returns a copy of the context with an updated output writer (e.g. stdout).
func (ctx CLIContext) WithOutput(w io.Writer) CLIContext {
ctx.Output = w
return ctx
}

// WithAccountStore returns a copy of the context with an updated AccountStore.
func (ctx CLIContext) WithAccountStore(accountStore string) CLIContext {
ctx.AccountStore = accountStore
return ctx
}

// WithFrom returns a copy of the context with an updated from address or name.
func (ctx CLIContext) WithFrom(from string) CLIContext {
ctx.From = from
Expand Down
76 changes: 0 additions & 76 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// GetNode returns an RPC client. If the context's client is not defined, an
Expand Down Expand Up @@ -63,26 +62,6 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd
return
}

// GetAccount queries for an account given an address and a block height. An
// error is returned if the query or decoding fails.
func (ctx CLIContext) GetAccount(address []byte) (authtypes.Account, error) {
if ctx.AccDecoder == nil {
return nil, errors.New("account decoder required but not provided")
}

res, err := ctx.queryAccount(address)
if err != nil {
return nil, err
}

var account authtypes.Account
if err := ctx.Codec.UnmarshalJSON(res, &account); err != nil {
return nil, err
}

return account, nil
}

// GetFromAddress returns the from address from the context's name.
func (ctx CLIContext) GetFromAddress() sdk.AccAddress {
return ctx.FromAddress
Expand All @@ -93,61 +72,6 @@ func (ctx CLIContext) GetFromName() string {
return ctx.FromName
}

// GetAccountNumber returns the next account number for the given account
// address.
func (ctx CLIContext) GetAccountNumber(address []byte) (uint64, error) {
account, err := ctx.GetAccount(address)
if err != nil {
return 0, err
}

return account.GetAccountNumber(), nil
}

// GetAccountSequence returns the sequence number for the given account
// address.
func (ctx CLIContext) GetAccountSequence(address []byte) (uint64, error) {
account, err := ctx.GetAccount(address)
if err != nil {
return 0, err
}

return account.GetSequence(), nil
}

// EnsureAccountExists ensures that an account exists for a given context. An
// error is returned if it does not.
func (ctx CLIContext) EnsureAccountExists() error {
addr := ctx.GetFromAddress()
return ctx.EnsureAccountExistsFromAddr(addr)
}

// EnsureAccountExistsFromAddr ensures that an account exists for a given
// address. Instead of using the context's from name, a direct address is
// given. An error is returned if it does not.
func (ctx CLIContext) EnsureAccountExistsFromAddr(addr sdk.AccAddress) error {
_, err := ctx.queryAccount(addr)
return err
}

// queryAccount queries an account using custom query endpoint of auth module
// returns an error if result is `null` otherwise account data
func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) {
bz, err := ctx.Codec.MarshalJSON(authtypes.NewQueryAccountParams(addr))
if err != nil {
return nil, err
}

route := fmt.Sprintf("custom/%s/%s", ctx.AccountStore, authtypes.QueryAccount)

res, _, err := ctx.query(route, bz)
if err != nil {
return nil, err
}

return res, nil
}

// query performs a query to a Tendermint node with the provided store name
// and path. It returns the result and height of the query upon success
// or an error if the query fails.
Expand Down
2 changes: 0 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
FlagFees = "fees"
FlagGasPrices = "gas-prices"
FlagBroadcastMode = "broadcast-mode"
FlagPrintResponse = "print-response"
FlagDryRun = "dry-run"
FlagGenerateOnly = "generate-only"
FlagIndentResponse = "indent"
Expand Down Expand Up @@ -96,7 +95,6 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device")
c.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
c.Flags().StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
c.Flags().Bool(FlagPrintResponse, true, "return tx response (only works with async = false)")
c.Flags().Bool(FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)")
c.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it")
c.Flags().Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible and the node operates offline)")
Expand Down
22 changes: 0 additions & 22 deletions client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@ import (
// MinPassLength is the minimum acceptable password length
const MinPassLength = 8

var currentStdin *bufio.Reader

func init() {
currentStdin = bufio.NewReader(os.Stdin)
}

// BufferStdin is used to allow reading prompts for stdin
// multiple times, when we read from non-tty
func BufferStdin() *bufio.Reader {
return currentStdin
}

// OverrideStdin allows to temporarily override stdin
func OverrideStdin(newStdin *bufio.Reader) (cleanUp func()) {
prevStdin := currentStdin
currentStdin = newStdin
cleanUp = func() {
currentStdin = prevStdin
}
return cleanUp
}

// GetPassword will prompt for a password one-time (to sign a tx)
// It enforces the password length
func GetPassword(prompt string, buf *bufio.Reader) (pass string, err error) {
Expand Down
Loading