Skip to content

Commit 2c9a5bc

Browse files
jackzampolincwgoes
authored andcommitted
Merge PR #3554: x/auth and x/bank review results
1 parent 6ee9c97 commit 2c9a5bc

File tree

17 files changed

+119
-203
lines changed

17 files changed

+119
-203
lines changed

client/rest/rest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func WriteGenerateStdTxResponse(
237237
}
238238
}
239239

240-
stdMsg, err := txBldr.Build(msgs)
240+
stdMsg, err := txBldr.BuildSignMsg(msgs)
241241
if err != nil {
242242
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
243243
return

client/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func buildUnsignedStdTxOffline(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
294294
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBldr.Gas())
295295
}
296296

297-
stdSignMsg, err := txBldr.Build(msgs)
297+
stdSignMsg, err := txBldr.BuildSignMsg(msgs)
298298
if err != nil {
299299
return
300300
}

x/auth/account.go

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/tendermint/tendermint/crypto"
99

10-
"github.com/cosmos/cosmos-sdk/codec"
1110
sdk "github.com/cosmos/cosmos-sdk/types"
1211
)
1312

@@ -62,6 +61,7 @@ type VestingAccount interface {
6261
}
6362

6463
// AccountDecoder unmarshals account bytes
64+
// TODO: Think about removing
6565
type AccountDecoder func(accountBytes []byte) (Account, error)
6666

6767
//-----------------------------------------------------------------------------
@@ -90,32 +90,33 @@ func (acc BaseAccount) String() string {
9090
}
9191

9292
return fmt.Sprintf(`Account:
93-
Address: %s
94-
Pubkey: %s
93+
Address: %s
94+
Pubkey: %s
9595
Coins: %s
9696
AccountNumber: %d
9797
Sequence: %d`,
9898
acc.Address, pubkey, acc.Coins, acc.AccountNumber, acc.Sequence,
9999
)
100100
}
101101

102-
// Prototype function for BaseAccount
102+
// ProtoBaseAccount - a prototype function for BaseAccount
103103
func ProtoBaseAccount() Account {
104104
return &BaseAccount{}
105105
}
106106

107+
// NewBaseAccountWithAddress - returns a new base account with a given address
107108
func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount {
108109
return BaseAccount{
109110
Address: addr,
110111
}
111112
}
112113

113-
// Implements sdk.Account.
114+
// GetAddress - Implements sdk.Account.
114115
func (acc BaseAccount) GetAddress() sdk.AccAddress {
115116
return acc.Address
116117
}
117118

118-
// Implements sdk.Account.
119+
// SetAddress - Implements sdk.Account.
119120
func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error {
120121
if len(acc.Address) != 0 {
121122
return errors.New("cannot override BaseAccount address")
@@ -124,45 +125,45 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error {
124125
return nil
125126
}
126127

127-
// Implements sdk.Account.
128+
// GetPubKey - Implements sdk.Account.
128129
func (acc BaseAccount) GetPubKey() crypto.PubKey {
129130
return acc.PubKey
130131
}
131132

132-
// Implements sdk.Account.
133+
// SetPubKey - Implements sdk.Account.
133134
func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
134135
acc.PubKey = pubKey
135136
return nil
136137
}
137138

138-
// Implements sdk.Account.
139+
// GetCoins - Implements sdk.Account.
139140
func (acc *BaseAccount) GetCoins() sdk.Coins {
140141
return acc.Coins
141142
}
142143

143-
// Implements sdk.Account.
144+
// SetCoins - Implements sdk.Account.
144145
func (acc *BaseAccount) SetCoins(coins sdk.Coins) error {
145146
acc.Coins = coins
146147
return nil
147148
}
148149

149-
// Implements Account
150+
// GetAccountNumber - Implements Account
150151
func (acc *BaseAccount) GetAccountNumber() uint64 {
151152
return acc.AccountNumber
152153
}
153154

154-
// Implements Account
155+
// SetAccountNumber - Implements Account
155156
func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error {
156157
acc.AccountNumber = accNumber
157158
return nil
158159
}
159160

160-
// Implements sdk.Account.
161+
// GetSequence - Implements sdk.Account.
161162
func (acc *BaseAccount) GetSequence() uint64 {
162163
return acc.Sequence
163164
}
164165

165-
// Implements sdk.Account.
166+
// SetSequence - Implements sdk.Account.
166167
func (acc *BaseAccount) SetSequence(seq uint64) error {
167168
acc.Sequence = seq
168169
return nil
@@ -198,8 +199,8 @@ func (bva BaseVestingAccount) String() string {
198199
}
199200

200201
return fmt.Sprintf(`Vesting Account:
201-
Address: %s
202-
Pubkey: %s
202+
Address: %s
203+
Pubkey: %s
203204
Coins: %s
204205
AccountNumber: %d
205206
Sequence: %d
@@ -345,6 +346,7 @@ type ContinuousVestingAccount struct {
345346
StartTime int64 // when the coins start to vest
346347
}
347348

349+
// NewContinuousVestingAccount returns a new ContinuousVestingAccount
348350
func NewContinuousVestingAccount(
349351
baseAcc *BaseAccount, StartTime, EndTime int64,
350352
) *ContinuousVestingAccount {
@@ -369,8 +371,8 @@ func (cva ContinuousVestingAccount) String() string {
369371
}
370372

371373
return fmt.Sprintf(`Continuous Vesting Account:
372-
Address: %s
373-
Pubkey: %s
374+
Address: %s
375+
Pubkey: %s
374376
Coins: %s
375377
AccountNumber: %d
376378
Sequence: %d
@@ -454,6 +456,7 @@ type DelayedVestingAccount struct {
454456
*BaseVestingAccount
455457
}
456458

459+
// NewDelayedVestingAccount returns a DelayedVestingAccount
457460
func NewDelayedVestingAccount(baseAcc *BaseAccount, EndTime int64) *DelayedVestingAccount {
458461
baseVestingAcc := &BaseVestingAccount{
459462
BaseAccount: baseAcc,
@@ -502,17 +505,3 @@ func (dva *DelayedVestingAccount) GetStartTime() int64 {
502505
func (dva *DelayedVestingAccount) GetEndTime() int64 {
503506
return dva.EndTime
504507
}
505-
506-
//-----------------------------------------------------------------------------
507-
// Codec
508-
509-
// Most users shouldn't use this, but this comes in handy for tests.
510-
func RegisterBaseAccount(cdc *codec.Codec) {
511-
cdc.RegisterInterface((*Account)(nil), nil)
512-
cdc.RegisterInterface((*VestingAccount)(nil), nil)
513-
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
514-
cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil)
515-
cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil)
516-
cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil)
517-
codec.RegisterCrypto(cdc)
518-
}

x/auth/ante.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
)
2323

2424
func init() {
25+
// This decodes a valid hex string into a sepc256k1Pubkey for use in transaction simulation
2526
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A")
2627
copy(simSecp256k1Pubkey[:], bz)
2728
}
@@ -192,9 +193,7 @@ func processSig(
192193
return nil, sdk.ErrUnauthorized("signature verification failed").Result()
193194
}
194195

195-
err = acc.SetSequence(acc.GetSequence() + 1)
196-
if err != nil {
197-
// Handle w/ #870
196+
if err := acc.SetSequence(acc.GetSequence() + 1); err != nil {
198197
panic(err)
199198
}
200199

@@ -327,7 +326,7 @@ func DeductFees(blockTime time.Time, acc Account, fee StdFee) (Account, sdk.Resu
327326
}
328327

329328
// EnsureSufficientMempoolFees verifies that the given transaction has supplied
330-
// enough fees to cover a proposer's minimum fees. An result object is returned
329+
// enough fees to cover a proposer's minimum fees. A result object is returned
331330
// indicating success or failure.
332331
//
333332
// Contract: This should only be called during CheckTx as it cannot be part of

x/auth/client/txbuilder/txbuilder.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,9 @@ func (bldr TxBuilder) WithAccountNumber(accnum uint64) TxBuilder {
174174
return bldr
175175
}
176176

177-
// Build builds a single message to be signed from a TxBuilder given a set of
177+
// BuildSignMsg builds a single message to be signed from a TxBuilder given a set of
178178
// messages. It returns an error if a fee is supplied but cannot be parsed.
179-
//
180-
// TODO: Should consider renaming to BuildSignMsg.
181-
func (bldr TxBuilder) Build(msgs []sdk.Msg) (StdSignMsg, error) {
179+
func (bldr TxBuilder) BuildSignMsg(msgs []sdk.Msg) (StdSignMsg, error) {
182180
chainID := bldr.chainID
183181
if chainID == "" {
184182
return StdSignMsg{}, fmt.Errorf("chain ID required but not specified")
@@ -226,7 +224,7 @@ func (bldr TxBuilder) Sign(name, passphrase string, msg StdSignMsg) ([]byte, err
226224
// with the built message given a name, passphrase, and a set of
227225
// messages.
228226
func (bldr TxBuilder) BuildAndSign(name, passphrase string, msgs []sdk.Msg) ([]byte, error) {
229-
msg, err := bldr.Build(msgs)
227+
msg, err := bldr.BuildSignMsg(msgs)
230228
if err != nil {
231229
return nil, err
232230
}
@@ -237,7 +235,7 @@ func (bldr TxBuilder) BuildAndSign(name, passphrase string, msgs []sdk.Msg) ([]b
237235
// BuildTxForSim creates a StdSignMsg and encodes a transaction with the
238236
// StdSignMsg with a single empty StdSignature for tx simulation.
239237
func (bldr TxBuilder) BuildTxForSim(msgs []sdk.Msg) ([]byte, error) {
240-
signMsg, err := bldr.Build(msgs)
238+
signMsg, err := bldr.BuildSignMsg(msgs)
241239
if err != nil {
242240
return nil, err
243241
}

x/auth/client/txbuilder/txbuilder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestTxBuilderBuild(t *testing.T) {
9494
tc.fields.ChainID, tc.fields.Memo, tc.fields.Fees, tc.fields.GasPrices,
9595
)
9696

97-
got, err := bldr.Build(tc.msgs)
97+
got, err := bldr.BuildSignMsg(tc.msgs)
9898
require.Equal(t, tc.wantErr, (err != nil), "TxBuilder.Build() error = %v, wantErr %v, tc %d", err, tc.wantErr, i)
9999
if !reflect.DeepEqual(got, tc.want) {
100100
t.Errorf("TxBuilder.Build() = %v, want %v", got, tc.want)

x/auth/codec.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/cosmos/cosmos-sdk/codec"
55
)
66

7-
// Register concrete types on codec codec for default AppAccount
7+
// RegisterCodec registers concrete types on the codec
88
func RegisterCodec(cdc *codec.Codec) {
99
cdc.RegisterInterface((*Account)(nil), nil)
1010
cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil)
@@ -15,6 +15,17 @@ func RegisterCodec(cdc *codec.Codec) {
1515
cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil)
1616
}
1717

18+
// RegisterBaseAccount most users shouldn't use this, but this comes in handy for tests.
19+
func RegisterBaseAccount(cdc *codec.Codec) {
20+
cdc.RegisterInterface((*Account)(nil), nil)
21+
cdc.RegisterInterface((*VestingAccount)(nil), nil)
22+
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
23+
cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil)
24+
cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil)
25+
cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil)
26+
codec.RegisterCrypto(cdc)
27+
}
28+
1829
var msgCdc = codec.New()
1930

2031
func init() {

x/auth/feekeeper.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var (
99
collectedFeesKey = []byte("collectedFees")
1010
)
1111

12-
// This FeeCollectionKeeper handles collection of fees in the anteHandler
12+
// FeeCollectionKeeper handles collection of fees in the anteHandler
1313
// and setting of MinFees for different fee tokens
1414
type FeeCollectionKeeper struct {
1515

@@ -20,14 +20,15 @@ type FeeCollectionKeeper struct {
2020
cdc *codec.Codec
2121
}
2222

23+
// NewFeeCollectionKeeper returns a new FeeCollectionKeeper
2324
func NewFeeCollectionKeeper(cdc *codec.Codec, key sdk.StoreKey) FeeCollectionKeeper {
2425
return FeeCollectionKeeper{
2526
key: key,
2627
cdc: cdc,
2728
}
2829
}
2930

30-
// retrieves the collected fee pool
31+
// GetCollectedFees - retrieves the collected fee pool
3132
func (fck FeeCollectionKeeper) GetCollectedFees(ctx sdk.Context) sdk.Coins {
3233
store := ctx.KVStore(fck.key)
3334
bz := store.Get(collectedFeesKey)
@@ -46,15 +47,15 @@ func (fck FeeCollectionKeeper) setCollectedFees(ctx sdk.Context, coins sdk.Coins
4647
store.Set(collectedFeesKey, bz)
4748
}
4849

49-
// add to the fee pool
50+
// AddCollectedFees - add to the fee pool
5051
func (fck FeeCollectionKeeper) AddCollectedFees(ctx sdk.Context, coins sdk.Coins) sdk.Coins {
5152
newCoins := fck.GetCollectedFees(ctx).Plus(coins)
5253
fck.setCollectedFees(ctx, newCoins)
5354

5455
return newCoins
5556
}
5657

57-
// clear the fee pool
58+
// ClearCollectedFees - clear the fee pool
5859
func (fck FeeCollectionKeeper) ClearCollectedFees(ctx sdk.Context) {
5960
fck.setCollectedFees(ctx, sdk.Coins{})
6061
}

x/auth/genesis.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import (
88

99
// GenesisState - all auth state that must be provided at genesis
1010
type GenesisState struct {
11-
CollectedFees sdk.Coins `json:"collected_fees"` // collected fees
11+
CollectedFees sdk.Coins `json:"collected_fees"`
1212
Params Params `json:"params"`
1313
}
1414

15-
// Create a new genesis state
15+
// NewGenesisState - Create a new genesis state
1616
func NewGenesisState(collectedFees sdk.Coins, params Params) GenesisState {
1717
return GenesisState{
18-
CollectedFees: collectedFees,
1918
Params: params,
19+
CollectedFees: collectedFees,
2020
}
2121
}
2222

23-
// Return a default genesis state
23+
// DefaultGenesisState - Return a default genesis state
2424
func DefaultGenesisState() GenesisState {
2525
return NewGenesisState(sdk.Coins{}, DefaultParams())
2626
}
2727

28-
// Init store state from genesis data
28+
// InitGenesis - Init store state from genesis data
2929
func InitGenesis(ctx sdk.Context, ak AccountKeeper, fck FeeCollectionKeeper, data GenesisState) {
3030
ak.SetParams(ctx, data.Params)
3131
fck.setCollectedFees(ctx, data.CollectedFees)
@@ -57,6 +57,5 @@ func ValidateGenesis(data GenesisState) error {
5757
if data.Params.TxSizeCostPerByte == 0 {
5858
return fmt.Errorf("invalid tx size cost per byte: %d", data.Params.TxSizeCostPerByte)
5959
}
60-
6160
return nil
6261
}

0 commit comments

Comments
 (0)