chore: update directory abi and addresses

closes: status-im/status-desktop#12569
This commit is contained in:
Patryk Osmaczko 2023-11-03 11:19:38 +01:00 committed by osmaczko
parent 071c431606
commit 953ed4c8e4
5 changed files with 114 additions and 27 deletions

View File

@ -9,7 +9,8 @@ import (
var errorNotAvailableOnChainID = errors.New("not available for chainID") var errorNotAvailableOnChainID = errors.New("not available for chainID")
var contractAddressByChainID = map[uint64]common.Address{ var contractAddressByChainID = map[uint64]common.Address{
420: common.HexToAddress("0x22EE86A14b49890957fE71990073C6C68E05F9C5"), // optimism goerli testnet 10: common.HexToAddress("0xA8d270048a086F5807A8dc0a9ae0e96280C41e3A"), // optimism mainnet
420: common.HexToAddress("0xB3Ef5B0825D5f665bE14394eea41E684CE96A4c5"), // optimism goerli testnet
} }
func ContractAddress(chainID uint64) (common.Address, error) { func ContractAddress(chainID uint64) (common.Address, error) {

View File

@ -1,6 +1,17 @@
[ [
{ {
"inputs": [], "inputs": [
{
"internalType": "address",
"name": "_votingContract",
"type": "address"
},
{
"internalType": "address",
"name": "_featuredVotingContract",
"type": "address"
}
],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
}, },
@ -17,6 +28,19 @@
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "featuredVotingContract",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [], "inputs": [],
"name": "getCommunities", "name": "getCommunities",
@ -106,5 +130,18 @@
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
},
{
"inputs": [],
"name": "votingContract",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
} }
] ]

View File

@ -31,7 +31,7 @@ var (
// DirectoryMetaData contains all meta data concerning the Directory contract. // DirectoryMetaData contains all meta data concerning the Directory contract.
var DirectoryMetaData = &bind.MetaData{ var DirectoryMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"addCommunity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getCommunities\",\"outputs\":[{\"internalType\":\"bytes[]\",\"name\":\"\",\"type\":\"bytes[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getFeaturedCommunities\",\"outputs\":[{\"internalType\":\"bytes[]\",\"name\":\"\",\"type\":\"bytes[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"isCommunityFeatured\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"isCommunityInDirectory\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"removeCommunity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes[]\",\"name\":\"_featuredCommunities\",\"type\":\"bytes[]\"}],\"name\":\"setFeaturedCommunities\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_votingContract\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_featuredVotingContract\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"addCommunity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"featuredVotingContract\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getCommunities\",\"outputs\":[{\"internalType\":\"bytes[]\",\"name\":\"\",\"type\":\"bytes[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getFeaturedCommunities\",\"outputs\":[{\"internalType\":\"bytes[]\",\"name\":\"\",\"type\":\"bytes[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"isCommunityFeatured\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"isCommunityInDirectory\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"community\",\"type\":\"bytes\"}],\"name\":\"removeCommunity\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes[]\",\"name\":\"_featuredCommunities\",\"type\":\"bytes[]\"}],\"name\":\"setFeaturedCommunities\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"votingContract\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
} }
// DirectoryABI is the input ABI used to generate the binding from. // DirectoryABI is the input ABI used to generate the binding from.
@ -180,6 +180,37 @@ func (_Directory *DirectoryTransactorRaw) Transact(opts *bind.TransactOpts, meth
return _Directory.Contract.contract.Transact(opts, method, params...) return _Directory.Contract.contract.Transact(opts, method, params...)
} }
// FeaturedVotingContract is a free data retrieval call binding the contract method 0x7475fe93.
//
// Solidity: function featuredVotingContract() view returns(address)
func (_Directory *DirectoryCaller) FeaturedVotingContract(opts *bind.CallOpts) (common.Address, error) {
var out []interface{}
err := _Directory.contract.Call(opts, &out, "featuredVotingContract")
if err != nil {
return *new(common.Address), err
}
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
return out0, err
}
// FeaturedVotingContract is a free data retrieval call binding the contract method 0x7475fe93.
//
// Solidity: function featuredVotingContract() view returns(address)
func (_Directory *DirectorySession) FeaturedVotingContract() (common.Address, error) {
return _Directory.Contract.FeaturedVotingContract(&_Directory.CallOpts)
}
// FeaturedVotingContract is a free data retrieval call binding the contract method 0x7475fe93.
//
// Solidity: function featuredVotingContract() view returns(address)
func (_Directory *DirectoryCallerSession) FeaturedVotingContract() (common.Address, error) {
return _Directory.Contract.FeaturedVotingContract(&_Directory.CallOpts)
}
// GetCommunities is a free data retrieval call binding the contract method 0xc251b565. // GetCommunities is a free data retrieval call binding the contract method 0xc251b565.
// //
// Solidity: function getCommunities() view returns(bytes[]) // Solidity: function getCommunities() view returns(bytes[])
@ -304,6 +335,37 @@ func (_Directory *DirectoryCallerSession) IsCommunityInDirectory(community []byt
return _Directory.Contract.IsCommunityInDirectory(&_Directory.CallOpts, community) return _Directory.Contract.IsCommunityInDirectory(&_Directory.CallOpts, community)
} }
// VotingContract is a free data retrieval call binding the contract method 0xc1fc006a.
//
// Solidity: function votingContract() view returns(address)
func (_Directory *DirectoryCaller) VotingContract(opts *bind.CallOpts) (common.Address, error) {
var out []interface{}
err := _Directory.contract.Call(opts, &out, "votingContract")
if err != nil {
return *new(common.Address), err
}
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
return out0, err
}
// VotingContract is a free data retrieval call binding the contract method 0xc1fc006a.
//
// Solidity: function votingContract() view returns(address)
func (_Directory *DirectorySession) VotingContract() (common.Address, error) {
return _Directory.Contract.VotingContract(&_Directory.CallOpts)
}
// VotingContract is a free data retrieval call binding the contract method 0xc1fc006a.
//
// Solidity: function votingContract() view returns(address)
func (_Directory *DirectoryCallerSession) VotingContract() (common.Address, error) {
return _Directory.Contract.VotingContract(&_Directory.CallOpts)
}
// AddCommunity is a paid mutator transaction binding the contract method 0x74837935. // AddCommunity is a paid mutator transaction binding the contract method 0x74837935.
// //
// Solidity: function addCommunity(bytes community) returns() // Solidity: function addCommunity(bytes community) returns()

View File

@ -660,20 +660,12 @@ func (m *Manager) GetStoredDescriptionForCommunities(communityIDs []types.HexByt
return return
} }
// TODO: use CommunityShard instead of appending the communityID response.ContractCommunities = append(response.ContractCommunities, communityID)
response.ContractCommunities = append(response.ContractCommunities, communityID) // , CommunityShard{
// CommunityID: communityID,
// Shard: community.Shard(),
// }
if community != nil { if community != nil {
response.Descriptions[community.IDString()] = community response.Descriptions[community.IDString()] = community
} else { } else {
response.UnknownCommunities = append(response.UnknownCommunities, communityID) // CommunityShard{ response.UnknownCommunities = append(response.UnknownCommunities, communityID)
// CommunityID: communityID,
// Shard: community.Shard(),
// })
} }
} }

View File

@ -633,15 +633,20 @@ func (m *Messenger) CuratedCommunities() (*communities.KnownCommunitiesResponse,
return nil, errors.New("contract maker not initialized") return nil, errors.New("contract maker not initialized")
} }
// Revert code to https://github.com/status-im/status-go/blob/e6a3f63ec7f2fa691878ed35f921413dc8acfc66/protocol/messenger_communities.go#L211-L226 once the curated communities contract is deployed to mainnet testNetworksEnabled, err := m.settings.GetTestNetworksEnabled()
if err != nil {
return nil, err
}
chainID := uint64(420) // Optimism Goerli chainID := uint64(10) // Optimism Mainnet
if testNetworksEnabled {
chainID = 420 // Optimism Goerli
}
directory, err := m.contractMaker.NewDirectory(chainID) directory, err := m.contractMaker.NewDirectory(chainID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// --- end delete
callOpts := &bind.CallOpts{Context: context.Background(), Pending: false} callOpts := &bind.CallOpts{Context: context.Background(), Pending: false}
@ -664,21 +669,11 @@ func (m *Messenger) CuratedCommunities() (*communities.KnownCommunitiesResponse,
return nil, err return nil, err
} }
// TODO: The curated communities smart contract should also store the community shard cluster and index
for _, c := range featuredCommunities { for _, c := range featuredCommunities {
response.ContractFeaturedCommunities = append(response.ContractFeaturedCommunities, types.HexBytes(c).String()) response.ContractFeaturedCommunities = append(response.ContractFeaturedCommunities, types.HexBytes(c).String())
// TODO: use CommunityShard instead of communityID
/*response.ContractFeaturedCommunities = append(response.ContractFeaturedCommunities, communities.CommunityShard{
CommunityID: types.HexBytes(c).String(),
// Shard: c.Shard, // TODO: obtain this value
})*/
} }
// TODO: this loop is added just to not revert the change from requestCommunitiesFromMailserver // TODO: use mechanism to obtain shard from community ID (https://github.com/status-im/status-desktop/issues/12585)
// Once support for shards is added in the contract, just pass the `response.UnknownCommunities` directly to
// the function
var unknownCommunities []communities.CommunityShard var unknownCommunities []communities.CommunityShard
for _, u := range response.UnknownCommunities { for _, u := range response.UnknownCommunities {
unknownCommunities = append(unknownCommunities, communities.CommunityShard{ unknownCommunities = append(unknownCommunities, communities.CommunityShard{