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.
- checksums.yaml +4 -4
- data/README.md +495 -76
- 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/group.rb +1 -1
- data/lib/entity/module_bytes.rb +16 -2
- data/lib/entity/status.rb +80 -0
- data/lib/entity/stored_contract_by_name.rb +2 -1
- data/lib/entity/stored_value.rb +86 -11
- data/lib/entity/stored_versioned_contract_by_hash.rb +2 -1
- data/lib/entity/stored_versioned_contract_by_name.rb +1 -1
- data/lib/entity/transfer.rb +7 -7
- data/lib/include.rb +2 -0
- data/lib/rpc/rpc_client.rb +1 -2
- data/lib/serialization/cl_type_serializer.rb +1 -0
- data/lib/serialization/cl_value_serializer.rb +70 -12
- data/lib/serialization/cl_value_serializer1.rb +314 -0
- data/lib/serialization/cl_value_serializer_update.rb +320 -0
- data/lib/serialization/deploy_approval_serializer.rb +1 -0
- data/lib/serialization/deploy_executable_serializer.rb +1 -1
- data/lib/serialization/deploy_header_serializer.rb +2 -1
- data/lib/serialization/deploy_named_arg_serializer.rb +2 -0
- data/lib/serialization/deploy_serializer.rb +145 -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 +30 -13
- data/lib/types/cl_option.rb +8 -2
- data/lib/types/cl_public_key.rb +2 -0
- data/lib/types/cl_type.rb +1 -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/client_spec.rb +20 -20
- 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
data/lib/include.rb
CHANGED
@@ -7,6 +7,8 @@ Dir[File.join(
|
|
7
7
|
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/rpc/*.rb")].each {|file| require file }
|
8
8
|
Dir[File.join(
|
9
9
|
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/utils/*.rb")].each {|file| require file }
|
10
|
+
# Dir[File.join(
|
11
|
+
# File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/crypto/*.rb")].each {|file| require file }
|
10
12
|
# path = File.join(
|
11
13
|
# File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
12
14
|
# '/lib/types/cl_bool'
|
data/lib/rpc/rpc_client.rb
CHANGED
@@ -8,9 +8,8 @@ require 'active_support/core_ext/hash/keys'
|
|
8
8
|
require 'timeout'
|
9
9
|
require 'net/http'
|
10
10
|
require_relative './rpc_error.rb'
|
11
|
-
|
12
11
|
module Casper
|
13
|
-
#
|
12
|
+
# Interacting with the network via RPC
|
14
13
|
class RpcClient
|
15
14
|
attr_accessor :ip_address, :port, :url, :state_root_hash
|
16
15
|
|
@@ -18,19 +18,26 @@ require_relative '../types/cl_uref.rb'
|
|
18
18
|
require_relative '../types/cl_tuple.rb'
|
19
19
|
require_relative '../types/cl_public_key.rb'
|
20
20
|
require_relative '../types/constants.rb'
|
21
|
-
require_relative '
|
21
|
+
require_relative './cl_value_bytes_parsers.rb'
|
22
|
+
require_relative '../utils/byte_utils.rb'
|
22
23
|
|
24
|
+
# Byte serializer for CLValue
|
23
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
|
24
35
|
|
25
36
|
def to_bytes(clvalue)
|
26
37
|
type = clvalue.get_cl_type
|
27
38
|
value = clvalue.get_value
|
28
39
|
tag = CLType::TAGS[type.to_sym]
|
29
|
-
|
30
|
-
# puts value
|
31
|
-
# puts CLType::TAGS[type.to_sym]
|
32
|
-
# puts tag
|
33
|
-
[1].pack("L<*").unpack1("H*")
|
40
|
+
|
34
41
|
serialized = ""
|
35
42
|
if type == "Bool"
|
36
43
|
[1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
@@ -49,7 +56,9 @@ class CLValueSerializer
|
|
49
56
|
elsif type == "U256"
|
50
57
|
[8].pack("L<*").unpack1("H*")
|
51
58
|
elsif type == "U512"
|
52
|
-
|
59
|
+
bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))[0...-2]
|
60
|
+
num_of_bytes = bytes.length/2
|
61
|
+
[num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
|
53
62
|
elsif type == "Unit"
|
54
63
|
[0].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
55
64
|
elsif type == "String"
|
@@ -62,7 +71,31 @@ class CLValueSerializer
|
|
62
71
|
size = clvalue.to_bytes(uref).length/2
|
63
72
|
[size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref) + [tag].pack("C*").unpack1("H*")
|
64
73
|
elsif type == "Option"
|
65
|
-
|
74
|
+
=begin
|
75
|
+
# Solution 1, If we choose
|
76
|
+
# CLOption.new(data, inner_type) = CLOption.new({ "cl_type": inner_type, "bytes": bytes, "parsed": parsed), "U64")
|
77
|
+
inner_type = value[:cl_type]
|
78
|
+
bytes = value[:bytes]
|
79
|
+
parsed = value[:parsed]
|
80
|
+
data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
|
81
|
+
serialize_option_cl_value(data)
|
82
|
+
=end
|
83
|
+
inner_clvalue = value # => CLu64.new(1)
|
84
|
+
inner_value = value.get_value
|
85
|
+
inner_type = value.get_cl_type
|
86
|
+
# or
|
87
|
+
# inner_type = clvalue.get_inner_type
|
88
|
+
|
89
|
+
# puts "inner_clvalue #{inner_clvalue}"
|
90
|
+
inner_type = clvalue.get_inner_type # => or
|
91
|
+
inner_type = value.get_cl_type
|
92
|
+
# puts "inner_type = #{inner_type}"
|
93
|
+
# puts inner_value
|
94
|
+
bytes = Utils::ByteUtils.to_u64(inner_value)
|
95
|
+
bytes = "01" + bytes
|
96
|
+
length = bytes.size/2
|
97
|
+
tag = CLType::TAGS[inner_type.to_sym]
|
98
|
+
[length].pack("L<*").unpack1("H*") + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
66
99
|
elsif type == "List"
|
67
100
|
[0].pack("L<*").unpack1("H*")
|
68
101
|
elsif type == "ByteArray"
|
@@ -77,7 +110,6 @@ class CLValueSerializer
|
|
77
110
|
value1 = clvalue1.get_value
|
78
111
|
tag1 = CLType::TAGS[type1.to_sym]
|
79
112
|
serialized += helper(clvalue.get_value[0]) + [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*")
|
80
|
-
# [18].pack("C*").unpack1("H*") + cl_type.get_data[0].to_bytes
|
81
113
|
elsif type == "Tuple2"
|
82
114
|
clvalue1 = clvalue.get_value[0]
|
83
115
|
type1 = clvalue1.get_cl_type
|
@@ -133,7 +165,8 @@ class CLValueSerializer
|
|
133
165
|
elsif type == "U8"
|
134
166
|
[1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*")
|
135
167
|
elsif type == "U32"
|
136
|
-
serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
168
|
+
# serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
169
|
+
[4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
137
170
|
elsif type == "U64"
|
138
171
|
[8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*")
|
139
172
|
elsif type == "U128"
|
@@ -141,7 +174,9 @@ class CLValueSerializer
|
|
141
174
|
elsif type == "U256"
|
142
175
|
[8].pack("L<*").unpack1("H*")
|
143
176
|
elsif type == "U512"
|
144
|
-
[
|
177
|
+
bytes = [value].pack("Q<*").unpack1("H*")
|
178
|
+
bytes = bytes[0, 8]
|
179
|
+
[8].pack("Q<*").unpack1("H*")
|
145
180
|
elsif type == "Unit"
|
146
181
|
[9].pack("C*").unpack1("H*")
|
147
182
|
elsif type == "String"
|
@@ -256,4 +291,27 @@ class CLValueSerializer
|
|
256
291
|
"Undefined"
|
257
292
|
end
|
258
293
|
end
|
259
|
-
|
294
|
+
|
295
|
+
def serialize_option_cl_value(data)
|
296
|
+
|
297
|
+
=begin
|
298
|
+
# Solution 1
|
299
|
+
# puts "\nOption:"
|
300
|
+
cl_type = data[:cl_type]
|
301
|
+
bytes = data[:bytes]
|
302
|
+
parsed = data[:parsed]
|
303
|
+
|
304
|
+
if cl_type == "U64"
|
305
|
+
length = bytes.length/2
|
306
|
+
# puts length
|
307
|
+
bytes = bytes[2..]
|
308
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
309
|
+
# puts value == 1650706686882
|
310
|
+
clvalue = CLu64.new(value)
|
311
|
+
tag = CLType::TAGS[cl_type.to_sym]
|
312
|
+
# puts "U64: " + [length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
313
|
+
[length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
314
|
+
end
|
315
|
+
=end
|
316
|
+
end
|
317
|
+
end
|
@@ -0,0 +1,314 @@
|
|
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
|
+
type = clvalue.get_cl_type
|
38
|
+
value = clvalue.get_value
|
39
|
+
tag = CLType::TAGS[type.to_sym]
|
40
|
+
# puts type
|
41
|
+
# puts value
|
42
|
+
# puts CLType::TAGS[type.to_sym]
|
43
|
+
# puts tag
|
44
|
+
[1].pack("L<*").unpack1("H*")
|
45
|
+
serialized = ""
|
46
|
+
if type == "Bool"
|
47
|
+
[1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
48
|
+
elsif type == "I32"
|
49
|
+
[4].pack("L<*").unpack1("H*") + [value].pack("l<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
50
|
+
elsif type == "I64"
|
51
|
+
[8].pack("L<*").unpack1("H*") + [value].pack("q<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
52
|
+
elsif type == "U8"
|
53
|
+
[1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
54
|
+
elsif type == "U32"
|
55
|
+
serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
56
|
+
elsif type == "U64"
|
57
|
+
[8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
58
|
+
elsif type == "U128"
|
59
|
+
[8].pack("L<*").unpack1("H*")
|
60
|
+
elsif type == "U256"
|
61
|
+
[8].pack("L<*").unpack1("H*")
|
62
|
+
elsif type == "U512"
|
63
|
+
# puts "value : #{value}"
|
64
|
+
# bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))
|
65
|
+
# puts bytes
|
66
|
+
# num_of_bytes = bytes.length/2
|
67
|
+
# puts num_of_bytes
|
68
|
+
# puts [num_of_bytes].pack("C*").unpack1("H*")
|
69
|
+
# puts [num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
|
70
|
+
|
71
|
+
bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))
|
72
|
+
num_of_bytes = bytes.length/2
|
73
|
+
puts "U512: " + [num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
|
74
|
+
[num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
|
75
|
+
elsif type == "Unit"
|
76
|
+
[0].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
77
|
+
elsif type == "String"
|
78
|
+
length = CLValueBytesParsers::CLStringBytesParser.to_bytes(value).length
|
79
|
+
[length/2].pack("L<*").unpack1("H*") + CLValueBytesParsers::CLStringBytesParser.to_bytes(value) + [tag].pack("C*").unpack1("H*")
|
80
|
+
elsif type == "Key"
|
81
|
+
[11].pack("C*").unpack1("H*")
|
82
|
+
elsif type == "URef"
|
83
|
+
uref = clvalue.get_value
|
84
|
+
size = clvalue.to_bytes(uref).length/2
|
85
|
+
[size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref) + [tag].pack("C*").unpack1("H*")
|
86
|
+
elsif type == "Option"
|
87
|
+
[0].pack("L<*").unpack1("H*")
|
88
|
+
inner_type = value[:cl_type]
|
89
|
+
bytes = value[:bytes]
|
90
|
+
parsed = value[:parsed]
|
91
|
+
# puts inner_type, bytes, parsed
|
92
|
+
# length = bytes.length/2
|
93
|
+
# inner_value_bytes = bytes[2..]
|
94
|
+
data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
|
95
|
+
# puts length
|
96
|
+
serialize_option_cl_value(data)
|
97
|
+
# "11111111111111111111111"
|
98
|
+
elsif type == "List"
|
99
|
+
[0].pack("L<*").unpack1("H*")
|
100
|
+
elsif type == "ByteArray"
|
101
|
+
[0].pack("L<*").unpack1("H*")
|
102
|
+
elsif type == "Result"
|
103
|
+
[0].pack("L<*").unpack1("H*")
|
104
|
+
elsif type == "Map"
|
105
|
+
[0].pack("L<*").unpack1("H*")
|
106
|
+
elsif type == "Tuple1"
|
107
|
+
clvalue1 = clvalue.get_value[0]
|
108
|
+
type1 = clvalue1.get_cl_type
|
109
|
+
value1 = clvalue1.get_value
|
110
|
+
tag1 = CLType::TAGS[type1.to_sym]
|
111
|
+
serialized += helper(clvalue.get_value[0]) + [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*")
|
112
|
+
# [18].pack("C*").unpack1("H*") + cl_type.get_data[0].to_bytes
|
113
|
+
elsif type == "Tuple2"
|
114
|
+
clvalue1 = clvalue.get_value[0]
|
115
|
+
type1 = clvalue1.get_cl_type
|
116
|
+
value1 = clvalue1.get_value
|
117
|
+
tag1 = CLType::TAGS[type1.to_sym]
|
118
|
+
|
119
|
+
clvalue2 = clvalue.get_value[1]
|
120
|
+
type2 = clvalue2.get_cl_type
|
121
|
+
value2 = clvalue2.get_value
|
122
|
+
tag2 = CLType::TAGS[type2.to_sym]
|
123
|
+
|
124
|
+
len = only_length(clvalue.get_value[0]) + only_length(clvalue.get_value[1])
|
125
|
+
[len].pack("L<*").unpack1("H*") + only_value(clvalue.get_value[0]) + only_value(clvalue.get_value[1]) +
|
126
|
+
[tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*") + [tag2].pack("C*").unpack1("H*")
|
127
|
+
elsif type == "Tuple3"
|
128
|
+
clvalue1 = clvalue.get_value[0]
|
129
|
+
type1 = clvalue1.get_cl_type
|
130
|
+
value1 = clvalue1.get_value
|
131
|
+
tag1 = CLType::TAGS[type1.to_sym]
|
132
|
+
|
133
|
+
clvalue2 = clvalue.get_value[1]
|
134
|
+
type2 = clvalue2.get_cl_type
|
135
|
+
value2 = clvalue2.get_value
|
136
|
+
tag2 = CLType::TAGS[type2.to_sym]
|
137
|
+
|
138
|
+
clvalue3 = clvalue.get_value[2]
|
139
|
+
type3 = clvalue3.get_cl_type
|
140
|
+
value3 = clvalue3.get_value
|
141
|
+
tag3 = CLType::TAGS[type3.to_sym]
|
142
|
+
|
143
|
+
len = only_length(clvalue.get_value[0]) + only_length(clvalue.get_value[1]) + only_length(clvalue.get_value[2])
|
144
|
+
[len].pack("L<*").unpack1("H*") + only_value(clvalue.get_value[0]) + only_value(clvalue.get_value[1]) + only_value(clvalue.get_value[2]) +
|
145
|
+
[tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*") + [tag2].pack("C*").unpack1("H*") + [tag3].pack("C*").unpack1("H*")
|
146
|
+
elsif type == "Any"
|
147
|
+
[0].pack("L<*").unpack1("H*")
|
148
|
+
elsif type == "PublicKey"
|
149
|
+
puts "?????????????: " + [tag].pack("C*").unpack1("H*")
|
150
|
+
[clvalue.to_hex.length/2].pack("L<*").unpack1("H*") + clvalue.to_hex + [tag].pack("C*").unpack1("H*")
|
151
|
+
# clvalue.to_hex + [tag].pack("C*").unpack1("H*")
|
152
|
+
else
|
153
|
+
"Undefined"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def helper(clvalue)
|
158
|
+
type = clvalue.get_cl_type
|
159
|
+
value = clvalue.get_value
|
160
|
+
serialized = ""
|
161
|
+
if type == "Bool"
|
162
|
+
[1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*")
|
163
|
+
elsif type == "I32"
|
164
|
+
[4].pack("L<*").unpack1("H*") + [value].pack("l<*").unpack1("H*")
|
165
|
+
elsif type == "I64"
|
166
|
+
[8].pack("L<*").unpack1("H*") + [value].pack("q<*").unpack1("H*")
|
167
|
+
elsif type == "U8"
|
168
|
+
[1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*")
|
169
|
+
elsif type == "U32"
|
170
|
+
# serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
171
|
+
[4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
172
|
+
elsif type == "U64"
|
173
|
+
[8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*")
|
174
|
+
elsif type == "U128"
|
175
|
+
[8].pack("L<*").unpack1("H*")
|
176
|
+
elsif type == "U256"
|
177
|
+
[8].pack("L<*").unpack1("H*")
|
178
|
+
elsif type == "U512"
|
179
|
+
bytes = [value].pack("Q<*").unpack1("H*")
|
180
|
+
bytes = bytes[0, 8]
|
181
|
+
[8].pack("Q<*").unpack1("H*")
|
182
|
+
elsif type == "Unit"
|
183
|
+
[9].pack("C*").unpack1("H*")
|
184
|
+
elsif type == "String"
|
185
|
+
length = CLValueBytesParsers::CLStringBytesParser.to_bytes(value).length
|
186
|
+
[length/2].pack("L<*").unpack1("H*") + CLValueBytesParsers::CLStringBytesParser.to_bytes(value)
|
187
|
+
elsif type == "Key"
|
188
|
+
[11].pack("C*").unpack1("H*")
|
189
|
+
elsif type == "URef"
|
190
|
+
uref = clvalue.get_value
|
191
|
+
size = clvalue.to_bytes(uref).length/2
|
192
|
+
[size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref)
|
193
|
+
elsif type == "Option"
|
194
|
+
[0].pack("L<*").unpack1("H*")
|
195
|
+
elsif type == "List"
|
196
|
+
[0].pack("L<*").unpack1("H*")
|
197
|
+
elsif type == "ByteArray"
|
198
|
+
[0].pack("L<*").unpack1("H*")
|
199
|
+
elsif type == "Result"
|
200
|
+
[0].pack("L<*").unpack1("H*")
|
201
|
+
elsif type == "Map"
|
202
|
+
[0].pack("L<*").unpack1("H*")
|
203
|
+
else
|
204
|
+
"Undefined"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def only_length(clvalue)
|
209
|
+
type = clvalue.get_cl_type
|
210
|
+
value = clvalue.get_value
|
211
|
+
if type == "Bool"
|
212
|
+
1
|
213
|
+
elsif type == "I32"
|
214
|
+
4
|
215
|
+
elsif type == "I64"
|
216
|
+
8
|
217
|
+
elsif type == "U8"
|
218
|
+
1
|
219
|
+
elsif type == "U32"
|
220
|
+
4
|
221
|
+
elsif type == "U64"
|
222
|
+
8
|
223
|
+
elsif type == "U128"
|
224
|
+
8
|
225
|
+
elsif type == "U256"
|
226
|
+
8
|
227
|
+
elsif type == "U512"
|
228
|
+
8
|
229
|
+
elsif type == "Unit"
|
230
|
+
8
|
231
|
+
elsif type == "String"
|
232
|
+
4 + value.length
|
233
|
+
elsif type == "Key"
|
234
|
+
32
|
235
|
+
elsif type == "URef"
|
236
|
+
uref = clvalue.get_value
|
237
|
+
size = clvalue.to_bytes(uref).length/2
|
238
|
+
elsif type == "Option"
|
239
|
+
8
|
240
|
+
elsif type == "List"
|
241
|
+
8
|
242
|
+
elsif type == "ByteArray"
|
243
|
+
8
|
244
|
+
elsif type == "Result"
|
245
|
+
8
|
246
|
+
elsif type == "Map"
|
247
|
+
8
|
248
|
+
else
|
249
|
+
0
|
250
|
+
end
|
251
|
+
end
|
252
|
+
def only_value(clvalue)
|
253
|
+
type = clvalue.get_cl_type
|
254
|
+
value = clvalue.get_value
|
255
|
+
if type == "Bool"
|
256
|
+
[value.to_i].pack("C*").unpack1("H*")
|
257
|
+
elsif type == "I32"
|
258
|
+
[value].pack("l<*").unpack1("H*")
|
259
|
+
elsif type == "I64"
|
260
|
+
[value].pack("q<*").unpack1("H*")
|
261
|
+
elsif type == "U8"
|
262
|
+
[value].pack("C*").unpack1("H*")
|
263
|
+
elsif type == "U32"
|
264
|
+
[value].pack("L<*").unpack1("H*")
|
265
|
+
elsif type == "U64"
|
266
|
+
[value].pack("Q<*").unpack1("H*")
|
267
|
+
elsif type == "U128"
|
268
|
+
[value].pack("Q<*").unpack1("H*")
|
269
|
+
elsif type == "U256"
|
270
|
+
[value].pack("Q<*").unpack1("H*")
|
271
|
+
elsif type == "U512"
|
272
|
+
[value].pack("Q<*").unpack1("H*")
|
273
|
+
elsif type == "Unit"
|
274
|
+
[value].pack("C*").unpack1("H*")
|
275
|
+
elsif type == "String"
|
276
|
+
CLValueBytesParsers::CLStringBytesParser.to_bytes(value)
|
277
|
+
elsif type == "Key"
|
278
|
+
[value].pack("C*").unpack1("H*")
|
279
|
+
elsif type == "URef"
|
280
|
+
uref = clvalue.get_value
|
281
|
+
clvalue.to_bytes(uref)
|
282
|
+
elsif type == "Option"
|
283
|
+
[0].pack("L<*").unpack1("H*")
|
284
|
+
elsif type == "List"
|
285
|
+
[0].pack("L<*").unpack1("H*")
|
286
|
+
elsif type == "ByteArray"
|
287
|
+
[0].pack("L<*").unpack1("H*")
|
288
|
+
elsif type == "Result"
|
289
|
+
[0].pack("L<*").unpack1("H*")
|
290
|
+
elsif type == "Map"
|
291
|
+
[0].pack("L<*").unpack1("H*")
|
292
|
+
else
|
293
|
+
"Undefined"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
def serialize_option_cl_value(data)
|
298
|
+
cl_type = data[:cl_type]
|
299
|
+
bytes = data[:bytes]
|
300
|
+
parsed = data[:parsed]
|
301
|
+
|
302
|
+
if cl_type == "U64"
|
303
|
+
length = bytes.length/2
|
304
|
+
puts length
|
305
|
+
bytes = bytes[2..]
|
306
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
307
|
+
puts value == 1650706686882
|
308
|
+
clvalue = CLu64.new(value)
|
309
|
+
tag = CLType::TAGS[cl_type.to_sym]
|
310
|
+
puts "U64: " + [length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
311
|
+
[length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|