-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move group related functions to group.go
- Loading branch information
Showing
2 changed files
with
23 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/group" | ||
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" | ||
) | ||
|
||
// GroupCheckerFunc convenient type to match the GroupChecker interface. | ||
type GroupCheckerFunc func(sdk.Context, sdk.AccAddress) bool | ||
|
||
// GroupPolicyQuerier provides functionality to query group policies. | ||
type GroupPolicyQuerier interface { | ||
GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error) | ||
} | ||
|
||
// IsGroupAddress checks if the account is a group address. | ||
func (t GroupCheckerFunc) IsGroupAddress(ctx sdk.Context, account sdk.AccAddress) bool { | ||
return t(ctx, account) | ||
} | ||
|
||
// NewGroupChecker creates a new GroupChecker function for checking if an account is in a group. | ||
func NewGroupCheckerFunc(keeper groupkeeper.Keeper) GroupCheckerFunc { | ||
func NewGroupCheckerFunc(querier GroupPolicyQuerier) GroupCheckerFunc { | ||
return GroupCheckerFunc(func(ctx sdk.Context, account sdk.AccAddress) bool { | ||
msg := &group.QueryGroupPolicyInfoRequest{Address: account.String()} | ||
goCtx := sdk.WrapSDKContext(ctx) | ||
_, err := keeper.GroupPolicyInfo(goCtx, msg) | ||
_, err := querier.GroupPolicyInfo(goCtx, msg) | ||
return err == nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app | ||
|
||
import "testing" | ||
|
||
type MockGroupPolicyQuerier struct { | ||
} | ||
|
||
func TestNewGroupCheckerFunc(t *testing.T) { | ||
|
||
} | ||
|
||
func TestIsGroupAddress(t *testing.T) { | ||
|
||
} |