feat: add 'GetCommunityMembersForWalletAddresses' endpoint (#3854)

For https://github.com/status-im/status-desktop/issues/11143
This commit is contained in:
Mikhail Rogachev 2023-08-14 12:59:02 +04:00 committed by GitHub
parent 1ca165c586
commit 0950721a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"sync"
"time"
"golang.org/x/exp/slices"
"golang.org/x/time/rate"
gethcommon "github.com/ethereum/go-ethereum/common"
@ -4366,3 +4367,27 @@ func (m *Messenger) rekeyAllCommunities(logger *zap.Logger) {
}
}
}
func (m *Messenger) GetCommunityMembersForWalletAddresses(communityID types.HexBytes, chainID uint64) (map[string]*Contact, error) {
community, err := m.communitiesManager.GetByID(communityID)
if err != nil {
return nil, err
}
membersForAddresses := map[string]*Contact{}
for memberID, member := range community.Members() {
for _, revealedAddress := range member.RevealedAccounts {
if slices.Contains(revealedAddress.ChainIds, chainID) {
contact, ok := m.allContacts.Load(memberID)
if ok {
membersForAddresses[revealedAddress.Address] = contact
} else {
m.logger.Error("community member is not a contact", zap.String("contact ID", memberID))
}
}
}
}
return membersForAddresses, nil
}

View File

@ -459,7 +459,11 @@ func (api *PublicAPI) ImportCommunity(ctx context.Context, hexPrivateKey string)
func (api *PublicAPI) GetCommunityPublicKeyFromPrivateKey(ctx context.Context, hexPrivateKey string) string {
publicKey := api.service.messenger.GetCommunityIDFromKey(hexPrivateKey)
return publicKey
}
// Get community members contact list for provided wallet addresses
func (api *PublicAPI) GetCommunityMembersForWalletAddresses(communityID types.HexBytes, chainID uint64) (map[string]*protocol.Contact, error) {
return api.service.messenger.GetCommunityMembersForWalletAddresses(communityID, chainID)
}
// Speeds up importing messages from archives