casper_network 0.1.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.
- checksums.yaml +7 -0
- data/lib/casper_network.rb +158 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3400a276df32c88603c8690f8a4d55f983e835054035a95252abe343676f152d
|
4
|
+
data.tar.gz: 8faa7b87cc8ad17b4c7ca5c4a5879ba6bd3670aa4a8350f149069eded499429d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df1f649a2132cdc74d72b583f62f4fe669db0628d492f9bdee84d556d3cef795c342411e64a948d171fa0070f1417cd4256a684368a0ca1e176693d23910aba7
|
7
|
+
data.tar.gz: 3811aebdeb5c104dd91907cf1afc082439e7ebb4d4fbdc939865ea9bd25b4928e317a7417ec0bca9b9fa4458d2cd8376cc86c2119e61a9e7fb87b5639864490f
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# casper_network.rb
|
2
|
+
require 'jimson'
|
3
|
+
require 'json'
|
4
|
+
require 'rdoc/rdoc'
|
5
|
+
require "ipaddress"
|
6
|
+
require 'resolv'
|
7
|
+
require 'rest-client'
|
8
|
+
require 'active_support/core_ext/hash/keys'
|
9
|
+
require 'timeout'
|
10
|
+
|
11
|
+
# Class for interacting with the network via RPC
|
12
|
+
class CasperClient
|
13
|
+
attr_accessor :ip_address, :port, :url, :state_root_hash
|
14
|
+
|
15
|
+
# Constructor
|
16
|
+
# * @param ip_address
|
17
|
+
# * @param port
|
18
|
+
def initialize(ip_address, port = 7777)
|
19
|
+
@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
|
+
|
37
|
+
@state_root_hash = ""
|
38
|
+
@peer_array = []
|
39
|
+
@deploy_hash = ""
|
40
|
+
@deploy_hashes = []
|
41
|
+
@auction_state_array = []
|
42
|
+
@auction_state = {}
|
43
|
+
@node_status = {}
|
44
|
+
@block_transfers = []
|
45
|
+
@block_info = {}
|
46
|
+
end
|
47
|
+
|
48
|
+
# * @return peers array
|
49
|
+
def info_get_peers
|
50
|
+
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
|
+
|
68
|
+
result = client.info_get_peers
|
69
|
+
@peer_array = result["peers"]
|
70
|
+
}
|
71
|
+
rescue Timeout::Error
|
72
|
+
'Timeout expired to retrieve peers!'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# * @return state_root_hash value
|
77
|
+
def chain_get_StateRootHash
|
78
|
+
begin
|
79
|
+
status = Timeout::timeout(5) {
|
80
|
+
client = Jimson::Client.new(self.url)
|
81
|
+
result = client.chain_get_state_root_hash
|
82
|
+
@state_root_hash = result["state_root_hash"]
|
83
|
+
}
|
84
|
+
rescue
|
85
|
+
'Timeout expired to retrieve state_root_hash value!'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# 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"]
|
98
|
+
end
|
99
|
+
|
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
|
+
|
108
|
+
# * Receive node status information
|
109
|
+
# * @return node_status
|
110
|
+
def info_get_status
|
111
|
+
client = Jimson::Client.new(self.url)
|
112
|
+
@node_status = client.info_get_status
|
113
|
+
end
|
114
|
+
|
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"]
|
119
|
+
end
|
120
|
+
|
121
|
+
# * @return block_info
|
122
|
+
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
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
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"]
|
139
|
+
end
|
140
|
+
|
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"]
|
152
|
+
end
|
153
|
+
|
154
|
+
def state_get_dictionary_item
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: casper_network
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mehmet Sait Gülmez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby gem enables developers to interact with the Casper Network.
|
14
|
+
email: cenggulmez.65@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/casper_network.rb
|
20
|
+
homepage: https://github.com/saitgulmez/casper-ruby-sdk.git
|
21
|
+
licenses:
|
22
|
+
- Apache-2.0
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.3.4
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Casper Ruby SDK
|
43
|
+
test_files: []
|