casper_network 0.2.0 → 1.0.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 +4 -4
- data/CONTRIBUTING.md +1 -0
- data/LICENSE +201 -0
- data/README.md +165 -0
- data/SECURITY.md +12 -0
- data/lib/casper_network.rb +253 -178
- 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 +26 -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/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 +119 -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 +162 -7
data/lib/casper_network.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# casper_network.rb
|
2
1
|
require 'jimson'
|
3
2
|
require 'json'
|
4
3
|
require 'rdoc/rdoc'
|
@@ -7,208 +6,284 @@ require 'resolv'
|
|
7
6
|
require 'rest-client'
|
8
7
|
require 'active_support/core_ext/hash/keys'
|
9
8
|
require 'timeout'
|
9
|
+
require 'net/http'
|
10
|
+
# require "./rpc/rpc.rb"
|
11
|
+
require_relative './rpc/rpc_error.rb'
|
12
|
+
require_relative './rpc/rpc_client.rb'
|
10
13
|
|
14
|
+
# Dir["./entity/*.rb"].each {|file| require file }
|
15
|
+
# Dir["./serialization/*.rb"].each {|file| require file }
|
16
|
+
# Dir["./types/*.rb"].each {|file| require file }
|
17
|
+
require_relative './include.rb'
|
11
18
|
# Class for interacting with the network via RPC
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
# puts "Hello"
|
20
|
+
module Casper
|
21
|
+
class CasperClient
|
22
|
+
attr_accessor :ip_address, :port, :url, :state_root_hash
|
23
|
+
|
24
|
+
# Constructor
|
25
|
+
# @param [String] ip_address
|
26
|
+
def initialize(ip_address)
|
27
|
+
@ip_address = ip_address
|
28
|
+
@url = "http://" + @ip_address + ":7777/rpc"
|
29
|
+
@state_root_hash = ""
|
30
|
+
@peer_array = []
|
31
|
+
@block_hash = ""
|
32
|
+
@deploy = {}
|
33
|
+
@node_status = {}
|
34
|
+
@block_transfers = []
|
35
|
+
@block_info = {}
|
36
|
+
@era_summary = {}
|
37
|
+
@balance_value = ""
|
38
|
+
@auction_state = {}
|
39
|
+
|
40
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
41
|
+
@err = @rpc_error.error_handling(@url)
|
42
|
+
|
43
|
+
@pr = []
|
31
44
|
|
32
|
-
# @return [Array<Hash>] peers array
|
33
|
-
def info_get_peers
|
34
|
-
begin
|
35
|
-
status = Timeout::timeout(20) {
|
36
|
-
client = Jimson::Client.new(@url)
|
37
|
-
result = client.info_get_peers
|
38
|
-
@peer_array = result["peers"]
|
39
|
-
}
|
40
|
-
rescue Timeout::Error
|
41
|
-
'Timeout expired to retrieve peers!'
|
42
45
|
end
|
43
|
-
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
begin
|
48
|
-
status = Timeout::timeout(10) {
|
49
|
-
client = Jimson::Client.new(@url)
|
50
|
-
result = client.chain_get_state_root_hash
|
51
|
-
@state_root_hash = result["state_root_hash"]
|
52
|
-
}
|
53
|
-
rescue
|
54
|
-
'Timeout expired to retrieve state_root_hash value!'
|
47
|
+
def get_error
|
48
|
+
@err
|
55
49
|
end
|
56
|
-
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
51
|
+
# @return [Array<Hash>] peers array
|
52
|
+
# def info_get_peers
|
53
|
+
# begin
|
54
|
+
# client = Jimson::Client.new(@url)
|
55
|
+
# response = client.info_get_peers
|
56
|
+
# @peer_array = response["peers"]
|
57
|
+
# rescue
|
58
|
+
# @rpc_error = Casper::RpcError::ErrorHandle.new
|
59
|
+
# @error = @rpc_error.error_handling(@url)
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
|
63
|
+
# @return [Array<Hash>] peers array
|
64
|
+
def info_get_peers
|
65
|
+
begin
|
66
|
+
client = Jimson::Client.new(@url)
|
67
|
+
response = client.info_get_peers
|
68
|
+
@peers = response["peers"]
|
69
|
+
# @peers.map! do |peer|
|
70
|
+
# peer.symbolize_keys
|
71
|
+
# end
|
72
|
+
@peers.map { |item| @pr << Casper::Entity::Peer.new(item.symbolize_keys) }
|
73
|
+
@pr
|
74
|
+
rescue
|
75
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
76
|
+
@error = @rpc_error.error_handling(@url)
|
77
|
+
end
|
74
78
|
end
|
75
|
-
end
|
76
79
|
|
80
|
+
# @return [String] state_root_hash value
|
81
|
+
def chain_get_StateRootHash(block_hash = "")
|
82
|
+
begin
|
83
|
+
status = Timeout::timeout(10) {
|
84
|
+
client = Jimson::Client.new(@url)
|
85
|
+
result = client.chain_get_state_root_hash
|
86
|
+
@state_root_hash = result["state_root_hash"]
|
87
|
+
}
|
88
|
+
rescue
|
89
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
90
|
+
@error = @rpc_error.error_handling(@url)
|
91
|
+
end
|
92
|
+
end
|
77
93
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
94
|
+
# Get information about a single deploy by hash.
|
95
|
+
# @param [String] deploy_hash
|
96
|
+
# @return [Hash] Deploy
|
97
|
+
# def info_get_deploy(deploy_hash)
|
98
|
+
# begin
|
99
|
+
# status = Timeout::timeout(10) {
|
100
|
+
# client = Jimson::Client.new(@url)
|
101
|
+
# response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
|
102
|
+
# if (deploy_hash == "" || deploy_hash == nil)
|
103
|
+
# Casper::RpcError::InvalidParameter.error
|
104
|
+
# end
|
105
|
+
# @deploy = response["deploy"]
|
106
|
+
# # @deploy.keys.each do |key|
|
107
|
+
# # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
|
108
|
+
# # end
|
109
|
+
# @deploy
|
110
|
+
# }
|
111
|
+
# rescue
|
112
|
+
# Casper::RpcError::InvalidParameter.error
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
def info_get_deploy(deploy_hash)
|
116
|
+
@dep = nil
|
117
|
+
begin
|
118
|
+
status = Timeout::timeout(60) {
|
119
|
+
client = Jimson::Client.new(@url)
|
120
|
+
response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
|
121
|
+
if (deploy_hash == "" || deploy_hash == nil)
|
122
|
+
Casper::RpcError::InvalidParameter.error
|
123
|
+
end
|
124
|
+
# @deploy.keys.each do |key|
|
125
|
+
# @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
|
126
|
+
# end
|
127
|
+
temp = []
|
128
|
+
@deploy = response["deploy"]
|
129
|
+
@deploy.deep_symbolize_keys!
|
130
|
+
Casper::Entity::Deploy.new(@deploy[:hash], @deploy[:header], @deploy[:payment], @deploy[:session], @deploy[:approvals])
|
131
|
+
}
|
132
|
+
rescue
|
133
|
+
Casper::RpcError::InvalidParameter.error
|
134
|
+
end
|
88
135
|
end
|
89
|
-
end
|
90
136
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
@
|
102
|
-
|
103
|
-
|
104
|
-
'Timeout expired to retrieve block_transfers'
|
137
|
+
|
138
|
+
# Receive node status information
|
139
|
+
# @return node_status
|
140
|
+
def info_get_status
|
141
|
+
begin
|
142
|
+
status = Timeout::timeout(10) {
|
143
|
+
client = Jimson::Client.new(@url)
|
144
|
+
@node_status = client.info_get_status
|
145
|
+
}
|
146
|
+
rescue
|
147
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
148
|
+
@error = @rpc_error.error_handling(@url)
|
149
|
+
end
|
105
150
|
end
|
106
|
-
end
|
107
151
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
152
|
+
# @param [String] block_hash
|
153
|
+
# @return [Array<Hash>] block_transfers
|
154
|
+
def chain_get_block_transfers(block_hash = "")
|
155
|
+
begin
|
156
|
+
status = Timeout::timeout(5) {
|
157
|
+
client = Jimson::Client.new(@url)
|
158
|
+
response = client.chain_get_block_transfers({
|
159
|
+
"block_identifier" => {"Hash" => block_hash}
|
160
|
+
})
|
161
|
+
@transfers = response["transfers"]
|
162
|
+
@transfers.map { |transfer| Casper::Entity::Transfer.new(transfer.deep_symbolize_keys!)}
|
163
|
+
}
|
164
|
+
rescue
|
165
|
+
Casper::RpcError::InvalidParameter.error
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# @param [String] block_hash
|
170
|
+
# @return [Hash] block_info
|
171
|
+
def chain_get_block(block_hash)
|
172
|
+
begin
|
173
|
+
state = Timeout::timeout(10) {
|
174
|
+
client = Jimson::Client.new(@url)
|
175
|
+
result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
|
176
|
+
@block_info = result["block"]
|
177
|
+
if (!@block_info.empty?() && @block_info["hash"] != block_hash)
|
178
|
+
raise("Returned block does not have a matching hash.")
|
179
|
+
else
|
180
|
+
@block_info
|
181
|
+
end
|
182
|
+
}
|
183
|
+
rescue
|
184
|
+
Casper::RpcError::InvalidParameter.error
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# @param [String] block_hash
|
189
|
+
# @return [Hash] era_summary
|
190
|
+
def chain_get_eraInfo_by_SwitchBlock(block_hash)
|
191
|
+
begin
|
192
|
+
state = Timeout::timeout(10) {
|
113
193
|
client = Jimson::Client.new(@url)
|
114
|
-
|
115
|
-
@
|
116
|
-
|
117
|
-
|
194
|
+
response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
|
195
|
+
@era_summary = response["era_summary"]
|
196
|
+
|
197
|
+
if @era_summary == nil
|
198
|
+
Casper::RpcError::InvalidParameter.error
|
118
199
|
else
|
119
|
-
@
|
200
|
+
@era_summary
|
120
201
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
202
|
+
}
|
203
|
+
rescue
|
204
|
+
Casper::RpcError::InvalidParameter.error
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# @param [String] state_root_hash
|
209
|
+
# @param [String] key
|
210
|
+
# @param [Array] path
|
211
|
+
def state_get_item(state_root_hash, key, path)
|
212
|
+
begin
|
213
|
+
state = Timeout::timeout(20) {
|
214
|
+
client = Jimson::Client.new(@url)
|
215
|
+
response = client.state_get_item({
|
216
|
+
"state_root_hash" => state_root_hash,
|
217
|
+
"key" => key,
|
218
|
+
"path" => path
|
219
|
+
})
|
220
|
+
@stored_value = response["stored_value"]
|
221
|
+
@stored_value
|
222
|
+
}
|
223
|
+
rescue
|
224
|
+
Casper::RpcError::InvalidParameter.error
|
225
|
+
end
|
124
226
|
end
|
125
|
-
end
|
126
227
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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'
|
228
|
+
# @param [String] state_root_hash
|
229
|
+
# @param [String] item_key
|
230
|
+
# @param [String] uref
|
231
|
+
def state_get_dictionary_item(state_root_hash, item_key, uref)
|
232
|
+
begin
|
233
|
+
state = Timeout::timeout(10) {
|
234
|
+
client = Jimson::Client.new(@url)
|
235
|
+
response = client.state_get_dictionary_item({
|
236
|
+
"state_root_hash" => state_root_hash,
|
237
|
+
"dictionary_identifier" => {'URef' =>
|
238
|
+
{'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
|
239
|
+
@stored_value = response["stored_value"]
|
240
|
+
@stored_value
|
241
|
+
}
|
242
|
+
rescue
|
243
|
+
Casper::RpcError::InvalidParameter.error
|
244
|
+
end
|
159
245
|
end
|
160
|
-
end
|
161
246
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
247
|
+
# @param [String] state_root_hash
|
248
|
+
# @param [String] balance_uref
|
249
|
+
def state_get_balance(state_root_hash, balance_uref)
|
250
|
+
begin
|
251
|
+
state = Timeout::timeout(5) {
|
252
|
+
client = Jimson::Client.new(@url)
|
253
|
+
response = client.state_get_balance({
|
254
|
+
"state_root_hash" => state_root_hash,
|
255
|
+
"purse_uref" => balance_uref
|
256
|
+
})
|
257
|
+
@balance_value = response["balance_value"]
|
258
|
+
@balance_value
|
259
|
+
}
|
260
|
+
rescue
|
261
|
+
Casper::RpcError::InvalidParameter.error
|
262
|
+
end
|
178
263
|
end
|
179
|
-
end
|
180
264
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
265
|
+
# Returns current auction system contract information.
|
266
|
+
# @return [Hash] auction_state
|
267
|
+
def state_get_AuctionInfo
|
268
|
+
begin
|
269
|
+
state = Timeout::timeout(50) {
|
186
270
|
client = Jimson::Client.new(@url)
|
187
|
-
response = client.
|
188
|
-
|
189
|
-
|
190
|
-
}
|
191
|
-
|
192
|
-
@
|
193
|
-
|
194
|
-
|
195
|
-
'Timeout expired to retrieve balance_value'
|
271
|
+
response = client.state_get_auction_info
|
272
|
+
@auction_state = response['auction_state']
|
273
|
+
@auction_state
|
274
|
+
}
|
275
|
+
rescue
|
276
|
+
@rpc_error = Casper::RpcError::ErrorHandle.new
|
277
|
+
@error = @rpc_error.error_handling(@url)
|
278
|
+
end
|
196
279
|
end
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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!'
|
280
|
+
|
281
|
+
def put_deploy(deploy)
|
282
|
+
client = Jimson::Client.new(url)
|
283
|
+
response = client.account_put_deploy(deploy)
|
284
|
+
response['deploy_hash']
|
211
285
|
end
|
286
|
+
|
212
287
|
end
|
213
|
-
end
|
214
288
|
|
289
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative '../utils/base_16.rb'
|
2
|
+
require_relative '../types/cl_public_key.rb'
|
3
|
+
require_relative '../utils/hex_utils.rb'
|
4
|
+
require_relative '../utils/hash_utils.rb'
|
5
|
+
|
6
|
+
CLPublicKeyTag = {
|
7
|
+
ED25519: 1,
|
8
|
+
SECP256K1: 2
|
9
|
+
}
|
10
|
+
|
11
|
+
SignatureAlgorithm = {
|
12
|
+
Ed25519: 'ed25519',
|
13
|
+
Secp256K1: 'secp256k1'
|
14
|
+
}
|
15
|
+
|
16
|
+
class AsymmetricKey
|
17
|
+
attr_reader :public_key, :private_key, :signature_algorithm
|
18
|
+
include Utils::HashUtils
|
19
|
+
# @param [CLPublicKey] public_key
|
20
|
+
# @param [Array] private_key
|
21
|
+
# @param [SignatureAlgorithm] signature_algorithm
|
22
|
+
def initialize(public_key, private_key, signature_algorithm)
|
23
|
+
@public_key = public_key
|
24
|
+
@private_key = private_key
|
25
|
+
@signature_algorithm = signature_algorithm
|
26
|
+
@tag = @public_key.get_cl_public_key_tag
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [CLPublicKey]
|
30
|
+
def get_public_key
|
31
|
+
@public_key
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_signature_algorithm
|
35
|
+
@signature_algorithm
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get public hex-encoded string
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
def get_public_key_hex
|
42
|
+
"0#{@tag}" + Utils::Base16.encode16(@public_key.get_value)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [CLPublicKey] public_key
|
46
|
+
# @return [String] account_hex
|
47
|
+
def account_hex(public_key)
|
48
|
+
account_hex = @public_key.to_hex
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Array<Integer>]
|
52
|
+
def account_hash
|
53
|
+
@tag = @public_key.get_cl_public_key_tag
|
54
|
+
key_name = CLPublicKeyTag.key(@tag).to_s
|
55
|
+
prefix = key_name.downcase.unpack("C*") + [0]
|
56
|
+
bytes = prefix + @public_key.get_value
|
57
|
+
result_array = Utils::HashUtils.byte_hash(bytes)
|
58
|
+
@public_key.get_value.length == 0 ? [] : result_array
|
59
|
+
# @public_key.to_account_hash_byte_array
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param [String] path_to_private_key
|
63
|
+
def create_from_private_key_file(path_to_private_key)
|
64
|
+
puts "AsymmetricKey::create_from_private_key_file is called!"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get public key which is stored in pem
|
68
|
+
def export_public_key_in_pem
|
69
|
+
puts "AsymmetricKey::export_public_key_in_pem is called!"
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [String] message
|
73
|
+
# @return [String]
|
74
|
+
def sign(message)
|
75
|
+
puts "AsymmetricKey:sign is called!"
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# @param [String] signature
|
80
|
+
# @param [String] message
|
81
|
+
# @return [Boolean]
|
82
|
+
def verify(signature, message)
|
83
|
+
puts "AsymmetricKey::verify is called!"
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
attr_accessor :private_key
|
88
|
+
|
89
|
+
def to_pem(tag, content)
|
90
|
+
line1 = "-----BEGIN #{tag}-----\n"
|
91
|
+
line2 = "#{content}"
|
92
|
+
line3 = "-----END #{tag}-----\n"
|
93
|
+
line1 + line2 + line3
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'ed25519'
|
3
|
+
require_relative './asymmetric_key.rb'
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
class Ed25519Key < AsymmetricKey
|
8
|
+
|
9
|
+
def initialize(public_key, private_key)
|
10
|
+
super(public_key, private_key, SignatureAlgorithm[:Ed25519])
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Array] public_key
|
14
|
+
# @return [String]
|
15
|
+
# def self.account_hex(public_key)
|
16
|
+
# '01' + Utils::Base16.encode16(public_key)
|
17
|
+
# end
|
18
|
+
|
19
|
+
|
20
|
+
def create_from_private_key_file(path_to_private_key)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def parse_private_key_file(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_public_key_file(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_private_key(bytes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_public_key(bytes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_base_64_with_pem(content)
|
38
|
+
end
|
39
|
+
|
40
|
+
# private method
|
41
|
+
def read_base_64_file(path)
|
42
|
+
end
|
43
|
+
|
44
|
+
# private
|
45
|
+
def parse_key(bytes, from, to)
|
46
|
+
end
|
47
|
+
|
48
|
+
def export_private_key_in_pem
|
49
|
+
end
|
50
|
+
|
51
|
+
def export_public_key_in_pem
|
52
|
+
end
|
53
|
+
|
54
|
+
def sign(msg)
|
55
|
+
end
|
56
|
+
|
57
|
+
def verify(signature, msg)
|
58
|
+
end
|
59
|
+
|
60
|
+
def private_to_public(private_key)
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_keypair_from_private_file(private_key_path)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|