test_sdk1 1.0.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +495 -76
  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/group.rb +1 -1
  22. data/lib/entity/module_bytes.rb +16 -2
  23. data/lib/entity/status.rb +80 -0
  24. data/lib/entity/stored_contract_by_name.rb +2 -1
  25. data/lib/entity/stored_value.rb +86 -11
  26. data/lib/entity/stored_versioned_contract_by_hash.rb +2 -1
  27. data/lib/entity/stored_versioned_contract_by_name.rb +1 -1
  28. data/lib/entity/transfer.rb +7 -7
  29. data/lib/include.rb +2 -0
  30. data/lib/rpc/rpc_client.rb +1 -2
  31. data/lib/serialization/cl_type_serializer.rb +1 -0
  32. data/lib/serialization/cl_value_serializer.rb +70 -12
  33. data/lib/serialization/cl_value_serializer1.rb +314 -0
  34. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  35. data/lib/serialization/deploy_approval_serializer.rb +1 -0
  36. data/lib/serialization/deploy_executable_serializer.rb +1 -1
  37. data/lib/serialization/deploy_header_serializer.rb +2 -1
  38. data/lib/serialization/deploy_named_arg_serializer.rb +2 -0
  39. data/lib/serialization/deploy_serializer.rb +145 -10
  40. data/lib/serialization/deploy_serializer1.rb +392 -0
  41. data/lib/serialization/deploy_serializer_update.rb +397 -0
  42. data/lib/serialization/test.rb +33 -13
  43. data/lib/test_sdk1.rb +30 -13
  44. data/lib/types/cl_option.rb +8 -2
  45. data/lib/types/cl_public_key.rb +2 -0
  46. data/lib/types/cl_type.rb +1 -0
  47. data/lib/types/cl_value.rb +8 -0
  48. data/lib/utils/byte_utils.rb +28 -0
  49. data/lib/utils/helpers.rb +10 -0
  50. data/lib/version.rb +1 -1
  51. data/spec/cl_value_serializer_spec.rb +16 -1
  52. data/spec/client_spec.rb +20 -20
  53. data/spec/dene_spec.rb +186 -0
  54. data/spec/deploy_executable_spec.rb +90 -0
  55. data/spec/deploy_executable_test_spec.rb +117 -0
  56. data/spec/deploy_serializer_spec.rb +5 -3
  57. data/spec/deploy_serializer_test_spec.rb +7 -1
  58. data/spec/testnet_spec.rb +3 -1
  59. data/spec/time_utils_spec.rb +3 -0
  60. metadata +20 -5
  61. data/lib/crypto/key_pair.rb +0 -40
  62. 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
@@ -3,6 +3,7 @@ require_relative '../serialization/cl_value_bytes_parsers.rb'
3
3
  require_relative '../utils/time_utils.rb'
4
4
  require_relative '../utils/byte_utils.rb'
5
5
 
6
+ # Byte serializer for DeployApproval object
6
7
  class DeployApprovalSerializer
7
8
  def to_bytes(deploy_approval)
8
9
  @approval_serializer = ""
@@ -1,6 +1,6 @@
1
1
  require_relative '../entity/deploy_executable.rb'
2
2
 
3
-
3
+ # Byte serializer for DeployExecutable object
4
4
  class DeployExecutableSerializer
5
5
 
6
6
  def initialize
@@ -3,7 +3,7 @@ require_relative '../serialization/cl_value_bytes_parsers.rb'
3
3
  require_relative '../utils/time_utils.rb'
4
4
  require_relative '../utils/byte_utils.rb'
5
5
 
6
-
6
+ # Byte serializer for DeployHeader object
7
7
  class DeployHeaderSerializer
8
8
 
9
9
  # @param [DeployerHeader] deploy_header
@@ -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
@@ -4,9 +4,11 @@ require_relative '../utils/byte_utils.rb'
4
4
  require_relative './cl_type_serializer.rb'
5
5
  require_relative './cl_value_serializer.rb'
6
6
 
7
+ # Byte serializer for DeployNamedArg object
7
8
  class DeployNamedArgSerializer
8
9
 
9
10
  def to_bytes(arg)
11
+ # puts arg
10
12
  name = arg.get_name
11
13
  serialized_name = CLValueBytesParsers::CLStringBytesParser.to_bytes(name)
12
14
  clvalue = arg.get_value
@@ -3,24 +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'
8
+ # Byte serializer for Deploy object
7
9
  class DeploySerializer
8
-
10
+ include Utils::Helpers
11
+ attr_accessor :payment_session_serializer, :transfer_serializer, :payment_serializer
12
+ def initialize
13
+ end
14
+
9
15
  def to_bytes(deploy)
16
+ @payment_session_serializer = ""
17
+ @amount_serializer = ""
18
+ @target_serializer = ""
19
+ @id_serializer = ""
20
+ @transfer_serializer = ""
21
+ @payment_serializer = ""
10
22
  result = ""
11
23
  deploy_header = Casper::Entity::DeployHeader.new(deploy.get_header)
12
24
  result += DeployHeaderSerializer.new().to_bytes(deploy_header)
13
25
 
14
26
  deploy_hash = Casper::Entity::DeployHash.new(deploy.get_hash)
15
27
  result += deploy_hash.get_hash
16
-
17
28
  payment = deploy.get_payment
18
29
  session = deploy.get_session
19
30
  if payment.keys[0] == :ModuleBytes
20
31
  temp_args = []
21
32
  module_bytes = payment[:ModuleBytes][:module_bytes]
22
33
  args = payment[:ModuleBytes][:args]
23
- module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
34
+ # module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
24
35
  args.each do |arg|
25
36
  name1 = arg[0]
26
37
  clvalue_hash = arg[1]
@@ -30,6 +41,8 @@ class DeploySerializer
30
41
  end
31
42
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
32
43
  result += temp
44
+ @payment_serializer += temp
45
+ @payment_session_serializer += temp
33
46
  temp = nil
34
47
  elsif payment.keys[0] == :StoredContractByHash
35
48
  temp_args = []
@@ -47,6 +60,7 @@ class DeploySerializer
47
60
  end
48
61
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
49
62
  result += temp
63
+ @payment_session_serializer += temp
50
64
  temp = nil
51
65
  elsif payment.keys[0] == :StoredContractByName
52
66
  temp_args = []
@@ -63,6 +77,7 @@ class DeploySerializer
63
77
  end
64
78
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
65
79
  result += temp
80
+ @payment_session_serializer += temp
66
81
  temp = nil
67
82
  elsif payment.keys[0] == :StoredVersionedContractByHash
68
83
  temp_args = []
@@ -80,6 +95,7 @@ class DeploySerializer
80
95
  end
81
96
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
82
97
  result += temp
98
+ @payment_session_serializer += temp
83
99
  temp = nil
84
100
  elsif payment.keys[0] == :StoredVersionedContractByName
85
101
  temp_args = []
@@ -97,6 +113,7 @@ class DeploySerializer
97
113
  end
98
114
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
99
115
  result += temp
116
+ @payment_session_serializer += temp
100
117
  temp = nil
101
118
  elsif payment.keys[0] == :Transfer
102
119
  temp_args = []
@@ -112,6 +129,7 @@ class DeploySerializer
112
129
  end
113
130
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
114
131
  result += temp
132
+ @payment_session_serializer += temp
115
133
  temp = nil
116
134
  end
117
135
 
@@ -119,7 +137,7 @@ class DeploySerializer
119
137
  temp_args = []
120
138
  module_bytes = session[:ModuleBytes][:module_bytes]
121
139
  args = session[:ModuleBytes][:args]
122
- module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
140
+ # module_bytes = Casper::Entity::ModuleBytes.new(module_bytes, args)
123
141
  args.each do |arg|
124
142
  name1 = arg[0]
125
143
  clvalue_hash = arg[1]
@@ -128,6 +146,7 @@ class DeploySerializer
128
146
  end
129
147
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::ModuleBytes.new(module_bytes, temp_args).to_bytes)
130
148
  result += temp
149
+ @payment_session_serializer += temp
131
150
  temp = nil
132
151
  elsif session.keys[0] == :StoredContractByHash
133
152
  temp_args = []
@@ -145,6 +164,7 @@ class DeploySerializer
145
164
  end
146
165
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByHash.new(name, entry_point, temp_args).to_bytes)
147
166
  result += temp
167
+ @payment_session_serializer += temp
148
168
  temp = nil
149
169
  elsif session.keys[0] == :StoredContractByName
150
170
  temp_args = []
@@ -161,6 +181,7 @@ class DeploySerializer
161
181
  end
162
182
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredContractByName.new(name, entry_point, temp_args).to_bytes)
163
183
  result += temp
184
+ @payment_session_serializer += temp
164
185
  temp = nil
165
186
  elsif session.keys[0] == :StoredVersionedContractByHash
166
187
  temp_args = []
@@ -178,6 +199,7 @@ class DeploySerializer
178
199
  end
179
200
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByHash.new(name, version,entry_point, temp_args).to_bytes)
180
201
  result += temp
202
+ @payment_session_serializer += temp
181
203
  temp = nil
182
204
  elsif session.keys[0] == :StoredVersionedContractByName
183
205
  temp_args = []
@@ -195,6 +217,7 @@ class DeploySerializer
195
217
  end
196
218
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::StoredVersionedContractByName.new(name, version,entry_point, temp_args).to_bytes)
197
219
  result += temp
220
+ @payment_session_serializer += temp
198
221
  temp = nil
199
222
 
200
223
  elsif session.keys[0] == :Transfer
@@ -202,26 +225,71 @@ class DeploySerializer
202
225
  args = session[:Transfer][:args]
203
226
 
204
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
+
205
236
  args.each do |arg|
206
- name1 = arg[0] # => "amount"
207
- clvalue_hash = arg[1] # => {:cl_type=>"I32", :bytes=>"e8030000", :parsed=>1000}
208
- clvalue = build_cl_value(arg[1])
209
- # puts clvalue
210
- 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
211
268
  end
212
269
  temp = Utils::ByteUtils.byte_array_to_hex(Casper::Entity::DeployExecutableTransfer.new(temp_args).to_bytes)
270
+ @target_serializer = temp
271
+ # puts @target_serializer
213
272
  result += temp
273
+ @transfer_serializer += temp
274
+ @payment_session_serializer += temp
214
275
  temp = nil
215
276
  end
216
277
 
217
278
  approvals = deploy.get_approvals
218
279
  num_of_approvals = approvals.size
280
+ # puts "num_of_approvals: #{num_of_approvals}"
281
+ approval_serializer = ""
219
282
  deploy_approval_serializer = DeployApprovalSerializer.new
220
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)
221
286
  for approval in approvals
222
287
  deploy_approval = Casper::Entity::DeployApproval.new(approval)
288
+ # @payment_session_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
223
289
  result += deploy_approval_serializer.to_bytes(deploy_approval)
290
+ approval_serializer += deploy_approval_serializer.to_bytes(deploy_approval)
224
291
  end
292
+ # puts "approval_serializer: #{approval_serializer}"
225
293
  # result
226
294
  Utils::ByteUtils.hex_to_byte_array(result)
227
295
  end
@@ -230,6 +298,8 @@ class DeploySerializer
230
298
  cl_type = h[:cl_type]
231
299
  bytes = h[:bytes]
232
300
  parsed = h[:parsed]
301
+ # puts "h[:bytes] = #{h[:bytes]}"
302
+ # puts "h[:parsed] = #{h[:parsed]}"
233
303
  if cl_type == "Bool"
234
304
  CLValueBytesParsers::CLBoolBytesParser.from_bytes([bytes])
235
305
  elsif cl_type == "I32"
@@ -247,6 +317,22 @@ class DeploySerializer
247
317
  elsif cl_type == "U64"
248
318
  value = Utils::ByteUtils.hex_to_u64_value(bytes)
249
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)
250
336
  elsif cl_type == "Unit"
251
337
  # value = CLValueBytesParsers::CLUnitBytesParser.from_bytes(bytes)
252
338
  if bytes == ""
@@ -259,6 +345,55 @@ class DeploySerializer
259
345
  elsif cl_type == "URef"
260
346
  value = Utils::ByteUtils.hex_to_byte_array(bytes)
261
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
+
262
397
  elsif cl_type == "PublicKey"
263
398
  CLPublicKey.from_hex(bytes)
264
399
  end