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
@@ -0,0 +1,25 @@
1
+ require_relative './cl_list_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLList < CLValue
8
+ include CLValueBytesParsers::CLListBytesParser
9
+
10
+ def initialize(value = nil)
11
+ super
12
+ @value = value
13
+ end
14
+
15
+ def get_cl_type
16
+ @cl_type = CLListType.new
17
+ @cl_type.to_string
18
+ end
19
+
20
+ def get_value
21
+ @value
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,26 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLListType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(14).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
+ [14].pack("C*").unpack1("H*")
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './cl_map_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLMap < CLValue
8
+ include CLValueBytesParsers::CLMapBytesParser
9
+
10
+ def initialize(value = nil)
11
+ super
12
+ @value = value
13
+ end
14
+
15
+ def get_cl_type
16
+ @cl_type = CLMapType.new
17
+ @cl_type.to_string
18
+ end
19
+
20
+ def get_value
21
+ @value
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,26 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLMapType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(17).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
+ [17].pack("C*").unpack1("H*")
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ require_relative './cl_option_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+ =begin
6
+ https://doc.rust-lang.org/stable/std/option/
7
+ =end
8
+
9
+ class CLOption < CLValue
10
+ include CLValueBytesParsers::CLOptionBytesParser
11
+
12
+ def initialize(data = nil, inner_type = nil)
13
+ super
14
+ @data = data
15
+ @inner_type = inner_type
16
+ if data == nil && inner_type == nil
17
+ raise ArgumentError.new("You had to assign innerType for None")
18
+ elsif data == nil && inner_type != nil
19
+ @inner_type = inner_type
20
+ else
21
+ @inner_type = data.get_cl_type
22
+ end
23
+ end
24
+
25
+ def get_value
26
+ @data
27
+ end
28
+
29
+ def get_cl_type
30
+ CLOptionType.new(@inner_type)
31
+ @inner_type
32
+ end
33
+ end
@@ -0,0 +1,52 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './cl_bool.rb'
3
+ require_relative './cl_bool_type.rb'
4
+ require_relative './constants.rb'
5
+
6
+ optionTags = {
7
+ NONE: 0,
8
+ SOME: 1
9
+ }
10
+
11
+ class CLOptionType < CLType
12
+
13
+ def initialize(inner = nil)
14
+ @tag = TAGS[:Option]
15
+ @inner = inner
16
+ # p @inner.to_string
17
+ # p @inner.to_json
18
+ # p @inner.get_tag
19
+ end
20
+
21
+ # @return [String]
22
+ def to_string
23
+ @inner == nil ? TAGS.key(13).to_s + " (None)" : TAGS.key(13).to_s + " (#{@inner.to_string})"
24
+ end
25
+
26
+ def to_json
27
+ jsoned = { "#{TAGS.key(13)}": @inner.to_string }.to_json
28
+ # h = JSON.parse(jsoned)
29
+ # h
30
+ end
31
+
32
+ def get_type
33
+ TAGS.key(13).to_s
34
+ end
35
+
36
+ def get_inner_type
37
+ @inner
38
+ end
39
+
40
+ def to_bytes
41
+ arr = []
42
+ arr << @tag << @inner.get_tag
43
+ end
44
+
45
+ def self.to_string
46
+ TAGS.key(13).to_s
47
+ end
48
+
49
+ def to_bytes
50
+ [13].pack("C*").unpack1("H*")
51
+ end
52
+ end
@@ -0,0 +1,152 @@
1
+ require_relative './cl_public_key_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+ require_relative '../utils/base_16.rb'
5
+ require_relative '../utils/hex_utils.rb'
6
+ require_relative '../utils/hash_utils.rb'
7
+ require 'blake2'
8
+ =begin
9
+ PublicKey serializes as a single byte tag representing the algorithm followed by 32 bytes of the PublicKey itself:
10
+ If the PublicKey is an Ed25519 key, the single tag byte is 1 followed by the individual bytes of the serialized key.
11
+ If the PublicKey is a Secp256k1 key, the single tag byte is a 2 followed by the individual bytes of the serialized key.
12
+ =end
13
+ ED25519_LENGTH = 32
14
+ SECP256K1_LENGTH = 33
15
+
16
+
17
+ CLPublicKeyTag = {
18
+ ED25519: 1,
19
+ SECP256K1: 2
20
+ }
21
+
22
+ SignatureAlgorithm = {
23
+ Ed25519: 'ed25519',
24
+ Secp256K1: 'secp256k1'
25
+ }
26
+
27
+
28
+
29
+
30
+ class CLPublicKey < CLValue
31
+ include CLValueBytesParsers::CLPublicKeyBytesParser
32
+ include Utils::HashUtils
33
+ # @param [Array<Integer>] raw_public_key
34
+ # @param [Integer] tag
35
+ def initialize(raw_public_key, tag)
36
+ super()
37
+ raw_public_key_length_valid?(raw_public_key, tag)
38
+ end
39
+
40
+ def raw_public_key_length_valid?(raw_public_key, tag)
41
+ if tag == CLPublicKeyTag[:ED25519] || tag == SignatureAlgorithm[:Ed25519]
42
+ if raw_public_key.length != ED25519_LENGTH
43
+ raise ArgumentError.new("Wrong length of ED25519 key. Expected #{ED25519_LENGTH}, but got #{raw_public_key.length}")
44
+ end
45
+ @raw_public_key = raw_public_key
46
+ @tag = tag
47
+ elsif tag == CLPublicKeyTag[:SECP256K1] || tag == SignatureAlgorithm[:Secp256K1]
48
+ if raw_public_key.length != SECP256K1_LENGTH
49
+ raise ArgumentError.new("Wrong length of SECP256K1 key. Expected #{SECP256K1_LENGTH}, but got #{raw_public_key.length}")
50
+ end
51
+ @raw_public_key = raw_public_key
52
+ @tag = tag
53
+ else
54
+ raise ArgumentError.new("Unsupported type of public key")
55
+ end
56
+ end
57
+
58
+ def get_cl_type
59
+ @cl_type = CLPublicKeyType.new
60
+ @cl_type.to_string
61
+ end
62
+
63
+
64
+ def get_value
65
+ @raw_public_key
66
+ end
67
+
68
+ def get_cl_public_key_tag
69
+ if @tag == CLPublicKeyTag[:ED25519] || @tag == SignatureAlgorithm[:Ed25519]
70
+ CLPublicKeyTag[:ED25519]
71
+ else
72
+ CLPublicKeyTag[:SECP256K1]
73
+ end
74
+ end
75
+
76
+ def get_signature_algorithm
77
+ if @tag == CLPublicKeyTag[:ED25519] || @tag == SignatureAlgorithm[:Ed25519]
78
+ SignatureAlgorithm[:Ed25519]
79
+ else
80
+ SignatureAlgorithm[:Secp256K1]
81
+ end
82
+ end
83
+
84
+ def ed25519?
85
+ @tag == CLPublicKeyTag[:ED25519]
86
+ end
87
+
88
+ def secp256k1?
89
+ @tag == CLPublicKeyTag[:SECP256K1]
90
+ end
91
+
92
+ # @return [Array<Integer>]
93
+ def to_account_hash_byte_array
94
+ key_name = CLPublicKeyTag.key(@tag).to_s
95
+ prefix = key_name.downcase.unpack("C*") + [0]
96
+ bytes = prefix + @raw_public_key
97
+ result_array = Utils::HashUtils.byte_hash(bytes)
98
+ @raw_public_key.length == 0 ? [] : result_array
99
+ end
100
+
101
+ # @return [String] hex
102
+ def to_account_hash_hex
103
+ bytes = to_account_hash_byte_array
104
+ hex = Utils::HashUtils.account_hash_from_byte_to_hex(bytes)
105
+ end
106
+
107
+ def from_ed25519(public_key)
108
+ CLPublicKey.new(public_key, CLPublicKeyTag[:ED25519])
109
+ end
110
+
111
+ def self.from_ed25519(public_key)
112
+ CLPublicKey.new(public_key, CLPublicKeyTag[:ED25519])
113
+ end
114
+
115
+ def from_secp256k1(public_key)
116
+ CLPublicKey.new(public_key, CLPublicKeyTag[:SECP256K1])
117
+ end
118
+
119
+ def self.from_secp256k1(public_key)
120
+ CLPublicKey.new(public_key, CLPublicKeyTag[:SECP256K1])
121
+ end
122
+
123
+ def to_hex
124
+ # "0#{@tag}#{Utils::Base16.encode16(@raw_public_key)}"
125
+ "0#{@tag}#{CLValueBytesParsers::CLPublicKeyBytesParser.encode_base_16(@raw_public_key)}"
126
+ end
127
+
128
+ def from_hex(public_key_hex)
129
+ raise ArgumentError.new("Invalid public key") unless Utils::HexUtils.valid_public_key_format?(public_key_hex)
130
+ public_key_hex_bytes = Utils::Base16.decode16(public_key_hex)
131
+ CLPublicKey.new(public_key_hex_bytes.drop(1), public_key_hex_bytes[0])
132
+ end
133
+
134
+ def self.from_hex(public_key_hex)
135
+ raise ArgumentError.new("Invalid public key") unless Utils::HexUtils.valid_public_key_format?(public_key_hex)
136
+ public_key_hex_bytes = Utils::Base16.decode16(public_key_hex)
137
+ CLPublicKey.new(public_key_hex_bytes.drop(1), public_key_hex_bytes[0])
138
+ end
139
+
140
+ def self.to_json(public_key)
141
+ json = {"bytes": public_key.to_hex, "cl_type": public_key.get_cl_type}.to_json
142
+ end
143
+
144
+ def self.from_json(json)
145
+ parsed = JSON.parse(json).deep_symbolize_keys
146
+ bytes = Utils::Base16.decode16(parsed[:bytes])
147
+ tag = bytes[0]
148
+ raw_public_key = bytes[1..]
149
+ CLPublicKey.new(raw_public_key, tag)
150
+ end
151
+
152
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLPublicKeyType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(22).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
+ [22].pack("C*").unpack1("H*")
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './cl_result_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+
7
+ class CLResult < CLValue
8
+ include CLValueBytesParsers::CLResultBytesParser
9
+
10
+ def initialize(value = nil)
11
+ super
12
+ @value = value
13
+ end
14
+
15
+ def get_cl_type
16
+ @cl_type = CLResultType.new
17
+ @cl_type.to_string
18
+ end
19
+
20
+ def get_value
21
+ @value
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,26 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLResultType < CLType
6
+ def initialize(value = nil)
7
+ super(value)
8
+ @value = value
9
+ end
10
+
11
+ def to_string
12
+ TAGS.key(16).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
+ [16].pack("C*").unpack1("H*")
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './cl_string_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
4
+
5
+
6
+ class CLString < CLValue
7
+ attr_accessor :cl_value
8
+ alias_method :clvalue?, :cl_value
9
+ include CLValueBytesParsers::CLStringBytesParser
10
+
11
+ def initialize(value)
12
+ super()
13
+ # raise "error" unless value.is_a?(String)
14
+ raise "error" unless value.instance_of? String
15
+ @value = value
16
+ end
17
+
18
+ def get_cl_type
19
+ @cl_string_type = CLStringType.new
20
+ @cl_string_type.to_string
21
+ end
22
+
23
+ def get_value
24
+ @value
25
+ end
26
+
27
+ def get_size
28
+ @value.length
29
+ end
30
+
31
+ def self.to_bytes(clvalue)
32
+ value = clvalue.get_value
33
+ len = value.length
34
+ hex1 = len.to_s(16).rjust(8, '0').scan(/../).reverse.join('')
35
+ hex2 = value.unpack("H*").first
36
+ hex1 + hex2
37
+ end
38
+ end
39
+
@@ -0,0 +1,32 @@
1
+ require_relative './cl_type.rb'
2
+ require_relative './constants.rb'
3
+
4
+
5
+ class CLStringType < CLType
6
+
7
+ def initialize(value = nil)
8
+ super(value)
9
+ @value = value
10
+ end
11
+
12
+ def to_string
13
+ TAGS.key(10).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 to_bytes
25
+ [10].pack("C*").unpack1("H*")
26
+ end
27
+ end
28
+
29
+
30
+
31
+
32
+
@@ -0,0 +1,151 @@
1
+ require_relative './cl_tuple_type.rb'
2
+ require_relative './cl_value.rb'
3
+ require_relative './error.rb'
4
+ require_relative '../serialization/cl_value_bytes_parsers.rb'
5
+
6
+
7
+
8
+ class CLTuple < CLValue
9
+ include CLValueBytesParsers::CLTupleBytesParser
10
+ attr_accessor :size, :data
11
+ # before_filter: get_cl_type
12
+ def initialize(size, data)
13
+ super()
14
+ @size = size
15
+ @data = data
16
+ @all_members_are_clvalues = data.all? { |item| item.is_a?(CLValue)}
17
+ @tuple_name = ""
18
+ if data.size > size && @all_members_are_clvalues
19
+ begin
20
+ raise Error.new("Too many elements!")
21
+ rescue => e
22
+ e.err
23
+ end
24
+ end
25
+
26
+ if @all_members_are_clvalues && data.size == size
27
+ @size = size
28
+ @data = data
29
+ else
30
+ begin
31
+ raise Error.new("Invalid data type(s) provided.")
32
+ rescue => e
33
+ e.err
34
+ end
35
+ end
36
+ get_full_type
37
+ end
38
+
39
+ def get_full_type
40
+ if @all_members_are_clvalues
41
+ if @data.size == @size
42
+ if @data.size == 1
43
+ @cl_type = CLTuple1Type.new
44
+ @tuple_name = @cl_type.to_string
45
+ @cl_type.to_string + " (" + @data[0].get_cl_type + ")"
46
+ elsif @data.size == 2
47
+ @cl_type = CLTuple2Type.new
48
+ @tuple_name = @cl_type.to_string
49
+ @cl_type.to_string + " (" + @data[0].get_cl_type + ", " + @data[1].get_cl_type + ")"
50
+ elsif @data.size == 3
51
+ @cl_type = CLTuple3Type.new
52
+ @tuple_name = @cl_type.to_string
53
+ @cl_type.to_string + " (" + @data[0].get_cl_type + ", " + @data[1].get_cl_type + ", " + @data[2].get_cl_type + ")"
54
+ else
55
+ begin
56
+ raise Error.new("Tuple is not defined!")
57
+ rescue => e
58
+ e.err
59
+ end
60
+ end
61
+ elsif @data.size > size
62
+ begin
63
+ raise Error.new("Too many elements!")
64
+ rescue => e
65
+ e.err
66
+ end
67
+ end
68
+ else
69
+ begin
70
+ raise Error.new("Invalid data type(s) provided.")
71
+ rescue => e
72
+ e.err
73
+ end
74
+ end
75
+ end
76
+
77
+ def get_tuple_name
78
+ @tuple_name
79
+ end
80
+
81
+ def get_value
82
+ @data
83
+ end
84
+
85
+ def get_size
86
+ @size
87
+ end
88
+
89
+ def get(index)
90
+ if index >= @size
91
+ Error.new("Tuple index out of bounds.")
92
+ else
93
+ @data[index]
94
+ end
95
+ end
96
+
97
+ def set(index, item)
98
+ if index >= @size
99
+ Error.new("Tuple index out of bounds.")
100
+ else
101
+ data[index] = item
102
+ end
103
+ end
104
+
105
+ def push(item)
106
+ if @data.size < @size
107
+ @data.push(item)
108
+ else
109
+ Error.new("No more space in this tuple!")
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+
116
+ class CLTuple1 < CLTuple
117
+
118
+ def initialize(data)
119
+ super(1, data)
120
+ end
121
+
122
+ def get_cl_type
123
+ @cl_tuple_type = CLTuple1Type.new
124
+ @cl_tuple_type.to_string
125
+ end
126
+ end
127
+
128
+ class CLTuple2 < CLTuple
129
+
130
+ def initialize(data)
131
+ super(2, data)
132
+ end
133
+
134
+ def get_cl_type
135
+ @cl_tuple_type = CLTuple2Type.new
136
+ @cl_tuple_type.to_string
137
+ end
138
+ end
139
+
140
+ class CLTuple3 < CLTuple
141
+
142
+ def initialize(data)
143
+ super(3, data)
144
+ # puts data
145
+ end
146
+
147
+ def get_cl_type
148
+ @cl_tuple_type = CLTuple3Type.new
149
+ @cl_tuple_type.to_string
150
+ end
151
+ end