scale.rb 0.2.17 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Cargo.lock +8 -4
  4. data/Cargo.toml +2 -3
  5. data/Dockerfile +4 -1
  6. data/Gemfile.lock +23 -21
  7. data/README.md +44 -1
  8. data/Rakefile +6 -0
  9. data/exe/scale +49 -0
  10. data/lib/helper.rb +19 -4
  11. data/lib/metadata/metadata.rb +27 -17
  12. data/lib/metadata/metadata_v0.rb +24 -20
  13. data/lib/metadata/metadata_v1.rb +13 -9
  14. data/lib/metadata/metadata_v10.rb +2 -2
  15. data/lib/metadata/metadata_v11.rb +2 -2
  16. data/lib/metadata/metadata_v12.rb +9 -8
  17. data/lib/metadata/metadata_v13.rb +161 -0
  18. data/lib/metadata/metadata_v2.rb +2 -2
  19. data/lib/metadata/metadata_v3.rb +2 -2
  20. data/lib/metadata/metadata_v4.rb +21 -11
  21. data/lib/metadata/metadata_v5.rb +21 -11
  22. data/lib/metadata/metadata_v6.rb +9 -9
  23. data/lib/metadata/metadata_v7.rb +26 -15
  24. data/lib/metadata/metadata_v8.rb +9 -9
  25. data/lib/metadata/metadata_v9.rb +2 -2
  26. data/lib/scale.rb +40 -339
  27. data/lib/scale/base.rb +175 -93
  28. data/lib/scale/block.rb +10 -10
  29. data/lib/scale/trie.rb +1 -1
  30. data/lib/scale/types.rb +139 -40
  31. data/lib/scale/version.rb +1 -1
  32. data/lib/scale_bytes.rb +63 -0
  33. data/lib/substrate_client.rb +11 -8
  34. data/lib/type_builder.rb +280 -0
  35. data/lib/type_registry.rb +91 -0
  36. data/lib/type_registry/crab.json +676 -595
  37. data/lib/type_registry/darwinia.json +730 -554
  38. data/lib/type_registry/default.json +3 -2
  39. data/lib/type_registry/pangolin.json +771 -0
  40. data/scale.gemspec +1 -0
  41. data/scripts/mmr_root_to_sign.rb +10 -0
  42. data/src/lib.rs +80 -25
  43. metadata +25 -10
  44. data/lib/type_registry/edgeware.json +0 -124
  45. data/lib/type_registry/joystream.json +0 -49
  46. data/lib/type_registry/kulupu.json +0 -15
  47. data/lib/type_registry/plasm.json +0 -89
  48. data/lib/type_registry/robonomics.json +0 -39
  49. data/lib/type_registry/westend.json +0 -63
  50. data/src/storage_key.rs +0 -41
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV2
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataModule>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataModule>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV3
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataModule>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataModule>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV4
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataV4Module>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataV4Module>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -49,7 +49,7 @@ module Scale
49
49
  end
50
50
 
51
51
  class MetadataV4Module
52
- include SingleValue
52
+ include Base
53
53
  def self.decode(scale_bytes)
54
54
  name = String.decode(scale_bytes).value
55
55
  prefix = String.decode(scale_bytes).value
@@ -61,19 +61,19 @@ module Scale
61
61
 
62
62
  has_storage = Bool.decode(scale_bytes).value
63
63
  if has_storage
64
- storages = Scale::Types.type_of("Vec<MetadataV4ModuleStorage>").decode(scale_bytes).value
64
+ storages = Scale::Types.get("Vec<MetadataV4ModuleStorage>").decode(scale_bytes).value
65
65
  result[:storage] = storages.map(&:value)
66
66
  end
67
67
 
68
68
  has_calls = Bool.decode(scale_bytes).value
69
69
  if has_calls
70
- calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
70
+ calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
71
71
  result[:calls] = calls.map(&:value)
72
72
  end
73
73
 
74
74
  has_events = Bool.decode(scale_bytes).value
75
75
  if has_events
76
- events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
76
+ events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
77
77
  result[:events] = events.map(&:value)
78
78
  end
79
79
 
@@ -82,14 +82,24 @@ module Scale
82
82
  end
83
83
 
84
84
  class MetadataV4ModuleStorage
85
- include SingleValue
85
+ include Base
86
86
  def self.decode(scale_bytes)
87
+ name = String.decode(scale_bytes).value
88
+ modifier_enum = {
89
+ "type" => "enum",
90
+ "value_list" => ["Optional", "Default"]
91
+ }
92
+ modifier = Scale::Types.get(modifier_enum).decode(scale_bytes).value
87
93
  result = {
88
- name: String.decode(scale_bytes).value,
89
- modifier: Scale::Types.type_of("Enum", %w[Optional Default]).decode(scale_bytes).value
94
+ name: name,
95
+ modifier: modifier
90
96
  }
91
97
 
92
- storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
98
+ storage_function_type_enum = {
99
+ "type" => "enum",
100
+ "value_list" => %w[Plain Map DoubleMap]
101
+ }
102
+ storage_function_type = Scale::Types.get(storage_function_type_enum).decode(scale_bytes).value
93
103
  if storage_function_type == "Plain"
94
104
  result[:type] = {
95
105
  Plain: String.decode(scale_bytes).value
@@ -116,7 +126,7 @@ module Scale
116
126
  end
117
127
 
118
128
  result[:fallback] = Hex.decode(scale_bytes).value
119
- result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
129
+ result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
120
130
 
121
131
  MetadataV4ModuleStorage.new(result)
122
132
  end
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV5
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataV5Module>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataV5Module>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -49,7 +49,7 @@ module Scale
49
49
  end
50
50
 
51
51
  class MetadataV5Module
52
- include SingleValue
52
+ include Base
53
53
  def self.decode(scale_bytes)
54
54
  name = String.decode(scale_bytes).value
55
55
  prefix = String.decode(scale_bytes).value
@@ -61,19 +61,19 @@ module Scale
61
61
 
62
62
  has_storage = Bool.decode(scale_bytes).value
63
63
  if has_storage
64
- storages = Scale::Types.type_of("Vec<MetadataV5ModuleStorage>").decode(scale_bytes).value
64
+ storages = Scale::Types.get("Vec<MetadataV5ModuleStorage>").decode(scale_bytes).value
65
65
  result[:storage] = storages.map(&:value)
66
66
  end
67
67
 
68
68
  has_calls = Bool.decode(scale_bytes).value
69
69
  if has_calls
70
- calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
70
+ calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
71
71
  result[:calls] = calls.map(&:value)
72
72
  end
73
73
 
74
74
  has_events = Bool.decode(scale_bytes).value
75
75
  if has_events
76
- events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
76
+ events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
77
77
  result[:events] = events.map(&:value)
78
78
  end
79
79
 
@@ -82,14 +82,24 @@ module Scale
82
82
  end
83
83
 
84
84
  class MetadataV5ModuleStorage
85
- include SingleValue
85
+ include Base
86
86
  def self.decode(scale_bytes)
87
+ name = String.decode(scale_bytes).value
88
+ modifier_enum = {
89
+ "type" => "enum",
90
+ "value_list" => ["Optional", "Default"]
91
+ }
92
+ modifier = Scale::Types.get(modifier_enum).decode(scale_bytes).value
87
93
  result = {
88
- name: String.decode(scale_bytes).value,
89
- modifier: Scale::Types.type_of("Enum", %w[Optional Default]).decode(scale_bytes).value
94
+ name: name,
95
+ modifier: modifier
90
96
  }
91
97
 
92
- storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
98
+ storage_function_type_enum = {
99
+ "type" => "enum",
100
+ "value_list" => %w[Plain Map DoubleMap]
101
+ }
102
+ storage_function_type = Scale::Types.get(storage_function_type_enum).decode(scale_bytes).value
93
103
  if storage_function_type == "Plain"
94
104
  result[:type] = {
95
105
  Plain: String.decode(scale_bytes).value
@@ -116,7 +126,7 @@ module Scale
116
126
  end
117
127
 
118
128
  result[:fallback] = Hex.decode(scale_bytes).value
119
- result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
129
+ result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
120
130
 
121
131
  MetadataV5ModuleStorage.new(result)
122
132
  end
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV6
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataV6Module>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataV6Module>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -49,7 +49,7 @@ module Scale
49
49
  end
50
50
 
51
51
  class MetadataV6Module
52
- include SingleValue
52
+ include Base
53
53
  def self.decode(scale_bytes)
54
54
  name = String.decode(scale_bytes).value
55
55
  prefix = String.decode(scale_bytes).value
@@ -61,23 +61,23 @@ module Scale
61
61
 
62
62
  has_storage = Bool.decode(scale_bytes).value
63
63
  if has_storage
64
- storages = Scale::Types.type_of("Vec<MetadataV6ModuleStorage>").decode(scale_bytes).value
64
+ storages = Scale::Types.get("Vec<MetadataV6ModuleStorage>").decode(scale_bytes).value
65
65
  result[:storage] = storages.map(&:value)
66
66
  end
67
67
 
68
68
  has_calls = Bool.decode(scale_bytes).value
69
69
  if has_calls
70
- calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
70
+ calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
71
71
  result[:calls] = calls.map(&:value)
72
72
  end
73
73
 
74
74
  has_events = Bool.decode(scale_bytes).value
75
75
  if has_events
76
- events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
76
+ events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
77
77
  result[:events] = events.map(&:value)
78
78
  end
79
79
 
80
- result[:constants] = Scale::Types.type_of("Vec<MetadataV6ModuleConstants>").decode(scale_bytes).value.map(&:value)
80
+ result[:constants] = Scale::Types.get("Vec<MetadataV6ModuleConstants>").decode(scale_bytes).value.map(&:value)
81
81
 
82
82
  MetadataV6Module.new(result)
83
83
  end
@@ -86,13 +86,13 @@ module Scale
86
86
  class MetadataV6ModuleStorage < MetadataV5ModuleStorage; end
87
87
 
88
88
  class MetadataV6ModuleConstants
89
- include SingleValue
89
+ include Base
90
90
  def self.decode(scale_bytes)
91
91
  result = {
92
92
  name: String.decode(scale_bytes).value,
93
93
  type: String.decode(scale_bytes).value, # convert
94
94
  value: Hex.decode(scale_bytes).value,
95
- documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
95
+ documentation: Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
96
96
  }
97
97
  MetadataV6ModuleConstants.new result
98
98
  end
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV7
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataV7Module>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataV7Module>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -49,7 +49,7 @@ module Scale
49
49
  end
50
50
 
51
51
  class MetadataV7Module
52
- include SingleValue
52
+ include Base
53
53
  def self.decode(scale_bytes)
54
54
  name = String.decode(scale_bytes).value
55
55
 
@@ -66,27 +66,27 @@ module Scale
66
66
 
67
67
  has_calls = Bool.decode(scale_bytes).value
68
68
  if has_calls
69
- calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
69
+ calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
70
70
  result[:calls] = calls.map(&:value)
71
71
  end
72
72
 
73
73
  has_events = Bool.decode(scale_bytes).value
74
74
  if has_events
75
- events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
75
+ events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
76
76
  result[:events] = events.map(&:value)
77
77
  end
78
78
 
79
- result[:constants] = Scale::Types.type_of("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
79
+ result[:constants] = Scale::Types.get("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
80
80
 
81
81
  MetadataV7Module.new(result)
82
82
  end
83
83
  end
84
84
 
85
85
  class MetadataV7ModuleStorage
86
- include SingleValue
86
+ include Base
87
87
  def self.decode(scale_bytes)
88
88
  prefix = String.decode(scale_bytes).value
89
- items = Scale::Types.type_of("Vec<MetadataV7ModuleStorageEntry>").decode(scale_bytes).value.map(&:value)
89
+ items = Scale::Types.get("Vec<MetadataV7ModuleStorageEntry>").decode(scale_bytes).value.map(&:value)
90
90
  result = {
91
91
  prefix: prefix,
92
92
  items: items
@@ -97,13 +97,24 @@ module Scale
97
97
  end
98
98
 
99
99
  class MetadataV7ModuleStorageEntry
100
- include SingleValue
100
+ include Base
101
101
  def self.decode(scale_bytes)
102
+ name = String.decode(scale_bytes).value
103
+ modifier_enum = {
104
+ "type" => "enum",
105
+ "value_list" => ["Optional", "Default"]
106
+ }
107
+ modifier = Scale::Types.get(modifier_enum).decode(scale_bytes).value
102
108
  result = {
103
- name: String.decode(scale_bytes).value,
104
- modifier: Scale::Types.type_of("Enum", %w[Optional Default]).decode(scale_bytes).value
109
+ name: name,
110
+ modifier: modifier
111
+ }
112
+
113
+ storage_function_type_enum = {
114
+ "type" => "enum",
115
+ "value_list" => %w[Plain Map DoubleMap]
105
116
  }
106
- storage_function_type = Scale::Types.type_of("Enum", %w[Plain Map DoubleMap]).decode(scale_bytes).value
117
+ storage_function_type = Scale::Types.get(storage_function_type_enum).decode(scale_bytes).value
107
118
  if storage_function_type == "Plain"
108
119
  result[:type] = {
109
120
  Plain: String.decode(scale_bytes).value
@@ -130,20 +141,20 @@ module Scale
130
141
  end
131
142
 
132
143
  result[:fallback] = Hex.decode(scale_bytes).value
133
- result[:documentation] = Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
144
+ result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
134
145
 
135
146
  MetadataV7ModuleStorageEntry.new(result)
136
147
  end
137
148
  end
138
149
 
139
150
  class MetadataV7ModuleConstants
140
- include SingleValue
151
+ include Base
141
152
  def self.decode(scale_bytes)
142
153
  result = {
143
154
  name: String.decode(scale_bytes).value,
144
155
  type: String.decode(scale_bytes).value, # convert
145
156
  value: Hex.decode(scale_bytes).value,
146
- documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
157
+ documentation: Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
147
158
  }
148
159
  MetadataV7ModuleConstants.new result
149
160
  end
@@ -1,7 +1,7 @@
1
1
  module Scale
2
2
  module Types
3
3
  class MetadataV8
4
- include SingleValue
4
+ include Base
5
5
  attr_accessor :call_index, :event_index
6
6
 
7
7
  def initialize(value)
@@ -11,7 +11,7 @@ module Scale
11
11
  end
12
12
 
13
13
  def self.decode(scale_bytes)
14
- modules = Scale::Types.type_of("Vec<MetadataV8Module>").decode(scale_bytes).value
14
+ modules = Scale::Types.get("Vec<MetadataV8Module>").decode(scale_bytes).value
15
15
 
16
16
  value = {
17
17
  magicNumber: 1_635_018_093,
@@ -49,7 +49,7 @@ module Scale
49
49
  end
50
50
 
51
51
  class MetadataV8Module
52
- include SingleValue
52
+ include Base
53
53
  def self.decode(scale_bytes)
54
54
  name = String.decode(scale_bytes).value
55
55
 
@@ -66,29 +66,29 @@ module Scale
66
66
 
67
67
  has_calls = Bool.decode(scale_bytes).value
68
68
  if has_calls
69
- calls = Scale::Types.type_of("Vec<MetadataModuleCall>").decode(scale_bytes).value
69
+ calls = Scale::Types.get("Vec<MetadataModuleCall>").decode(scale_bytes).value
70
70
  result[:calls] = calls.map(&:value)
71
71
  end
72
72
 
73
73
  has_events = Bool.decode(scale_bytes).value
74
74
  if has_events
75
- events = Scale::Types.type_of("Vec<MetadataModuleEvent>").decode(scale_bytes).value
75
+ events = Scale::Types.get("Vec<MetadataModuleEvent>").decode(scale_bytes).value
76
76
  result[:events] = events.map(&:value)
77
77
  end
78
78
 
79
- result[:constants] = Scale::Types.type_of("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
80
- result[:errors] = Scale::Types.type_of("Vec<MetadataModuleError>").decode(scale_bytes).value.map(&:value)
79
+ result[:constants] = Scale::Types.get("Vec<MetadataV7ModuleConstants>").decode(scale_bytes).value.map(&:value)
80
+ result[:errors] = Scale::Types.get("Vec<MetadataModuleError>").decode(scale_bytes).value.map(&:value)
81
81
 
82
82
  MetadataV8Module.new(result)
83
83
  end
84
84
  end
85
85
 
86
86
  class MetadataModuleError
87
- include SingleValue
87
+ include Base
88
88
  def self.decode(scale_bytes)
89
89
  result = {
90
90
  name: String.decode(scale_bytes).value,
91
- documentation: Scale::Types.type_of("Vec<String>").decode(scale_bytes).value.map(&:value)
91
+ documentation: Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)
92
92
  }
93
93
 
94
94
  MetadataModuleError.new(result)