feat(x/accounts): add event emission to accounts module (#19636)
Co-authored-by: sontrinh16 <trinhleson2000@gmail.com>
This commit is contained in:
parent
89bba66111
commit
0d3f4a82d4
@ -1,6 +1,6 @@
|
||||
go 1.22
|
||||
|
||||
toolchain go1.22.0
|
||||
toolchain go1.22
|
||||
|
||||
use (
|
||||
.
|
||||
|
||||
@ -37,7 +37,6 @@ func NewAccount(name string, handlerMap *signing.HandlerMap) accountstd.AccountC
|
||||
PubKey: collections.NewItem(deps.SchemaBuilder, PubKeyPrefix, "pub_key", codec.CollValue[secp256k1.PubKey](deps.LegacyStateCodec)),
|
||||
Sequence: collections.NewSequence(deps.SchemaBuilder, SequencePrefix, "sequence"),
|
||||
addrCodec: deps.AddressCodec,
|
||||
hs: deps.HeaderService,
|
||||
signingHandlers: handlerMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -10,8 +10,12 @@ import (
|
||||
|
||||
func TestRouterDoubleRegistration(t *testing.T) {
|
||||
router := NewExecuteBuilder()
|
||||
RegisterExecuteHandler(router, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) { return nil, nil })
|
||||
RegisterExecuteHandler(router, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) { return nil, nil })
|
||||
RegisterExecuteHandler(router, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) {
|
||||
return nil, nil
|
||||
})
|
||||
RegisterExecuteHandler(router, func(_ context.Context, req *types.StringValue) (*types.StringValue, error) {
|
||||
return nil, nil
|
||||
})
|
||||
|
||||
_, err := router.makeHandler()
|
||||
require.ErrorContains(t, err, "already registered")
|
||||
|
||||
@ -5,8 +5,6 @@ import (
|
||||
"encoding/binary"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/gas"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/x/accounts/internal/prefixstore"
|
||||
|
||||
@ -137,39 +135,3 @@ func Whoami(ctx context.Context) []byte {
|
||||
|
||||
// Funds returns the funds associated with the execution context.
|
||||
func Funds(ctx context.Context) sdk.Coins { return getCtx(ctx).funds }
|
||||
|
||||
type headerService struct{ hs header.Service }
|
||||
|
||||
func (h headerService) GetHeaderInfo(ctx context.Context) header.Info {
|
||||
return h.hs.GetHeaderInfo(getParentContext(ctx))
|
||||
}
|
||||
|
||||
var _ gas.Service = (*gasService)(nil)
|
||||
|
||||
type gasService struct{ gs gas.Service }
|
||||
|
||||
func (g gasService) GetGasMeter(ctx context.Context) gas.Meter {
|
||||
return g.gs.GetGasMeter(getParentContext(ctx))
|
||||
}
|
||||
|
||||
func (g gasService) GetBlockGasMeter(ctx context.Context) gas.Meter {
|
||||
return g.gs.GetBlockGasMeter(getParentContext(ctx))
|
||||
}
|
||||
|
||||
func (g gasService) GetGasConfig(ctx context.Context) gas.GasConfig {
|
||||
return g.gs.GetGasConfig(getParentContext(ctx))
|
||||
}
|
||||
|
||||
func (g gasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context {
|
||||
v := getCtx(ctx)
|
||||
v.parentContext = g.gs.WithGasMeter(v.parentContext, meter)
|
||||
return context.WithValue(v.parentContext, contextKey{}, v)
|
||||
}
|
||||
|
||||
func (g gasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context {
|
||||
v := getCtx(ctx)
|
||||
v.parentContext = g.gs.WithBlockGasMeter(v.parentContext, meter)
|
||||
return addCtx(v.parentContext, v)
|
||||
}
|
||||
|
||||
func getParentContext(ctx context.Context) context.Context { return getCtx(ctx).parentContext }
|
||||
|
||||
@ -8,8 +8,7 @@ import (
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/gas"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
@ -18,8 +17,7 @@ import (
|
||||
type Dependencies struct {
|
||||
SchemaBuilder *collections.SchemaBuilder
|
||||
AddressCodec address.Codec
|
||||
HeaderService header.Service
|
||||
GasService gas.Service
|
||||
Environment appmodule.Environment
|
||||
LegacyStateCodec interface {
|
||||
Marshal(gogoproto.Message) ([]byte, error)
|
||||
Unmarshal([]byte, gogoproto.Message) error
|
||||
@ -34,8 +32,7 @@ type AccountCreatorFunc = func(deps Dependencies) (string, Account, error)
|
||||
func MakeAccountsMap(
|
||||
cdc codec.BinaryCodec,
|
||||
addressCodec address.Codec,
|
||||
hs header.Service,
|
||||
gs gas.Service,
|
||||
env appmodule.Environment,
|
||||
accounts []AccountCreatorFunc,
|
||||
) (map[string]Implementation, error) {
|
||||
accountsMap := make(map[string]Implementation, len(accounts))
|
||||
@ -44,8 +41,7 @@ func MakeAccountsMap(
|
||||
deps := Dependencies{
|
||||
SchemaBuilder: stateSchemaBuilder,
|
||||
AddressCodec: addressCodec,
|
||||
HeaderService: headerService{hs},
|
||||
GasService: gasService{gs},
|
||||
Environment: env,
|
||||
LegacyStateCodec: cdc,
|
||||
}
|
||||
name, accountInterface, err := makeAccount(deps)
|
||||
|
||||
@ -90,7 +90,7 @@ func NewKeeper(
|
||||
return Keeper{}, err
|
||||
}
|
||||
keeper.Schema = schema
|
||||
keeper.accounts, err = implementation.MakeAccountsMap(cdc, keeper.addressCodec, env.HeaderService, env.GasService, accounts)
|
||||
keeper.accounts, err = implementation.MakeAccountsMap(cdc, keeper.addressCodec, env, accounts)
|
||||
if err != nil {
|
||||
return Keeper{}, err
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
|
||||
"cosmossdk.io/api/cosmos/crypto/secp256k1"
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/x/accounts/accountstd"
|
||||
account_abstractionv1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1"
|
||||
rotationv1 "cosmossdk.io/x/accounts/testing/rotation/v1"
|
||||
@ -24,6 +26,7 @@ func NewMinimalAbstractedAccount(d accountstd.Dependencies) (MinimalAbstractedAc
|
||||
return MinimalAbstractedAccount{
|
||||
PubKey: collections.NewItem(d.SchemaBuilder, PubKeyPrefix, "pubkey", codec.CollValueV2[secp256k1.PubKey]()),
|
||||
Sequence: collections.NewSequence(d.SchemaBuilder, SequencePrefix, "sequence"),
|
||||
Env: d.Environment,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -32,6 +35,7 @@ func NewMinimalAbstractedAccount(d accountstd.Dependencies) (MinimalAbstractedAc
|
||||
type MinimalAbstractedAccount struct {
|
||||
PubKey collections.Item[*secp256k1.PubKey]
|
||||
Sequence collections.Sequence
|
||||
Env appmodule.Environment
|
||||
}
|
||||
|
||||
func (a MinimalAbstractedAccount) Init(ctx context.Context, msg *rotationv1.MsgInit) (*rotationv1.MsgInitResponse, error) {
|
||||
@ -45,6 +49,11 @@ func (a MinimalAbstractedAccount) RotatePubKey(ctx context.Context, msg *rotatio
|
||||
// Authenticate authenticates the account, auth always passess.
|
||||
func (a MinimalAbstractedAccount) Authenticate(ctx context.Context, msg *account_abstractionv1.MsgAuthenticate) (*account_abstractionv1.MsgAuthenticateResponse, error) {
|
||||
_, err := a.Sequence.Next(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = a.Env.EventService.EventManager(ctx).EmitKV("account_bundler_authentication", event.NewAttribute("address", msg.Bundler))
|
||||
|
||||
return &account_abstractionv1.MsgAuthenticateResponse{}, err
|
||||
}
|
||||
|
||||
|
||||
@ -29,9 +29,7 @@ func NewAccount(d accountstd.Dependencies) (Account, error) {
|
||||
Owner: collections.NewItem(d.SchemaBuilder, OwnerPrefix, "owner", collections.BytesValue),
|
||||
Counter: collections.NewItem(d.SchemaBuilder, CounterPrefix, "counter", collections.Uint64Value),
|
||||
TestStateCodec: collections.NewItem(d.SchemaBuilder, TestStateCodecPrefix, "test_state_codec", codec.CollValue[counterv1.MsgTestDependencies](d.LegacyStateCodec)),
|
||||
hs: d.HeaderService,
|
||||
addressCodec: d.AddressCodec,
|
||||
gs: d.GasService,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user