eth 0.5.9 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,73 +0,0 @@
1
- # Copyright (c) 2016-2023 The Ruby-Eth Contributors
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "net/http"
16
-
17
- # Provides the {Eth} module.
18
- module Eth
19
-
20
- # Provides an HTTP/S-RPC client with basic authentication.
21
- class Client::HttpAuth < Client
22
-
23
- # The host of the HTTP endpoint.
24
- attr_reader :host
25
-
26
- # The port of the HTTP endpoint.
27
- attr_reader :port
28
-
29
- # The full URI of the HTTP endpoint, including path.
30
- attr_reader :uri
31
-
32
- # Attribute indicator for SSL.
33
- attr_reader :ssl
34
-
35
- # Attribute for user.
36
- attr_reader :user
37
-
38
- # Constructor for the HTTP Client. Should not be used; use
39
- # {Client.create} intead.
40
- #
41
- # @param host [String] an URI pointing to an HTTP RPC-API.
42
- def initialize(host)
43
- super
44
- uri = URI.parse(host)
45
- raise ArgumentError, "Unable to parse the HTTP-URI!" unless ["http", "https"].include? uri.scheme
46
- @host = uri.host
47
- @port = uri.port
48
- @ssl = uri.scheme == "https"
49
- @user = uri.user
50
- @password = uri.password
51
- @uri = URI("#{uri.scheme}://#{uri.user}:#{uri.password}@#{@host}:#{@port}#{uri.path}")
52
- end
53
-
54
- # Sends an RPC request to the connected HTTP client.
55
- #
56
- # @param payload [Hash] the RPC request parameters.
57
- # @return [String] a JSON-encoded response.
58
- def send(payload)
59
- http = Net::HTTP.new(@host, @port)
60
- http.use_ssl = @ssl
61
- header = { "Content-Type" => "application/json" }
62
- request = Net::HTTP::Post.new(@uri, header)
63
- request.body = payload
64
- response = http.request(request)
65
- response.body
66
- end
67
- end
68
-
69
- private
70
-
71
- # Attribute for password.
72
- attr_reader :password
73
- end