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/auth): define simplified account query service #13210

Merged
merged 28 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7ae0b47
feat(x/auth): define simplified account query service
aaronc Sep 8, 2022
b3d2dac
updates
aaronc Sep 8, 2022
03df3ff
docs
aaronc Sep 12, 2022
bd2f410
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/simpl…
aaronc Sep 12, 2022
bdc1efa
protogen
aaronc Sep 12, 2022
6e9203e
Merge branch 'main' into aaronc/simple-auth-query-proto
aaronc Sep 12, 2022
9512872
Update proto/cosmos/auth/v1/query.proto
aaronc Sep 12, 2022
4d5294d
Merge branch 'main' into aaronc/simple-auth-query-proto
alexanderbez Sep 12, 2022
3e456fe
updates
alexanderbez Sep 13, 2022
76724c7
updates
alexanderbez Sep 13, 2022
326e4f9
move to v1beta1
aaronc Sep 13, 2022
52a68f0
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/simpl…
aaronc Sep 13, 2022
9058c0f
proto-gen
aaronc Sep 13, 2022
abb207c
Merge branch 'aaronc/simple-auth-query-proto' of github.com:cosmos/co…
aaronc Sep 13, 2022
6e81e26
WIP on API changes
aaronc Sep 13, 2022
d4a5f9f
fix proto-gen + tests
aaronc Sep 14, 2022
2483b74
Merge branch 'main' into aaronc/simple-auth-query-proto
aaronc Sep 14, 2022
bc2b88e
address review comments
aaronc Sep 14, 2022
2d1fee9
Merge remote-tracking branch 'origin/aaronc/simple-auth-query-proto' …
aaronc Sep 14, 2022
1a603a5
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/simpl…
aaronc Sep 14, 2022
6e5bc01
Update x/auth/keeper/grpc_query.go
aaronc Sep 15, 2022
733d63e
update CHANGELOG.md
aaronc Sep 15, 2022
76d000e
docs
aaronc Sep 15, 2022
463a54f
Merge branch 'main' into aaronc/simple-auth-query-proto
aaronc Sep 15, 2022
9e52403
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/simpl…
aaronc Sep 15, 2022
a936af7
proto lint
aaronc Sep 15, 2022
e39b8dd
Merge remote-tracking branch 'origin/aaronc/simple-auth-query-proto' …
aaronc Sep 15, 2022
5193994
Merge branch 'main' into aaronc/simple-auth-query-proto
alexanderbez Sep 16, 2022
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
1,228 changes: 1,104 additions & 124 deletions api/cosmos/auth/v1beta1/query.pulsar.go

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions api/cosmos/auth/v1beta1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ service Query {
option (cosmos.query.v1.deterministic) = true;
option (google.api.http).get = "/cosmos/auth/v1beta1/bech32/{address_string}";
}


// AccountInfo queries account info which is common to all account types.
//
// Since: cosmos-sdk 0.47
rpc AccountInfo(QueryAccountInfoRequest) returns (QueryAccountInfoResponse) {
aaronc marked this conversation as resolved.
Show resolved Hide resolved
option (cosmos.query.v1.deterministic) = true;
option (google.api.http).get = "/cosmos/auth/v1beta1/account_info/{address}";
}
}

// QueryAccountsRequest is the request type for the Query/Accounts RPC method.
Expand Down Expand Up @@ -176,3 +185,17 @@ message QueryAccountAddressByIDRequest {
message QueryAccountAddressByIDResponse {
string account_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryAccountInfoRequest is the Query/AccountInfo request type.
message QueryAccountInfoRequest {

// address is the account address string.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryAccountInfoResponse is the Query/AccountInfo response type.
message QueryAccountInfoResponse {

// info is the account info which is represented by BaseAccount.
BaseAccount info = 1;
}
2 changes: 1 addition & 1 deletion proto/cosmos/autocli/v1/options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package cosmos.autocli.v1;

import "google/protobuf/descriptor.proto";

option go_package = "github.com/cosmos/cosmos-sdk/api/cosmos/base/cli/v1;cliv1";
option go_package = "cosmossdk.io/api/cosmos/base/cli/v1;cliv1";

// ModuleOptions describes the CLI options for a Cosmos SDK module.
message ModuleOptions {
Expand Down
7 changes: 5 additions & 2 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
# docker build --pull --rm -f "contrib/devtools/Dockerfile" -t cosmossdk-proto:latest "contrib/devtools"
# docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh

set -eo pipefail
aaronc marked this conversation as resolved.
Show resolved Hide resolved
set -e

echo "Generating gogo proto code"
cd proto
proto_dirs=$(find ./cosmos -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
if grep "option go_package.*(?!cosmos-sdk/api)" $file &> /dev/null ; then
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/...
# gogo proto files SHOULD ONLY be generated if this is false
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*cosmossdk.io/api' "$file" | grep -q ':0$'; then
buf generate --template buf.gen.gogo.yaml $file
fi
done
Expand Down
35 changes: 35 additions & 0 deletions x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,38 @@ func (ak AccountKeeper) AddressStringToBytes(ctx context.Context, req *types.Add

return &types.AddressStringToBytesResponse{AddressBytes: bz}, nil
}

func (ak AccountKeeper) AccountInfo(goCtx context.Context, req *types.QueryAccountInfoRequest) (*types.QueryAccountInfoResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

if req.Address == "" {
return nil, status.Error(codes.InvalidArgument, "Address cannot be empty")
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
aaronc marked this conversation as resolved.
Show resolved Hide resolved
}

ctx := sdk.UnwrapSDKContext(goCtx)
addr, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, err
}

account := ak.GetAccount(ctx, addr)
if account == nil {
return nil, status.Errorf(codes.NotFound, "account %s not found", req.Address)
}

pkAny, err := codectypes.NewAnyWithValue(account.GetPubKey())
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}

return &types.QueryAccountInfoResponse{
Info: &types.BaseAccount{
Address: addr.String(),
PubKey: pkAny,
AccountNumber: account.GetAccountNumber(),
Sequence: account.GetSequence(),
},
}, nil
}
24 changes: 24 additions & 0 deletions x/auth/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math"
"sort"

"github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -443,3 +445,25 @@ func (suite *KeeperTestSuite) TestAddressStringToBytes() {
})
}
}

func (suite *KeeperTestSuite) TestQueryAccountInfo() {
_, pk, addr := testdata.KeyTestPubAddr()
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.Require().NoError(acc.SetPubKey(pk))
suite.Require().NoError(acc.SetSequence(10))
suite.accountKeeper.SetAccount(suite.ctx, acc)

res, err := suite.queryClient.AccountInfo(context.Background(), &types.QueryAccountInfoRequest{
Address: addr.String(),
})

suite.Require().NoError(err)
suite.Require().NotNil(res.Info)
suite.Require().Equal(addr.String(), res.Info.Address)
suite.Require().Equal(acc.GetAccountNumber(), res.Info.AccountNumber)
suite.Require().Equal(acc.GetSequence(), res.Info.Sequence)
suite.Require().Equal("/"+proto.MessageName(pk), res.Info.PubKey.TypeUrl)
pkBz, err := proto.Marshal(pk)
suite.Require().NoError(err)
suite.Require().Equal(pkBz, res.Info.PubKey.Value)
}
3 changes: 2 additions & 1 deletion x/auth/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (

"github.com/stretchr/testify/suite"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"encoding/json"
"fmt"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

modulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
aaronc marked this conversation as resolved.
Show resolved Hide resolved

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -123,6 +122,7 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.accountKeeper))
types.RegisterQueryServer(cfg.QueryServer(), am.accountKeeper)

m := keeper.NewMigrator(am.accountKeeper, cfg.QueryServer(), am.legacySubspace)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(err)
Expand Down
Loading