test_sdk1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +1 -0
  3. data/LICENSE +201 -0
  4. data/README.md +147 -0
  5. data/SECURITY.md +12 -0
  6. data/lib/crypto/00_asymmetric_key.rb +95 -0
  7. data/lib/crypto/01_ed25519.rb +67 -0
  8. data/lib/crypto/asymmetric_key.rb +87 -0
  9. data/lib/crypto/ed25519_key.rb +44 -0
  10. data/lib/crypto/key_pair.rb +40 -0
  11. data/lib/crypto/keys.rb +7 -0
  12. data/lib/crypto/secp256k1_key.rb +0 -0
  13. data/lib/crypto/test_ed25519_key.rb +44 -0
  14. data/lib/entity/account.rb +45 -0
  15. data/lib/entity/action_thresholds.rb +25 -0
  16. data/lib/entity/associated_key.rb +24 -0
  17. data/lib/entity/auction_state.rb +36 -0
  18. data/lib/entity/bid.rb +24 -0
  19. data/lib/entity/bid_info.rb +51 -0
  20. data/lib/entity/contract.rb +47 -0
  21. data/lib/entity/contract_package.rb +41 -0
  22. data/lib/entity/contract_version.rb +33 -0
  23. data/lib/entity/delegator.rb +37 -0
  24. data/lib/entity/deploy.rb +44 -0
  25. data/lib/entity/deploy_approval.rb +24 -0
  26. data/lib/entity/deploy_executable.rb +162 -0
  27. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  28. data/lib/entity/deploy_executable_transfer.rb +50 -0
  29. data/lib/entity/deploy_hash.rb +16 -0
  30. data/lib/entity/deploy_header.rb +60 -0
  31. data/lib/entity/deploy_info.rb +44 -0
  32. data/lib/entity/deploy_named_argument.rb +19 -0
  33. data/lib/entity/deploy_transfer.rb +10 -0
  34. data/lib/entity/disabled_version.rb +26 -0
  35. data/lib/entity/era_info.rb +18 -0
  36. data/lib/entity/era_summary.rb +44 -0
  37. data/lib/entity/era_validator.rb +23 -0
  38. data/lib/entity/executable_deploy_item.rb +11 -0
  39. data/lib/entity/group.rb +25 -0
  40. data/lib/entity/module_bytes.rb +50 -0
  41. data/lib/entity/peer.rb +25 -0
  42. data/lib/entity/seigniorage_allocation.rb +18 -0
  43. data/lib/entity/stored_contract_by_hash.rb +50 -0
  44. data/lib/entity/stored_contract_by_name.rb +50 -0
  45. data/lib/entity/stored_value.rb +57 -0
  46. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  47. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  48. data/lib/entity/transfer.rb +65 -0
  49. data/lib/entity/validator_weight.rb +23 -0
  50. data/lib/entity/vesting_schedule.rb +22 -0
  51. data/lib/include.rb +18 -0
  52. data/lib/rpc/rpc.rb +227 -0
  53. data/lib/rpc/rpc_client.rb +233 -0
  54. data/lib/rpc/rpc_error.rb +79 -0
  55. data/lib/serialization/cl_type_serializer.rb +76 -0
  56. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  57. data/lib/serialization/cl_value_serializer.rb +259 -0
  58. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  59. data/lib/serialization/deploy_executable_serializer.rb +27 -0
  60. data/lib/serialization/deploy_header_serializer.rb +49 -0
  61. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  62. data/lib/serialization/deploy_serializer.rb +268 -0
  63. data/lib/serialization/test.rb +431 -0
  64. data/lib/test_sdk1.rb +289 -0
  65. data/lib/types/cl_account_hash.rb +24 -0
  66. data/lib/types/cl_account_hash_type.rb +22 -0
  67. data/lib/types/cl_any.rb +25 -0
  68. data/lib/types/cl_any_type.rb +22 -0
  69. data/lib/types/cl_bool.rb +32 -0
  70. data/lib/types/cl_bool_type.rb +35 -0
  71. data/lib/types/cl_byte_array.rb +25 -0
  72. data/lib/types/cl_byte_array_type.rb +27 -0
  73. data/lib/types/cl_i32.rb +26 -0
  74. data/lib/types/cl_i32_type.rb +26 -0
  75. data/lib/types/cl_i64.rb +26 -0
  76. data/lib/types/cl_i64_type.rb +27 -0
  77. data/lib/types/cl_key.rb +39 -0
  78. data/lib/types/cl_key_type.rb +27 -0
  79. data/lib/types/cl_list.rb +25 -0
  80. data/lib/types/cl_list_type.rb +26 -0
  81. data/lib/types/cl_map.rb +25 -0
  82. data/lib/types/cl_map_type.rb +26 -0
  83. data/lib/types/cl_option.rb +33 -0
  84. data/lib/types/cl_option_type.rb +52 -0
  85. data/lib/types/cl_public_key.rb +152 -0
  86. data/lib/types/cl_public_key_type.rb +26 -0
  87. data/lib/types/cl_result.rb +25 -0
  88. data/lib/types/cl_result_type.rb +26 -0
  89. data/lib/types/cl_string.rb +39 -0
  90. data/lib/types/cl_string_type.rb +32 -0
  91. data/lib/types/cl_tuple.rb +151 -0
  92. data/lib/types/cl_tuple_type.rb +108 -0
  93. data/lib/types/cl_type.rb +94 -0
  94. data/lib/types/cl_type_tag.rb +51 -0
  95. data/lib/types/cl_u128.rb +26 -0
  96. data/lib/types/cl_u128_type.rb +26 -0
  97. data/lib/types/cl_u256.rb +26 -0
  98. data/lib/types/cl_u256_type.rb +26 -0
  99. data/lib/types/cl_u32.rb +26 -0
  100. data/lib/types/cl_u32_type.rb +26 -0
  101. data/lib/types/cl_u512.rb +26 -0
  102. data/lib/types/cl_u512_type.rb +26 -0
  103. data/lib/types/cl_u64.rb +26 -0
  104. data/lib/types/cl_u64_type.rb +27 -0
  105. data/lib/types/cl_u8.rb +26 -0
  106. data/lib/types/cl_u8_type.rb +26 -0
  107. data/lib/types/cl_unit.rb +38 -0
  108. data/lib/types/cl_unit_type.rb +22 -0
  109. data/lib/types/cl_uref.rb +120 -0
  110. data/lib/types/cl_uref_type.rb +46 -0
  111. data/lib/types/cl_value.rb +10 -0
  112. data/lib/types/constants.rb +50 -0
  113. data/lib/types/error.rb +7 -0
  114. data/lib/utils/base_16.rb +18 -0
  115. data/lib/utils/byte_utils.rb +107 -0
  116. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  117. data/lib/utils/hash_utils.rb +19 -0
  118. data/lib/utils/hex_utils.rb +12 -0
  119. data/lib/utils/time_utils.rb +85 -0
  120. data/lib/utils/utils.rb +2 -0
  121. data/lib/version.rb +3 -0
  122. data/spec/a_spec.rb +697 -0
  123. data/spec/byte_utils_spec.rb +72 -0
  124. data/spec/cl_public_spec.rb +169 -0
  125. data/spec/cl_types_spec.rb +715 -0
  126. data/spec/cl_value_serializer_spec.rb +140 -0
  127. data/spec/client_spec.rb +25 -0
  128. data/spec/crypto_spec.rb +42 -0
  129. data/spec/deploy_approval_serializer_spec.rb +26 -0
  130. data/spec/deploy_executable_serializer_spec.rb +0 -0
  131. data/spec/deploy_header_serializer_spec.rb +21 -0
  132. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  133. data/spec/deploy_serializer_spec.rb +77 -0
  134. data/spec/deploy_serializer_test_spec.rb +225 -0
  135. data/spec/mainnet_spec.rb +452 -0
  136. data/spec/spec_helper.rb +100 -0
  137. data/spec/string_spec.rb +68 -0
  138. data/spec/testnet_spec.rb +498 -0
  139. data/spec/time_utils_spec.rb +87 -0
  140. metadata +198 -0
data/lib/test_sdk1.rb ADDED
@@ -0,0 +1,289 @@
1
+ require 'jimson'
2
+ require 'json'
3
+ require 'rdoc/rdoc'
4
+ require "ipaddress"
5
+ require 'resolv'
6
+ require 'rest-client'
7
+ require 'active_support/core_ext/hash/keys'
8
+ require 'timeout'
9
+ require 'net/http'
10
+ # require "./rpc/rpc.rb"
11
+ require_relative './rpc/rpc_error.rb'
12
+ require_relative './rpc/rpc_client.rb'
13
+
14
+ # Dir["./entity/*.rb"].each {|file| require file }
15
+ # Dir["./serialization/*.rb"].each {|file| require file }
16
+ # Dir["./types/*.rb"].each {|file| require file }
17
+ require_relative './include.rb'
18
+ # Class for interacting with the network via RPC
19
+ # puts "Hello"
20
+ module Casper
21
+ class CasperClient
22
+ attr_accessor :ip_address, :port, :url, :state_root_hash
23
+
24
+ # Constructor
25
+ # @param [String] ip_address
26
+ def initialize(ip_address)
27
+ @ip_address = ip_address
28
+ @url = "http://" + @ip_address + ":7777/rpc"
29
+ @state_root_hash = ""
30
+ @peer_array = []
31
+ @block_hash = ""
32
+ @deploy = {}
33
+ @node_status = {}
34
+ @block_transfers = []
35
+ @block_info = {}
36
+ @era_summary = {}
37
+ @balance_value = ""
38
+ @auction_state = {}
39
+
40
+ @rpc_error = Casper::RpcError::ErrorHandle.new
41
+ @err = @rpc_error.error_handling(@url)
42
+
43
+ @pr = []
44
+
45
+ end
46
+
47
+ def get_error
48
+ @err
49
+ end
50
+
51
+ # @return [Array<Hash>] peers array
52
+ # def info_get_peers
53
+ # begin
54
+ # client = Jimson::Client.new(@url)
55
+ # response = client.info_get_peers
56
+ # @peer_array = response["peers"]
57
+ # rescue
58
+ # @rpc_error = Casper::RpcError::ErrorHandle.new
59
+ # @error = @rpc_error.error_handling(@url)
60
+ # end
61
+ # end
62
+
63
+ # @return [Array<Hash>] peers array
64
+ def info_get_peers
65
+ begin
66
+ client = Jimson::Client.new(@url)
67
+ response = client.info_get_peers
68
+ @peers = response["peers"]
69
+ # @peers.map! do |peer|
70
+ # peer.symbolize_keys
71
+ # end
72
+ @peers.map { |item| @pr << Casper::Entity::Peer.new(item.symbolize_keys) }
73
+ @pr
74
+ rescue
75
+ @rpc_error = Casper::RpcError::ErrorHandle.new
76
+ @error = @rpc_error.error_handling(@url)
77
+ end
78
+ end
79
+
80
+ # @return [String] state_root_hash value
81
+ def chain_get_StateRootHash(block_hash = "")
82
+ begin
83
+ status = Timeout::timeout(10) {
84
+ client = Jimson::Client.new(@url)
85
+ result = client.chain_get_state_root_hash
86
+ @state_root_hash = result["state_root_hash"]
87
+ }
88
+ rescue
89
+ @rpc_error = Casper::RpcError::ErrorHandle.new
90
+ @error = @rpc_error.error_handling(@url)
91
+ end
92
+ end
93
+
94
+ # Get information about a single deploy by hash.
95
+ # @param [String] deploy_hash
96
+ # @return [Hash] Deploy
97
+ # def info_get_deploy(deploy_hash)
98
+ # begin
99
+ # status = Timeout::timeout(10) {
100
+ # client = Jimson::Client.new(@url)
101
+ # response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
102
+ # if (deploy_hash == "" || deploy_hash == nil)
103
+ # Casper::RpcError::InvalidParameter.error
104
+ # end
105
+ # @deploy = response["deploy"]
106
+ # # @deploy.keys.each do |key|
107
+ # # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
108
+ # # end
109
+ # @deploy
110
+ # }
111
+ # rescue
112
+ # Casper::RpcError::InvalidParameter.error
113
+ # end
114
+ # end
115
+ def info_get_deploy(deploy_hash)
116
+ @dep = nil
117
+ begin
118
+ status = Timeout::timeout(60) {
119
+ client = Jimson::Client.new(@url)
120
+ response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
121
+ if (deploy_hash == "" || deploy_hash == nil)
122
+ Casper::RpcError::InvalidParameter.error
123
+ end
124
+ # @deploy.keys.each do |key|
125
+ # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
126
+ # end
127
+ temp = []
128
+ @deploy = response["deploy"]
129
+ @deploy.deep_symbolize_keys!
130
+ Casper::Entity::Deploy.new(@deploy[:hash], @deploy[:header], @deploy[:payment], @deploy[:session], @deploy[:approvals])
131
+ }
132
+ rescue
133
+ Casper::RpcError::InvalidParameter.error
134
+ end
135
+ end
136
+
137
+
138
+ # Receive node status information
139
+ # @return node_status
140
+ def info_get_status
141
+ begin
142
+ status = Timeout::timeout(10) {
143
+ client = Jimson::Client.new(@url)
144
+ @node_status = client.info_get_status
145
+ }
146
+ rescue
147
+ @rpc_error = Casper::RpcError::ErrorHandle.new
148
+ @error = @rpc_error.error_handling(@url)
149
+ end
150
+ end
151
+
152
+ # @param [String] block_hash
153
+ # @return [Array<Hash>] block_transfers
154
+ def chain_get_block_transfers(block_hash = "")
155
+ begin
156
+ status = Timeout::timeout(5) {
157
+ client = Jimson::Client.new(@url)
158
+ response = client.chain_get_block_transfers({
159
+ "block_identifier" => {"Hash" => block_hash}
160
+ })
161
+ @transfers = response["transfers"]
162
+ @transfers.map { |transfer| Casper::Entity::Transfer.new(transfer.deep_symbolize_keys!)}
163
+ }
164
+ rescue
165
+ Casper::RpcError::InvalidParameter.error
166
+ end
167
+ end
168
+
169
+ # @param [String] block_hash
170
+ # @return [Hash] block_info
171
+ def chain_get_block(block_hash)
172
+ begin
173
+ state = Timeout::timeout(10) {
174
+ client = Jimson::Client.new(@url)
175
+ result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
176
+ @block_info = result["block"]
177
+ if (!@block_info.empty?() && @block_info["hash"] != block_hash)
178
+ raise("Returned block does not have a matching hash.")
179
+ else
180
+ @block_info
181
+ end
182
+ }
183
+ rescue
184
+ Casper::RpcError::InvalidParameter.error
185
+ end
186
+ end
187
+
188
+ # @param [String] block_hash
189
+ # @return [Hash] era_summary
190
+ def chain_get_eraInfo_by_SwitchBlock(block_hash)
191
+ begin
192
+ state = Timeout::timeout(10) {
193
+ client = Jimson::Client.new(@url)
194
+ response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
195
+ @era_summary = response["era_summary"]
196
+
197
+ if @era_summary == nil
198
+ Casper::RpcError::InvalidParameter.error
199
+ else
200
+ @era_summary
201
+ end
202
+ }
203
+ rescue
204
+ Casper::RpcError::InvalidParameter.error
205
+ end
206
+ end
207
+
208
+ # @param [String] state_root_hash
209
+ # @param [String] key
210
+ # @param [Array] path
211
+ def state_get_item(state_root_hash, key, path)
212
+ begin
213
+ state = Timeout::timeout(20) {
214
+ client = Jimson::Client.new(@url)
215
+ response = client.state_get_item({
216
+ "state_root_hash" => state_root_hash,
217
+ "key" => key,
218
+ "path" => path
219
+ })
220
+ @stored_value = response["stored_value"]
221
+ @stored_value
222
+ }
223
+ rescue
224
+ Casper::RpcError::InvalidParameter.error
225
+ end
226
+ end
227
+
228
+ # @param [String] state_root_hash
229
+ # @param [String] item_key
230
+ # @param [String] uref
231
+ def state_get_dictionary_item(state_root_hash, item_key, uref)
232
+ begin
233
+ state = Timeout::timeout(10) {
234
+ client = Jimson::Client.new(@url)
235
+ response = client.state_get_dictionary_item({
236
+ "state_root_hash" => state_root_hash,
237
+ "dictionary_identifier" => {'URef' =>
238
+ {'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
239
+ @stored_value = response["stored_value"]
240
+ @stored_value
241
+ }
242
+ rescue
243
+ Casper::RpcError::InvalidParameter.error
244
+ end
245
+ end
246
+
247
+ # @param [String] state_root_hash
248
+ # @param [String] balance_uref
249
+ def state_get_balance(state_root_hash, balance_uref)
250
+ begin
251
+ state = Timeout::timeout(5) {
252
+ client = Jimson::Client.new(@url)
253
+ response = client.state_get_balance({
254
+ "state_root_hash" => state_root_hash,
255
+ "purse_uref" => balance_uref
256
+ })
257
+ @balance_value = response["balance_value"]
258
+ @balance_value
259
+ }
260
+ rescue
261
+ Casper::RpcError::InvalidParameter.error
262
+ end
263
+ end
264
+
265
+ # Returns current auction system contract information.
266
+ # @return [Hash] auction_state
267
+ def state_get_AuctionInfo
268
+ begin
269
+ state = Timeout::timeout(50) {
270
+ client = Jimson::Client.new(@url)
271
+ response = client.state_get_auction_info
272
+ @auction_state = response['auction_state']
273
+ @auction_state
274
+ }
275
+ rescue
276
+ @rpc_error = Casper::RpcError::ErrorHandle.new
277
+ @error = @rpc_error.error_handling(@url)
278
+ end
279
+ end
280
+
281
+ def put_deploy(deploy)
282
+ client = Jimson::Client.new(url)
283
+ response = client.account_put_deploy(deploy)
284
+ response['deploy_hash']
285
+ end
286
+
287
+ end
288
+
289
+ end
@@ -0,0 +1,24 @@
1
+ require_relative './cl_account_hash_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+ class CLAccountHash < CLValue
7
+
8
+ def initialize(value)
9
+ super()
10
+ @value = value
11
+ end
12
+
13
+ def get_cl_type
14
+ @cl_type = CLAccountHashType.new
15
+ @cl_type.to_string
16
+ end
17
+
18
+ def get_value
19
+ @value
20
+ end
21
+ end
22
+
23
+ # cl_account_hash = CLAccountHash.new([10, 20])
24
+ # puts cl_account_hash.get_cl_type
@@ -0,0 +1,22 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLAccountHashType < CLType
6
+ # def initialize(value = nil)
7
+ # super(value)
8
+ # @value = value
9
+ # end
10
+
11
+ def to_string
12
+ ACCOUNT_HASH_ID
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './cl_any_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLAny < CLValue
8
+ include CLValueBytesParsers::CLAnyBytesParser
9
+
10
+ def initialize(value = nil)
11
+ super
12
+ @value = value
13
+ end
14
+
15
+ def get_cl_type
16
+ @cl_type = CLAnyType.new
17
+ @cl_type.to_string
18
+ end
19
+
20
+ def get_value
21
+ @value
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,22 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLAnyType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(21).to_s
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ require_relative './cl_bool_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+ module Boolean; end
7
+ class TrueClass; include Boolean; end
8
+ class FalseClass; include Boolean; end
9
+
10
+ class CLBool < CLValue
11
+ include Boolean
12
+ include CLValueBytesParsers::CLBoolBytesParser
13
+ def initialize(value)
14
+ super
15
+ raise "error" unless value.is_a?(Boolean)
16
+ @value = value
17
+ end
18
+
19
+ def get_cl_type
20
+ @cl_bool_type = CLBoolType.new(true)
21
+ @cl_bool_type.to_string
22
+ end
23
+
24
+ def get_cl_tag
25
+ CLBoolType.get_tag
26
+ end
27
+
28
+ def get_value
29
+ @value
30
+ end
31
+ end
32
+
@@ -0,0 +1,35 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLBoolType < CLType
6
+
7
+ def initialize(value = nil)
8
+ super(value)
9
+ @value = value
10
+ end
11
+
12
+ def to_string
13
+ TAGS.key(0).to_s
14
+ end
15
+
16
+ # def get_value
17
+ # @value
18
+ # end
19
+
20
+ def to_json
21
+ to_string
22
+ end
23
+
24
+ def self.get_tag
25
+ TAGS[:Bool]
26
+ end
27
+
28
+ def get_tag
29
+ TAGS[:Bool]
30
+ end
31
+
32
+ def to_bytes
33
+ [0].pack("C*").unpack1("H*")
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './cl_byte_array_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLByteArray < CLValue
8
+ include CLValueBytesParsers::CLByteArrayBytesParser
9
+
10
+ def initialize(value = nil)
11
+ super
12
+ @value = value
13
+ end
14
+
15
+ def get_cl_type
16
+ @cl_type = CLByteArrayType.new
17
+ @cl_type.to_string
18
+ end
19
+
20
+ def get_value
21
+ @value
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,27 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLByteArrayType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(15).to_s
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+
23
+ def to_bytes
24
+ [15].pack("C*").unpack1("H*")
25
+ end
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './cl_i32_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLi32 < CLValue
8
+ include CLValueBytesParsers::CLI32BytesParser
9
+
10
+ def initialize(value)
11
+ raise "error" unless value.instance_of? Integer
12
+ super
13
+ @value = value
14
+ end
15
+
16
+ def get_cl_type
17
+ @cl_type = CLI32Type.new
18
+ @cl_type.to_string
19
+ end
20
+
21
+ def get_value
22
+ @value
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,26 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLI32Type < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(1).to_s
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+
23
+ def to_bytes
24
+ [1].pack("C*").unpack1("H*")
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './cl_i64_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLi64 < CLValue
8
+ include CLValueBytesParsers::CLI64BytesParser
9
+
10
+ def initialize(value = nil)
11
+ raise "error" unless value.instance_of? Integer
12
+ super
13
+ @value = value
14
+ end
15
+
16
+ def get_cl_type
17
+ @cl_type = CLI64Type.new
18
+ @cl_type.to_string
19
+ end
20
+
21
+ def get_value
22
+ @value
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,27 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLI64Type < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(2).to_s
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+
23
+ def to_bytes
24
+ [2].pack("C*").unpack1("H*")
25
+ end
26
+
27
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './cl_key_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+ =begin
5
+ Key values serialize as a single byte tag representing the variant, followed by the serialization of the data that variant contains.
6
+ For most variants, this is simply a fixed-length 32-byte array.
7
+ The exception is Key::URef, which contains a URef; so its data serializes per the description above.
8
+ The tags are as follows: Key::Account serializes as 0, Key::Hash as 1, Key::URef as 2.
9
+ =end
10
+
11
+
12
+ KEY_TYPE_ACCOUNT = 0
13
+ KEY_TYPE_HASH = 1
14
+ KEY_TYPE_UREF = 2
15
+
16
+ # ACCOUNT_HASH_ID = 'AccountHash'
17
+ ACCOUNT_HASH_LENGTH = 32
18
+
19
+ # UREF_ID = 'URef'
20
+
21
+ class CLKey < CLValue
22
+ include CLValueBytesParsers::CLKeyBytesParser
23
+
24
+ def initialize(value)
25
+ super
26
+ @value = value
27
+ end
28
+
29
+ def get_cl_type
30
+ @cl_type = CLKeyType.new
31
+ @cl_type.to_string
32
+ end
33
+
34
+ def get_value
35
+ @value
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,27 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLKeyType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(11).to_s
13
+ end
14
+
15
+ def get_value
16
+ @value
17
+ end
18
+
19
+ def to_json
20
+ to_string
21
+ end
22
+
23
+ def to_bytes
24
+ [11].pack("C*").unpack1("H*")
25
+ end
26
+
27
+ end