casper_network 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/casper_network.rb +151 -95
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3400a276df32c88603c8690f8a4d55f983e835054035a95252abe343676f152d
4
- data.tar.gz: 8faa7b87cc8ad17b4c7ca5c4a5879ba6bd3670aa4a8350f149069eded499429d
3
+ metadata.gz: f1844fc3cd9eedecd9935d31d099666dae34d6e863e797dca8bc40b18c9d8f37
4
+ data.tar.gz: 52ae933784296f3a4a488bb8068200b4018ecf3530cc69eaa7b3046b26987129
5
5
  SHA512:
6
- metadata.gz: df1f649a2132cdc74d72b583f62f4fe669db0628d492f9bdee84d556d3cef795c342411e64a948d171fa0070f1417cd4256a684368a0ca1e176693d23910aba7
7
- data.tar.gz: 3811aebdeb5c104dd91907cf1afc082439e7ebb4d4fbdc939865ea9bd25b4928e317a7417ec0bca9b9fa4458d2cd8376cc86c2119e61a9e7fb87b5639864490f
6
+ metadata.gz: 6b93a15e23d06b420edba0ee9dddcc18945d48ddde62ef1415358f4a593bbf90e94107a68ece219523ea84460c50e57f30c0ebf4caa1230670000455af6cb6d5
7
+ data.tar.gz: 45c008a7a384a30808c8cd5d01dbc73fdcd917c04d4d2c9e746c664bf58eb356f0e4a0b0997ca4a728b2b5470583b1b59d4913181e19fedfe716dd03ae1911f0
@@ -13,58 +13,27 @@ class CasperClient
13
13
  attr_accessor :ip_address, :port, :url, :state_root_hash
14
14
 
15
15
  # Constructor
16
- # * @param ip_address
17
- # * @param port
18
- def initialize(ip_address, port = 7777)
16
+ # @param [String] ip_address
17
+ def initialize(ip_address)
19
18
  @ip_address = ip_address
20
- @port = port
21
- @url = "http://" + self.ip_address + ":" + self.port.to_s + "/rpc"
22
-
23
- # begin
24
- # response = RestClient.get(self.url)
25
- # rescue RestClient::ResourceNotFound => e
26
- # # p e.class
27
- # p "ResourceNotFound"
28
- # # rescue SocketError => e
29
- # # p e.class
30
- # rescue Errno::ECONNREFUSED => e
31
- # # p e.class
32
- # p "ECONNREFUSED"
33
- # rescue SocketError => e
34
- # p "In Socket errror"
35
- # end
36
-
19
+ @url = "http://" + @ip_address + ":7777/rpc"
37
20
  @state_root_hash = ""
38
21
  @peer_array = []
39
- @deploy_hash = ""
40
- @deploy_hashes = []
41
- @auction_state_array = []
42
- @auction_state = {}
22
+ @block_hash = ""
23
+ @deploy = {}
43
24
  @node_status = {}
44
25
  @block_transfers = []
45
26
  @block_info = {}
27
+ @era_summary = {}
28
+ @balance_value = ""
29
+ @auction_state = {}
46
30
  end
47
31
 
48
- # * @return peers array
32
+ # @return [Array<Hash>] peers array
49
33
  def info_get_peers
50
34
  begin
51
- status = Timeout::timeout(5) {
52
- begin
53
- response = RestClient.get(self.url)
54
- rescue RestClient::ResourceNotFound => e
55
- # p e.class
56
- p "ResourceNotFound"
57
- # rescue SocketError => e
58
- # p e.class
59
- rescue Errno::ECONNREFUSED => e
60
- # p e.class
61
- "ECONNREFUSED"
62
- rescue SocketError => e
63
- p "In Socket errror"
64
- end
65
- client = Jimson::Client.new(self.url)
66
-
67
-
35
+ status = Timeout::timeout(20) {
36
+ client = Jimson::Client.new(@url)
68
37
  result = client.info_get_peers
69
38
  @peer_array = result["peers"]
70
39
  }
@@ -73,11 +42,11 @@ class CasperClient
73
42
  end
74
43
  end
75
44
 
76
- # * @return state_root_hash value
77
- def chain_get_StateRootHash
45
+ # @return [String] state_root_hash value
46
+ def chain_get_StateRootHash(block_hash = "")
78
47
  begin
79
- status = Timeout::timeout(5) {
80
- client = Jimson::Client.new(self.url)
48
+ status = Timeout::timeout(10) {
49
+ client = Jimson::Client.new(@url)
81
50
  result = client.chain_get_state_root_hash
82
51
  @state_root_hash = result["state_root_hash"]
83
52
  }
@@ -87,72 +56,159 @@ class CasperClient
87
56
  end
88
57
 
89
58
  # Get information about a single deploy by hash.
90
- # * @param deploy_hash
91
- # * @return Deploy
92
- def info_get_deploy(deploy_Hash)
93
- @h = {'deploy_hash' => deploy_Hash }
94
- client = Jimson::Client.new(self.url)
95
- result = client.info_get_deploy(@h)
96
- hash1 = result["deploy"]
97
- @deploy_hash = result["deploy"]
59
+ # @param [String] deploy_hash
60
+ # @return [Hash] Deploy
61
+ def info_get_deploy(deploy_hash)
62
+ begin
63
+ status = Timeout::timeout(20) {
64
+ client = Jimson::Client.new(@url)
65
+ response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
66
+ @deploy = response["deploy"]
67
+ # @deploy.keys.each do |key|
68
+ # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
69
+ # end
70
+ @deploy
71
+ }
72
+ rescue
73
+ 'Timeout expired to retrieve Deploy!'
74
+ end
98
75
  end
99
76
 
100
- # Returns current auction system contract information.
101
- # * @return auction_state
102
- def state_get_AuctionInfo
103
- client = Jimson::Client.new(self.url)
104
- result = client.state_get_auction_info
105
- @auction_state = result['auction_state']
106
- end
107
77
 
108
- # * Receive node status information
109
- # * @return node_status
78
+ # Receive node status information
79
+ # @return node_status
110
80
  def info_get_status
111
- client = Jimson::Client.new(self.url)
112
- @node_status = client.info_get_status
81
+ begin
82
+ status = Timeout::timeout(10) {
83
+ client = Jimson::Client.new(@url)
84
+ @node_status = client.info_get_status
85
+ }
86
+ rescue
87
+ 'Timeout expired to retrieve node status information'
88
+ end
113
89
  end
114
90
 
115
- # * @return block_transfers
116
- def chain_get_block_transfers
117
- client = Jimson::Client.new(self.url)
118
- @block_transfers = client.chain_get_block_transfers["transfers"]
91
+ # @param [String] block_hash
92
+ # @return [Array<Hash>] block_transfers
93
+ def chain_get_block_transfers(block_hash = "")
94
+ begin
95
+ status = Timeout::timeout(5) {
96
+ client = Jimson::Client.new(@url)
97
+ response = client.chain_get_block_transfers({
98
+ "block_identifier" => {"Hash" => block_hash}
99
+ })
100
+ @block_transfers = response["transfers"]
101
+ @block_transfers
102
+ }
103
+ rescue
104
+ 'Timeout expired to retrieve block_transfers'
105
+ end
119
106
  end
120
107
 
121
- # * @return block_info
108
+ # @param [String] block_hash
109
+ # @return [Hash] block_info
122
110
  def chain_get_block(block_hash)
123
- client = Jimson::Client.new(self.url)
124
- result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
125
- @block_info = result["block"]
126
- if (!@block_info.empty?() && @block_info["hash"] != block_hash)
127
- raise("Returned block does not have a matching hash.")
128
- else
129
- @block_info
111
+ begin
112
+ state = Timeout::timeout(10) {
113
+ client = Jimson::Client.new(@url)
114
+ result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
115
+ @block_info = result["block"]
116
+ if (!@block_info.empty?() && @block_info["hash"] != block_hash)
117
+ raise("Returned block does not have a matching hash.")
118
+ else
119
+ @block_info
120
+ end
121
+ }
122
+ rescue
123
+ 'Timeout expired to retrieve block_info'
130
124
  end
131
125
  end
132
126
 
133
- # * @param block_hash
134
- # * @return era_summary
135
- def chain_get_eraInfo_by_SwitchBlock
136
- client = Jimson::Client.new(self.url)
137
- result = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
138
- result["era_summary"]
127
+ # @param [String] block_hash
128
+ # @return [Hash] era_summary
129
+ def chain_get_eraInfo_by_SwitchBlock(block_hash)
130
+ begin
131
+ state = Timeout::timeout(60) {
132
+ client = Jimson::Client.new(@url)
133
+ response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
134
+ @era_summary = response["era_summary"]
135
+ @era_summary
136
+ }
137
+ rescue
138
+ 'Timeout expired to retrieve era_summary'
139
+ end
139
140
  end
140
141
 
141
- # * @param state_root_hash
142
- # * @param key
143
- # * @param path
144
- def state_get_item(stateRootHash, key, path)
145
- client = Jimson::Client.new(self.url)
146
- response = client.state_get_item({
147
- "state_root_hash" => stateRootHash,
148
- "key" => key,
149
- "path" => path
150
- })
151
- response["stored_value"]
142
+ # @param [String] state_root_hash
143
+ # @param [String] key
144
+ # @param [Array] path
145
+ def state_get_item(state_root_hash, key, path)
146
+ begin
147
+ state = Timeout::timeout(20) {
148
+ client = Jimson::Client.new(@url)
149
+ response = client.state_get_item({
150
+ "state_root_hash" => state_root_hash,
151
+ "key" => key,
152
+ "path" => path
153
+ })
154
+ @stored_value = response["stored_value"]
155
+ @stored_value
156
+ }
157
+ rescue
158
+ 'Timeout expired to retrieve stored_value'
159
+ end
160
+ end
161
+
162
+ # @param [String] state_root_hash
163
+ # @param [String] item_key
164
+ # @param [String] uref
165
+ def state_get_dictionary_item(state_root_hash, item_key, uref)
166
+ begin
167
+ state = Timeout::timeout(5) {
168
+ client = Jimson::Client.new(@url)
169
+ response = client.state_get_dictionary_item({
170
+ "state_root_hash" => state_root_hash,
171
+ "dictionary_identifier" => {'URef' =>
172
+ {'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
173
+ @stored_value = response["stored_value"]
174
+ @stored_value
175
+ }
176
+ rescue
177
+ 'Timeout expired to retrieve stored_value'
178
+ end
152
179
  end
153
180
 
154
- def state_get_dictionary_item
181
+ # @param [String] state_root_hash
182
+ # @param [String] balance_uref
183
+ def state_get_balance(state_root_hash, balance_uref)
184
+ begin
185
+ state = Timeout::timeout(5) {
186
+ client = Jimson::Client.new(@url)
187
+ response = client.state_get_balance({
188
+ "state_root_hash" => state_root_hash,
189
+ "purse_uref" => balance_uref
190
+ })
191
+ @balance_value = response["balance_value"]
192
+ @balance_value
193
+ }
194
+ rescue
195
+ 'Timeout expired to retrieve balance_value'
196
+ end
155
197
  end
156
198
 
199
+ # Returns current auction system contract information.
200
+ # @return [Hash] auction_state
201
+ def state_get_AuctionInfo
202
+ begin
203
+ state = Timeout::timeout(50) {
204
+ client = Jimson::Client.new(@url)
205
+ response = client.state_get_auction_info
206
+ @auction_state = response['auction_state']
207
+ @auction_state
208
+ }
209
+ rescue
210
+ 'Timeout expired to retrieve auction_state information!'
211
+ end
212
+ end
157
213
  end
158
214
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casper_network
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Sait Gülmez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem enables developers to interact with the Casper Network.
14
14
  email: cenggulmez.65@gmail.com