github.com/tacshi/go-ethereum@v0.0.0-20230616113857-84a434e20921/rpc/client_arbitrum.go (about) 1 // Copyright 2022 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package rpc 18 19 import ( 20 "context" 21 "fmt" 22 "net/http" 23 "net/url" 24 ) 25 26 func DialTransport(ctx context.Context, rawUrl string, transport *http.Transport) (*Client, error) { 27 u, err := url.Parse(rawUrl) 28 if err != nil { 29 return nil, err 30 } 31 32 var rpcClient *Client 33 switch u.Scheme { 34 case "http", "https": 35 client := &http.Client{ 36 Transport: transport, 37 } 38 rpcClient, err = DialHTTPWithClient(rawUrl, client) 39 case "ws", "wss": 40 rpcClient, err = DialWebsocket(ctx, rawUrl, "") 41 case "stdio": 42 return DialStdIO(ctx) 43 case "": 44 return DialIPC(ctx, rawUrl) 45 default: 46 return nil, fmt.Errorf("no known transport for scheme %q in URL %s", u.Scheme, rawUrl) 47 } 48 if err != nil { 49 return nil, err 50 } 51 return rpcClient, nil 52 }