status-go/protocol/communities/utils.go
Pascal Precht 1a2ca21070 Add chainIds to revealed accounts in memberhsip requests
This commit does a few things:

- Adds a migration that adds chainids to communities_request_to_join_revealed_addresses
- Removes RevealedAddress in favor of RevealedAccount which is now a struct that contains the revealed address, as well as the signature and a list of chain IDs on which to check for user funds
- Changes the logic of sending requests to join a community, such that after creating address signatures, the user node will also check which of the addresses has funds on which networks for the community's token permissions, and add the chainds to the RevealedAccount
- Updates checkPermissionToJoin() such that only relevant chainids are used when checking user's funds. Chain IDs are retrieved from RevealedAccounts and matched against token permission criteria chain IDs
2023-06-12 10:49:29 +02:00

60 lines
2 KiB
Go

package communities
import (
"fmt"
"strings"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/protobuf"
)
func CalculateRequestID(publicKey string, communityID types.HexBytes) types.HexBytes {
idString := fmt.Sprintf("%s-%s", publicKey, communityID)
return crypto.Keccak256([]byte(idString))
}
func ExtractTokenCriteria(permissions []*protobuf.CommunityTokenPermission) (erc20TokenCriteria map[uint64]map[string]*protobuf.TokenCriteria, erc721TokenCriteria map[uint64]map[string]*protobuf.TokenCriteria, ensTokenCriteria []string) {
erc20TokenCriteria = make(map[uint64]map[string]*protobuf.TokenCriteria)
erc721TokenCriteria = make(map[uint64]map[string]*protobuf.TokenCriteria)
ensTokenCriteria = make([]string, 0)
for _, tokenPermission := range permissions {
for _, tokenRequirement := range tokenPermission.TokenCriteria {
isERC721 := tokenRequirement.Type == protobuf.CommunityTokenType_ERC721
isERC20 := tokenRequirement.Type == protobuf.CommunityTokenType_ERC20
isENS := tokenRequirement.Type == protobuf.CommunityTokenType_ENS
for chainID, contractAddress := range tokenRequirement.ContractAddresses {
_, existsERC721 := erc721TokenCriteria[chainID]
if isERC721 && !existsERC721 {
erc721TokenCriteria[chainID] = make(map[string]*protobuf.TokenCriteria)
}
_, existsERC20 := erc20TokenCriteria[chainID]
if isERC20 && !existsERC20 {
erc20TokenCriteria[chainID] = make(map[string]*protobuf.TokenCriteria)
}
_, existsERC721 = erc721TokenCriteria[chainID][contractAddress]
if isERC721 && !existsERC721 {
erc721TokenCriteria[chainID][strings.ToLower(contractAddress)] = tokenRequirement
}
_, existsERC20 = erc20TokenCriteria[chainID][contractAddress]
if isERC20 && !existsERC20 {
erc20TokenCriteria[chainID][strings.ToLower(contractAddress)] = tokenRequirement
}
if isENS {
ensTokenCriteria = append(ensTokenCriteria, tokenRequirement.EnsPattern)
}
}
}
}
return
}