test_sdk1 1.0.3 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +478 -89
- data/lib/crypto/asymmetric_key.rb +19 -18
- data/lib/crypto/ed25519_key.rb +99 -10
- data/lib/crypto/keys.rb +1 -2
- data/lib/crypto/keys_util.rb +20 -0
- data/lib/entity/auction_state.rb +56 -8
- data/lib/entity/bid.rb +1 -1
- data/lib/entity/bid_info.rb +1 -1
- data/lib/entity/block.rb +39 -0
- data/lib/entity/block_body.rb +35 -0
- data/lib/entity/block_header.rb +81 -0
- data/lib/entity/block_info.rb +56 -0
- data/lib/entity/block_proof.rb +24 -0
- data/lib/entity/deploy.rb +154 -1
- data/lib/entity/deploy_executable.rb +108 -6
- data/lib/entity/deploy_executable_item_internal.rb +1 -1
- data/lib/entity/deploy_header.rb +17 -0
- data/lib/entity/deploy_named_argument.rb +69 -2
- data/lib/entity/era_summary.rb +13 -12
- data/lib/entity/module_bytes.rb +16 -2
- data/lib/entity/status.rb +80 -0
- data/lib/entity/stored_value.rb +86 -11
- data/lib/entity/transfer.rb +7 -7
- data/lib/include.rb +2 -0
- data/lib/serialization/cl_value_serializer.rb +69 -12
- data/lib/serialization/cl_value_serializer1.rb +314 -0
- data/lib/serialization/cl_value_serializer_update.rb +320 -0
- data/lib/serialization/deploy_header_serializer.rb +1 -0
- data/lib/serialization/deploy_named_arg_serializer.rb +1 -0
- data/lib/serialization/deploy_serializer.rb +144 -10
- data/lib/serialization/deploy_serializer1.rb +392 -0
- data/lib/serialization/deploy_serializer_update.rb +397 -0
- data/lib/serialization/test.rb +33 -13
- data/lib/test_sdk1.rb +29 -10
- data/lib/types/cl_option.rb +8 -2
- data/lib/types/cl_public_key.rb +2 -0
- data/lib/types/cl_value.rb +8 -0
- data/lib/utils/byte_utils.rb +28 -0
- data/lib/utils/helpers.rb +10 -0
- data/lib/version.rb +1 -1
- data/spec/cl_value_serializer_spec.rb +16 -1
- data/spec/dene_spec.rb +186 -0
- data/spec/deploy_executable_spec.rb +90 -0
- data/spec/deploy_executable_test_spec.rb +117 -0
- data/spec/deploy_serializer_spec.rb +5 -3
- data/spec/deploy_serializer_test_spec.rb +7 -1
- data/spec/testnet_spec.rb +3 -1
- data/spec/time_utils_spec.rb +3 -0
- metadata +20 -5
- data/lib/crypto/key_pair.rb +0 -40
- data/spec/deploy_executable_serializer_spec.rb +0 -0
@@ -0,0 +1,397 @@
|
|
1
|
+
require_relative './deploy_header_serializer'
|
2
|
+
require_relative './deploy_approval_serializer'
|
3
|
+
require_relative './deploy_executable_serializer'
|
4
|
+
require_relative './deploy_named_arg_serializer'
|
5
|
+
require_relative '../utils/byte_utils.rb'
|
6
|
+
require_relative '../types/cl_option.rb'
|
7
|
+
# Byte serializer for Deploy object
|
8
|
+
class DeploySerializer
|
9
|
+
attr_accessor :payment_session_serializer, :transfer_serializer, :payment_serializer
|
10
|
+
def initialize
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_bytes(deploy)
|
14
|
+
@payment_session_serializer = ""
|
15
|
+
@amount_serializer = ""
|
16
|
+
@target_serializer = ""
|
17
|
+
@id_serializer = ""
|
18
|
+
@transfer_serializer = ""
|
19
|
+
@payment_serializer = ""
|
20
|
+
result = ""
|
21
|
+
deploy_header = Casper::Entity::DeployHeader.new(deploy.get_header)
|
22
|
+
result += DeployHeaderSerializer.new().to_bytes(deploy_header)
|
23
|
+
|
24
|
+
deploy_hash = Casper::Entity::DeployHash.new(deploy.get_hash)
|
25
|
+
result += deploy_hash.get_hash
|
26
|
+
payment = deploy.get_payment
|
27
|
+
session = deploy.get_session
|
28
|
+
if payment.keys[0] == :ModuleBytes
|
29
|
+
temp_args = []
|
30
|
+
module_bytes = payment[:ModuleBytes][:module_bytes]
|
31
|
+
args = payment[:ModuleBytes][:args]
|
32
|
+
# module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
|
33
|
+
args.each do |arg|
|
34
|
+
name1 = arg[0]
|
35
|
+
clvalue_hash = arg[1]
|
36
|
+
clvalue = build_cl_value(arg[1])
|
37
|
+
# puts clvalue
|
38
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
39
|
+
end
|
40
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
|
41
|
+
result += temp
|
42
|
+
@payment_serializer += temp
|
43
|
+
@payment_session_serializer += temp
|
44
|
+
temp = nil
|
45
|
+
elsif payment.keys[0] == :StoredContractByHash
|
46
|
+
temp_args = []
|
47
|
+
hash = payment[:StoredContractByHash][:hash]
|
48
|
+
entry_point = payment[:StoredContractByHash][:entry_point]
|
49
|
+
args = payment[:StoredContractByHash][:args]
|
50
|
+
stored_contract_by_hash = Casper::Entity::StoredContractByHash.new(hash, entry_point, args)
|
51
|
+
|
52
|
+
args.each do |arg|
|
53
|
+
name1 = arg[0] # => "quantity"
|
54
|
+
clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
55
|
+
clvalue = build_cl_value(arg[1])
|
56
|
+
# puts clvalue
|
57
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
58
|
+
end
|
59
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
|
60
|
+
result += temp
|
61
|
+
@payment_session_serializer += temp
|
62
|
+
temp = nil
|
63
|
+
elsif payment.keys[0] == :StoredContractByName
|
64
|
+
temp_args = []
|
65
|
+
name = payment[:StoredContractByName][:name]
|
66
|
+
entry_point = payment[:StoredContractByName][:entry_point]
|
67
|
+
args = payment[:StoredContractByName][:args]
|
68
|
+
|
69
|
+
stored_contract_by_name = Casper::Entity::StoredContractByName.new(name, entry_point, args)
|
70
|
+
args.each do |arg|
|
71
|
+
name1 = arg[0] # => "quantity"
|
72
|
+
clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
73
|
+
clvalue = build_cl_value(arg[1])
|
74
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
75
|
+
end
|
76
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
|
77
|
+
result += temp
|
78
|
+
@payment_session_serializer += temp
|
79
|
+
temp = nil
|
80
|
+
elsif payment.keys[0] == :StoredVersionedContractByHash
|
81
|
+
temp_args = []
|
82
|
+
hash = payment[:StoredVersionedContractByHash][:name]
|
83
|
+
version = payment[:StoredVersionedContractByHash][:version]
|
84
|
+
entry_point = payment[:StoredVersionedContractByHash][:entry_point]
|
85
|
+
args = payment[:StoredVersionedContractByHash][:args]
|
86
|
+
|
87
|
+
stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByHash.new(hash, version, entry_point, args)
|
88
|
+
args.each do |arg|
|
89
|
+
name1 = arg[0]
|
90
|
+
clvalue_hash = arg[1]
|
91
|
+
clvalue = build_cl_value(arg[1])
|
92
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
93
|
+
end
|
94
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
|
95
|
+
result += temp
|
96
|
+
@payment_session_serializer += temp
|
97
|
+
temp = nil
|
98
|
+
elsif payment.keys[0] == :StoredVersionedContractByName
|
99
|
+
temp_args = []
|
100
|
+
name = payment[:StoredVersionedContractByName][:name]
|
101
|
+
version = payment[:StoredVersionedContractByName][:version]
|
102
|
+
entry_point = payment[:StoredVersionedContractByName][:entry_point]
|
103
|
+
args = payment[:StoredVersionedContractByName][:args]
|
104
|
+
|
105
|
+
stored_versioned_contract_by_name = Casper::Entity::StoredVersionedContractByName.new(name, version, entry_point, args)
|
106
|
+
args.each do |arg|
|
107
|
+
name1 = arg[0]
|
108
|
+
clvalue_hash = arg[1]
|
109
|
+
clvalue = build_cl_value(arg[1])
|
110
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
111
|
+
end
|
112
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
|
113
|
+
result += temp
|
114
|
+
@payment_session_serializer += temp
|
115
|
+
temp = nil
|
116
|
+
elsif payment.keys[0] == :Transfer
|
117
|
+
temp_args = []
|
118
|
+
args = payment[:Transfer][:args]
|
119
|
+
|
120
|
+
transfer = Casper::Entity::DeployExecutableTransfer.new(args)
|
121
|
+
args.each do |arg|
|
122
|
+
name1 = arg[0] # => "amount"
|
123
|
+
clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
124
|
+
clvalue = build_cl_value(arg[1])
|
125
|
+
# puts clvalue
|
126
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
127
|
+
end
|
128
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
|
129
|
+
result += temp
|
130
|
+
@payment_session_serializer += temp
|
131
|
+
temp = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
if session.keys[0] == :ModuleBytes
|
135
|
+
temp_args = []
|
136
|
+
module_bytes = session[:ModuleBytes][:module_bytes]
|
137
|
+
args = session[:ModuleBytes][:args]
|
138
|
+
# module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
|
139
|
+
args.each do |arg|
|
140
|
+
name1 = arg[0]
|
141
|
+
clvalue_hash = arg[1]
|
142
|
+
clvalue = build_cl_value(arg[1])
|
143
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
144
|
+
end
|
145
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
|
146
|
+
result += temp
|
147
|
+
@payment_session_serializer += temp
|
148
|
+
temp = nil
|
149
|
+
elsif session.keys[0] == :StoredContractByHash
|
150
|
+
temp_args = []
|
151
|
+
hash = session[:StoredContractByHash][:hash]
|
152
|
+
entry_point = session[:StoredContractByHash][:entry_point]
|
153
|
+
args = session[:StoredContractByHash][:args]
|
154
|
+
stored_contract_by_hash = Casper::Entity::StoredContractByHash.new(hash, entry_point, args)
|
155
|
+
|
156
|
+
args.each do |arg|
|
157
|
+
name1 = arg[0] # => "quantity"
|
158
|
+
clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
159
|
+
clvalue = build_cl_value(arg[1])
|
160
|
+
# puts clvalue
|
161
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
162
|
+
end
|
163
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
|
164
|
+
result += temp
|
165
|
+
@payment_session_serializer += temp
|
166
|
+
temp = nil
|
167
|
+
elsif session.keys[0] == :StoredContractByName
|
168
|
+
temp_args = []
|
169
|
+
name = session[:StoredContractByName][:name]
|
170
|
+
entry_point = session[:StoredContractByName][:entry_point]
|
171
|
+
args = session[:StoredContractByName][:args]
|
172
|
+
|
173
|
+
stored_contract_by_name = Casper::Entity::StoredContractByName.new(name, entry_point, args)
|
174
|
+
args.each do |arg|
|
175
|
+
name1 = arg[0] # => "quantity"
|
176
|
+
clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
177
|
+
clvalue = build_cl_value(arg[1])
|
178
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
179
|
+
end
|
180
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
|
181
|
+
result += temp
|
182
|
+
@payment_session_serializer += temp
|
183
|
+
temp = nil
|
184
|
+
elsif session.keys[0] == :StoredVersionedContractByHash
|
185
|
+
temp_args = []
|
186
|
+
hash = session[:StoredVersionedContractByHash][:name]
|
187
|
+
version = session[:StoredVersionedContractByHash][:version]
|
188
|
+
entry_point = session[:StoredVersionedContractByHash][:entry_point]
|
189
|
+
args = session[:StoredVersionedContractByHash][:args]
|
190
|
+
|
191
|
+
stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByHash.new(hash, version, entry_point, args)
|
192
|
+
args.each do |arg|
|
193
|
+
name1 = arg[0]
|
194
|
+
clvalue_hash = arg[1]
|
195
|
+
clvalue = build_cl_value(arg[1])
|
196
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
197
|
+
end
|
198
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
|
199
|
+
result += temp
|
200
|
+
@payment_session_serializer += temp
|
201
|
+
temp = nil
|
202
|
+
elsif session.keys[0] == :StoredVersionedContractByName
|
203
|
+
temp_args = []
|
204
|
+
name = session[:StoredVersionedContractByName][:name]
|
205
|
+
version = session[:StoredVersionedContractByName][:version]
|
206
|
+
entry_point = session[:StoredVersionedContractByName][:entry_point]
|
207
|
+
args = session[:StoredVersionedContractByName][:args]
|
208
|
+
|
209
|
+
stored_versioned_contract_by_name = Casper::Entity::StoredVersionedContractByName.new(name, version, entry_point, args)
|
210
|
+
args.each do |arg|
|
211
|
+
name1 = arg[0]
|
212
|
+
clvalue_hash = arg[1]
|
213
|
+
clvalue = build_cl_value(arg[1])
|
214
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
215
|
+
end
|
216
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
|
217
|
+
result += temp
|
218
|
+
@payment_session_serializer += temp
|
219
|
+
temp = nil
|
220
|
+
|
221
|
+
elsif session.keys[0] == :Transfer
|
222
|
+
temp_args = []
|
223
|
+
args = session[:Transfer][:args]
|
224
|
+
|
225
|
+
transfer = Casper::Entity::DeployExecutableTransfer.new(args)
|
226
|
+
# args.each do |arg|
|
227
|
+
# name1 = arg[0] # => "amount"
|
228
|
+
# clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
|
229
|
+
# clvalue = build_cl_value(arg[1])
|
230
|
+
# # puts clvalue
|
231
|
+
# temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
232
|
+
# end
|
233
|
+
|
234
|
+
args.each do |arg|
|
235
|
+
name1 = arg[0]
|
236
|
+
if name1 == "amount" || name1 == "target"
|
237
|
+
clvalue_hash = arg[1]
|
238
|
+
clvalue = build_cl_value(arg[1])
|
239
|
+
# puts "clvalue.get_value: #{clvalue.get_value}"
|
240
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
241
|
+
elsif name1 == "id"
|
242
|
+
bytes = arg[1][:bytes]
|
243
|
+
parsed = arg[1][:parsed]
|
244
|
+
h = arg[1][:cl_type]
|
245
|
+
key, value = h.first
|
246
|
+
cl_type = h.keys[0]
|
247
|
+
# puts key, value
|
248
|
+
inner_type = value
|
249
|
+
data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
|
250
|
+
clvalue = CLOption.new(data, inner_type)
|
251
|
+
# type = clvalue.get_cl_type
|
252
|
+
# puts type
|
253
|
+
# value = clvalue.get_value
|
254
|
+
# puts value
|
255
|
+
# tag = CLType::TAGS[type.to_sym]
|
256
|
+
# puts tag
|
257
|
+
# cl_value = { "cl_type": cl_type, "bytes": bytes, "parsed": parsed}
|
258
|
+
# clvalue = build_cl_value(cloption)
|
259
|
+
# puts cloption.get_value
|
260
|
+
temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
|
261
|
+
end
|
262
|
+
end
|
263
|
+
temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
|
264
|
+
@target_serializer = temp
|
265
|
+
# puts @target_serializer
|
266
|
+
result += temp
|
267
|
+
@transfer_serializer += temp
|
268
|
+
@payment_session_serializer += temp
|
269
|
+
temp = nil
|
270
|
+
end
|
271
|
+
|
272
|
+
approvals = deploy.get_approvals
|
273
|
+
num_of_approvals = approvals.size
|
274
|
+
# puts "num_of_approvals: #{num_of_approvals}"
|
275
|
+
approval_serializer = ""
|
276
|
+
deploy_approval_serializer = DeployApprovalSerializer.new
|
277
|
+
result += Utils::ByteUtils.to_u32(num_of_approvals)
|
278
|
+
approval_serializer += Utils::ByteUtils.to_u32(num_of_approvals)
|
279
|
+
# @payment_session_serializer += Utils::ByteUtils.to_u32(num_of_approvals)
|
280
|
+
for approval in approvals
|
281
|
+
deploy_approval = Casper::Entity::DeployApproval.new(approval)
|
282
|
+
# @payment_session_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
|
283
|
+
result += deploy_approval_serializer.to_bytes(deploy_approval)
|
284
|
+
approval_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
|
285
|
+
end
|
286
|
+
# puts "approval_serializer: #{approval_serializer}"
|
287
|
+
# result
|
288
|
+
Utils::ByteUtils.hex_to_byte_array(result)
|
289
|
+
end
|
290
|
+
|
291
|
+
def build_cl_value(h = {})
|
292
|
+
cl_type = h[:cl_type]
|
293
|
+
bytes = h[:bytes]
|
294
|
+
parsed = h[:parsed]
|
295
|
+
# puts "h[:bytes] = #{h[:bytes]}"
|
296
|
+
# puts "h[:parsed] = #{h[:parsed]}"
|
297
|
+
if cl_type == "Bool"
|
298
|
+
CLValueBytesParsers::CLBoolBytesParser.from_bytes([bytes])
|
299
|
+
elsif cl_type == "I32"
|
300
|
+
value = Utils::ByteUtils.hex_to_integer(bytes)
|
301
|
+
CLi32.new(value)
|
302
|
+
elsif cl_type == "I64"
|
303
|
+
value = Utils::ByteUtils.hex_to_i64_value(bytes)
|
304
|
+
CLi64.new(value)
|
305
|
+
elsif cl_type == "U8"
|
306
|
+
value = Utils::ByteUtils.hex_to_u8_value(bytes)
|
307
|
+
CLu8.new(value)
|
308
|
+
elsif cl_type == "U32"
|
309
|
+
value = Utils::ByteUtils.hex_to_u32_value(bytes)
|
310
|
+
CLu32.new(value)
|
311
|
+
elsif cl_type == "U64"
|
312
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
313
|
+
CLu32.new(value)
|
314
|
+
elsif cl_type == "U512"
|
315
|
+
bytes = h[:bytes] # => 0400f90295
|
316
|
+
# puts "bytes:\t#{bytes}"
|
317
|
+
num_of_bytes = bytes[0..1] # => 04
|
318
|
+
bytes = bytes[2..] # => "00f90295"
|
319
|
+
# puts "bytes[2..]:\t#{bytes}"
|
320
|
+
value = [bytes].pack("H*").unpack("L*").first
|
321
|
+
# puts "value:\t#{value}"
|
322
|
+
# CLu512.new(value)
|
323
|
+
# puts "parsed:\t#{parsed}"
|
324
|
+
# puts "parsed.to_i: #{parsed.to_i}"
|
325
|
+
CLu512.new(parsed.to_i)
|
326
|
+
# value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
327
|
+
# CLu512.new(value)
|
328
|
+
# value = Utils::ByteUtils.hex_to_u512_value(bytes)
|
329
|
+
# CLu512.new(value)
|
330
|
+
elsif cl_type == "Unit"
|
331
|
+
# value = CLValueBytesParsers::CLUnitBytesParser.from_bytes(bytes)
|
332
|
+
if bytes == ""
|
333
|
+
value = nil
|
334
|
+
CLUnit.new(value)
|
335
|
+
end
|
336
|
+
elsif cl_type == "String"
|
337
|
+
value = CLValueBytesParsers::CLStringBytesParser.from_bytes(bytes)
|
338
|
+
CLString.new(value)
|
339
|
+
elsif cl_type == "URef"
|
340
|
+
value = Utils::ByteUtils.hex_to_byte_array(bytes)
|
341
|
+
CLValueBytesParsers::CLURefBytesParser.from_bytes(value)
|
342
|
+
# elsif cl_type = "Option"
|
343
|
+
|
344
|
+
elsif cl_type == "PublicKey"
|
345
|
+
CLPublicKey.from_hex(bytes)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def build_cl_value_with_option(h = {})
|
350
|
+
cl_type = h[:cl_type]
|
351
|
+
bytes = h[:bytes]
|
352
|
+
# puts bytes
|
353
|
+
parsed = h[:parsed]
|
354
|
+
if cl_type == "Bool"
|
355
|
+
CLValueBytesParsers::CLBoolBytesParser.from_bytes([bytes])
|
356
|
+
elsif cl_type == "I32"
|
357
|
+
value = Utils::ByteUtils.hex_to_integer(bytes)
|
358
|
+
CLi32.new(value)
|
359
|
+
elsif cl_type == "I64"
|
360
|
+
value = Utils::ByteUtils.hex_to_i64_value(bytes)
|
361
|
+
CLi64.new(value)
|
362
|
+
elsif cl_type == "U8"
|
363
|
+
value = Utils::ByteUtils.hex_to_u8_value(bytes)
|
364
|
+
CLu8.new(value)
|
365
|
+
elsif cl_type == "U32"
|
366
|
+
value = Utils::ByteUtils.hex_to_u32_value(bytes)
|
367
|
+
CLu32.new(value)
|
368
|
+
elsif cl_type == "U64"
|
369
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
370
|
+
CLu32.new(value)
|
371
|
+
elsif cl_type == "U512"
|
372
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
373
|
+
# puts "value:\t#{value}"
|
374
|
+
CLu512.new(value)
|
375
|
+
# value = Utils::ByteUtils.hex_to_u512_value(bytes)
|
376
|
+
# CLu512.new(value)
|
377
|
+
elsif cl_type == "Unit"
|
378
|
+
# value = CLValueBytesParsers::CLUnitBytesParser.from_bytes(bytes)
|
379
|
+
if bytes == ""
|
380
|
+
value = nil
|
381
|
+
CLUnit.new(value)
|
382
|
+
end
|
383
|
+
elsif cl_type == "String"
|
384
|
+
value = CLValueBytesParsers::CLStringBytesParser.from_bytes(bytes)
|
385
|
+
CLString.new(value)
|
386
|
+
elsif cl_type == "URef"
|
387
|
+
value = Utils::ByteUtils.hex_to_byte_array(bytes)
|
388
|
+
CLValueBytesParsers::CLURefBytesParser.from_bytes(value)
|
389
|
+
# elsif cl_type = "Option"
|
390
|
+
|
391
|
+
elsif cl_type == "PublicKey"
|
392
|
+
CLPublicKey.from_hex(bytes)
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
end
|
397
|
+
end
|
data/lib/serialization/test.rb
CHANGED
@@ -98,7 +98,7 @@ clvalue = CLTuple3.new([u32_2, str, u32_2])
|
|
98
98
|
|
99
99
|
clvalue = CLOption.new(CLBool.new(false))
|
100
100
|
|
101
|
-
|
101
|
+
puts clvalue.get_cl_type
|
102
102
|
|
103
103
|
temp = CLType.new(false)
|
104
104
|
# p temp.get_cl_type_tag(:Bool)
|
@@ -120,7 +120,17 @@ cl_opt = CLOption.new(CLBool.new(true))
|
|
120
120
|
# serializer = CLValueSerializer.new
|
121
121
|
# puts serializer.to_bytes(cloption1)
|
122
122
|
|
123
|
-
|
123
|
+
deploy_serializer = DeploySerializer.new
|
124
|
+
h = {
|
125
|
+
"bytes": "0179df0d8648700000",
|
126
|
+
"parsed": 123456789012345,
|
127
|
+
"cl_type": {
|
128
|
+
"Option": "U64"
|
129
|
+
}
|
130
|
+
}
|
131
|
+
h.deep_symbolize_keys!
|
132
|
+
cl_value = deploy_serializer.build_cl_value(h)
|
133
|
+
puts cl_value
|
124
134
|
# *************************** CLValueSerializer::End *****************************************************#
|
125
135
|
|
126
136
|
|
@@ -372,9 +382,9 @@ deploy_bytes_array = deploy_serializer.to_bytes(deploy)
|
|
372
382
|
deploy_hex = Utils::ByteUtils.byte_array_to_hex(deploy_bytes_array)
|
373
383
|
# puts Blake2b.hex(deploy_hex)
|
374
384
|
|
375
|
-
input = "abc"
|
376
|
-
key = Blake2b::Key.none
|
377
|
-
out_len = 32
|
385
|
+
# input = "abc"
|
386
|
+
# key = Blake2b::Key.none
|
387
|
+
# out_len = 32
|
378
388
|
|
379
389
|
# puts Blake2b.hex(input)
|
380
390
|
# puts Blake2b.hex(input, key)
|
@@ -389,7 +399,6 @@ out_len = 32
|
|
389
399
|
key = "01ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1"
|
390
400
|
|
391
401
|
|
392
|
-
# puts Blake2b.hex(deploy_hex)
|
393
402
|
require 'openssl'
|
394
403
|
|
395
404
|
# k = OpenSSL::PKey::RSA.new(File.read("/home/mehmet/Documents/ed25519_secret_key.pem"))
|
@@ -397,10 +406,20 @@ require 'openssl'
|
|
397
406
|
require "ssh_data"
|
398
407
|
require "ed25519"
|
399
408
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
409
|
+
path = File.join(
|
410
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
411
|
+
'crypto/ed25519_secret_key.pem'
|
412
|
+
)
|
413
|
+
# puts path
|
414
|
+
# file = File.open(path)
|
415
|
+
# puts file
|
416
|
+
# file_data = file.readlines.map(&:chomp)
|
417
|
+
# puts file_data
|
418
|
+
|
419
|
+
# key_data = File.read(path)
|
420
|
+
# key = SSHData::PrivateKey.parse_openssh(key_data)
|
421
|
+
# #=> <SSHData::PrivateKey::ED25519>
|
422
|
+
# puts key[0]
|
404
423
|
SSHData::PrivateKey::ED25519.generate
|
405
424
|
#=> raises SSHData::AlgorithmError
|
406
425
|
|
@@ -417,15 +436,16 @@ SSHData::PrivateKey::ED25519.generate
|
|
417
436
|
# puts file_data
|
418
437
|
# puts "/home/mehmet/Document/hetzner.txt"
|
419
438
|
# puts "#{Dir.home}"
|
439
|
+
# puts File.dirname(File.dirname(File.absolute_path(__FILE__)))
|
420
440
|
require 'json'
|
421
441
|
path = File.join(
|
422
442
|
File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
423
443
|
'serialization/ed25519.pem'
|
424
444
|
)
|
425
|
-
puts path
|
445
|
+
# puts path
|
426
446
|
|
427
447
|
file = File.open(path)
|
428
|
-
puts file
|
448
|
+
# puts file
|
429
449
|
file_data = file.readlines.map(&:chomp)
|
430
|
-
puts file_data.inspect
|
450
|
+
# puts file_data.inspect
|
431
451
|
file.close
|
data/lib/test_sdk1.rb
CHANGED
@@ -10,11 +10,13 @@ require 'net/http'
|
|
10
10
|
# require "./rpc/rpc.rb"
|
11
11
|
require_relative './rpc/rpc_error.rb'
|
12
12
|
require_relative './rpc/rpc_client.rb'
|
13
|
-
|
13
|
+
require_relative './serialization/deploy_serializer.rb'
|
14
14
|
# Dir["./entity/*.rb"].each {|file| require file }
|
15
15
|
# Dir["./serialization/*.rb"].each {|file| require file }
|
16
16
|
# Dir["./types/*.rb"].each {|file| require file }
|
17
17
|
require_relative './include.rb'
|
18
|
+
require_relative './crypto/ed25519_key.rb'
|
19
|
+
require_relative './crypto/asymmetric_key.rb'
|
18
20
|
module Casper
|
19
21
|
# Interacting with the network
|
20
22
|
class CasperClient
|
@@ -141,6 +143,8 @@ module Casper
|
|
141
143
|
status = Timeout::timeout(10) {
|
142
144
|
client = Jimson::Client.new(@url)
|
143
145
|
@node_status = client.info_get_status
|
146
|
+
@node_status.deep_symbolize_keys!
|
147
|
+
Casper::Entity::Status.new(@node_status)
|
144
148
|
}
|
145
149
|
rescue
|
146
150
|
@rpc_error = Casper::RpcError::ErrorHandle.new
|
@@ -176,7 +180,8 @@ module Casper
|
|
176
180
|
if (!@block_info.empty?() && @block_info["hash"] != block_hash)
|
177
181
|
raise("Returned block does not have a matching hash.")
|
178
182
|
else
|
179
|
-
@block_info
|
183
|
+
@block_info.deep_symbolize_keys!
|
184
|
+
Casper::Entity::Block.new(@block_info[:hash], @block_info[:header], @block_info[:body], @block_info[:proofs])
|
180
185
|
end
|
181
186
|
}
|
182
187
|
rescue
|
@@ -196,7 +201,8 @@ module Casper
|
|
196
201
|
if @era_summary == nil
|
197
202
|
Casper::RpcError::InvalidParameter.error
|
198
203
|
else
|
199
|
-
@era_summary
|
204
|
+
@era_summary.deep_symbolize_keys!
|
205
|
+
Casper::Entity::EraSummary.new(@era_summary)
|
200
206
|
end
|
201
207
|
}
|
202
208
|
rescue
|
@@ -217,7 +223,8 @@ module Casper
|
|
217
223
|
"path" => path
|
218
224
|
})
|
219
225
|
@stored_value = response["stored_value"]
|
220
|
-
@stored_value
|
226
|
+
@stored_value.deep_symbolize_keys!
|
227
|
+
Casper::Entity::StoredValue.new(@stored_value)
|
221
228
|
}
|
222
229
|
rescue
|
223
230
|
Casper::RpcError::InvalidParameter.error
|
@@ -236,7 +243,10 @@ module Casper
|
|
236
243
|
"dictionary_identifier" => {'URef' =>
|
237
244
|
{'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
|
238
245
|
@stored_value = response["stored_value"]
|
239
|
-
@stored_value
|
246
|
+
@stored_value.deep_symbolize_keys!
|
247
|
+
# cl_type = @stored_value[:CLValue][:cl_type]
|
248
|
+
# bytes = @stored_value[:CLValue][:bytes]
|
249
|
+
DeploySerializer.new().build_cl_value(@stored_value[:CLValue])
|
240
250
|
}
|
241
251
|
rescue
|
242
252
|
Casper::RpcError::InvalidParameter.error
|
@@ -263,13 +273,18 @@ module Casper
|
|
263
273
|
|
264
274
|
# Returns current auction system contract information.
|
265
275
|
# @return [Hash] auction_state
|
266
|
-
def state_get_AuctionInfo
|
276
|
+
def state_get_AuctionInfo(block_hash = "")
|
267
277
|
begin
|
268
278
|
state = Timeout::timeout(50) {
|
269
279
|
client = Jimson::Client.new(@url)
|
270
280
|
response = client.state_get_auction_info
|
271
281
|
@auction_state = response['auction_state']
|
272
|
-
@auction_state
|
282
|
+
@auction_state.deep_symbolize_keys!
|
283
|
+
state_root_hash = @auction_state[:state_root_hash]
|
284
|
+
block_height = @auction_state[:block_height]
|
285
|
+
era_validators = @auction_state[:era_validators]
|
286
|
+
bids = @auction_state[:bids]
|
287
|
+
Casper::Entity::AuctionState.new(state_root_hash, block_height, era_validators, bids)
|
273
288
|
}
|
274
289
|
rescue
|
275
290
|
@rpc_error = Casper::RpcError::ErrorHandle.new
|
@@ -277,10 +292,14 @@ module Casper
|
|
277
292
|
end
|
278
293
|
end
|
279
294
|
|
295
|
+
# @param [Deploy] deploy
|
280
296
|
def put_deploy(deploy)
|
281
|
-
client = Jimson::Client.new(url)
|
282
|
-
response = client.account_put_deploy(deploy)
|
283
|
-
response['deploy_hash']
|
297
|
+
client = Jimson::Client.new(@url)
|
298
|
+
# response = client.account_put_deploy(deploy)
|
299
|
+
# response['deploy_hash']
|
300
|
+
response = client.account_put_deploy({
|
301
|
+
"deploy" => deploy
|
302
|
+
})
|
284
303
|
end
|
285
304
|
|
286
305
|
end
|
data/lib/types/cl_option.rb
CHANGED
@@ -18,6 +18,7 @@ class CLOption < CLValue
|
|
18
18
|
elsif data == nil && inner_type != nil
|
19
19
|
@inner_type = inner_type
|
20
20
|
else
|
21
|
+
# @inner_type = data[:cl_type]
|
21
22
|
@inner_type = data.get_cl_type
|
22
23
|
end
|
23
24
|
end
|
@@ -27,7 +28,12 @@ class CLOption < CLValue
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def get_cl_type
|
30
|
-
CLOptionType.new(@inner_type)
|
31
|
-
@inner_type
|
31
|
+
CLOptionType.new(@inner_type).get_type
|
32
|
+
# @inner_type
|
33
|
+
# get_type
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_inner_type
|
37
|
+
@inner_type
|
32
38
|
end
|
33
39
|
end
|
data/lib/types/cl_public_key.rb
CHANGED
data/lib/types/cl_value.rb
CHANGED
data/lib/utils/byte_utils.rb
CHANGED
@@ -27,6 +27,11 @@ module Utils
|
|
27
27
|
# byte_array.pack("C*").unpack1("H*")
|
28
28
|
byte_array.pack("C*").unpack("H*").first
|
29
29
|
end
|
30
|
+
|
31
|
+
def byte_array_to_hex_64(byte_array)
|
32
|
+
# byte_array.pack("C*").unpack1("H*")
|
33
|
+
byte_array.pack("C*").unpack("H*").first
|
34
|
+
end
|
30
35
|
|
31
36
|
# @param [String] str
|
32
37
|
# @return [Array]
|
@@ -74,6 +79,15 @@ module Utils
|
|
74
79
|
# @param [Integer] n
|
75
80
|
# @return [String]
|
76
81
|
def to_u64(n)
|
82
|
+
# bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(n)) + "0000"
|
83
|
+
# puts "bytes: #{bytes}"
|
84
|
+
# puts "bytes_conversion: #{[bytes].pack("H*").unpack("C*")}"
|
85
|
+
[n].pack("Q<*").unpack("H*").first
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [Integer] n
|
89
|
+
# @return [String]
|
90
|
+
def to_u512(n)
|
77
91
|
[n].pack("Q<*").unpack("H*").first
|
78
92
|
end
|
79
93
|
|
@@ -103,5 +117,19 @@ module Utils
|
|
103
117
|
def hex_to_u64_value(hex_str)
|
104
118
|
[hex_str].pack("H*").unpack("Q*").first
|
105
119
|
end
|
120
|
+
def hex_to_u512_value(hex_str)
|
121
|
+
[hex_str].pack("H*").unpack("Q*").first
|
122
|
+
end
|
123
|
+
|
124
|
+
# @return byte array containing two's complement representation of Bignum/Fixnum
|
125
|
+
def to_byte_array(num)
|
126
|
+
result = []
|
127
|
+
begin
|
128
|
+
result << (num & 0xff)
|
129
|
+
num >>= 8
|
130
|
+
end until (num == 0 || num == -1) && (result.last[7] == num[7])
|
131
|
+
# result.reverse
|
132
|
+
result
|
133
|
+
end
|
106
134
|
end
|
107
135
|
end
|