scale_rb 0.1.3 → 0.1.4
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/codec.rb +27 -9
- data/lib/metadata/metadata.rb +55 -0
- data/lib/metadata/metadata_v10.rb +79 -0
- data/lib/metadata/metadata_v11.rb +85 -0
- data/lib/metadata/metadata_v12.rb +47 -0
- data/lib/metadata/metadata_v13.rb +78 -0
- data/lib/metadata/metadata_v14.rb +176 -0
- data/lib/metadata/metadata_v9.rb +99 -0
- data/lib/monkey_patching.rb +1 -1
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +7 -2
- metadata +8 -3
- data/lib/metadata.rb +0 -199
- data/lib/metadata_v14.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04c1447c216cac863ad108d269030a8f3d180d1666c2bba347efad2fa7939335
|
4
|
+
data.tar.gz: bc3b74a6e4ed311491e0369d2b73ae3ac5ab98d430df311257385503db6b70d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac868163255299dcba6094edbe98daed394ede7130262bebf449befc21cdb921e52f1b0a455ae61d46547fa30d28af6927705ed99ae8b7035025d095527f9d4
|
7
|
+
data.tar.gz: 4f9394ab7bb01d73d96e160c4b0c76dae593dd7331e9a276a090e9a7d03060085763c378f5ab0bba5daf64d5bc62b0f4ae0e054d406905c549f8b667d7db7e43
|
data/Gemfile.lock
CHANGED
data/lib/codec.rb
CHANGED
@@ -16,6 +16,22 @@ end
|
|
16
16
|
# TODO: set, bitvec
|
17
17
|
module ScaleRb
|
18
18
|
class << self
|
19
|
+
def type_def?(type)
|
20
|
+
type.instance_of?(String) && (
|
21
|
+
bytes?(type) ||
|
22
|
+
boolean?(type) ||
|
23
|
+
string?(type) ||
|
24
|
+
compact?(type) ||
|
25
|
+
int?(type) ||
|
26
|
+
uint?(type) ||
|
27
|
+
option?(type) ||
|
28
|
+
array?(type) ||
|
29
|
+
vec?(type) ||
|
30
|
+
tuple?(type)
|
31
|
+
) ||
|
32
|
+
type.instance_of?(Hash)
|
33
|
+
end
|
34
|
+
|
19
35
|
def bytes?(type)
|
20
36
|
type.downcase == 'bytes'
|
21
37
|
end
|
@@ -25,7 +41,7 @@ module ScaleRb
|
|
25
41
|
end
|
26
42
|
|
27
43
|
def string?(type)
|
28
|
-
type.downcase == 'str' || type.downcase == 'string' || type.downcase == 'text'
|
44
|
+
type.downcase == 'str' || type.downcase == 'string' || type.downcase == 'text' || type.downcase == 'type'
|
29
45
|
end
|
30
46
|
|
31
47
|
def compact?(type)
|
@@ -97,14 +113,16 @@ end
|
|
97
113
|
module ScaleRb
|
98
114
|
class << self
|
99
115
|
def _get_final_type_from_registry(registry, type)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
116
|
+
raise "Wrong lookup type #{type.class}" if !type.instance_of?(String) && !type.instance_of?(Hash)
|
117
|
+
|
118
|
+
return if type.instance_of?(Hash)
|
119
|
+
|
120
|
+
mapped = registry._get(type) # mapped: String(name, type_def) | Hash(type_def: struct, enum) | nil
|
121
|
+
|
122
|
+
return if mapped.nil?
|
123
|
+
return mapped if type_def?(mapped)
|
124
|
+
|
125
|
+
_get_final_type_from_registry(registry, mapped)
|
108
126
|
end
|
109
127
|
|
110
128
|
def _decode_types(types, bytes, registry)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
class << self
|
5
|
+
def decode_metadata(bytes)
|
6
|
+
metadata, = ScaleRb.decode('MetadataTop', bytes, TYPES)
|
7
|
+
metadata
|
8
|
+
end
|
9
|
+
|
10
|
+
def build_registry(metadata)
|
11
|
+
raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
|
12
|
+
|
13
|
+
metadata_v14 = metadata._get(:metadata)._get(:v14)
|
14
|
+
MetadataV14.build_registry(metadata_v14)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_storage_item(pallet_name, item_name, metadata)
|
18
|
+
raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
|
19
|
+
|
20
|
+
metadata_v14 = metadata._get(:metadata)._get(:v14)
|
21
|
+
MetadataV14.get_storage_item(pallet_name, item_name, metadata_v14)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
TYPES = {
|
26
|
+
'MetadataTop' => {
|
27
|
+
magicNumber: 'U32',
|
28
|
+
metadata: 'Metadata'
|
29
|
+
},
|
30
|
+
'Metadata' => {
|
31
|
+
_enum: {
|
32
|
+
v0: 'MetadataV0',
|
33
|
+
v1: 'MetadataV1',
|
34
|
+
v2: 'MetadataV2',
|
35
|
+
v3: 'MetadataV3',
|
36
|
+
v4: 'MetadataV4',
|
37
|
+
v5: 'MetadataV5',
|
38
|
+
v6: 'MetadataV6',
|
39
|
+
v7: 'MetadataV7',
|
40
|
+
v8: 'MetadataV8',
|
41
|
+
v9: 'MetadataV9',
|
42
|
+
v10: 'MetadataV10',
|
43
|
+
v11: 'MetadataV11',
|
44
|
+
v12: 'MetadataV12',
|
45
|
+
v13: 'MetadataV13',
|
46
|
+
v14: 'MetadataV14'
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}.merge(MetadataV14::TYPES)
|
50
|
+
.merge(MetadataV13::TYPES)
|
51
|
+
.merge(MetadataV12::TYPES)
|
52
|
+
.merge(MetadataV11::TYPES)
|
53
|
+
.merge(MetadataV10::TYPES)
|
54
|
+
.merge(MetadataV9::TYPES)
|
55
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV10
|
5
|
+
class << self
|
6
|
+
def get_module(module_name, metadata)
|
7
|
+
metadata._get(:metadata)._get(:v10)._get(:modules).find do |m|
|
8
|
+
m._get(:name) == module_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_storage_item(module_name, item_name, metadata)
|
13
|
+
modula = get_module(module_name, metadata)
|
14
|
+
modula._get(:storage)._get(:items).find do |item|
|
15
|
+
item._get(:name) == item_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TYPES = {
|
21
|
+
ErrorMetadataV10: 'ErrorMetadataV9',
|
22
|
+
EventMetadataV10: 'EventMetadataV9',
|
23
|
+
FunctionArgumentMetadataV10: 'FunctionArgumentMetadataV9',
|
24
|
+
FunctionMetadataV10: 'FunctionMetadataV9',
|
25
|
+
MetadataV10: {
|
26
|
+
modules: 'Vec<ModuleMetadataV10>'
|
27
|
+
},
|
28
|
+
ModuleConstantMetadataV10: 'ModuleConstantMetadataV9',
|
29
|
+
ModuleMetadataV10: {
|
30
|
+
name: 'Text',
|
31
|
+
storage: 'Option<StorageMetadataV10>',
|
32
|
+
calls: 'Option<Vec<FunctionMetadataV10>>',
|
33
|
+
events: 'Option<Vec<EventMetadataV10>>',
|
34
|
+
constants: 'Vec<ModuleConstantMetadataV10>',
|
35
|
+
errors: 'Vec<ErrorMetadataV10>'
|
36
|
+
},
|
37
|
+
StorageEntryModifierV10: 'StorageEntryModifierV9',
|
38
|
+
StorageEntryMetadataV10: {
|
39
|
+
name: 'Text',
|
40
|
+
modifier: 'StorageEntryModifierV10',
|
41
|
+
type: 'StorageEntryTypeV10',
|
42
|
+
fallback: 'Bytes',
|
43
|
+
docs: 'Vec<Text>'
|
44
|
+
},
|
45
|
+
StorageEntryTypeV10: {
|
46
|
+
_enum: {
|
47
|
+
Plain: 'Type',
|
48
|
+
Map: {
|
49
|
+
hasher: 'StorageHasherV10',
|
50
|
+
key: 'Type',
|
51
|
+
value: 'Type',
|
52
|
+
linked: 'bool'
|
53
|
+
},
|
54
|
+
DoubleMap: {
|
55
|
+
hasher: 'StorageHasherV10',
|
56
|
+
key1: 'Type',
|
57
|
+
key2: 'Type',
|
58
|
+
value: 'Type',
|
59
|
+
key2Hasher: 'StorageHasherV10'
|
60
|
+
}
|
61
|
+
}
|
62
|
+
},
|
63
|
+
StorageMetadataV10: {
|
64
|
+
prefix: 'Text',
|
65
|
+
items: 'Vec<StorageEntryMetadataV10>'
|
66
|
+
},
|
67
|
+
StorageHasherV10: {
|
68
|
+
_enum: %w[
|
69
|
+
Blake2_128
|
70
|
+
Blake2_256
|
71
|
+
Blake2_128Concat
|
72
|
+
Twox128
|
73
|
+
Twox256
|
74
|
+
Twox64Concat
|
75
|
+
]
|
76
|
+
}
|
77
|
+
}.freeze
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV11
|
5
|
+
class << self
|
6
|
+
def get_module(module_name, metadata)
|
7
|
+
metadata._get(:metadata)._get(:v11)._get(:modules).find do |m|
|
8
|
+
m._get(:name) == module_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_storage_item(module_name, item_name, metadata)
|
13
|
+
modula = get_module(module_name, metadata)
|
14
|
+
modula._get(:storage)._get(:items).find do |item|
|
15
|
+
item._get(:name) == item_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TYPES = {
|
21
|
+
ErrorMetadataV11: 'ErrorMetadataV10',
|
22
|
+
EventMetadataV11: 'EventMetadataV10',
|
23
|
+
ExtrinsicMetadataV11: {
|
24
|
+
version: 'u8',
|
25
|
+
signedExtensions: 'Vec<Text>'
|
26
|
+
},
|
27
|
+
FunctionArgumentMetadataV11: 'FunctionArgumentMetadataV10',
|
28
|
+
FunctionMetadataV11: 'FunctionMetadataV10',
|
29
|
+
MetadataV11: {
|
30
|
+
modules: 'Vec<ModuleMetadataV11>',
|
31
|
+
extrinsic: 'ExtrinsicMetadataV11'
|
32
|
+
},
|
33
|
+
ModuleConstantMetadataV11: 'ModuleConstantMetadataV10',
|
34
|
+
ModuleMetadataV11: {
|
35
|
+
name: 'Text',
|
36
|
+
storage: 'Option<StorageMetadataV11>',
|
37
|
+
calls: 'Option<Vec<FunctionMetadataV11>>',
|
38
|
+
events: 'Option<Vec<EventMetadataV11>>',
|
39
|
+
constants: 'Vec<ModuleConstantMetadataV11>',
|
40
|
+
errors: 'Vec<ErrorMetadataV11>'
|
41
|
+
},
|
42
|
+
StorageEntryModifierV11: 'StorageEntryModifierV10',
|
43
|
+
StorageEntryMetadataV11: {
|
44
|
+
name: 'Text',
|
45
|
+
modifier: 'StorageEntryModifierV11',
|
46
|
+
type: 'StorageEntryTypeV11',
|
47
|
+
fallback: 'Bytes',
|
48
|
+
docs: 'Vec<Text>'
|
49
|
+
},
|
50
|
+
StorageEntryTypeV11: {
|
51
|
+
_enum: {
|
52
|
+
Plain: 'Type',
|
53
|
+
Map: {
|
54
|
+
hasher: 'StorageHasherV11',
|
55
|
+
key: 'Type',
|
56
|
+
value: 'Type',
|
57
|
+
linked: 'bool'
|
58
|
+
},
|
59
|
+
DoubleMap: {
|
60
|
+
hasher: 'StorageHasherV11',
|
61
|
+
key1: 'Type',
|
62
|
+
key2: 'Type',
|
63
|
+
value: 'Type',
|
64
|
+
key2Hasher: 'StorageHasherV11'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
},
|
68
|
+
StorageMetadataV11: {
|
69
|
+
prefix: 'Text',
|
70
|
+
items: 'Vec<StorageEntryMetadataV11>'
|
71
|
+
},
|
72
|
+
StorageHasherV11: {
|
73
|
+
_enum: %w[
|
74
|
+
Blake2_128
|
75
|
+
Blake2_256
|
76
|
+
Blake2_128Concat
|
77
|
+
Twox128
|
78
|
+
Twox256
|
79
|
+
Twox64Concat
|
80
|
+
Identity
|
81
|
+
]
|
82
|
+
}
|
83
|
+
}.freeze
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV12
|
5
|
+
class << self
|
6
|
+
def get_module(module_name, metadata)
|
7
|
+
metadata._get(:metadata)._get(:v12)._get(:modules).find do |m|
|
8
|
+
m._get(:name) == module_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_storage_item(module_name, item_name, metadata)
|
13
|
+
modula = get_module(module_name, metadata)
|
14
|
+
modula._get(:storage)._get(:items).find do |item|
|
15
|
+
item._get(:name) == item_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TYPES = {
|
21
|
+
ErrorMetadataV12: 'ErrorMetadataV11',
|
22
|
+
EventMetadataV12: 'EventMetadataV11',
|
23
|
+
ExtrinsicMetadataV12: 'ExtrinsicMetadataV11',
|
24
|
+
FunctionArgumentMetadataV12: 'FunctionArgumentMetadataV11',
|
25
|
+
FunctionMetadataV12: 'FunctionMetadataV11',
|
26
|
+
MetadataV12: {
|
27
|
+
modules: 'Vec<ModuleMetadataV12>',
|
28
|
+
extrinsic: 'ExtrinsicMetadataV12'
|
29
|
+
},
|
30
|
+
ModuleConstantMetadataV12: 'ModuleConstantMetadataV11',
|
31
|
+
ModuleMetadataV12: {
|
32
|
+
name: 'Text',
|
33
|
+
storage: 'Option<StorageMetadataV12>',
|
34
|
+
calls: 'Option<Vec<FunctionMetadataV12>>',
|
35
|
+
events: 'Option<Vec<EventMetadataV12>>',
|
36
|
+
constants: 'Vec<ModuleConstantMetadataV12>',
|
37
|
+
errors: 'Vec<ErrorMetadataV12>',
|
38
|
+
index: 'u8'
|
39
|
+
},
|
40
|
+
StorageEntryModifierV12: 'StorageEntryModifierV11',
|
41
|
+
StorageEntryMetadataV12: 'StorageEntryMetadataV11',
|
42
|
+
StorageEntryTypeV12: 'StorageEntryTypeV11',
|
43
|
+
StorageMetadataV12: 'StorageMetadataV11',
|
44
|
+
StorageHasherV12: 'StorageHasherV11'
|
45
|
+
}.freeze
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV13
|
5
|
+
class << self
|
6
|
+
def get_module(module_name, metadata)
|
7
|
+
metadata._get(:metadata)._get(:v13)._get(:modules).find do |m|
|
8
|
+
m._get(:name) == module_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_storage_item(module_name, item_name, metadata)
|
13
|
+
modula = get_module(module_name, metadata)
|
14
|
+
modula._get(:storage)._get(:items).find do |item|
|
15
|
+
item._get(:name) == item_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TYPES = {
|
21
|
+
MetadataV13: {
|
22
|
+
modules: 'Vec<ModuleMetadataV13>',
|
23
|
+
extrinsic: 'ExtrinsicMetadataV13'
|
24
|
+
},
|
25
|
+
|
26
|
+
ModuleMetadataV13: {
|
27
|
+
name: 'Text',
|
28
|
+
storage: 'Option<StorageMetadataV13>',
|
29
|
+
calls: 'Option<Vec<FunctionMetadataV13>>',
|
30
|
+
events: 'Option<Vec<EventMetadataV13>>',
|
31
|
+
constants: 'Vec<ModuleConstantMetadataV13>',
|
32
|
+
errors: 'Vec<ErrorMetadataV13>',
|
33
|
+
index: 'u8'
|
34
|
+
},
|
35
|
+
StorageMetadataV13: {
|
36
|
+
prefix: 'Text',
|
37
|
+
items: 'Vec<StorageEntryMetadataV13>'
|
38
|
+
},
|
39
|
+
StorageEntryMetadataV13: {
|
40
|
+
name: 'Text',
|
41
|
+
modifier: 'StorageEntryModifierV13',
|
42
|
+
type: 'StorageEntryTypeV13',
|
43
|
+
fallback: 'Bytes',
|
44
|
+
docs: 'Vec<Text>'
|
45
|
+
},
|
46
|
+
StorageEntryModifierV13: 'StorageEntryModifierV12',
|
47
|
+
StorageEntryTypeV13: {
|
48
|
+
_enum: {
|
49
|
+
plain: 'Type',
|
50
|
+
map: {
|
51
|
+
hasher: 'StorageHasherV13',
|
52
|
+
key: 'Type',
|
53
|
+
value: 'Type',
|
54
|
+
linked: 'bool'
|
55
|
+
},
|
56
|
+
doubleMap: {
|
57
|
+
hasher: 'StorageHasherV13',
|
58
|
+
key1: 'Type',
|
59
|
+
key2: 'Type',
|
60
|
+
value: 'Type',
|
61
|
+
key2Hasher: 'StorageHasherV13'
|
62
|
+
},
|
63
|
+
nMap: {
|
64
|
+
keyVec: 'Vec<Type>',
|
65
|
+
hashers: 'Vec<StorageHasherV13>',
|
66
|
+
value: 'Type'
|
67
|
+
}
|
68
|
+
}
|
69
|
+
},
|
70
|
+
StorageHasherV13: 'StorageHasherV12',
|
71
|
+
FunctionMetadataV13: 'FunctionMetadataV12',
|
72
|
+
EventMetadataV13: 'EventMetadataV12',
|
73
|
+
ModuleConstantMetadataV13: 'ModuleConstantMetadataV12',
|
74
|
+
ErrorMetadataV13: 'ErrorMetadataV12',
|
75
|
+
ExtrinsicMetadataV13: 'ExtrinsicMetadataV12'
|
76
|
+
}.freeze
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV14
|
5
|
+
class << self
|
6
|
+
def build_registry(metadata)
|
7
|
+
types = metadata._get(:lookup)._get(:types)
|
8
|
+
types.map { |type| [type._get(:id), type._get(:type)] }.to_h
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_module(pallet_name, metadata)
|
12
|
+
metadata._get(:metadata)._get(:v14)._get(:pallets).find do |p|
|
13
|
+
p._get(:name) == pallet_name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_storage_item(pallet_name, item_name, metadata)
|
18
|
+
pallet = get_module(pallet_name, metadata)
|
19
|
+
pallet._get(:storage)._get(:items).find do |item|
|
20
|
+
item._get(:name) == item_name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
TYPES = {
|
26
|
+
MetadataV14: {
|
27
|
+
lookup: 'PortableRegistry',
|
28
|
+
pallets: 'Vec<PalletMetadataV14>',
|
29
|
+
extrinsic: 'ExtrinsicMetadataV14',
|
30
|
+
type: 'SiLookupTypeId'
|
31
|
+
},
|
32
|
+
|
33
|
+
# PortableRegistry begin
|
34
|
+
PortableRegistry: {
|
35
|
+
types: 'Vec<PortableTypeV14>'
|
36
|
+
},
|
37
|
+
PortableTypeV14: {
|
38
|
+
id: 'Si1LookupTypeId',
|
39
|
+
type: 'Si1Type'
|
40
|
+
},
|
41
|
+
Si1LookupTypeId: 'Compact',
|
42
|
+
Si1Type: {
|
43
|
+
path: 'Si1Path',
|
44
|
+
params: 'Vec<Si1TypeParameter>',
|
45
|
+
def: 'Si1TypeDef',
|
46
|
+
docs: 'Vec<Text>'
|
47
|
+
},
|
48
|
+
Si1Path: 'Vec<Text>',
|
49
|
+
Si1TypeParameter: {
|
50
|
+
name: 'Text',
|
51
|
+
type: 'Option<Si1LookupTypeId>'
|
52
|
+
},
|
53
|
+
Si1TypeDef: {
|
54
|
+
_enum: {
|
55
|
+
composite: 'Si1TypeDefComposite',
|
56
|
+
variant: 'Si1TypeDefVariant',
|
57
|
+
sequence: 'Si1TypeDefSequence',
|
58
|
+
array: 'Si1TypeDefArray',
|
59
|
+
tuple: 'Si1TypeDefTuple',
|
60
|
+
primitive: 'Si1TypeDefPrimitive',
|
61
|
+
compact: 'Si1TypeDefCompact',
|
62
|
+
bitSequence: 'Si1TypeDefBitSequence',
|
63
|
+
historicMetaCompat: 'Text' # TODO: sanitize?
|
64
|
+
}
|
65
|
+
},
|
66
|
+
Si1TypeDefComposite: {
|
67
|
+
fields: 'Vec<Si1Field>'
|
68
|
+
},
|
69
|
+
Si1Field: {
|
70
|
+
name: 'Option<Text>',
|
71
|
+
type: 'Si1LookupTypeId',
|
72
|
+
typeName: 'Option<Text>',
|
73
|
+
docs: 'Vec<Text>'
|
74
|
+
},
|
75
|
+
Si1TypeDefVariant: {
|
76
|
+
variants: 'Vec<Si1Variant>'
|
77
|
+
},
|
78
|
+
Si1Variant: {
|
79
|
+
name: 'Text',
|
80
|
+
fields: 'Vec<Si1Field>',
|
81
|
+
index: 'u8',
|
82
|
+
docs: 'Vec<Text>'
|
83
|
+
},
|
84
|
+
Si1TypeDefSequence: {
|
85
|
+
type: 'Si1LookupTypeId'
|
86
|
+
},
|
87
|
+
Si1TypeDefArray: {
|
88
|
+
len: 'u32',
|
89
|
+
type: 'Si1LookupTypeId'
|
90
|
+
},
|
91
|
+
Si1TypeDefTuple: 'Vec<Si1LookupTypeId>',
|
92
|
+
Si1TypeDefPrimitive: {
|
93
|
+
_enum: %w[
|
94
|
+
Bool Char Str U8 U16 U32 U64 U128 U256 I8 I16 I32 I64 I128 I256
|
95
|
+
]
|
96
|
+
},
|
97
|
+
Si1TypeDefCompact: {
|
98
|
+
type: 'Si1LookupTypeId'
|
99
|
+
},
|
100
|
+
Si1TypeDefBitSequence: {
|
101
|
+
bitStoreType: 'Si1LookupTypeId',
|
102
|
+
bitOrderType: 'Si1LookupTypeId'
|
103
|
+
},
|
104
|
+
# PortableRegistry end
|
105
|
+
|
106
|
+
# PalletMetadataV14 begin
|
107
|
+
PalletMetadataV14: {
|
108
|
+
name: 'Text',
|
109
|
+
storage: 'Option<PalletStorageMetadataV14>',
|
110
|
+
calls: 'Option<PalletCallMetadataV14>',
|
111
|
+
events: 'Option<PalletEventMetadataV14>',
|
112
|
+
constants: 'Vec<PalletConstantMetadataV14>',
|
113
|
+
errors: 'Option<PalletErrorMetadataV14>',
|
114
|
+
index: 'U8'
|
115
|
+
},
|
116
|
+
PalletStorageMetadataV14: {
|
117
|
+
prefix: 'Text',
|
118
|
+
items: 'Vec<StorageEntryMetadataV14>'
|
119
|
+
},
|
120
|
+
StorageEntryMetadataV14: {
|
121
|
+
name: 'Text',
|
122
|
+
modifier: 'StorageEntryModifierV14',
|
123
|
+
type: 'StorageEntryTypeV14',
|
124
|
+
fallback: 'Bytes',
|
125
|
+
docs: 'Vec<Text>'
|
126
|
+
},
|
127
|
+
StorageEntryModifierV14: {
|
128
|
+
_enum: %w[Optional Default Required]
|
129
|
+
},
|
130
|
+
StorageEntryTypeV14: {
|
131
|
+
_enum: {
|
132
|
+
plain: 'SiLookupTypeId',
|
133
|
+
map: {
|
134
|
+
hashers: 'Vec<StorageHasherV14>',
|
135
|
+
key: 'SiLookupTypeId',
|
136
|
+
value: 'SiLookupTypeId'
|
137
|
+
}
|
138
|
+
}
|
139
|
+
},
|
140
|
+
StorageHasherV14: {
|
141
|
+
_enum: %w[Blake2128 Blake2256 Blake2128Concat Twox128 Twox256 Twox64Concat Identity]
|
142
|
+
},
|
143
|
+
PalletCallMetadataV14: {
|
144
|
+
type: 'Si1LookupTypeId'
|
145
|
+
},
|
146
|
+
PalletEventMetadataV14: {
|
147
|
+
type: 'SiLookupTypeId'
|
148
|
+
},
|
149
|
+
PalletConstantMetadataV14: {
|
150
|
+
name: 'Text',
|
151
|
+
type: 'SiLookupTypeId',
|
152
|
+
value: 'Bytes',
|
153
|
+
docs: 'Vec<Text>'
|
154
|
+
},
|
155
|
+
PalletErrorMetadataV14: {
|
156
|
+
type: 'SiLookupTypeId'
|
157
|
+
},
|
158
|
+
# PalletMetadataV14 end
|
159
|
+
|
160
|
+
# ExtrinsicMetadataV14 begin
|
161
|
+
ExtrinsicMetadataV14: {
|
162
|
+
type: 'SiLookupTypeId',
|
163
|
+
version: 'u8',
|
164
|
+
signedExtensions: 'Vec<SignedExtensionMetadataV14>'
|
165
|
+
},
|
166
|
+
SignedExtensionMetadataV14: {
|
167
|
+
identifier: 'Text',
|
168
|
+
type: 'SiLookupTypeId',
|
169
|
+
additionalSigned: 'SiLookupTypeId'
|
170
|
+
},
|
171
|
+
# ExtrinsicMetadataV14 end
|
172
|
+
|
173
|
+
SiLookupTypeId: 'Compact'
|
174
|
+
}.freeze
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Metadata
|
4
|
+
module MetadataV9
|
5
|
+
class << self
|
6
|
+
def get_module(module_name, metadata)
|
7
|
+
metadata._get(:metadata)._get(:v9)._get(:modules).find do |m|
|
8
|
+
m._get(:name) == module_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_storage_item(module_name, item_name, metadata)
|
13
|
+
modula = get_module(module_name, metadata)
|
14
|
+
modula._get(:storage)._get(:items).find do |item|
|
15
|
+
item._get(:name) == item_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
TYPES = {
|
21
|
+
ErrorMetadataV9: {
|
22
|
+
name: 'Text',
|
23
|
+
docs: 'Vec<Text>'
|
24
|
+
},
|
25
|
+
EventMetadataV9: {
|
26
|
+
name: 'Text',
|
27
|
+
args: 'Vec<Type>',
|
28
|
+
docs: 'Vec<Text>'
|
29
|
+
},
|
30
|
+
FunctionArgumentMetadataV9: {
|
31
|
+
name: 'Text',
|
32
|
+
type: 'Type'
|
33
|
+
},
|
34
|
+
FunctionMetadataV9: {
|
35
|
+
name: 'Text',
|
36
|
+
args: 'Vec<FunctionArgumentMetadataV9>',
|
37
|
+
docs: 'Vec<Text>'
|
38
|
+
},
|
39
|
+
MetadataV9: {
|
40
|
+
modules: 'Vec<ModuleMetadataV9>'
|
41
|
+
},
|
42
|
+
ModuleConstantMetadataV9: {
|
43
|
+
name: 'Text',
|
44
|
+
type: 'Type',
|
45
|
+
value: 'Bytes',
|
46
|
+
docs: 'Vec<Text>'
|
47
|
+
},
|
48
|
+
ModuleMetadataV9: {
|
49
|
+
name: 'Text',
|
50
|
+
storage: 'Option<StorageMetadataV9>',
|
51
|
+
calls: 'Option<Vec<FunctionMetadataV9>>',
|
52
|
+
events: 'Option<Vec<EventMetadataV9>>',
|
53
|
+
constants: 'Vec<ModuleConstantMetadataV9>',
|
54
|
+
errors: 'Vec<ErrorMetadataV9>'
|
55
|
+
},
|
56
|
+
StorageEntryMetadataV9: {
|
57
|
+
name: 'Text',
|
58
|
+
modifier: 'StorageEntryModifierV9',
|
59
|
+
type: 'StorageEntryTypeV9',
|
60
|
+
fallback: 'Bytes',
|
61
|
+
docs: 'Vec<Text>'
|
62
|
+
},
|
63
|
+
StorageEntryModifierV9: {
|
64
|
+
_enum: %w[Optional Default Required]
|
65
|
+
},
|
66
|
+
StorageEntryTypeV9: {
|
67
|
+
_enum: {
|
68
|
+
Plain: 'Type',
|
69
|
+
Map: {
|
70
|
+
hasher: 'StorageHasherV9',
|
71
|
+
key: 'Type',
|
72
|
+
value: 'Type',
|
73
|
+
linked: 'bool'
|
74
|
+
},
|
75
|
+
DoubleMap: {
|
76
|
+
hasher: 'StorageHasherV9',
|
77
|
+
key1: 'Type',
|
78
|
+
key2: 'Type',
|
79
|
+
value: 'Type',
|
80
|
+
key2Hasher: 'StorageHasherV9'
|
81
|
+
}
|
82
|
+
}
|
83
|
+
},
|
84
|
+
StorageHasherV9: {
|
85
|
+
_enum: %w[
|
86
|
+
Blake2_128
|
87
|
+
Blake2_256
|
88
|
+
Twox128
|
89
|
+
Twox256
|
90
|
+
Twox64Concat
|
91
|
+
]
|
92
|
+
},
|
93
|
+
StorageMetadataV9: {
|
94
|
+
prefix: 'Text',
|
95
|
+
items: 'Vec<StorageEntryMetadataV9>'
|
96
|
+
}
|
97
|
+
}.freeze
|
98
|
+
end
|
99
|
+
end
|
data/lib/monkey_patching.rb
CHANGED
data/lib/scale_rb/version.rb
CHANGED
data/lib/scale_rb.rb
CHANGED
@@ -9,8 +9,13 @@ require 'codec'
|
|
9
9
|
require 'portable_codec'
|
10
10
|
|
11
11
|
# metadata types, decoding and helpers
|
12
|
-
require 'metadata'
|
13
|
-
require '
|
12
|
+
require 'metadata/metadata_v9'
|
13
|
+
require 'metadata/metadata_v10'
|
14
|
+
require 'metadata/metadata_v11'
|
15
|
+
require 'metadata/metadata_v12'
|
16
|
+
require 'metadata/metadata_v13'
|
17
|
+
require 'metadata/metadata_v14'
|
18
|
+
require 'metadata/metadata'
|
14
19
|
|
15
20
|
require 'hasher'
|
16
21
|
require 'storage_helper'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scale_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aki Wu
|
@@ -61,8 +61,13 @@ files:
|
|
61
61
|
- exe/metadata
|
62
62
|
- lib/codec.rb
|
63
63
|
- lib/hasher.rb
|
64
|
-
- lib/metadata.rb
|
65
|
-
- lib/
|
64
|
+
- lib/metadata/metadata.rb
|
65
|
+
- lib/metadata/metadata_v10.rb
|
66
|
+
- lib/metadata/metadata_v11.rb
|
67
|
+
- lib/metadata/metadata_v12.rb
|
68
|
+
- lib/metadata/metadata_v13.rb
|
69
|
+
- lib/metadata/metadata_v14.rb
|
70
|
+
- lib/metadata/metadata_v9.rb
|
66
71
|
- lib/monkey_patching.rb
|
67
72
|
- lib/portable_codec.rb
|
68
73
|
- lib/registry.rb
|
data/lib/metadata.rb
DELETED
@@ -1,199 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Metadata
|
4
|
-
class << self
|
5
|
-
def decode_metadata(bytes)
|
6
|
-
metadata, = ScaleRb.decode('MetadataTop', bytes, TYPES)
|
7
|
-
metadata
|
8
|
-
end
|
9
|
-
|
10
|
-
def build_registry(metadata)
|
11
|
-
raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
|
12
|
-
|
13
|
-
metadata_v14 = metadata._get(:metadata)._get(:v14)
|
14
|
-
MetadataV14.build_registry(metadata_v14)
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_storage_item(pallet_name, item_name, metadata)
|
18
|
-
raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
|
19
|
-
|
20
|
-
metadata_v14 = metadata._get(:metadata)._get(:v14)
|
21
|
-
MetadataV14.get_storage_item(pallet_name, item_name, metadata_v14)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
TYPES = {
|
26
|
-
'MetadataTop' => {
|
27
|
-
magicNumber: 'U32',
|
28
|
-
metadata: 'Metadata'
|
29
|
-
},
|
30
|
-
'Metadata' => {
|
31
|
-
_enum: {
|
32
|
-
v0: 'MetadataV0',
|
33
|
-
v1: 'MetadataV1',
|
34
|
-
v2: 'MetadataV2',
|
35
|
-
v3: 'MetadataV3',
|
36
|
-
v4: 'MetadataV4',
|
37
|
-
v5: 'MetadataV5',
|
38
|
-
v6: 'MetadataV6',
|
39
|
-
v7: 'MetadataV7',
|
40
|
-
v8: 'MetadataV8',
|
41
|
-
v9: 'MetadataV9',
|
42
|
-
v10: 'MetadataV10',
|
43
|
-
v11: 'MetadataV11',
|
44
|
-
v12: 'MetadataV12',
|
45
|
-
v13: 'MetadataV13',
|
46
|
-
v14: 'MetadataV14'
|
47
|
-
}
|
48
|
-
},
|
49
|
-
|
50
|
-
'MetadataV14' => {
|
51
|
-
lookup: 'PortableRegistry',
|
52
|
-
pallets: 'Vec<PalletMetadataV14>',
|
53
|
-
extrinsic: 'ExtrinsicMetadataV14',
|
54
|
-
type: 'SiLookupTypeId'
|
55
|
-
},
|
56
|
-
|
57
|
-
# PortableRegistry begin
|
58
|
-
'PortableRegistry' => {
|
59
|
-
types: 'Vec<PortableTypeV14>'
|
60
|
-
},
|
61
|
-
'PortableTypeV14' => {
|
62
|
-
id: 'Si1LookupTypeId',
|
63
|
-
type: 'Si1Type'
|
64
|
-
},
|
65
|
-
'Si1LookupTypeId' => 'Compact',
|
66
|
-
'Si1Type' => {
|
67
|
-
path: 'Si1Path',
|
68
|
-
params: 'Vec<Si1TypeParameter>',
|
69
|
-
def: 'Si1TypeDef',
|
70
|
-
docs: 'Vec<Text>'
|
71
|
-
},
|
72
|
-
'Si1Path' => 'Vec<Text>',
|
73
|
-
'Si1TypeParameter' => {
|
74
|
-
name: 'Text',
|
75
|
-
type: 'Option<Si1LookupTypeId>'
|
76
|
-
},
|
77
|
-
'Si1TypeDef' => {
|
78
|
-
_enum: {
|
79
|
-
composite: 'Si1TypeDefComposite',
|
80
|
-
variant: 'Si1TypeDefVariant',
|
81
|
-
sequence: 'Si1TypeDefSequence',
|
82
|
-
array: 'Si1TypeDefArray',
|
83
|
-
tuple: 'Si1TypeDefTuple',
|
84
|
-
primitive: 'Si1TypeDefPrimitive',
|
85
|
-
compact: 'Si1TypeDefCompact',
|
86
|
-
bitSequence: 'Si1TypeDefBitSequence',
|
87
|
-
historicMetaCompat: 'Text' # TODO: sanitize?
|
88
|
-
}
|
89
|
-
},
|
90
|
-
'Si1TypeDefComposite' => {
|
91
|
-
fields: 'Vec<Si1Field>'
|
92
|
-
},
|
93
|
-
'Si1Field' => {
|
94
|
-
name: 'Option<Text>',
|
95
|
-
type: 'Si1LookupTypeId',
|
96
|
-
typeName: 'Option<Text>',
|
97
|
-
docs: 'Vec<Text>'
|
98
|
-
},
|
99
|
-
'Si1TypeDefVariant' => {
|
100
|
-
variants: 'Vec<Si1Variant>'
|
101
|
-
},
|
102
|
-
'Si1Variant' => {
|
103
|
-
name: 'Text',
|
104
|
-
fields: 'Vec<Si1Field>',
|
105
|
-
index: 'u8',
|
106
|
-
docs: 'Vec<Text>'
|
107
|
-
},
|
108
|
-
'Si1TypeDefSequence' => {
|
109
|
-
type: 'Si1LookupTypeId'
|
110
|
-
},
|
111
|
-
'Si1TypeDefArray' => {
|
112
|
-
len: 'u32',
|
113
|
-
type: 'Si1LookupTypeId'
|
114
|
-
},
|
115
|
-
'Si1TypeDefTuple' => 'Vec<Si1LookupTypeId>',
|
116
|
-
'Si1TypeDefPrimitive' => {
|
117
|
-
_enum: %w[
|
118
|
-
Bool Char Str U8 U16 U32 U64 U128 U256 I8 I16 I32 I64 I128 I256
|
119
|
-
]
|
120
|
-
},
|
121
|
-
'Si1TypeDefCompact' => {
|
122
|
-
type: 'Si1LookupTypeId'
|
123
|
-
},
|
124
|
-
'Si1TypeDefBitSequence' => {
|
125
|
-
bitStoreType: 'Si1LookupTypeId',
|
126
|
-
bitOrderType: 'Si1LookupTypeId'
|
127
|
-
},
|
128
|
-
# PortableRegistry end
|
129
|
-
|
130
|
-
# PalletMetadataV14 begin
|
131
|
-
'PalletMetadataV14' => {
|
132
|
-
name: 'Text',
|
133
|
-
storage: 'Option<PalletStorageMetadataV14>',
|
134
|
-
calls: 'Option<PalletCallMetadataV14>',
|
135
|
-
events: 'Option<PalletEventMetadataV14>',
|
136
|
-
constants: 'Vec<PalletConstantMetadataV14>',
|
137
|
-
errors: 'Option<PalletErrorMetadataV14>',
|
138
|
-
index: 'U8'
|
139
|
-
},
|
140
|
-
'PalletStorageMetadataV14' => {
|
141
|
-
prefix: 'Text',
|
142
|
-
items: 'Vec<StorageEntryMetadataV14>'
|
143
|
-
},
|
144
|
-
'StorageEntryMetadataV14' => {
|
145
|
-
name: 'Text',
|
146
|
-
modifier: 'StorageEntryModifierV14',
|
147
|
-
type: 'StorageEntryTypeV14',
|
148
|
-
fallback: 'Bytes',
|
149
|
-
docs: 'Vec<Text>'
|
150
|
-
},
|
151
|
-
'StorageEntryModifierV14' => {
|
152
|
-
_enum: %w[Optional Default Required]
|
153
|
-
},
|
154
|
-
'StorageEntryTypeV14' => {
|
155
|
-
_enum: {
|
156
|
-
plain: 'SiLookupTypeId',
|
157
|
-
map: {
|
158
|
-
hashers: 'Vec<StorageHasherV14>',
|
159
|
-
key: 'SiLookupTypeId',
|
160
|
-
value: 'SiLookupTypeId'
|
161
|
-
}
|
162
|
-
}
|
163
|
-
},
|
164
|
-
'StorageHasherV14' => {
|
165
|
-
_enum: %w[Blake2128 Blake2256 Blake2128Concat Twox128 Twox256 Twox64Concat Identity]
|
166
|
-
},
|
167
|
-
'PalletCallMetadataV14' => {
|
168
|
-
type: 'Si1LookupTypeId'
|
169
|
-
},
|
170
|
-
'PalletEventMetadataV14' => {
|
171
|
-
type: 'SiLookupTypeId'
|
172
|
-
},
|
173
|
-
'PalletConstantMetadataV14' => {
|
174
|
-
name: 'Text',
|
175
|
-
type: 'SiLookupTypeId',
|
176
|
-
value: 'Bytes',
|
177
|
-
docs: 'Vec<Text>'
|
178
|
-
},
|
179
|
-
'PalletErrorMetadataV14' => {
|
180
|
-
type: 'SiLookupTypeId'
|
181
|
-
},
|
182
|
-
# PalletMetadataV14 end
|
183
|
-
|
184
|
-
# ExtrinsicMetadataV14 begin
|
185
|
-
'ExtrinsicMetadataV14' => {
|
186
|
-
type: 'SiLookupTypeId',
|
187
|
-
version: 'u8',
|
188
|
-
signedExtensions: 'Vec<SignedExtensionMetadataV14>'
|
189
|
-
},
|
190
|
-
'SignedExtensionMetadataV14' => {
|
191
|
-
identifier: 'Text',
|
192
|
-
type: 'SiLookupTypeId',
|
193
|
-
additionalSigned: 'SiLookupTypeId'
|
194
|
-
},
|
195
|
-
# ExtrinsicMetadataV14 end
|
196
|
-
|
197
|
-
'SiLookupTypeId' => 'Compact'
|
198
|
-
}.freeze
|
199
|
-
end
|
data/lib/metadata_v14.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MetadataV14
|
4
|
-
class << self
|
5
|
-
def build_registry(metadata)
|
6
|
-
types = metadata._get(:lookup)._get(:types)
|
7
|
-
types.map { |type| [type._get(:id), type._get(:type)] }.to_h
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_storage_item(pallet_name, item_name, metadata)
|
11
|
-
pallet =
|
12
|
-
metadata._get(:pallets).find do |p|
|
13
|
-
p._get(:name) == pallet_name
|
14
|
-
end
|
15
|
-
|
16
|
-
pallet._get(:storage)._get(:items).find do |item|
|
17
|
-
item._get(:name) == item_name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|