client.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "github.com/ethereum/go-ethereum/log"
  7. "github.com/ethereum/go-ethereum/private/engine"
  8. )
  9. func CreateClient(cfg Config) (*engine.Client, error) {
  10. var client *engine.Client
  11. if IsSocketConfigured(cfg) {
  12. log.Info("Connecting to private tx manager using IPC socket")
  13. client = &engine.Client{
  14. HttpClient: &http.Client{
  15. Transport: unixTransport(cfg),
  16. },
  17. BaseURL: "http+unix://c",
  18. }
  19. } else {
  20. transport := httpTransport(cfg)
  21. if cfg.TlsMode == TlsOff {
  22. log.Info("Connecting to private tx manager using HTTP")
  23. } else {
  24. log.Info("Connecting to private tx manager using HTTPS")
  25. tlsConfig, err := newTLSConfig(cfg)
  26. if err != nil {
  27. return nil, fmt.Errorf("unable to create http.client to private tx manager due to: %s", err)
  28. }
  29. transport.TLSClientConfig = tlsConfig
  30. }
  31. client = &engine.Client{
  32. HttpClient: &http.Client{
  33. Timeout: time.Duration(cfg.Timeout) * time.Second,
  34. Transport: transport,
  35. },
  36. BaseURL: cfg.HttpUrl,
  37. }
  38. }
  39. return client, nil
  40. }