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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +478 -89
  3. data/lib/crypto/asymmetric_key.rb +19 -18
  4. data/lib/crypto/ed25519_key.rb +99 -10
  5. data/lib/crypto/keys.rb +1 -2
  6. data/lib/crypto/keys_util.rb +20 -0
  7. data/lib/entity/auction_state.rb +56 -8
  8. data/lib/entity/bid.rb +1 -1
  9. data/lib/entity/bid_info.rb +1 -1
  10. data/lib/entity/block.rb +39 -0
  11. data/lib/entity/block_body.rb +35 -0
  12. data/lib/entity/block_header.rb +81 -0
  13. data/lib/entity/block_info.rb +56 -0
  14. data/lib/entity/block_proof.rb +24 -0
  15. data/lib/entity/deploy.rb +154 -1
  16. data/lib/entity/deploy_executable.rb +108 -6
  17. data/lib/entity/deploy_executable_item_internal.rb +1 -1
  18. data/lib/entity/deploy_header.rb +17 -0
  19. data/lib/entity/deploy_named_argument.rb +69 -2
  20. data/lib/entity/era_summary.rb +13 -12
  21. data/lib/entity/module_bytes.rb +16 -2
  22. data/lib/entity/status.rb +80 -0
  23. data/lib/entity/stored_value.rb +86 -11
  24. data/lib/entity/transfer.rb +7 -7
  25. data/lib/include.rb +2 -0
  26. data/lib/serialization/cl_value_serializer.rb +69 -12
  27. data/lib/serialization/cl_value_serializer1.rb +314 -0
  28. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  29. data/lib/serialization/deploy_header_serializer.rb +1 -0
  30. data/lib/serialization/deploy_named_arg_serializer.rb +1 -0
  31. data/lib/serialization/deploy_serializer.rb +144 -10
  32. data/lib/serialization/deploy_serializer1.rb +392 -0
  33. data/lib/serialization/deploy_serializer_update.rb +397 -0
  34. data/lib/serialization/test.rb +33 -13
  35. data/lib/test_sdk1.rb +29 -10
  36. data/lib/types/cl_option.rb +8 -2
  37. data/lib/types/cl_public_key.rb +2 -0
  38. data/lib/types/cl_value.rb +8 -0
  39. data/lib/utils/byte_utils.rb +28 -0
  40. data/lib/utils/helpers.rb +10 -0
  41. data/lib/version.rb +1 -1
  42. data/spec/cl_value_serializer_spec.rb +16 -1
  43. data/spec/dene_spec.rb +186 -0
  44. data/spec/deploy_executable_spec.rb +90 -0
  45. data/spec/deploy_executable_test_spec.rb +117 -0
  46. data/spec/deploy_serializer_spec.rb +5 -3
  47. data/spec/deploy_serializer_test_spec.rb +7 -1
  48. data/spec/testnet_spec.rb +3 -1
  49. data/spec/time_utils_spec.rb +3 -0
  50. metadata +20 -5
  51. data/lib/crypto/key_pair.rb +0 -40
  52. data/spec/deploy_executable_serializer_spec.rb +0 -0
@@ -0,0 +1,320 @@
1
+ require_relative '../types/cl_type.rb'
2
+ require_relative '../types/cl_bool.rb'
3
+ require_relative '../types/cl_i32.rb'
4
+ require_relative '../types/cl_i64.rb'
5
+ require_relative '../types/cl_u8.rb'
6
+ require_relative '../types/cl_u32.rb'
7
+ require_relative '../types/cl_u64.rb'
8
+ require_relative '../types/cl_u128.rb'
9
+ require_relative '../types/cl_u256.rb'
10
+ require_relative '../types/cl_u512.rb'
11
+ require_relative '../types/cl_unit.rb'
12
+ require_relative '../types/cl_tuple.rb'
13
+ require_relative '../types/cl_uref.rb'
14
+ require_relative '../types/cl_option.rb'
15
+ require_relative '../types/cl_string.rb'
16
+ # require_relative '../types/cl_key.rb'
17
+ require_relative '../types/cl_uref.rb'
18
+ require_relative '../types/cl_tuple.rb'
19
+ require_relative '../types/cl_public_key.rb'
20
+ require_relative '../types/constants.rb'
21
+ require_relative './cl_value_bytes_parsers.rb'
22
+ require_relative '../utils/byte_utils.rb'
23
+
24
+ # Byte serializer for CLValue
25
+ class CLValueSerializer
26
+ def to_byte_array(num)
27
+ result = []
28
+ begin
29
+ result << (num & 0xff)
30
+ num >>= 8
31
+ end until (num == 0 || num == -1) && (result.last[7] == num[7])
32
+ # result.reverse
33
+ result
34
+ end
35
+
36
+ def to_bytes(clvalue)
37
+ puts "\nCLValueSerializer:"
38
+ type = clvalue.get_cl_type
39
+ value = clvalue.get_value
40
+ tag = CLType::TAGS[type.to_sym]
41
+ puts "\n clvalue: "
42
+ puts "type:\t#{type}"
43
+ puts "to_bytes(clvalue): #{value}"
44
+ # puts CLType::TAGS[type.to_sym]
45
+ puts "tag:\t#{tag}"
46
+ [1].pack("L<*").unpack1("H*")
47
+ serialized = ""
48
+ if type == "Bool"
49
+ [1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
50
+ elsif type == "I32"
51
+ [4].pack("L<*").unpack1("H*") + [value].pack("l<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
52
+ elsif type == "I64"
53
+ [8].pack("L<*").unpack1("H*") + [value].pack("q<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
54
+ elsif type == "U8"
55
+ [1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
56
+ elsif type == "U32"
57
+ serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
58
+ elsif type == "U64"
59
+ [8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
60
+ elsif type == "U128"
61
+ [8].pack("L<*").unpack1("H*")
62
+ elsif type == "U256"
63
+ [8].pack("L<*").unpack1("H*")
64
+ elsif type == "U512"
65
+ puts "\n U512: "
66
+
67
+ # puts "value : #{value}"
68
+ # bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))
69
+ # puts bytes
70
+ # num_of_bytes = bytes.length/2
71
+ # puts num_of_bytes
72
+ # puts [num_of_bytes].pack("C*").unpack1("H*")
73
+ # puts [num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
74
+ # puts "to_byte_array(value):\t #{to_byte_array(value)}"
75
+ bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))[0...-2]
76
+ puts "bytes: #{bytes}"
77
+ num_of_bytes = bytes.length/2
78
+ puts "num_of_bytes:\t#{num_of_bytes}"
79
+ puts "U512: " + [num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
80
+ [num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
81
+ elsif type == "Unit"
82
+ [0].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
83
+ elsif type == "String"
84
+ length = CLValueBytesParsers::CLStringBytesParser.to_bytes(value).length
85
+ [length/2].pack("L<*").unpack1("H*") + CLValueBytesParsers::CLStringBytesParser.to_bytes(value) + [tag].pack("C*").unpack1("H*")
86
+ elsif type == "Key"
87
+ [11].pack("C*").unpack1("H*")
88
+ elsif type == "URef"
89
+ uref = clvalue.get_value
90
+ size = clvalue.to_bytes(uref).length/2
91
+ [size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref) + [tag].pack("C*").unpack1("H*")
92
+ elsif type == "Option"
93
+ [0].pack("L<*").unpack1("H*")
94
+ inner_type = value[:cl_type]
95
+ bytes = value[:bytes]
96
+ parsed = value[:parsed]
97
+ # puts inner_type, bytes, parsed
98
+ # length = bytes.length/2
99
+ # inner_value_bytes = bytes[2..]
100
+ data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
101
+ # puts length
102
+ serialize_option_cl_value(data)
103
+ # "11111111111111111111111"
104
+ elsif type == "List"
105
+ [0].pack("L<*").unpack1("H*")
106
+ elsif type == "ByteArray"
107
+ [0].pack("L<*").unpack1("H*")
108
+ elsif type == "Result"
109
+ [0].pack("L<*").unpack1("H*")
110
+ elsif type == "Map"
111
+ [0].pack("L<*").unpack1("H*")
112
+ elsif type == "Tuple1"
113
+ clvalue1 = clvalue.get_value[0]
114
+ type1 = clvalue1.get_cl_type
115
+ value1 = clvalue1.get_value
116
+ tag1 = CLType::TAGS[type1.to_sym]
117
+ serialized += helper(clvalue.get_value[0]) + [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*")
118
+ # [18].pack("C*").unpack1("H*") + cl_type.get_data[0].to_bytes
119
+ elsif type == "Tuple2"
120
+ clvalue1 = clvalue.get_value[0]
121
+ type1 = clvalue1.get_cl_type
122
+ value1 = clvalue1.get_value
123
+ tag1 = CLType::TAGS[type1.to_sym]
124
+
125
+ clvalue2 = clvalue.get_value[1]
126
+ type2 = clvalue2.get_cl_type
127
+ value2 = clvalue2.get_value
128
+ tag2 = CLType::TAGS[type2.to_sym]
129
+
130
+ len = only_length(clvalue.get_value[0]) + only_length(clvalue.get_value[1])
131
+ [len].pack("L<*").unpack1("H*") + only_value(clvalue.get_value[0]) + only_value(clvalue.get_value[1]) +
132
+ [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*") + [tag2].pack("C*").unpack1("H*")
133
+ elsif type == "Tuple3"
134
+ clvalue1 = clvalue.get_value[0]
135
+ type1 = clvalue1.get_cl_type
136
+ value1 = clvalue1.get_value
137
+ tag1 = CLType::TAGS[type1.to_sym]
138
+
139
+ clvalue2 = clvalue.get_value[1]
140
+ type2 = clvalue2.get_cl_type
141
+ value2 = clvalue2.get_value
142
+ tag2 = CLType::TAGS[type2.to_sym]
143
+
144
+ clvalue3 = clvalue.get_value[2]
145
+ type3 = clvalue3.get_cl_type
146
+ value3 = clvalue3.get_value
147
+ tag3 = CLType::TAGS[type3.to_sym]
148
+
149
+ len = only_length(clvalue.get_value[0]) + only_length(clvalue.get_value[1]) + only_length(clvalue.get_value[2])
150
+ [len].pack("L<*").unpack1("H*") + only_value(clvalue.get_value[0]) + only_value(clvalue.get_value[1]) + only_value(clvalue.get_value[2]) +
151
+ [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*") + [tag2].pack("C*").unpack1("H*") + [tag3].pack("C*").unpack1("H*")
152
+ elsif type == "Any"
153
+ [0].pack("L<*").unpack1("H*")
154
+ elsif type == "PublicKey"
155
+ puts "?????????????: " + [tag].pack("C*").unpack1("H*")
156
+ [clvalue.to_hex.length/2].pack("L<*").unpack1("H*") + clvalue.to_hex + [tag].pack("C*").unpack1("H*")
157
+ # clvalue.to_hex + [tag].pack("C*").unpack1("H*")
158
+ else
159
+ "Undefined"
160
+ end
161
+ end
162
+
163
+ def helper(clvalue)
164
+ type = clvalue.get_cl_type
165
+ value = clvalue.get_value
166
+ serialized = ""
167
+ if type == "Bool"
168
+ [1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*")
169
+ elsif type == "I32"
170
+ [4].pack("L<*").unpack1("H*") + [value].pack("l<*").unpack1("H*")
171
+ elsif type == "I64"
172
+ [8].pack("L<*").unpack1("H*") + [value].pack("q<*").unpack1("H*")
173
+ elsif type == "U8"
174
+ [1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*")
175
+ elsif type == "U32"
176
+ # serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
177
+ [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
178
+ elsif type == "U64"
179
+ [8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*")
180
+ elsif type == "U128"
181
+ [8].pack("L<*").unpack1("H*")
182
+ elsif type == "U256"
183
+ [8].pack("L<*").unpack1("H*")
184
+ elsif type == "U512"
185
+ bytes = [value].pack("Q<*").unpack1("H*")
186
+ bytes = bytes[0, 8]
187
+ [8].pack("Q<*").unpack1("H*")
188
+ elsif type == "Unit"
189
+ [9].pack("C*").unpack1("H*")
190
+ elsif type == "String"
191
+ length = CLValueBytesParsers::CLStringBytesParser.to_bytes(value).length
192
+ [length/2].pack("L<*").unpack1("H*") + CLValueBytesParsers::CLStringBytesParser.to_bytes(value)
193
+ elsif type == "Key"
194
+ [11].pack("C*").unpack1("H*")
195
+ elsif type == "URef"
196
+ uref = clvalue.get_value
197
+ size = clvalue.to_bytes(uref).length/2
198
+ [size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref)
199
+ elsif type == "Option"
200
+ [0].pack("L<*").unpack1("H*")
201
+ elsif type == "List"
202
+ [0].pack("L<*").unpack1("H*")
203
+ elsif type == "ByteArray"
204
+ [0].pack("L<*").unpack1("H*")
205
+ elsif type == "Result"
206
+ [0].pack("L<*").unpack1("H*")
207
+ elsif type == "Map"
208
+ [0].pack("L<*").unpack1("H*")
209
+ else
210
+ "Undefined"
211
+ end
212
+ end
213
+
214
+ def only_length(clvalue)
215
+ type = clvalue.get_cl_type
216
+ value = clvalue.get_value
217
+ if type == "Bool"
218
+ 1
219
+ elsif type == "I32"
220
+ 4
221
+ elsif type == "I64"
222
+ 8
223
+ elsif type == "U8"
224
+ 1
225
+ elsif type == "U32"
226
+ 4
227
+ elsif type == "U64"
228
+ 8
229
+ elsif type == "U128"
230
+ 8
231
+ elsif type == "U256"
232
+ 8
233
+ elsif type == "U512"
234
+ 8
235
+ elsif type == "Unit"
236
+ 8
237
+ elsif type == "String"
238
+ 4 + value.length
239
+ elsif type == "Key"
240
+ 32
241
+ elsif type == "URef"
242
+ uref = clvalue.get_value
243
+ size = clvalue.to_bytes(uref).length/2
244
+ elsif type == "Option"
245
+ 8
246
+ elsif type == "List"
247
+ 8
248
+ elsif type == "ByteArray"
249
+ 8
250
+ elsif type == "Result"
251
+ 8
252
+ elsif type == "Map"
253
+ 8
254
+ else
255
+ 0
256
+ end
257
+ end
258
+ def only_value(clvalue)
259
+ type = clvalue.get_cl_type
260
+ value = clvalue.get_value
261
+ if type == "Bool"
262
+ [value.to_i].pack("C*").unpack1("H*")
263
+ elsif type == "I32"
264
+ [value].pack("l<*").unpack1("H*")
265
+ elsif type == "I64"
266
+ [value].pack("q<*").unpack1("H*")
267
+ elsif type == "U8"
268
+ [value].pack("C*").unpack1("H*")
269
+ elsif type == "U32"
270
+ [value].pack("L<*").unpack1("H*")
271
+ elsif type == "U64"
272
+ [value].pack("Q<*").unpack1("H*")
273
+ elsif type == "U128"
274
+ [value].pack("Q<*").unpack1("H*")
275
+ elsif type == "U256"
276
+ [value].pack("Q<*").unpack1("H*")
277
+ elsif type == "U512"
278
+ [value].pack("Q<*").unpack1("H*")
279
+ elsif type == "Unit"
280
+ [value].pack("C*").unpack1("H*")
281
+ elsif type == "String"
282
+ CLValueBytesParsers::CLStringBytesParser.to_bytes(value)
283
+ elsif type == "Key"
284
+ [value].pack("C*").unpack1("H*")
285
+ elsif type == "URef"
286
+ uref = clvalue.get_value
287
+ clvalue.to_bytes(uref)
288
+ elsif type == "Option"
289
+ [0].pack("L<*").unpack1("H*")
290
+ elsif type == "List"
291
+ [0].pack("L<*").unpack1("H*")
292
+ elsif type == "ByteArray"
293
+ [0].pack("L<*").unpack1("H*")
294
+ elsif type == "Result"
295
+ [0].pack("L<*").unpack1("H*")
296
+ elsif type == "Map"
297
+ [0].pack("L<*").unpack1("H*")
298
+ else
299
+ "Undefined"
300
+ end
301
+ end
302
+
303
+ def serialize_option_cl_value(data)
304
+ cl_type = data[:cl_type]
305
+ bytes = data[:bytes]
306
+ parsed = data[:parsed]
307
+
308
+ if cl_type == "U64"
309
+ length = bytes.length/2
310
+ puts length
311
+ bytes = bytes[2..]
312
+ value = Utils::ByteUtils.hex_to_u64_value(bytes)
313
+ puts value == 1650706686882
314
+ clvalue = CLu64.new(value)
315
+ tag = CLType::TAGS[cl_type.to_sym]
316
+ puts "U64: " + [length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
317
+ [length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
318
+ end
319
+ end
320
+ end
@@ -18,6 +18,7 @@ class DeployHeaderSerializer
18
18
  @timestamp = deploy_header.get_timestamp
19
19
  timestamp_ms = Utils::TimeUtils.to_epoc_ms(@timestamp)
20
20
  @serialized_timestamp = Utils::ByteUtils.to_u64(timestamp_ms)
21
+ # puts "serialized_timestamp: " + @serialized_timestamp
21
22
  @serialized_header << @serialized_timestamp
22
23
 
23
24
  @ttl = deploy_header.get_ttl
@@ -8,6 +8,7 @@ require_relative './cl_value_serializer.rb'
8
8
  class DeployNamedArgSerializer
9
9
 
10
10
  def to_bytes(arg)
11
+ # puts arg
11
12
  name = arg.get_name
12
13
  serialized_name = CLValueBytesParsers::CLStringBytesParser.to_bytes(name)
13
14
  clvalue = arg.get_value
@@ -3,25 +3,35 @@ require_relative './deploy_approval_serializer'
3
3
  require_relative './deploy_executable_serializer'
4
4
  require_relative './deploy_named_arg_serializer'
5
5
  require_relative '../utils/byte_utils.rb'
6
-
6
+ require_relative '../types/cl_option.rb'
7
+ require_relative '../utils/helpers.rb'
7
8
  # Byte serializer for Deploy object
8
9
  class DeploySerializer
9
-
10
+ include Utils::Helpers
11
+ attr_accessor :payment_session_serializer, :transfer_serializer, :payment_serializer
12
+ def initialize
13
+ end
14
+
10
15
  def to_bytes(deploy)
16
+ @payment_session_serializer = ""
17
+ @amount_serializer = ""
18
+ @target_serializer = ""
19
+ @id_serializer = ""
20
+ @transfer_serializer = ""
21
+ @payment_serializer = ""
11
22
  result = ""
12
23
  deploy_header = Casper::Entity::DeployHeader.new(deploy.get_header)
13
24
  result += DeployHeaderSerializer.new().to_bytes(deploy_header)
14
25
 
15
26
  deploy_hash = Casper::Entity::DeployHash.new(deploy.get_hash)
16
27
  result += deploy_hash.get_hash
17
-
18
28
  payment = deploy.get_payment
19
29
  session = deploy.get_session
20
30
  if payment.keys[0] == :ModuleBytes
21
31
  temp_args = []
22
32
  module_bytes = payment[:ModuleBytes][:module_bytes]
23
33
  args = payment[:ModuleBytes][:args]
24
- module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
34
+ # module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
25
35
  args.each do |arg|
26
36
  name1 = arg[0]
27
37
  clvalue_hash = arg[1]
@@ -31,6 +41,8 @@ class DeploySerializer
31
41
  end
32
42
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
33
43
  result += temp
44
+ @payment_serializer += temp
45
+ @payment_session_serializer += temp
34
46
  temp = nil
35
47
  elsif payment.keys[0] == :StoredContractByHash
36
48
  temp_args = []
@@ -48,6 +60,7 @@ class DeploySerializer
48
60
  end
49
61
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
50
62
  result += temp
63
+ @payment_session_serializer += temp
51
64
  temp = nil
52
65
  elsif payment.keys[0] == :StoredContractByName
53
66
  temp_args = []
@@ -64,6 +77,7 @@ class DeploySerializer
64
77
  end
65
78
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
66
79
  result += temp
80
+ @payment_session_serializer += temp
67
81
  temp = nil
68
82
  elsif payment.keys[0] == :StoredVersionedContractByHash
69
83
  temp_args = []
@@ -81,6 +95,7 @@ class DeploySerializer
81
95
  end
82
96
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
83
97
  result += temp
98
+ @payment_session_serializer += temp
84
99
  temp = nil
85
100
  elsif payment.keys[0] == :StoredVersionedContractByName
86
101
  temp_args = []
@@ -98,6 +113,7 @@ class DeploySerializer
98
113
  end
99
114
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
100
115
  result += temp
116
+ @payment_session_serializer += temp
101
117
  temp = nil
102
118
  elsif payment.keys[0] == :Transfer
103
119
  temp_args = []
@@ -113,6 +129,7 @@ class DeploySerializer
113
129
  end
114
130
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
115
131
  result += temp
132
+ @payment_session_serializer += temp
116
133
  temp = nil
117
134
  end
118
135
 
@@ -120,7 +137,7 @@ class DeploySerializer
120
137
  temp_args = []
121
138
  module_bytes = session[:ModuleBytes][:module_bytes]
122
139
  args = session[:ModuleBytes][:args]
123
- module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
140
+ # module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
124
141
  args.each do |arg|
125
142
  name1 = arg[0]
126
143
  clvalue_hash = arg[1]
@@ -129,6 +146,7 @@ class DeploySerializer
129
146
  end
130
147
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
131
148
  result += temp
149
+ @payment_session_serializer += temp
132
150
  temp = nil
133
151
  elsif session.keys[0] == :StoredContractByHash
134
152
  temp_args = []
@@ -146,6 +164,7 @@ class DeploySerializer
146
164
  end
147
165
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
148
166
  result += temp
167
+ @payment_session_serializer += temp
149
168
  temp = nil
150
169
  elsif session.keys[0] == :StoredContractByName
151
170
  temp_args = []
@@ -162,6 +181,7 @@ class DeploySerializer
162
181
  end
163
182
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
164
183
  result += temp
184
+ @payment_session_serializer += temp
165
185
  temp = nil
166
186
  elsif session.keys[0] == :StoredVersionedContractByHash
167
187
  temp_args = []
@@ -179,6 +199,7 @@ class DeploySerializer
179
199
  end
180
200
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
181
201
  result += temp
202
+ @payment_session_serializer += temp
182
203
  temp = nil
183
204
  elsif session.keys[0] == :StoredVersionedContractByName
184
205
  temp_args = []
@@ -196,6 +217,7 @@ class DeploySerializer
196
217
  end
197
218
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
198
219
  result += temp
220
+ @payment_session_serializer += temp
199
221
  temp = nil
200
222
 
201
223
  elsif session.keys[0] == :Transfer
@@ -203,26 +225,71 @@ class DeploySerializer
203
225
  args = session[:Transfer][:args]
204
226
 
205
227
  transfer = Casper::Entity::DeployExecutableTransfer.new(args)
228
+ # args.each do |arg|
229
+ # name1 = arg[0] # => "amount"
230
+ # clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
231
+ # clvalue = build_cl_value(arg[1])
232
+ # # puts clvalue
233
+ # temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
234
+ # end
235
+
206
236
  args.each do |arg|
207
- name1 = arg[0] # => "amount"
208
- clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
209
- clvalue = build_cl_value(arg[1])
210
- # puts clvalue
211
- temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
237
+ name1 = arg[0]
238
+ if name1 == "amount" || name1 == "target"
239
+ clvalue_hash = arg[1]
240
+ clvalue = build_cl_value(arg[1])
241
+ # puts "clvalue.get_value: #{clvalue.get_value}"
242
+ temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
243
+ elsif name1 == "id"
244
+ bytes = arg[1][:bytes]
245
+ parsed = arg[1][:parsed]
246
+ h = arg[1][:cl_type]
247
+ key, value = h.first
248
+ cl_type = h.keys[0]
249
+ # puts key, value
250
+ inner_type = value
251
+ puts "Inner Type = #{value}"
252
+ # data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
253
+ # clvalue = CLOption.new(data, inner_type)
254
+
255
+ inner_clvalue = Utils::Helpers.construct_inner_clvalue(inner_type, parsed)
256
+ clvalue = CLOption.new(inner_clvalue, inner_type)
257
+ # type = clvalue.get_cl_type
258
+ # puts type
259
+ # value = clvalue.get_value
260
+ # puts value
261
+ # tag = CLType::TAGS[type.to_sym]
262
+ # puts tag
263
+ # cl_value = { "cl_type": cl_type, "bytes": bytes, "parsed": parsed}
264
+ # clvalue = build_cl_value(cloption)
265
+ # puts cloption.get_value
266
+ temp_args << [Casper::Entity::DeployNamedArgument.new(name1, clvalue)]
267
+ end
212
268
  end
213
269
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
270
+ @target_serializer = temp
271
+ # puts @target_serializer
214
272
  result += temp
273
+ @transfer_serializer += temp
274
+ @payment_session_serializer += temp
215
275
  temp = nil
216
276
  end
217
277
 
218
278
  approvals = deploy.get_approvals
219
279
  num_of_approvals = approvals.size
280
+ # puts "num_of_approvals: #{num_of_approvals}"
281
+ approval_serializer = ""
220
282
  deploy_approval_serializer = DeployApprovalSerializer.new
221
283
  result += Utils::ByteUtils.to_u32(num_of_approvals)
284
+ approval_serializer += Utils::ByteUtils.to_u32(num_of_approvals)
285
+ # @payment_session_serializer += Utils::ByteUtils.to_u32(num_of_approvals)
222
286
  for approval in approvals
223
287
  deploy_approval = Casper::Entity::DeployApproval.new(approval)
288
+ # @payment_session_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
224
289
  result += deploy_approval_serializer.to_bytes(deploy_approval)
290
+ approval_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
225
291
  end
292
+ # puts "approval_serializer: #{approval_serializer}"
226
293
  # result
227
294
  Utils::ByteUtils.hex_to_byte_array(result)
228
295
  end
@@ -231,6 +298,8 @@ class DeploySerializer
231
298
  cl_type = h[:cl_type]
232
299
  bytes = h[:bytes]
233
300
  parsed = h[:parsed]
301
+ # puts "h[:bytes] = #{h[:bytes]}"
302
+ # puts "h[:parsed] = #{h[:parsed]}"
234
303
  if cl_type == "Bool"
235
304
  CLValueBytesParsers::CLBoolBytesParser.from_bytes([bytes])
236
305
  elsif cl_type == "I32"
@@ -248,6 +317,22 @@ class DeploySerializer
248
317
  elsif cl_type == "U64"
249
318
  value = Utils::ByteUtils.hex_to_u64_value(bytes)
250
319
  CLu32.new(value)
320
+ elsif cl_type == "U512"
321
+ bytes = h[:bytes] # => 0400f90295
322
+ # puts "bytes:\t#{bytes}"
323
+ num_of_bytes = bytes[0..1] # => 04
324
+ bytes = bytes[2..] # => "00f90295"
325
+ # puts "bytes[2..]:\t#{bytes}"
326
+ value = [bytes].pack("H*").unpack("L*").first
327
+ # puts "value:\t#{value}"
328
+ # CLu512.new(value)
329
+ # puts "parsed:\t#{parsed}"
330
+ # puts "parsed.to_i: #{parsed.to_i}"
331
+ CLu512.new(parsed.to_i)
332
+ # value = Utils::ByteUtils.hex_to_u64_value(bytes)
333
+ # CLu512.new(value)
334
+ # value = Utils::ByteUtils.hex_to_u512_value(bytes)
335
+ # CLu512.new(value)
251
336
  elsif cl_type == "Unit"
252
337
  # value = CLValueBytesParsers::CLUnitBytesParser.from_bytes(bytes)
253
338
  if bytes == ""
@@ -260,6 +345,55 @@ class DeploySerializer
260
345
  elsif cl_type == "URef"
261
346
  value = Utils::ByteUtils.hex_to_byte_array(bytes)
262
347
  CLValueBytesParsers::CLURefBytesParser.from_bytes(value)
348
+ # elsif cl_type = "Option"
349
+
350
+ elsif cl_type == "PublicKey"
351
+ CLPublicKey.from_hex(bytes)
352
+ end
353
+ end
354
+
355
+ def build_cl_value_with_option(h = {})
356
+ cl_type = h[:cl_type]
357
+ bytes = h[:bytes]
358
+ # puts bytes
359
+ parsed = h[:parsed]
360
+ if cl_type == "Bool"
361
+ CLValueBytesParsers::CLBoolBytesParser.from_bytes([bytes])
362
+ elsif cl_type == "I32"
363
+ value = Utils::ByteUtils.hex_to_integer(bytes)
364
+ CLi32.new(value)
365
+ elsif cl_type == "I64"
366
+ value = Utils::ByteUtils.hex_to_i64_value(bytes)
367
+ CLi64.new(value)
368
+ elsif cl_type == "U8"
369
+ value = Utils::ByteUtils.hex_to_u8_value(bytes)
370
+ CLu8.new(value)
371
+ elsif cl_type == "U32"
372
+ value = Utils::ByteUtils.hex_to_u32_value(bytes)
373
+ CLu32.new(value)
374
+ elsif cl_type == "U64"
375
+ value = Utils::ByteUtils.hex_to_u64_value(bytes)
376
+ CLu32.new(value)
377
+ elsif cl_type == "U512"
378
+ value = Utils::ByteUtils.hex_to_u64_value(bytes)
379
+ # puts "value:\t#{value}"
380
+ CLu512.new(value)
381
+ # value = Utils::ByteUtils.hex_to_u512_value(bytes)
382
+ # CLu512.new(value)
383
+ elsif cl_type == "Unit"
384
+ # value = CLValueBytesParsers::CLUnitBytesParser.from_bytes(bytes)
385
+ if bytes == ""
386
+ value = nil
387
+ CLUnit.new(value)
388
+ end
389
+ elsif cl_type == "String"
390
+ value = CLValueBytesParsers::CLStringBytesParser.from_bytes(bytes)
391
+ CLString.new(value)
392
+ elsif cl_type == "URef"
393
+ value = Utils::ByteUtils.hex_to_byte_array(bytes)
394
+ CLValueBytesParsers::CLURefBytesParser.from_bytes(value)
395
+ # elsif cl_type = "Option"
396
+
263
397
  elsif cl_type == "PublicKey"
264
398
  CLPublicKey.from_hex(bytes)
265
399
  end