Skip to content

Commit fb3e0af

Browse files
fedekunzealexanderbez
authored andcommitted
Merge PR #4760: update x/auth to match module spec
1 parent 24b9e84 commit fb3e0af

21 files changed

+603
-554
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#4760 update `x/auth` to match module spec

client/cmd_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// nolint: misspell
12
package client_test
23

34
import (

x/auth/alias.go

+63-42
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// nolint
22
// autogenerated code using github.com/rigelrozanski/multitool
33
// aliases generated for the following subdirectories:
4+
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/ante
5+
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/keeper
46
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types
57
package auth
68

79
import (
10+
"github.com/cosmos/cosmos-sdk/x/auth/ante"
811
"github.com/cosmos/cosmos-sdk/x/auth/exported"
12+
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
913
"github.com/cosmos/cosmos-sdk/x/auth/types"
1014
)
1115

@@ -25,33 +29,46 @@ const (
2529

2630
var (
2731
// functions aliases
28-
NewBaseAccount = types.NewBaseAccount
29-
ProtoBaseAccount = types.ProtoBaseAccount
30-
NewBaseAccountWithAddress = types.NewBaseAccountWithAddress
31-
NewBaseVestingAccount = types.NewBaseVestingAccount
32-
NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw
33-
NewContinuousVestingAccount = types.NewContinuousVestingAccount
34-
NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw
35-
NewDelayedVestingAccount = types.NewDelayedVestingAccount
36-
RegisterCodec = types.RegisterCodec
37-
NewGenesisState = types.NewGenesisState
38-
DefaultGenesisState = types.DefaultGenesisState
39-
ValidateGenesis = types.ValidateGenesis
40-
AddressStoreKey = types.AddressStoreKey
41-
NewParams = types.NewParams
42-
ParamKeyTable = types.ParamKeyTable
43-
DefaultParams = types.DefaultParams
44-
NewQueryAccountParams = types.NewQueryAccountParams
45-
NewStdTx = types.NewStdTx
46-
CountSubKeys = types.CountSubKeys
47-
NewStdFee = types.NewStdFee
48-
StdSignBytes = types.StdSignBytes
49-
DefaultTxDecoder = types.DefaultTxDecoder
50-
DefaultTxEncoder = types.DefaultTxEncoder
51-
NewTxBuilder = types.NewTxBuilder
52-
NewTxBuilderFromCLI = types.NewTxBuilderFromCLI
53-
MakeSignature = types.MakeSignature
54-
NewAccountRetriever = types.NewAccountRetriever
32+
NewAnteHandler = ante.NewAnteHandler
33+
GetSignerAcc = ante.GetSignerAcc
34+
ValidateSigCount = ante.ValidateSigCount
35+
ValidateMemo = ante.ValidateMemo
36+
ProcessPubKey = ante.ProcessPubKey
37+
DefaultSigVerificationGasConsumer = ante.DefaultSigVerificationGasConsumer
38+
DeductFees = ante.DeductFees
39+
EnsureSufficientMempoolFees = ante.EnsureSufficientMempoolFees
40+
SetGasMeter = ante.SetGasMeter
41+
GetSignBytes = ante.GetSignBytes
42+
NewAccountKeeper = keeper.NewAccountKeeper
43+
NewDummySupplyKeeper = keeper.NewDummySupplyKeeper
44+
NewQuerier = keeper.NewQuerier
45+
NewBaseAccount = types.NewBaseAccount
46+
ProtoBaseAccount = types.ProtoBaseAccount
47+
NewBaseAccountWithAddress = types.NewBaseAccountWithAddress
48+
NewBaseVestingAccount = types.NewBaseVestingAccount
49+
NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw
50+
NewContinuousVestingAccount = types.NewContinuousVestingAccount
51+
NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw
52+
NewDelayedVestingAccount = types.NewDelayedVestingAccount
53+
NewAccountRetriever = types.NewAccountRetriever
54+
RegisterCodec = types.RegisterCodec
55+
NewGenesisState = types.NewGenesisState
56+
DefaultGenesisState = types.DefaultGenesisState
57+
ValidateGenesis = types.ValidateGenesis
58+
AddressStoreKey = types.AddressStoreKey
59+
NewParams = types.NewParams
60+
ParamKeyTable = types.ParamKeyTable
61+
DefaultParams = types.DefaultParams
62+
NewQueryAccountParams = types.NewQueryAccountParams
63+
NewStdTx = types.NewStdTx
64+
CountSubKeys = types.CountSubKeys
65+
NewStdFee = types.NewStdFee
66+
StdSignBytes = types.StdSignBytes
67+
DefaultTxDecoder = types.DefaultTxDecoder
68+
DefaultTxEncoder = types.DefaultTxEncoder
69+
NewTxBuilder = types.NewTxBuilder
70+
NewTxBuilderFromCLI = types.NewTxBuilderFromCLI
71+
MakeSignature = types.MakeSignature
5572

5673
// variable aliases
5774
ModuleCdc = types.ModuleCdc
@@ -65,19 +82,23 @@ var (
6582
)
6683

6784
type (
68-
Account = exported.Account
69-
VestingAccount = exported.VestingAccount
70-
BaseAccount = types.BaseAccount
71-
BaseVestingAccount = types.BaseVestingAccount
72-
ContinuousVestingAccount = types.ContinuousVestingAccount
73-
DelayedVestingAccount = types.DelayedVestingAccount
74-
GenesisState = types.GenesisState
75-
Params = types.Params
76-
QueryAccountParams = types.QueryAccountParams
77-
StdSignMsg = types.StdSignMsg
78-
StdTx = types.StdTx
79-
StdFee = types.StdFee
80-
StdSignDoc = types.StdSignDoc
81-
StdSignature = types.StdSignature
82-
TxBuilder = types.TxBuilder
85+
SignatureVerificationGasConsumer = ante.SignatureVerificationGasConsumer
86+
Account = exported.Account
87+
VestingAccount = exported.VestingAccount
88+
AccountKeeper = keeper.AccountKeeper
89+
BaseAccount = types.BaseAccount
90+
BaseVestingAccount = types.BaseVestingAccount
91+
ContinuousVestingAccount = types.ContinuousVestingAccount
92+
DelayedVestingAccount = types.DelayedVestingAccount
93+
NodeQuerier = types.NodeQuerier
94+
AccountRetriever = types.AccountRetriever
95+
GenesisState = types.GenesisState
96+
Params = types.Params
97+
QueryAccountParams = types.QueryAccountParams
98+
StdSignMsg = types.StdSignMsg
99+
StdTx = types.StdTx
100+
StdFee = types.StdFee
101+
StdSignDoc = types.StdSignDoc
102+
StdSignature = types.StdSignature
103+
TxBuilder = types.TxBuilder
83104
)

x/auth/ante.go renamed to x/auth/ante/ante.go

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package auth
1+
package ante
22

33
import (
44
"bytes"
@@ -13,6 +13,8 @@ import (
1313

1414
"github.com/cosmos/cosmos-sdk/codec"
1515
sdk "github.com/cosmos/cosmos-sdk/types"
16+
"github.com/cosmos/cosmos-sdk/x/auth/exported"
17+
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
1618
"github.com/cosmos/cosmos-sdk/x/auth/types"
1719
)
1820

@@ -30,12 +32,12 @@ func init() {
3032

3133
// SignatureVerificationGasConsumer is the type of function that is used to both consume gas when verifying signatures
3234
// and also to accept or reject different types of PubKey's. This is where apps can define their own PubKey
33-
type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params Params) sdk.Result
35+
type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) sdk.Result
3436

3537
// NewAnteHandler returns an AnteHandler that checks and increments sequence
3638
// numbers, checks signatures & account numbers, and deducts fees from the first
3739
// signer.
38-
func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
40+
func NewAnteHandler(ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasConsumer SignatureVerificationGasConsumer) sdk.AnteHandler {
3941
return func(
4042
ctx sdk.Context, tx sdk.Tx, simulate bool,
4143
) (newCtx sdk.Context, res sdk.Result, abort bool) {
@@ -45,7 +47,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
4547
}
4648

4749
// all transactions must be of type auth.StdTx
48-
stdTx, ok := tx.(StdTx)
50+
stdTx, ok := tx.(types.StdTx)
4951
if !ok {
5052
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
5153
// during runTx.
@@ -107,7 +109,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
107109
// stdSigs contains the sequence number, account number, and signatures.
108110
// When simulating, this would just be a 0-length slice.
109111
signerAddrs := stdTx.GetSigners()
110-
signerAccs := make([]Account, len(signerAddrs))
112+
signerAccs := make([]exported.Account, len(signerAddrs))
111113
isGenesis := ctx.BlockHeight() == 0
112114

113115
// fetch first signer, who's going to pay the fees
@@ -150,14 +152,13 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
150152
ak.SetAccount(newCtx, signerAccs[i])
151153
}
152154

153-
// TODO: tx tags (?)
154155
return newCtx, sdk.Result{GasWanted: stdTx.Fee.Gas}, false // continue...
155156
}
156157
}
157158

158159
// GetSignerAcc returns an account for a given address that is expected to sign
159160
// a transaction.
160-
func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (Account, sdk.Result) {
161+
func GetSignerAcc(ctx sdk.Context, ak keeper.AccountKeeper, addr sdk.AccAddress) (exported.Account, sdk.Result) {
161162
if acc := ak.GetAccount(ctx, addr); acc != nil {
162163
return acc, sdk.Result{}
163164
}
@@ -166,12 +167,12 @@ func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (Accou
166167

167168
// ValidateSigCount validates that the transaction has a valid cumulative total
168169
// amount of signatures.
169-
func ValidateSigCount(stdTx StdTx, params Params) sdk.Result {
170+
func ValidateSigCount(stdTx types.StdTx, params types.Params) sdk.Result {
170171
stdSigs := stdTx.GetSignatures()
171172

172173
sigCount := 0
173174
for i := 0; i < len(stdSigs); i++ {
174-
sigCount += CountSubKeys(stdSigs[i].PubKey)
175+
sigCount += types.CountSubKeys(stdSigs[i].PubKey)
175176
if uint64(sigCount) > params.TxSigLimit {
176177
return sdk.ErrTooManySignatures(
177178
fmt.Sprintf("signatures: %d, limit: %d", sigCount, params.TxSigLimit),
@@ -183,7 +184,7 @@ func ValidateSigCount(stdTx StdTx, params Params) sdk.Result {
183184
}
184185

185186
// ValidateMemo validates the memo size.
186-
func ValidateMemo(stdTx StdTx, params Params) sdk.Result {
187+
func ValidateMemo(stdTx types.StdTx, params types.Params) sdk.Result {
187188
memoLength := len(stdTx.GetMemo())
188189
if uint64(memoLength) > params.MaxMemoCharacters {
189190
return sdk.ErrMemoTooLarge(
@@ -200,9 +201,9 @@ func ValidateMemo(stdTx StdTx, params Params) sdk.Result {
200201
// verify the signature and increment the sequence. If the account doesn't have
201202
// a pubkey, set it.
202203
func processSig(
203-
ctx sdk.Context, acc Account, sig StdSignature, signBytes []byte, simulate bool, params Params,
204+
ctx sdk.Context, acc exported.Account, sig types.StdSignature, signBytes []byte, simulate bool, params types.Params,
204205
sigGasConsumer SignatureVerificationGasConsumer,
205-
) (updatedAcc Account, res sdk.Result) {
206+
) (updatedAcc exported.Account, res sdk.Result) {
206207

207208
pubKey, res := ProcessPubKey(acc, sig, simulate)
208209
if !res.IsOK() {
@@ -237,13 +238,13 @@ func processSig(
237238
return acc, res
238239
}
239240

240-
func consumeSimSigGas(gasmeter sdk.GasMeter, pubkey crypto.PubKey, sig StdSignature, params Params) {
241-
simSig := StdSignature{PubKey: pubkey}
241+
func consumeSimSigGas(gasmeter sdk.GasMeter, pubkey crypto.PubKey, sig types.StdSignature, params types.Params) {
242+
simSig := types.StdSignature{PubKey: pubkey}
242243
if len(sig.Signature) == 0 {
243244
simSig.Signature = simSecp256k1Sig[:]
244245
}
245246

246-
sigBz := ModuleCdc.MustMarshalBinaryLengthPrefixed(simSig)
247+
sigBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(simSig)
247248
cost := sdk.Gas(len(sigBz) + 6)
248249

249250
// If the pubkey is a multi-signature pubkey, then we estimate for the maximum
@@ -258,8 +259,8 @@ func consumeSimSigGas(gasmeter sdk.GasMeter, pubkey crypto.PubKey, sig StdSignat
258259
// ProcessPubKey verifies that the given account address matches that of the
259260
// StdSignature. In addition, it will set the public key of the account if it
260261
// has not been set.
261-
func ProcessPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey, sdk.Result) {
262-
// If pubkey is not known for account, set it from the StdSignature.
262+
func ProcessPubKey(acc exported.Account, sig types.StdSignature, simulate bool) (crypto.PubKey, sdk.Result) {
263+
// If pubkey is not known for account, set it from the types.StdSignature.
263264
pubKey := acc.GetPubKey()
264265
if simulate {
265266
// In simulate mode the transaction comes with no signatures, thus if the
@@ -292,7 +293,7 @@ func ProcessPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey,
292293
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
293294
// by the concrete type.
294295
func DefaultSigVerificationGasConsumer(
295-
meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params Params,
296+
meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params,
296297
) sdk.Result {
297298
switch pubkey := pubkey.(type) {
298299
case ed25519.PubKeyEd25519:
@@ -317,7 +318,7 @@ func DefaultSigVerificationGasConsumer(
317318

318319
func consumeMultisignatureVerificationGas(meter sdk.GasMeter,
319320
sig multisig.Multisignature, pubkey multisig.PubKeyMultisigThreshold,
320-
params Params) {
321+
params types.Params) {
321322

322323
size := sig.BitArray.Size()
323324
sigIndex := 0
@@ -333,7 +334,7 @@ func consumeMultisignatureVerificationGas(meter sdk.GasMeter,
333334
//
334335
// NOTE: We could use the CoinKeeper (in addition to the AccountKeeper, because
335336
// the CoinKeeper doesn't give us accounts), but it seems easier to do this.
336-
func DeductFees(supplyKeeper types.SupplyKeeper, ctx sdk.Context, acc Account, fees sdk.Coins) sdk.Result {
337+
func DeductFees(supplyKeeper types.SupplyKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) sdk.Result {
337338
blockTime := ctx.BlockHeader().Time
338339
coins := acc.GetCoins()
339340

@@ -372,7 +373,7 @@ func DeductFees(supplyKeeper types.SupplyKeeper, ctx sdk.Context, acc Account, f
372373
//
373374
// Contract: This should only be called during CheckTx as it cannot be part of
374375
// consensus.
375-
func EnsureSufficientMempoolFees(ctx sdk.Context, stdFee StdFee) sdk.Result {
376+
func EnsureSufficientMempoolFees(ctx sdk.Context, stdFee types.StdFee) sdk.Result {
376377
minGasPrices := ctx.MinGasPrices()
377378
if !minGasPrices.IsZero() {
378379
requiredFees := make(sdk.Coins, len(minGasPrices))
@@ -410,13 +411,13 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {
410411

411412
// GetSignBytes returns a slice of bytes to sign over for a given transaction
412413
// and an account.
413-
func GetSignBytes(chainID string, stdTx StdTx, acc Account, genesis bool) []byte {
414+
func GetSignBytes(chainID string, stdTx types.StdTx, acc exported.Account, genesis bool) []byte {
414415
var accNum uint64
415416
if !genesis {
416417
accNum = acc.GetAccountNumber()
417418
}
418419

419-
return StdSignBytes(
420+
return types.StdSignBytes(
420421
chainID, accNum, acc.GetSequence(), stdTx.Fee, stdTx.Msgs, stdTx.Memo,
421422
)
422423
}

0 commit comments

Comments
 (0)