Class: CasperClient
- Inherits:
-
Object
- Object
- CasperClient
- Defined in:
- lib/casper_test.rb
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#port ⇒ Object
Returns the value of attribute port.
-
#state_root_hash ⇒ Object
Returns the value of attribute state_root_hash.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#chain_get_block(block_hash) ⇒ Object
def chain_get_block client = Jimson::Client.new(self.url) result = client.chain_get_block result end.
- #chain_get_block_transfers ⇒ Object
-
#chain_get_eraInfo_by_SwitchBlock(block_hash) ⇒ Object
-
@param block_hash * @return era_summary.
-
-
#chain_get_StateRootHash ⇒ Object
Return state_root_hash value.
-
#info_get_deploy(deploy_Hash) ⇒ Object
Get information about a single deploy by deploy hash.
-
#info_get_peers ⇒ Object
-
@return peers array.
-
-
#info_get_status ⇒ Object
-
Receive node status information * @return node_status.
-
-
#initialize(ip_address) ⇒ CasperClient
constructor
A new instance of CasperClient.
-
#state_get_AuctionInfo ⇒ Object
Returns current auction system contract information.
- #state_get_balance ⇒ Object
- #state_get_dictionary_item ⇒ Object
-
#state_get_item(stateRootHash, key, path) ⇒ Object
-
@param stateRootHash * @param key * @param path.
-
Constructor Details
#initialize(ip_address) ⇒ CasperClient
Returns a new instance of CasperClient.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/casper_test.rb', line 14 def initialize(ip_address) @ip_address = ip_address @url = "http://" + ip_address + ":7777/rpc" # temp = "http://" + ip_address + ":7777" # response = RestClient.get(temp) # rescue RestClient::ResourceNotFound => e # p e.class # rescue SocketError => e # p e.class # rescue Errno::ECONNREFUSED => e # p e.class # rescue SocketError => e # puts "In Socket errror" # rescue => e # puts (e.class.inspect) # end @state_root_hash = "" @peer_array = [] @deploy_hash = "" @deploy_hashes = [] @auction_state_array = [] @auction_state = {} @node_status = {} @block_transfers = [] @block_info = {} end |
Instance Attribute Details
#ip_address ⇒ Object
Returns the value of attribute ip_address.
12 13 14 |
# File 'lib/casper_test.rb', line 12 def ip_address @ip_address end |
#port ⇒ Object
Returns the value of attribute port.
12 13 14 |
# File 'lib/casper_test.rb', line 12 def port @port end |
#state_root_hash ⇒ Object
Returns the value of attribute state_root_hash.
12 13 14 |
# File 'lib/casper_test.rb', line 12 def state_root_hash @state_root_hash end |
#url ⇒ Object
Returns the value of attribute url.
12 13 14 |
# File 'lib/casper_test.rb', line 12 def url @url end |
Instance Method Details
#chain_get_block(block_hash) ⇒ Object
def chain_get_block
client = Jimson::Client.new(self.url)
result = client.chain_get_block
result
end
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/casper_test.rb', line 121 def chain_get_block(block_hash) client = Jimson::Client.new(self.url) result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}}) @block_info = result["block"] if (!@block_info.empty?() && @block_info["hash"] != block_hash) raise("error") else @block_info end end |
#chain_get_block_transfers ⇒ Object
110 111 112 113 114 |
# File 'lib/casper_test.rb', line 110 def chain_get_block_transfers client = Jimson::Client.new(self.url) @block_transfers = client.chain_get_block_transfers["transfers"] @block_transfers end |
#chain_get_eraInfo_by_SwitchBlock(block_hash) ⇒ Object
-
@param block_hash
-
@return era_summary
136 137 138 139 140 |
# File 'lib/casper_test.rb', line 136 def chain_get_eraInfo_by_SwitchBlock(block_hash) client = Jimson::Client.new(self.url) result = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash}) result["era_summary"] end |
#chain_get_StateRootHash ⇒ Object
Return state_root_hash value
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/casper_test.rb', line 67 def chain_get_StateRootHash begin status = Timeout::timeout(5) { client = Jimson::Client.new(self.url) result = client.chain_get_state_root_hash @state_root_hash = result["state_root_hash"] @state_root_hash } rescue Timeout::Error # puts e.message "Timeout!" end end |
#info_get_deploy(deploy_Hash) ⇒ Object
Get information about a single deploy by deploy hash.
-
@param deploy_hash
-
@return Deploy
84 85 86 87 88 89 |
# File 'lib/casper_test.rb', line 84 def info_get_deploy(deploy_Hash) client = Jimson::Client.new(self.url) result = client.info_get_deploy({'deploy_hash' => deploy_Hash }) @deploy_hash = result["deploy"] @deploy_hash end |
#info_get_peers ⇒ Object
-
@return peers array
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/casper_test.rb', line 43 def info_get_peers begin status = Timeout::timeout(5) { # Something that should be interrupted if it takes too much time... client = Jimson::Client.new(self.url) result = client.info_get_peers # result.map! { |item| item.symbolize_keys } # @peer_array = result["peers"] # @peer_array values = result["peers"] } rescue Timeout::Error puts 'Timeout!' end # values.map! do |peer| # peer.symbolize_keys # end # values[0][:address] # a = {"a"=>1, "b"=>2, "c"=>3} # b = a.symbolize_keys # b[:a] end |
#info_get_status ⇒ Object
-
Receive node status information
-
@return node_status
104 105 106 107 108 |
# File 'lib/casper_test.rb', line 104 def info_get_status client = Jimson::Client.new(self.url) @node_status = client.info_get_status @node_status end |
#state_get_AuctionInfo ⇒ Object
Returns current auction system contract information.
93 94 95 96 97 98 99 100 |
# File 'lib/casper_test.rb', line 93 def state_get_AuctionInfo client = Jimson::Client.new(self.url) result = client.state_get_auction_info @auction_state = result['auction_state'] @auction_state.to_json @auction_state["state_root_hash"] @auction_state[0] end |
#state_get_balance ⇒ Object
156 157 |
# File 'lib/casper_test.rb', line 156 def state_get_balance end |
#state_get_dictionary_item ⇒ Object
151 152 153 154 |
# File 'lib/casper_test.rb', line 151 def state_get_dictionary_item client = Jimson::Client.new(self.url) response = client.GetDictionaryItem end |
#state_get_item(stateRootHash, key, path) ⇒ Object
-
@param stateRootHash
-
@param key
-
@param path
145 146 147 148 149 |
# File 'lib/casper_test.rb', line 145 def state_get_item(stateRootHash, key, path) client = Jimson::Client.new(self.url) response = client.state_get_item({ "state_root_hash" => stateRootHash, "key" => key, "path" => path}) response["stored_value"] end |