prysm-pulse/beacon-chain/node/fetch_contract_address.go
Preston Van Loon 210edfc940 P2P handshake handling (#2306)
* proto: illegal wireType 7 :(

* set addr to todo for now so somethign gets sent

* push latest progress

* Add feedback from @raulk. Stream never connects

* working handshake handler

* add exclusions for relay/bootstrap node

* fix tests, still need to add new ones

* remove race, fails coverage

* Add test for negotiation

* gazelle

* regen pb

* Update shared/p2p/handshake_handler.go

Co-Authored-By: prestonvanloon <preston@prysmaticlabs.com>
2019-04-27 14:08:27 -05:00

42 lines
848 B
Go

package node
import (
"io/ioutil"
"net/http"
"sync"
"github.com/prysmaticlabs/prysm/shared/params"
)
var cachedDepositAddress string
var fetchLock sync.Mutex
// fetchDepositContract from the cluster endpoint.
func fetchDepositContract() (string, error) {
fetchLock.Lock()
defer fetchLock.Unlock()
if cachedDepositAddress != "" {
return cachedDepositAddress, nil
}
log.WithField(
"endpoint",
params.BeaconConfig().TestnetContractEndpoint,
).Info("Fetching testnet cluster address")
resp, err := http.Get(params.BeaconConfig().TestnetContractEndpoint)
if err != nil {
return "", err
}
contractResponse, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
if err := resp.Body.Close(); err != nil {
return "", err
}
cachedDepositAddress = string(contractResponse)
return cachedDepositAddress, nil
}