test_sdk1 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE +201 -0
- data/README.md +147 -0
- data/SECURITY.md +12 -0
- data/lib/crypto/00_asymmetric_key.rb +95 -0
- data/lib/crypto/01_ed25519.rb +67 -0
- data/lib/crypto/asymmetric_key.rb +87 -0
- data/lib/crypto/ed25519_key.rb +44 -0
- data/lib/crypto/key_pair.rb +40 -0
- data/lib/crypto/keys.rb +7 -0
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +44 -0
- data/lib/entity/account.rb +45 -0
- data/lib/entity/action_thresholds.rb +25 -0
- data/lib/entity/associated_key.rb +24 -0
- data/lib/entity/auction_state.rb +36 -0
- data/lib/entity/bid.rb +24 -0
- data/lib/entity/bid_info.rb +51 -0
- data/lib/entity/contract.rb +47 -0
- data/lib/entity/contract_package.rb +41 -0
- data/lib/entity/contract_version.rb +33 -0
- data/lib/entity/delegator.rb +37 -0
- data/lib/entity/deploy.rb +44 -0
- data/lib/entity/deploy_approval.rb +24 -0
- data/lib/entity/deploy_executable.rb +162 -0
- data/lib/entity/deploy_executable_item_internal.rb +26 -0
- data/lib/entity/deploy_executable_transfer.rb +50 -0
- data/lib/entity/deploy_hash.rb +16 -0
- data/lib/entity/deploy_header.rb +60 -0
- data/lib/entity/deploy_info.rb +44 -0
- data/lib/entity/deploy_named_argument.rb +19 -0
- data/lib/entity/deploy_transfer.rb +10 -0
- data/lib/entity/disabled_version.rb +26 -0
- data/lib/entity/era_info.rb +18 -0
- data/lib/entity/era_summary.rb +44 -0
- data/lib/entity/era_validator.rb +23 -0
- data/lib/entity/executable_deploy_item.rb +11 -0
- data/lib/entity/group.rb +25 -0
- data/lib/entity/module_bytes.rb +50 -0
- data/lib/entity/peer.rb +25 -0
- data/lib/entity/seigniorage_allocation.rb +18 -0
- data/lib/entity/stored_contract_by_hash.rb +50 -0
- data/lib/entity/stored_contract_by_name.rb +50 -0
- data/lib/entity/stored_value.rb +57 -0
- data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
- data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
- data/lib/entity/transfer.rb +65 -0
- data/lib/entity/validator_weight.rb +23 -0
- data/lib/entity/vesting_schedule.rb +22 -0
- data/lib/include.rb +18 -0
- data/lib/rpc/rpc.rb +227 -0
- data/lib/rpc/rpc_client.rb +233 -0
- data/lib/rpc/rpc_error.rb +79 -0
- data/lib/serialization/cl_type_serializer.rb +76 -0
- data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
- data/lib/serialization/cl_value_serializer.rb +259 -0
- data/lib/serialization/deploy_approval_serializer.rb +15 -0
- data/lib/serialization/deploy_executable_serializer.rb +27 -0
- data/lib/serialization/deploy_header_serializer.rb +49 -0
- data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
- data/lib/serialization/deploy_serializer.rb +268 -0
- data/lib/serialization/test.rb +431 -0
- data/lib/test_sdk1.rb +289 -0
- data/lib/types/cl_account_hash.rb +24 -0
- data/lib/types/cl_account_hash_type.rb +22 -0
- data/lib/types/cl_any.rb +25 -0
- data/lib/types/cl_any_type.rb +22 -0
- data/lib/types/cl_bool.rb +32 -0
- data/lib/types/cl_bool_type.rb +35 -0
- data/lib/types/cl_byte_array.rb +25 -0
- data/lib/types/cl_byte_array_type.rb +27 -0
- data/lib/types/cl_i32.rb +26 -0
- data/lib/types/cl_i32_type.rb +26 -0
- data/lib/types/cl_i64.rb +26 -0
- data/lib/types/cl_i64_type.rb +27 -0
- data/lib/types/cl_key.rb +39 -0
- data/lib/types/cl_key_type.rb +27 -0
- data/lib/types/cl_list.rb +25 -0
- data/lib/types/cl_list_type.rb +26 -0
- data/lib/types/cl_map.rb +25 -0
- data/lib/types/cl_map_type.rb +26 -0
- data/lib/types/cl_option.rb +33 -0
- data/lib/types/cl_option_type.rb +52 -0
- data/lib/types/cl_public_key.rb +152 -0
- data/lib/types/cl_public_key_type.rb +26 -0
- data/lib/types/cl_result.rb +25 -0
- data/lib/types/cl_result_type.rb +26 -0
- data/lib/types/cl_string.rb +39 -0
- data/lib/types/cl_string_type.rb +32 -0
- data/lib/types/cl_tuple.rb +151 -0
- data/lib/types/cl_tuple_type.rb +108 -0
- data/lib/types/cl_type.rb +94 -0
- data/lib/types/cl_type_tag.rb +51 -0
- data/lib/types/cl_u128.rb +26 -0
- data/lib/types/cl_u128_type.rb +26 -0
- data/lib/types/cl_u256.rb +26 -0
- data/lib/types/cl_u256_type.rb +26 -0
- data/lib/types/cl_u32.rb +26 -0
- data/lib/types/cl_u32_type.rb +26 -0
- data/lib/types/cl_u512.rb +26 -0
- data/lib/types/cl_u512_type.rb +26 -0
- data/lib/types/cl_u64.rb +26 -0
- data/lib/types/cl_u64_type.rb +27 -0
- data/lib/types/cl_u8.rb +26 -0
- data/lib/types/cl_u8_type.rb +26 -0
- data/lib/types/cl_unit.rb +38 -0
- data/lib/types/cl_unit_type.rb +22 -0
- data/lib/types/cl_uref.rb +120 -0
- data/lib/types/cl_uref_type.rb +46 -0
- data/lib/types/cl_value.rb +10 -0
- data/lib/types/constants.rb +50 -0
- data/lib/types/error.rb +7 -0
- data/lib/utils/base_16.rb +18 -0
- data/lib/utils/byte_utils.rb +107 -0
- data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
- data/lib/utils/hash_utils.rb +19 -0
- data/lib/utils/hex_utils.rb +12 -0
- data/lib/utils/time_utils.rb +85 -0
- data/lib/utils/utils.rb +2 -0
- data/lib/version.rb +3 -0
- data/spec/a_spec.rb +697 -0
- data/spec/byte_utils_spec.rb +72 -0
- data/spec/cl_public_spec.rb +169 -0
- data/spec/cl_types_spec.rb +715 -0
- data/spec/cl_value_serializer_spec.rb +140 -0
- data/spec/client_spec.rb +25 -0
- data/spec/crypto_spec.rb +42 -0
- data/spec/deploy_approval_serializer_spec.rb +26 -0
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_header_serializer_spec.rb +21 -0
- data/spec/deploy_named_arg_serializer_spec.rb +49 -0
- data/spec/deploy_serializer_spec.rb +77 -0
- data/spec/deploy_serializer_test_spec.rb +225 -0
- data/spec/mainnet_spec.rb +452 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/string_spec.rb +68 -0
- data/spec/testnet_spec.rb +498 -0
- data/spec/time_utils_spec.rb +87 -0
- metadata +198 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative './deploy_executable_item_internal.rb'
|
2
|
+
|
3
|
+
module Casper
|
4
|
+
module Entity
|
5
|
+
class StoredVersionedContractByName < DeployExecutableItemInternal
|
6
|
+
|
7
|
+
# @param [String] name
|
8
|
+
# @param [Integer] version
|
9
|
+
# @param [String] entry_point
|
10
|
+
# @param [Array<Array<DeployNamedArgument>>] args
|
11
|
+
def initialize(name, version, entry_point, args)
|
12
|
+
@tag = 4
|
13
|
+
@name = name
|
14
|
+
@version = version
|
15
|
+
@entry_point = entry_point
|
16
|
+
@args = args
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_tag
|
20
|
+
@tag
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_name
|
24
|
+
@name
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_version
|
28
|
+
@version
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_entry_point
|
32
|
+
@entry_point
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_args
|
36
|
+
@args
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_bytes
|
40
|
+
serializer = DeployNamedArgSerializer.new
|
41
|
+
num_of_args = @args.length
|
42
|
+
bytes = Utils::ByteUtils.to_u8(@tag)
|
43
|
+
bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@name)
|
44
|
+
if @version == nil
|
45
|
+
bytes += Utils::ByteUtils.to_u8(0)
|
46
|
+
else
|
47
|
+
bytes += Utils::ByteUtils.to_u8(1)
|
48
|
+
end
|
49
|
+
bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@entry_point)
|
50
|
+
bytes += Utils::ByteUtils.to_u32(num_of_args)
|
51
|
+
@args.each do |arg|
|
52
|
+
arg.each do |item|
|
53
|
+
bytes += serializer.to_bytes(item)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
Utils::ByteUtils.hex_to_byte_array(bytes)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Casper
|
2
|
+
module Entity
|
3
|
+
class Transfer
|
4
|
+
|
5
|
+
# @param [Hash] transfer
|
6
|
+
# @option transfer [String] :deploy_hash
|
7
|
+
# @option transfer [String] :from
|
8
|
+
# @option transfer [String] :to
|
9
|
+
# @option transfer [String] :source
|
10
|
+
# @option transfer [String] :target
|
11
|
+
# @option transfer [String] :amount
|
12
|
+
# @option transfer [String] :gas
|
13
|
+
# @option transfer [Integer] :id
|
14
|
+
def initialize(transfer = {})
|
15
|
+
@deploy_hash = transfer[:deploy_hash]
|
16
|
+
@from = transfer[:from]
|
17
|
+
@to = transfer[:to]
|
18
|
+
@source = transfer[:source]
|
19
|
+
@target = transfer[:target]
|
20
|
+
@amount = transfer[:amount]
|
21
|
+
@gas = transfer[:gas]
|
22
|
+
@id = transfer[:id]
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String] deploy_hash
|
26
|
+
def get_deploy_hash
|
27
|
+
@deploy_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] from
|
31
|
+
def get_from
|
32
|
+
@from
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String] to
|
36
|
+
def get_to
|
37
|
+
@to
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String] source
|
41
|
+
def get_source
|
42
|
+
@source
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String] target
|
46
|
+
def get_target
|
47
|
+
@target
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String] amount
|
51
|
+
def get_amount
|
52
|
+
@amount
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] gas
|
56
|
+
def get_gas
|
57
|
+
@gas
|
58
|
+
end
|
59
|
+
# @return [Integer] id
|
60
|
+
def get_id
|
61
|
+
@id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Casper
|
2
|
+
module Entity
|
3
|
+
class ValidatorWeight
|
4
|
+
|
5
|
+
# @param [String] public_key
|
6
|
+
# @param [String] weight
|
7
|
+
def initialize(public_key, weight)
|
8
|
+
@public_key = public_key
|
9
|
+
@weight = weight
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String] public_key
|
13
|
+
def get_public_key
|
14
|
+
@public_key
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String] weight
|
18
|
+
def get_weight
|
19
|
+
@weight
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Casper
|
2
|
+
module Entity
|
3
|
+
|
4
|
+
# Vesting schedule for a genesis validator.
|
5
|
+
class VestingSchedule
|
6
|
+
|
7
|
+
def initialize(vesting_schedule = {})
|
8
|
+
@initial_release_timestamp_millis = vesting_schedule[:initial_release_timestamp_millis]
|
9
|
+
@locked_amounts = vesting_schedule[:locked_amounts]
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_initial_release_timestamp_millis
|
13
|
+
@initial_release_timestamp_millis
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_locked_amounts
|
17
|
+
@locked_amounts
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/include.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Dir["./types/*.rb"].each {|file| require file }
|
2
|
+
Dir[File.join(
|
3
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/types/*.rb")].each {|file| require file }
|
4
|
+
Dir[File.join(
|
5
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/entity/*.rb")].each {|file| require file }
|
6
|
+
Dir[File.join(
|
7
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/rpc/*.rb")].each {|file| require file }
|
8
|
+
Dir[File.join(
|
9
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/utils/*.rb")].each {|file| require file }
|
10
|
+
# path = File.join(
|
11
|
+
# File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
12
|
+
# '/lib/types/cl_bool'
|
13
|
+
# )
|
14
|
+
# puts path
|
15
|
+
# require path
|
16
|
+
# require_relative "./types/cl_bool.rb"
|
17
|
+
# require_relative "./types/cl_string.rb"
|
18
|
+
|
data/lib/rpc/rpc.rb
ADDED
@@ -0,0 +1,227 @@
|
|
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
|
+
require_relative '../entity/peer.rb'
|
11
|
+
module Casper
|
12
|
+
# Class for interacting with the network via RPC
|
13
|
+
class RpcClient
|
14
|
+
attr_accessor :ip_address, :port, :url, :state_root_hash
|
15
|
+
|
16
|
+
# Constructor
|
17
|
+
# @param [String] ip_address
|
18
|
+
def initialize(ip_address)
|
19
|
+
@ip_address = ip_address
|
20
|
+
@url = "http://" + @ip_address + ":7777/rpc"
|
21
|
+
@state_root_hash = ""
|
22
|
+
@peer_array = []
|
23
|
+
@block_hash = ""
|
24
|
+
@deploy = {}
|
25
|
+
@node_status = {}
|
26
|
+
@block_transfers = []
|
27
|
+
@block_info = {}
|
28
|
+
@era_summary = {}
|
29
|
+
@balance_value = ""
|
30
|
+
@auction_state = {}
|
31
|
+
|
32
|
+
@peers = []
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Array<Hash>] peers array
|
36
|
+
def info_get_peers
|
37
|
+
begin
|
38
|
+
status = Timeout::timeout(20) {
|
39
|
+
client = Jimson::Client.new(@url)
|
40
|
+
response = client.info_get_peers
|
41
|
+
response.deep_symbolize_keys!
|
42
|
+
@peer_array = response[:peers]
|
43
|
+
@peer_array.map { |item| @peers << Casper::Entity::Peer.new(item) }
|
44
|
+
# @peers[0].get_node_id
|
45
|
+
# @peers[0].get_node_id
|
46
|
+
# @peers[0].get_address
|
47
|
+
@peer_array
|
48
|
+
}
|
49
|
+
rescue Timeout::Error
|
50
|
+
'Timeout expired to retrieve peers!'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String] state_root_hash value
|
55
|
+
def chain_get_StateRootHash(block_hash = "")
|
56
|
+
begin
|
57
|
+
status = Timeout::timeout(10) {
|
58
|
+
client = Jimson::Client.new(@url)
|
59
|
+
result = client.chain_get_state_root_hash
|
60
|
+
@state_root_hash = result["state_root_hash"]
|
61
|
+
}
|
62
|
+
rescue
|
63
|
+
'Timeout expired to retrieve state_root_hash value!'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get information about a single deploy by hash.
|
68
|
+
# @param [String] deploy_hash
|
69
|
+
# @return [Hash] Deploy
|
70
|
+
def info_get_deploy(deploy_hash)
|
71
|
+
begin
|
72
|
+
status = Timeout::timeout(20) {
|
73
|
+
if (deploy_hash == "" || deploy_hash == nil)
|
74
|
+
return "Server error -32602: Invalid params"
|
75
|
+
end
|
76
|
+
client = Jimson::Client.new(@url)
|
77
|
+
response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
|
78
|
+
@deploy = response["deploy"]
|
79
|
+
# @deploy.keys.each do |key|
|
80
|
+
# @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
|
81
|
+
# end
|
82
|
+
@deploy
|
83
|
+
}
|
84
|
+
rescue
|
85
|
+
'Timeout expired to retrieve Deploy!'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Receive node status information
|
91
|
+
# @return node_status
|
92
|
+
def info_get_status
|
93
|
+
begin
|
94
|
+
status = Timeout::timeout(10) {
|
95
|
+
client = Jimson::Client.new(@url)
|
96
|
+
@node_status = client.info_get_status
|
97
|
+
}
|
98
|
+
rescue
|
99
|
+
'Timeout expired to retrieve node status information'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# @param [String] block_hash
|
104
|
+
# @return [Array<Hash>] block_transfers
|
105
|
+
def chain_get_block_transfers(block_hash = "")
|
106
|
+
begin
|
107
|
+
status = Timeout::timeout(5) {
|
108
|
+
client = Jimson::Client.new(@url)
|
109
|
+
response = client.chain_get_block_transfers({
|
110
|
+
"block_identifier" => {"Hash" => block_hash}
|
111
|
+
})
|
112
|
+
@block_transfers = response["transfers"]
|
113
|
+
@block_transfers
|
114
|
+
}
|
115
|
+
rescue
|
116
|
+
'Timeout expired to retrieve block_transfers'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# @param [String] block_hash
|
121
|
+
# @return [Hash] block_info
|
122
|
+
def chain_get_block(block_hash)
|
123
|
+
begin
|
124
|
+
state = Timeout::timeout(10) {
|
125
|
+
client = Jimson::Client.new(@url)
|
126
|
+
result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
|
127
|
+
@block_info = result["block"]
|
128
|
+
if (!@block_info.empty?() && @block_info["hash"] != block_hash)
|
129
|
+
raise("Returned block does not have a matching hash.")
|
130
|
+
else
|
131
|
+
@block_info
|
132
|
+
end
|
133
|
+
}
|
134
|
+
rescue
|
135
|
+
'Timeout expired to retrieve block_info'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# @param [String] block_hash
|
140
|
+
# @return [Hash] era_summary
|
141
|
+
def chain_get_eraInfo_by_SwitchBlock(block_hash)
|
142
|
+
begin
|
143
|
+
state = Timeout::timeout(60) {
|
144
|
+
client = Jimson::Client.new(@url)
|
145
|
+
response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
|
146
|
+
@era_summary = response["era_summary"]
|
147
|
+
@era_summary
|
148
|
+
}
|
149
|
+
rescue
|
150
|
+
'Timeout expired to retrieve era_summary'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# @param [String] state_root_hash
|
155
|
+
# @param [String] key
|
156
|
+
# @param [Array] path
|
157
|
+
def state_get_item(state_root_hash, key, path)
|
158
|
+
begin
|
159
|
+
state = Timeout::timeout(20) {
|
160
|
+
client = Jimson::Client.new(@url)
|
161
|
+
response = client.state_get_item({
|
162
|
+
"state_root_hash" => state_root_hash,
|
163
|
+
"key" => key,
|
164
|
+
"path" => path
|
165
|
+
})
|
166
|
+
@stored_value = response["stored_value"]
|
167
|
+
@stored_value
|
168
|
+
}
|
169
|
+
rescue
|
170
|
+
'Timeout expired to retrieve stored_value'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# @param [String] state_root_hash
|
175
|
+
# @param [String] item_key
|
176
|
+
# @param [String] uref
|
177
|
+
def state_get_dictionary_item(state_root_hash, item_key, uref)
|
178
|
+
begin
|
179
|
+
state = Timeout::timeout(5) {
|
180
|
+
client = Jimson::Client.new(@url)
|
181
|
+
response = client.state_get_dictionary_item({
|
182
|
+
"state_root_hash" => state_root_hash,
|
183
|
+
"dictionary_identifier" => {'URef' =>
|
184
|
+
{'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
|
185
|
+
@stored_value = response["stored_value"]
|
186
|
+
@stored_value
|
187
|
+
}
|
188
|
+
rescue
|
189
|
+
'Timeout expired to retrieve stored_value'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# @param [String] state_root_hash
|
194
|
+
# @param [String] balance_uref
|
195
|
+
def state_get_balance(state_root_hash, balance_uref)
|
196
|
+
begin
|
197
|
+
state = Timeout::timeout(5) {
|
198
|
+
client = Jimson::Client.new(@url)
|
199
|
+
response = client.state_get_balance({
|
200
|
+
"state_root_hash" => state_root_hash,
|
201
|
+
"purse_uref" => balance_uref
|
202
|
+
})
|
203
|
+
@balance_value = response["balance_value"]
|
204
|
+
@balance_value
|
205
|
+
}
|
206
|
+
rescue
|
207
|
+
'Timeout expired to retrieve balance_value'
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Returns current auction system contract information.
|
212
|
+
# @return [Hash] auction_state
|
213
|
+
def state_get_AuctionInfo
|
214
|
+
begin
|
215
|
+
state = Timeout::timeout(50) {
|
216
|
+
client = Jimson::Client.new(@url)
|
217
|
+
response = client.state_get_auction_info
|
218
|
+
@auction_state = response['auction_state']
|
219
|
+
@auction_state
|
220
|
+
}
|
221
|
+
rescue
|
222
|
+
'Timeout expired to retrieve auction_state information!'
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'jimson'
|
2
|
+
require 'json'
|
3
|
+
require 'rdoc/rdoc'
|
4
|
+
require "ipaddress"
|
5
|
+
require 'resolv'
|
6
|
+
require 'rest-client'
|
7
|
+
require 'active_support/core_ext/hash/keys'
|
8
|
+
require 'timeout'
|
9
|
+
require 'net/http'
|
10
|
+
require_relative './rpc_error.rb'
|
11
|
+
# Class for interacting with the network via RPC
|
12
|
+
module Casper
|
13
|
+
class RpcClient
|
14
|
+
attr_accessor :ip_address, :port, :url, :state_root_hash
|
15
|
+
|
16
|
+
# Constructor
|
17
|
+
# @param [String] ip_address
|
18
|
+
def initialize(ip_address)
|
19
|
+
@ip_address = ip_address
|
20
|
+
@url = "http://" + @ip_address + ":7777/rpc"
|
21
|
+
@state_root_hash = ""
|
22
|
+
@peer_array = []
|
23
|
+
@block_hash = ""
|
24
|
+
@deploy = {}
|
25
|
+
@node_status = {}
|
26
|
+
@block_transfers = []
|
27
|
+
@block_info = {}
|
28
|
+
@era_summary = {}
|
29
|
+
@balance_value = ""
|
30
|
+
@auction_state = {}
|
31
|
+
|
32
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
33
|
+
@err = @rpc_error.error_handling(@url)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_error
|
38
|
+
@err
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Array<Hash>] peers array
|
42
|
+
def info_get_peers
|
43
|
+
begin
|
44
|
+
client = Jimson::Client.new(@url)
|
45
|
+
response = client.info_get_peers
|
46
|
+
@peer_array = response["peers"]
|
47
|
+
rescue
|
48
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
49
|
+
@error = @rpc_error.error_handling(@url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [String] state_root_hash value
|
54
|
+
def chain_get_StateRootHash(block_hash = "")
|
55
|
+
begin
|
56
|
+
status = Timeout::timeout(10) {
|
57
|
+
client = Jimson::Client.new(@url)
|
58
|
+
result = client.chain_get_state_root_hash
|
59
|
+
@state_root_hash = result["state_root_hash"]
|
60
|
+
}
|
61
|
+
rescue
|
62
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
63
|
+
@error = @rpc_error.error_handling(@url)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get information about a single deploy by hash.
|
68
|
+
# @param [String] deploy_hash
|
69
|
+
# @return [Hash] Deploy
|
70
|
+
def info_get_deploy(deploy_hash)
|
71
|
+
begin
|
72
|
+
status = Timeout::timeout(10) {
|
73
|
+
client = Jimson::Client.new(@url)
|
74
|
+
response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
|
75
|
+
if (deploy_hash == "" || deploy_hash == nil)
|
76
|
+
Casper::RpcError::InvalidParameter.error
|
77
|
+
end
|
78
|
+
@deploy = response["deploy"]
|
79
|
+
# @deploy.keys.each do |key|
|
80
|
+
# @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
|
81
|
+
# end
|
82
|
+
@deploy
|
83
|
+
}
|
84
|
+
rescue
|
85
|
+
Casper::RpcError::InvalidParameter.error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Receive node status information
|
91
|
+
# @return node_status
|
92
|
+
def info_get_status
|
93
|
+
begin
|
94
|
+
status = Timeout::timeout(10) {
|
95
|
+
client = Jimson::Client.new(@url)
|
96
|
+
@node_status = client.info_get_status
|
97
|
+
}
|
98
|
+
rescue
|
99
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
100
|
+
@error = @rpc_error.error_handling(@url)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param [String] block_hash
|
105
|
+
# @return [Array<Hash>] block_transfers
|
106
|
+
def chain_get_block_transfers(block_hash = "")
|
107
|
+
begin
|
108
|
+
status = Timeout::timeout(5) {
|
109
|
+
client = Jimson::Client.new(@url)
|
110
|
+
response = client.chain_get_block_transfers({
|
111
|
+
"block_identifier" => {"Hash" => block_hash}
|
112
|
+
})
|
113
|
+
@block_transfers = response["transfers"]
|
114
|
+
@block_transfers
|
115
|
+
}
|
116
|
+
rescue
|
117
|
+
Casper::RpcError::InvalidParameter.error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param [String] block_hash
|
122
|
+
# @return [Hash] block_info
|
123
|
+
def chain_get_block(block_hash)
|
124
|
+
begin
|
125
|
+
state = Timeout::timeout(10) {
|
126
|
+
client = Jimson::Client.new(@url)
|
127
|
+
result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
|
128
|
+
@block_info = result["block"]
|
129
|
+
if (!@block_info.empty?() && @block_info["hash"] != block_hash)
|
130
|
+
raise("Returned block does not have a matching hash.")
|
131
|
+
else
|
132
|
+
@block_info
|
133
|
+
end
|
134
|
+
}
|
135
|
+
rescue
|
136
|
+
Casper::RpcError::InvalidParameter.error
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# @param [String] block_hash
|
141
|
+
# @return [Hash] era_summary
|
142
|
+
def chain_get_eraInfo_by_SwitchBlock(block_hash)
|
143
|
+
begin
|
144
|
+
state = Timeout::timeout(10) {
|
145
|
+
client = Jimson::Client.new(@url)
|
146
|
+
response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
|
147
|
+
@era_summary = response["era_summary"]
|
148
|
+
|
149
|
+
if @era_summary == nil
|
150
|
+
Casper::RpcError::InvalidParameter.error
|
151
|
+
else
|
152
|
+
@era_summary
|
153
|
+
end
|
154
|
+
}
|
155
|
+
rescue
|
156
|
+
Casper::RpcError::InvalidParameter.error
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# @param [String] state_root_hash
|
161
|
+
# @param [String] key
|
162
|
+
# @param [Array] path
|
163
|
+
def state_get_item(state_root_hash, key, path)
|
164
|
+
begin
|
165
|
+
state = Timeout::timeout(20) {
|
166
|
+
client = Jimson::Client.new(@url)
|
167
|
+
response = client.state_get_item({
|
168
|
+
"state_root_hash" => state_root_hash,
|
169
|
+
"key" => key,
|
170
|
+
"path" => path
|
171
|
+
})
|
172
|
+
@stored_value = response["stored_value"]
|
173
|
+
@stored_value
|
174
|
+
}
|
175
|
+
rescue
|
176
|
+
Casper::RpcError::InvalidParameter.error
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# @param [String] state_root_hash
|
181
|
+
# @param [String] item_key
|
182
|
+
# @param [String] uref
|
183
|
+
def state_get_dictionary_item(state_root_hash, item_key, uref)
|
184
|
+
begin
|
185
|
+
state = Timeout::timeout(10) {
|
186
|
+
client = Jimson::Client.new(@url)
|
187
|
+
response = client.state_get_dictionary_item({
|
188
|
+
"state_root_hash" => state_root_hash,
|
189
|
+
"dictionary_identifier" => {'URef' =>
|
190
|
+
{'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
|
191
|
+
@stored_value = response["stored_value"]
|
192
|
+
@stored_value
|
193
|
+
}
|
194
|
+
rescue
|
195
|
+
Casper::RpcError::InvalidParameter.error
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param [String] state_root_hash
|
200
|
+
# @param [String] balance_uref
|
201
|
+
def state_get_balance(state_root_hash, balance_uref)
|
202
|
+
begin
|
203
|
+
state = Timeout::timeout(5) {
|
204
|
+
client = Jimson::Client.new(@url)
|
205
|
+
response = client.state_get_balance({
|
206
|
+
"state_root_hash" => state_root_hash,
|
207
|
+
"purse_uref" => balance_uref
|
208
|
+
})
|
209
|
+
@balance_value = response["balance_value"]
|
210
|
+
@balance_value
|
211
|
+
}
|
212
|
+
rescue
|
213
|
+
Casper::RpcError::InvalidParameter.error
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
# Returns current auction system contract information.
|
218
|
+
# @return [Hash] auction_state
|
219
|
+
def state_get_AuctionInfo
|
220
|
+
begin
|
221
|
+
state = Timeout::timeout(50) {
|
222
|
+
client = Jimson::Client.new(@url)
|
223
|
+
response = client.state_get_auction_info
|
224
|
+
@auction_state = response['auction_state']
|
225
|
+
@auction_state
|
226
|
+
}
|
227
|
+
rescue
|
228
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
229
|
+
@error = @rpc_error.error_handling(@url)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|