scale_rb 0.1.14 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/address.rb +85 -89
- data/lib/client/abstract_ws_client.rb +85 -81
- data/lib/client/http_client.rb +2 -170
- data/lib/client/http_client_metadata.rb +10 -8
- data/lib/client/http_client_storage.rb +180 -0
- data/lib/client/rpc_request_builder.rb +44 -42
- data/lib/codec.rb +28 -29
- data/lib/hasher.rb +39 -37
- data/lib/metadata/metadata.rb +130 -122
- data/lib/metadata/metadata_v10.rb +72 -69
- data/lib/metadata/metadata_v11.rb +78 -75
- data/lib/metadata/metadata_v12.rb +42 -39
- data/lib/metadata/metadata_v13.rb +71 -68
- data/lib/metadata/metadata_v14.rb +185 -181
- data/lib/metadata/metadata_v9.rb +92 -89
- data/lib/monkey_patching.rb +22 -22
- data/lib/portable_codec.rb +236 -232
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +0 -1
- data/lib/storage_helper.rb +52 -50
- metadata +3 -2
data/lib/metadata/metadata_v9.rb
CHANGED
@@ -1,100 +1,103 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module ScaleRb
|
4
|
+
module Metadata
|
5
|
+
module MetadataV9
|
6
|
+
class << self
|
7
|
+
def get_module(module_name, metadata)
|
8
|
+
metadata._get(:metadata)._get(:v9)._get(:modules).find do |m|
|
9
|
+
m._get(:name) == module_name
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def get_storage_item(module_name, item_name, metadata)
|
14
|
+
modula = get_module(module_name, metadata)
|
15
|
+
raise "Module `#{module_name}` not found" if modula.nil?
|
16
|
+
|
17
|
+
modula._get(:storage)._get(:items).find do |item|
|
18
|
+
item._get(:name) == item_name
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
23
|
+
TYPES = {
|
24
|
+
ErrorMetadataV9: {
|
25
|
+
name: 'Text',
|
26
|
+
docs: 'Vec<Text>'
|
27
|
+
},
|
28
|
+
EventMetadataV9: {
|
29
|
+
name: 'Text',
|
30
|
+
args: 'Vec<Type>',
|
31
|
+
docs: 'Vec<Text>'
|
32
|
+
},
|
33
|
+
FunctionArgumentMetadataV9: {
|
34
|
+
name: 'Text',
|
35
|
+
type: 'Type'
|
36
|
+
},
|
37
|
+
FunctionMetadataV9: {
|
38
|
+
name: 'Text',
|
39
|
+
args: 'Vec<FunctionArgumentMetadataV9>',
|
40
|
+
docs: 'Vec<Text>'
|
41
|
+
},
|
42
|
+
MetadataV9: {
|
43
|
+
modules: 'Vec<ModuleMetadataV9>'
|
44
|
+
},
|
45
|
+
ModuleConstantMetadataV9: {
|
46
|
+
name: 'Text',
|
47
|
+
type: 'Type',
|
48
|
+
value: 'Bytes',
|
49
|
+
docs: 'Vec<Text>'
|
50
|
+
},
|
51
|
+
ModuleMetadataV9: {
|
52
|
+
name: 'Text',
|
53
|
+
storage: 'Option<StorageMetadataV9>',
|
54
|
+
calls: 'Option<Vec<FunctionMetadataV9>>',
|
55
|
+
events: 'Option<Vec<EventMetadataV9>>',
|
56
|
+
constants: 'Vec<ModuleConstantMetadataV9>',
|
57
|
+
errors: 'Vec<ErrorMetadataV9>'
|
58
|
+
},
|
59
|
+
StorageEntryMetadataV9: {
|
60
|
+
name: 'Text',
|
61
|
+
modifier: 'StorageEntryModifierV9',
|
62
|
+
type: 'StorageEntryTypeV9',
|
63
|
+
fallback: 'Bytes',
|
64
|
+
docs: 'Vec<Text>'
|
65
|
+
},
|
66
|
+
StorageEntryModifierV9: {
|
67
|
+
_enum: %w[Optional Default Required]
|
68
|
+
},
|
69
|
+
StorageEntryTypeV9: {
|
70
|
+
_enum: {
|
71
|
+
Plain: 'Type',
|
72
|
+
Map: {
|
73
|
+
hasher: 'StorageHasherV9',
|
74
|
+
key: 'Type',
|
75
|
+
value: 'Type',
|
76
|
+
linked: 'bool'
|
77
|
+
},
|
78
|
+
DoubleMap: {
|
79
|
+
hasher: 'StorageHasherV9',
|
80
|
+
key1: 'Type',
|
81
|
+
key2: 'Type',
|
82
|
+
value: 'Type',
|
83
|
+
key2Hasher: 'StorageHasherV9'
|
84
|
+
}
|
82
85
|
}
|
86
|
+
},
|
87
|
+
StorageHasherV9: {
|
88
|
+
_enum: %w[
|
89
|
+
Blake2_128
|
90
|
+
Blake2_256
|
91
|
+
Twox128
|
92
|
+
Twox256
|
93
|
+
Twox64Concat
|
94
|
+
]
|
95
|
+
},
|
96
|
+
StorageMetadataV9: {
|
97
|
+
prefix: 'Text',
|
98
|
+
items: 'Vec<StorageEntryMetadataV9>'
|
83
99
|
}
|
84
|
-
}
|
85
|
-
|
86
|
-
_enum: %w[
|
87
|
-
Blake2_128
|
88
|
-
Blake2_256
|
89
|
-
Twox128
|
90
|
-
Twox256
|
91
|
-
Twox64Concat
|
92
|
-
]
|
93
|
-
},
|
94
|
-
StorageMetadataV9: {
|
95
|
-
prefix: 'Text',
|
96
|
-
items: 'Vec<StorageEntryMetadataV9>'
|
97
|
-
}
|
98
|
-
}.freeze
|
100
|
+
}.freeze
|
101
|
+
end
|
99
102
|
end
|
100
103
|
end
|
data/lib/monkey_patching.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# https://www.rubyguides.com/2017/01/read-binary-data/
|
4
4
|
class String
|
5
|
-
def
|
5
|
+
def _to_bytes
|
6
6
|
data = start_with?('0x') ? self[2..] : self
|
7
7
|
raise 'Not valid hex string' if data =~ /[^\da-f]+/i
|
8
8
|
|
@@ -10,11 +10,11 @@ class String
|
|
10
10
|
data.scan(/../).map(&:hex)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def _to_camel
|
14
14
|
split('_').collect(&:capitalize).join
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def _underscore
|
18
18
|
gsub(/::/, '/')
|
19
19
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
20
20
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
@@ -24,22 +24,22 @@ class String
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class Integer
|
27
|
-
def
|
28
|
-
return to_s(16).
|
27
|
+
def _to_bytes(bit_length = nil)
|
28
|
+
return to_s(16)._to_bytes unless bit_length
|
29
29
|
|
30
30
|
hex = to_s(16).rjust(bit_length / 4, '0')
|
31
|
-
hex.
|
31
|
+
hex._to_bytes
|
32
32
|
end
|
33
33
|
|
34
34
|
# unsigned to signed
|
35
|
-
def
|
35
|
+
def _to_signed(bit_length)
|
36
36
|
unsigned_mid = 2**(bit_length - 1)
|
37
37
|
unsigned_ceiling = 2**bit_length
|
38
38
|
self >= unsigned_mid ? self - unsigned_ceiling : self
|
39
39
|
end
|
40
40
|
|
41
41
|
# signed to unsigned
|
42
|
-
def
|
42
|
+
def _to_unsigned(bit_length)
|
43
43
|
unsigned_mid = 2**(bit_length - 1)
|
44
44
|
unsigned_ceiling = 2**bit_length
|
45
45
|
raise 'out of scope' if self >= unsigned_mid || self <= -unsigned_mid
|
@@ -48,48 +48,48 @@ class Integer
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# unix timestamp to utc
|
51
|
-
def
|
51
|
+
def _to_utc
|
52
52
|
Time.at(self).utc.asctime
|
53
53
|
end
|
54
54
|
|
55
55
|
# utc to unix timestamp
|
56
|
-
def
|
56
|
+
def _from_utc(utc_asctime)
|
57
57
|
Time.parse(utc_asctime)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
class Array
|
62
|
-
def
|
63
|
-
raise 'Not a byte array' unless
|
62
|
+
def _to_hex
|
63
|
+
raise 'Not a byte array' unless _byte_array?
|
64
64
|
|
65
65
|
reduce('0x') { |hex, byte| hex + byte.to_s(16).rjust(2, '0') }
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
raise 'Not a byte array' unless
|
68
|
+
def _to_bin
|
69
|
+
raise 'Not a byte array' unless _byte_array?
|
70
70
|
|
71
71
|
reduce('0b') { |bin, byte| bin + byte.to_s(2).rjust(8, '0') }
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
75
|
-
raise 'Not a byte array' unless
|
74
|
+
def _to_utf8
|
75
|
+
raise 'Not a byte array' unless _byte_array?
|
76
76
|
|
77
77
|
pack('C*').force_encoding('utf-8')
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
|
80
|
+
def _to_uint
|
81
|
+
_to_hex.to_i(16)
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
85
|
-
|
84
|
+
def _to_int(bit_length)
|
85
|
+
_to_uint._to_signed(bit_length)
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
88
|
+
def _flip
|
89
89
|
reverse
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def _byte_array?
|
93
93
|
all? { |e| e >= 0 and e <= 255 }
|
94
94
|
end
|
95
95
|
end
|