mirror of
https://github.com/status-im/status-go.git
synced 2025-02-16 08:50:09 +00:00
feat: add 'GetCommunityMembersForWalletAddresses' endpoint (#3854)
For https://github.com/status-im/status-desktop/issues/11143
This commit is contained in:
parent
1ca165c586
commit
0950721a6d
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user