1
- package auth
1
+ package ante
2
2
3
3
import (
4
4
"bytes"
@@ -13,6 +13,8 @@ import (
13
13
14
14
"github.com/cosmos/cosmos-sdk/codec"
15
15
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"
16
18
"github.com/cosmos/cosmos-sdk/x/auth/types"
17
19
)
18
20
@@ -30,12 +32,12 @@ func init() {
30
32
31
33
// SignatureVerificationGasConsumer is the type of function that is used to both consume gas when verifying signatures
32
34
// 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
34
36
35
37
// NewAnteHandler returns an AnteHandler that checks and increments sequence
36
38
// numbers, checks signatures & account numbers, and deducts fees from the first
37
39
// 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 {
39
41
return func (
40
42
ctx sdk.Context , tx sdk.Tx , simulate bool ,
41
43
) (newCtx sdk.Context , res sdk.Result , abort bool ) {
@@ -45,7 +47,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
45
47
}
46
48
47
49
// all transactions must be of type auth.StdTx
48
- stdTx , ok := tx .(StdTx )
50
+ stdTx , ok := tx .(types. StdTx )
49
51
if ! ok {
50
52
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
51
53
// during runTx.
@@ -107,7 +109,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
107
109
// stdSigs contains the sequence number, account number, and signatures.
108
110
// When simulating, this would just be a 0-length slice.
109
111
signerAddrs := stdTx .GetSigners ()
110
- signerAccs := make ([]Account , len (signerAddrs ))
112
+ signerAccs := make ([]exported. Account , len (signerAddrs ))
111
113
isGenesis := ctx .BlockHeight () == 0
112
114
113
115
// fetch first signer, who's going to pay the fees
@@ -150,14 +152,13 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper, sigGasCon
150
152
ak .SetAccount (newCtx , signerAccs [i ])
151
153
}
152
154
153
- // TODO: tx tags (?)
154
155
return newCtx , sdk.Result {GasWanted : stdTx .Fee .Gas }, false // continue...
155
156
}
156
157
}
157
158
158
159
// GetSignerAcc returns an account for a given address that is expected to sign
159
160
// 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 ) {
161
162
if acc := ak .GetAccount (ctx , addr ); acc != nil {
162
163
return acc , sdk.Result {}
163
164
}
@@ -166,12 +167,12 @@ func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (Accou
166
167
167
168
// ValidateSigCount validates that the transaction has a valid cumulative total
168
169
// amount of signatures.
169
- func ValidateSigCount (stdTx StdTx , params Params ) sdk.Result {
170
+ func ValidateSigCount (stdTx types. StdTx , params types. Params ) sdk.Result {
170
171
stdSigs := stdTx .GetSignatures ()
171
172
172
173
sigCount := 0
173
174
for i := 0 ; i < len (stdSigs ); i ++ {
174
- sigCount += CountSubKeys (stdSigs [i ].PubKey )
175
+ sigCount += types . CountSubKeys (stdSigs [i ].PubKey )
175
176
if uint64 (sigCount ) > params .TxSigLimit {
176
177
return sdk .ErrTooManySignatures (
177
178
fmt .Sprintf ("signatures: %d, limit: %d" , sigCount , params .TxSigLimit ),
@@ -183,7 +184,7 @@ func ValidateSigCount(stdTx StdTx, params Params) sdk.Result {
183
184
}
184
185
185
186
// 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 {
187
188
memoLength := len (stdTx .GetMemo ())
188
189
if uint64 (memoLength ) > params .MaxMemoCharacters {
189
190
return sdk .ErrMemoTooLarge (
@@ -200,9 +201,9 @@ func ValidateMemo(stdTx StdTx, params Params) sdk.Result {
200
201
// verify the signature and increment the sequence. If the account doesn't have
201
202
// a pubkey, set it.
202
203
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 ,
204
205
sigGasConsumer SignatureVerificationGasConsumer ,
205
- ) (updatedAcc Account , res sdk.Result ) {
206
+ ) (updatedAcc exported. Account , res sdk.Result ) {
206
207
207
208
pubKey , res := ProcessPubKey (acc , sig , simulate )
208
209
if ! res .IsOK () {
@@ -237,13 +238,13 @@ func processSig(
237
238
return acc , res
238
239
}
239
240
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 }
242
243
if len (sig .Signature ) == 0 {
243
244
simSig .Signature = simSecp256k1Sig [:]
244
245
}
245
246
246
- sigBz := ModuleCdc .MustMarshalBinaryLengthPrefixed (simSig )
247
+ sigBz := types . ModuleCdc .MustMarshalBinaryLengthPrefixed (simSig )
247
248
cost := sdk .Gas (len (sigBz ) + 6 )
248
249
249
250
// 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
258
259
// ProcessPubKey verifies that the given account address matches that of the
259
260
// StdSignature. In addition, it will set the public key of the account if it
260
261
// 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.
263
264
pubKey := acc .GetPubKey ()
264
265
if simulate {
265
266
// 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,
292
293
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
293
294
// by the concrete type.
294
295
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 ,
296
297
) sdk.Result {
297
298
switch pubkey := pubkey .(type ) {
298
299
case ed25519.PubKeyEd25519 :
@@ -317,7 +318,7 @@ func DefaultSigVerificationGasConsumer(
317
318
318
319
func consumeMultisignatureVerificationGas (meter sdk.GasMeter ,
319
320
sig multisig.Multisignature , pubkey multisig.PubKeyMultisigThreshold ,
320
- params Params ) {
321
+ params types. Params ) {
321
322
322
323
size := sig .BitArray .Size ()
323
324
sigIndex := 0
@@ -333,7 +334,7 @@ func consumeMultisignatureVerificationGas(meter sdk.GasMeter,
333
334
//
334
335
// NOTE: We could use the CoinKeeper (in addition to the AccountKeeper, because
335
336
// 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 {
337
338
blockTime := ctx .BlockHeader ().Time
338
339
coins := acc .GetCoins ()
339
340
@@ -372,7 +373,7 @@ func DeductFees(supplyKeeper types.SupplyKeeper, ctx sdk.Context, acc Account, f
372
373
//
373
374
// Contract: This should only be called during CheckTx as it cannot be part of
374
375
// consensus.
375
- func EnsureSufficientMempoolFees (ctx sdk.Context , stdFee StdFee ) sdk.Result {
376
+ func EnsureSufficientMempoolFees (ctx sdk.Context , stdFee types. StdFee ) sdk.Result {
376
377
minGasPrices := ctx .MinGasPrices ()
377
378
if ! minGasPrices .IsZero () {
378
379
requiredFees := make (sdk.Coins , len (minGasPrices ))
@@ -410,13 +411,13 @@ func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context {
410
411
411
412
// GetSignBytes returns a slice of bytes to sign over for a given transaction
412
413
// 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 {
414
415
var accNum uint64
415
416
if ! genesis {
416
417
accNum = acc .GetAccountNumber ()
417
418
}
418
419
419
- return StdSignBytes (
420
+ return types . StdSignBytes (
420
421
chainID , accNum , acc .GetSequence (), stdTx .Fee , stdTx .Msgs , stdTx .Memo ,
421
422
)
422
423
}
0 commit comments