-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathante.go
60 lines (49 loc) · 1.82 KB
/
ante.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package forwarding
import (
storetypes "cosmossdk.io/store/types"
txsigning "cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/noble-assets/forwarding/v2/types"
)
// SigVerificationGasConsumer is a wrapper around the default provided by the
// Cosmos SDK that supports forwarding account public keys.
func SigVerificationGasConsumer(
meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
) error {
switch sig.PubKey.(type) {
case *types.ForwardingPubKey:
return nil
default:
return ante.DefaultSigVerificationGasConsumer(meter, sig, params)
}
}
//
type SigVerificationDecorator struct {
underlying ante.SigVerificationDecorator
bank types.BankKeeper
}
var _ sdk.AnteDecorator = SigVerificationDecorator{}
func NewSigVerificationDecorator(ak ante.AccountKeeper, bk types.BankKeeper, signModeHandler *txsigning.HandlerMap) SigVerificationDecorator {
return SigVerificationDecorator{
underlying: ante.NewSigVerificationDecorator(ak, signModeHandler),
bank: bk,
}
}
func (d SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if msgs := tx.GetMsgs(); len(msgs) == 1 {
msg, ok := msgs[0].(*types.MsgRegisterAccount)
if !ok {
return d.underlying.AnteHandle(ctx, tx, simulate, next)
}
address := types.GenerateAddress(msg.Channel, msg.Recipient, msg.Fallback)
balance := d.bank.GetAllBalances(ctx, address)
if balance.IsZero() || msg.Signer != address.String() {
return d.underlying.AnteHandle(ctx, tx, simulate, next)
}
return next(ctx, tx, simulate)
}
return d.underlying.AnteHandle(ctx, tx, simulate, next)
}