Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/accounts): add event emission to accounts module #19636

Merged
merged 8 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.work.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
go 1.22

toolchain go1.22.0
toolchain go1.22

use (
.
Expand Down
1 change: 0 additions & 1 deletion x/accounts/defaults/base/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions x/accounts/internal/implementation/api_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 0 additions & 34 deletions x/accounts/internal/implementation/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -137,35 +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) 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 }
10 changes: 2 additions & 8 deletions x/accounts/internal/implementation/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -34,8 +32,6 @@ type AccountCreatorFunc = func(deps Dependencies) (string, Account, error)
func MakeAccountsMap(
sontrinh16 marked this conversation as resolved.
Show resolved Hide resolved
cdc codec.BinaryCodec,
addressCodec address.Codec,
hs header.Service,
gs gas.Service,
accounts []AccountCreatorFunc,
) (map[string]Implementation, error) {
accountsMap := make(map[string]Implementation, len(accounts))
Expand All @@ -44,8 +40,6 @@ func MakeAccountsMap(
deps := Dependencies{
sontrinh16 marked this conversation as resolved.
Show resolved Hide resolved
SchemaBuilder: stateSchemaBuilder,
AddressCodec: addressCodec,
HeaderService: headerService{hs},
GasService: gasService{gs},
LegacyStateCodec: cdc,
}
name, accountInterface, err := makeAccount(deps)
Expand Down
2 changes: 1 addition & 1 deletion x/accounts/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, accounts)
if err != nil {
return Keeper{}, err
}
Expand Down
9 changes: 9 additions & 0 deletions x/accounts/testing/account_abstraction/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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) {
Expand All @@ -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
}

Expand Down
2 changes: 0 additions & 2 deletions x/accounts/testing/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading