chore: hardcode optimism testnet for retrieving communities portal (#2810)

This commit is contained in:
Richard Ramos 2022-09-06 14:07:22 -04:00 committed by GitHub
parent e5408fa993
commit 37d3f9f612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package contracts
import ( import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/status-im/status-go/contracts/directory" "github.com/status-im/status-go/contracts/directory"
"github.com/status-im/status-go/contracts/registrar" "github.com/status-im/status-go/contracts/registrar"
"github.com/status-im/status-go/contracts/resolver" "github.com/status-im/status-go/contracts/resolver"
@ -133,3 +134,15 @@ func (c *ContractMaker) NewDirectory(chainID uint64) (*directory.Directory, erro
backend, backend,
) )
} }
func (c *ContractMaker) NewDirectoryWithBackend(chainID uint64, backend *ethclient.Client) (*directory.Directory, error) {
contractAddr, err := directory.ContractAddress(chainID)
if err != nil {
return nil, err
}
return directory.NewDirectory(
contractAddr,
backend,
)
}

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"go.uber.org/zap" "go.uber.org/zap"
@ -18,6 +19,7 @@ import (
"github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities" "github.com/status-im/status-go/protocol/communities"
"github.com/status-im/status-go/protocol/discord" "github.com/status-im/status-go/protocol/discord"
@ -208,20 +210,32 @@ func (m *Messenger) JoinedCommunities() ([]*communities.Community, error) {
} }
func (m *Messenger) CuratedCommunities() (*communities.KnownCommunitiesResponse, error) { func (m *Messenger) CuratedCommunities() (*communities.KnownCommunitiesResponse, error) {
testNetworksEnabled, err := m.settings.TestNetworksEnabled() // 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
chainID := uint64(69) // Optimism Kovan
sDB, err := accounts.NewDB(m.database)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nodeConfig, err := sDB.GetNodeConfig()
chainID := uint64(10) // Optimism (mainnet)
if testNetworksEnabled {
chainID = 69 // Optimism (kovan)
}
directory, err := m.contractMaker.NewDirectory(chainID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var backend *ethclient.Client
for _, n := range nodeConfig.Networks {
if n.ChainID == chainID {
b, err := ethclient.Dial(n.RPCURL)
if err != nil {
return nil, err
}
backend = b
}
}
directory, err := m.contractMaker.NewDirectoryWithBackend(chainID, backend)
if err != nil {
return nil, err
}
// --- end delete
callOpts := &bind.CallOpts{Context: context.Background(), Pending: false} callOpts := &bind.CallOpts{Context: context.Background(), Pending: false}