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: add endpoint to check if an user is member of a dao #1302

Merged
merged 8 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 12 additions & 2 deletions api/dao/v1/dao.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ option go_package = "./daopb";

service DAOService {
rpc DAOs(DAOsRequest) returns (DAOsResponse);
rpc IsUserDAOMember(IsUserDAOMemberRequest) returns (IsUserDAOMemberResponse);
}

message DAOsRequest {
string network_id = 1;
string member_address = 2;
string network_id = 1;
string member_address = 2;
}

message DAOsResponse {
repeated DAO daos = 1;
}

message IsUserDAOMemberRequest {
string user_id = 1;
string dao_id = 2;
}
message IsUserDAOMemberResponse {
bool is_member = 1;
}

message DAO {
string id = 1;
string admin = 2;
Expand All @@ -28,3 +37,4 @@ message DAO {
string token_symbol = 10;
uint64 unstaking_duration = 11;
}

38 changes: 38 additions & 0 deletions go/pkg/dao/dao_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,41 @@ func (s *DAOService) DAOs(ctx context.Context, req *daopb.DAOsRequest) (*daopb.D
Daos: pbdaos,
}, nil
}

func (s *DAOService) IsUserDAOMember(ctx context.Context, req *daopb.IsUserDAOMemberRequest) (*daopb.IsUserDAOMemberResponse, error) {
db := s.conf.IndexerDB
userId := req.GetUserId()
daoId := req.GetDaoId()

daoNetwork, daoAddress, err := s.conf.NetStore.ParseUserID(daoId)
if err != nil {
return nil,
errors.Wrap(err, "failed to parse dao id")
}

_, userAddress, err := s.conf.NetStore.ParseUserID(userId)
if err != nil {
return nil,
errors.Wrap(err, "failed to parse user id")
}

var isMember bool
dbErr := db.Raw(`SELECT EXISTS (
SELECT 1
FROM dao_members dm
JOIN daos d ON dm.dao_contract_address = d.contract_address
WHERE d.contract_address = ?
AND d.network_id = ?
AND dm.member_address = ?
) AS dao_exists;`,
daoAddress,
daoNetwork.GetBase().ID,
userAddress,
).Scan(&isMember).Error
if dbErr != nil {
return nil, errors.Wrap(dbErr, "failed to query database")
}
return &daopb.IsUserDAOMemberResponse{
IsMember: isMember,
}, nil
}
221 changes: 182 additions & 39 deletions go/pkg/daopb/dao.pb.go

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

Loading
Loading