Class: Scale::Types::MetadataV0ModuleStorage

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/metadata/metadata_v0.rb

Instance Attribute Summary

Attributes included from Base

#value

Class Method Summary collapse

Methods included from Base

#==, included, #initialize, #to_human

Class Method Details

.decode(scale_bytes) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/metadata/metadata_v0.rb', line 157

def self.decode(scale_bytes)
  name = Bytes.decode(scale_bytes).value
  enum = {
    "type" => "enum",
    "value_list" => ["Optional", "Default"]
  }
  modifier = Scale::Types.get(enum).decode(scale_bytes).value

  is_key_value = Bool.decode(scale_bytes).value

  if is_key_value
    type = {
      Map: {
        key: Bytes.decode(scale_bytes).value,
        value: Bytes.decode(scale_bytes).value
      }
    }
  else
    type = {
      Plain: Bytes.decode(scale_bytes).value
    }
  end

  fallback = Hex.decode(scale_bytes).value
  documentation = Scale::Types.get("Vec<Bytes>").decode(scale_bytes).value.map(&:value)

  MetadataV0ModuleStorage.new({
    name: name,
    modifier: modifier,
    type: type,
    fallback: fallback,
    documentation: documentation
  })
end