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

[SmartAccount] Get authenticator query #8142

Merged
merged 12 commits into from
Apr 26, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### State Compatible

* [#8142](https://github.com/osmosis-labs/osmosis/pull/8142) Add query for getting single authenticator and add stargate whitelist for the query.

## v24.0.3

* [#21](https://github.com/osmosis-labs/cometbft/pull/21) Move websocket logs to Debug
Expand Down
17 changes: 17 additions & 0 deletions proto/osmosis/smartaccount/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ service Query {
option (google.api.http).get = "/osmosis/smartaccount/params";
}

rpc GetAuthenticator(GetAuthenticatorRequest)
returns (GetAuthenticatorResponse) {
option (google.api.http).get =
"/osmosis/smartaccount/authenticator/{account}/{authenticator_id}";
}

rpc GetAuthenticators(GetAuthenticatorsRequest)
returns (GetAuthenticatorsResponse) {
option (google.api.http).get =
Expand All @@ -38,4 +44,15 @@ message GetAuthenticatorsRequest { string account = 1; }
// MsgGetAuthenticatorsResponse defines the Msg/GetAuthenticators response type.
message GetAuthenticatorsResponse {
repeated AccountAuthenticator account_authenticators = 1;
}

// MsgGetAuthenticatorRequest defines the Msg/GetAuthenticator request type.
message GetAuthenticatorRequest {
string account = 1;
string authenticator_id = 2;
}

// MsgGetAuthenticatorResponse defines the Msg/GetAuthenticator response type.
message GetAuthenticatorResponse {
AccountAuthenticator account_authenticator = 1;
}
5 changes: 5 additions & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
minttypes "github.com/osmosis-labs/osmosis/v24/x/mint/types"
poolincentivestypes "github.com/osmosis-labs/osmosis/v24/x/pool-incentives/types"
poolmanagerqueryproto "github.com/osmosis-labs/osmosis/v24/x/poolmanager/client/queryproto"
smartaccounttypes "github.com/osmosis-labs/osmosis/v24/x/smart-account/types"
superfluidtypes "github.com/osmosis-labs/osmosis/v24/x/superfluid/types"
tokenfactorytypes "github.com/osmosis-labs/osmosis/v24/x/tokenfactory/types"
twapquerytypes "github.com/osmosis-labs/osmosis/v24/x/twap/client/queryproto"
Expand Down Expand Up @@ -139,6 +140,10 @@ func init() {
setWhitelistedQuery("/osmosis.superfluid.Query/AllAssets", &superfluidtypes.AllAssetsResponse{})
setWhitelistedQuery("/osmosis.superfluid.Query/AssetMultiplier", &superfluidtypes.AssetMultiplierResponse{})

// smartaccount
setWhitelistedQuery("/osmosis.smartaccount.v1beta1.Query/GetAuthenticator", &smartaccounttypes.GetAuthenticatorResponse{})
setWhitelistedQuery("/osmosis.smartaccount.v1beta1.Query/GetAuthenticators", &smartaccounttypes.GetAuthenticatorsResponse{})

// poolmanager
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/NumPools", &poolmanagerqueryproto.NumPoolsResponse{})
setWhitelistedQuery("/osmosis.poolmanager.v1beta1.Query/EstimateSwapExactAmountIn", &poolmanagerqueryproto.EstimateSwapExactAmountInResponse{})
Expand Down
22 changes: 22 additions & 0 deletions x/smart-account/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ func (k Keeper) GetAuthenticators(

return &types.GetAuthenticatorsResponse{AccountAuthenticators: authenticators}, nil
}

func (k Keeper) GetAuthenticator(
ctx context.Context,
request *types.GetAuthenticatorRequest,
) (*types.GetAuthenticatorResponse, error) {
if request == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
acc, err := sdk.AccAddressFromBech32(request.Account)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

authenticator, err := k.GetSelectedAuthenticatorData(sdkCtx, acc, int(request.AuthenticatorId))
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.GetAuthenticatorResponse{AccountAuthenticator: authenticator}, nil
}
Loading